
    ij!                         d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ dd	lmZ d
 Zd Zd Zd Z	 	 	 	 ddZ	 ddZ	 ddZy)z;Communicating tracebacks and source code with debug server.    N)debug_service_pb2)	debug_pb2)common)debug_service_pb2_grpc)source_utils)gfile)tfprof_loggerc                    t        j                  |       }t        j                         |_        | |_        |j                  |_        |j                  |_	        	 t        j                  | d      5 }|j                  j                  |j                         j                                d d d        y # 1 sw Y   y xY w# t        $ r Y y w xY w)Nr)r   Statsocketgethostnamehost	file_path
mtime_nseclast_modifiedlengthbytesOpenlinesextendread
splitlinesIOError)r   source_file_proto	file_statfs       ~/var/www/html/emotional.easysim.app/public_html/venv/lib/python3.12/site-packages/tensorflow/python/debug/lib/source_remote.py_load_debugged_source_filer      s    jj#)!--/ )$-$8$8!%,,		Is	# <q$$QVVX%8%8%:;< < <	 		s0   B< /8B0'B< 0B95B< 9B< <	CCc                 0    | |vrt        |      || <   ||    S N)len)stringstring_to_ids     r   _string_to_idr%   +   s$    <|,L	f	    c           
         i }d|d<   | D ]P  }|\  }}}}|j                   j                  j                  t        ||      |t        ||      t        ||             R |j                  }|j                         D ]  \  }	}
|	|	nd||
<    y)zFormat a traceback stack for a `CallTraceback` proto.

  Args:
    origin_stack: The stack list as returned by `traceback.extract_stack()`.
    call_traceback_proto: A `CallTraceback` proto whose fields are to be
      populated.
  r   N)file_idlinenofunction_idline_id )origin_stacktracesaddr%   origin_id_to_stringitems)r-   call_traceback_protor$   framer   r)   	func_name	line_textid_to_stringkeyvalues              r   _format_origin_stackr9   1   s     ,,t 8e.3+Ivy)%%,,00i6!)\:i6	 1 88 &99, &&( 9jc5!$#bL9r&   c                     t               }| D ].  }|j                  D ]  }|j                  |j                          0 fd|D        }d |D        }|S )a4  Extract source file paths outside TensorFlow Python library.

  Args:
    code_defs: An iterable of `CodeDef` protos, i.e., an iterable of stack
      traces.
    id_to_string: A proto map from integer ids to strings.

  Returns:
    An iterable of source file paths outside the TensorFlow Python library.
  c              3   (   K   | ]	  }|     y wr!    ).0r(   r6   s     r   	<genexpr>zC_source_file_paths_outside_tensorflow_py_library.<locals>.<genexpr>W   s     @G,w'@s   c              3   t   K   | ]0  }t        j                  |      st        j                  |      r| 2 y wr!   )r   guess_is_tensorflow_py_libraryr   Exists)r=   r   s     r   r>   zC_source_file_paths_outside_tensorflow_py_library.<locals>.<genexpr>X   s2      Q88;Q Qs   68)setr.   r/   r(   )	code_defsr6   file_idscode_deftracenon_tf_filess    `    r   0_source_file_paths_outside_tensorflow_py_libraryrH   H   sd     U( "h "ll5==!"" Ax@,QQ, 
r&   c                 F   t        | t              s| g} | D cg c]?  }|j                  t        j                        r|t        t        j                        d n|A } }|rt        j                  j                  nt        j                  j                  }|rt        j                  |d      nd}t        j                  ||||r|j                  nd      }	t        ||	       |rt               }
|
j                  t!        d |	j"                  j$                  D        |	j"                  j&                               |
j                  t!        |	j(                  g|	j*                               g }|
D ]K  }t-        j.                         }t1        ||j2                  j5                                |j7                  |       M | D ]^  }ddg}t9        j:                  ||      }t=        j>                  |      }|jA                  |	       |sGD ]  }|jC                  |        ` yc c}w )	ar  Send the tracebacks of a TensorFlow execution call.

  To gRPC debug server(s). This applies to graph execution (`tf.Session.run()`)
  calls and eager execution calls.

  If `send_source`, also sends the underlying source files outside the
  TensorFlow library.

  Args:
    destinations: gRPC destination addresses, a `str` or a `list` of `str`s,
      e.g., "localhost:4242". If a `list`, gRPC requests containing the same
      `CallTraceback` proto payload will be sent to all the destinations.
    origin_stack: The traceback stack for the origin of the execution call. For
      graph execution, this is the traceback of the `tf.Session.run()`
      invocation. For eager execution, this is the traceback of the Python
      line that executes the eager operation.
    is_eager_execution: (`bool`) whether an eager execution call (i.e., not a
      `tf.Session.run` or derived methods) is being sent.
    call_key: The key of the execution call, as a string. For graph execution,
      this is a string describing the feeds, fetches (and targets) names of the
      `tf.Session.run` call. For eager execution, this is ignored.
    graph: A Python `tf.Graph` object (i.e., *not* a `tf.compat.v1.GraphDef`),
      which contains op tracebacks, if applicable.
    send_source: Whether the source files involved in the op tracebacks but
      outside the TensorFlow library are to be sent.
  NF)add_trainable_var)	call_typecall_keygraph_tracebackgraph_versionc              3   4   K   | ]  }|j                     y wr!   )rE   )r=   	log_entrys     r   r>   z(_send_call_tracebacks.<locals>.<genexpr>   s      	8			 	8s   )zgrpc.max_receive_message_length)zgrpc.max_send_message_lengthrQ   )options)"
isinstancelist
startswithr   GRPC_URL_PREFIXr"   r   CallTracebackEAGER_EXECUTIONGRAPH_EXECUTIONr	   merge_default_with_oplogversionr9   rB   updaterH   rM   log_entriesr6   r-   r0   r   DebuggedSourceFilesr   source_filesr/   appendgrpcinsecure_channelr   EventListenerStubSendTracebacksSendSourceFiles)destinationsr-   is_eager_executionrL   graphsend_sourcedestrK   rM   call_tracebacksource_file_pathsdebugged_source_filesr   r_   destinationno_max_message_sizeschannelstubs                     r   _send_call_tracebacksrr   ^   s   @ 
L$	' >L
    
//	0 3v%%&'(6:; ,   % !..>>%33CC  */ "::u&48 $22Ho%*EMM6. |^4M	8**66	8&&335 6 M		$	$%~'I'IK L & 1	224l 
\..2246""<0	1 " +kC@B##K9MNG!33G<D'/ +,\*++A s   AHc                 &    t        | |d|||       y)a  Send the tracebacks of a graph execution call to debug server(s).

  Args:
    destinations: gRPC destination addresses, a `str` or a `list` of `str`s,
      e.g., "localhost:4242". If a `list`, gRPC requests containing the same
      `CallTraceback` proto payload will be sent to all the destinations.
    run_key: A string describing the feeds, fetches (and targets) names of the
      `tf.Session.run` call.
    origin_stack: The traceback of the `tf.Session.run()` invocation.
    graph: A Python `tf.Graph` object (i.e., *not* a `tf.compat.v1.GraphDef`),
      which contains op tracebacks.
    send_source: Whether the source files involved in the op tracebacks but
      outside the TensorFlow library are to be sent.
  F)rg   rL   rh   ri   Nrr   )rf   run_keyr-   rh   ri   s        r   send_graph_tracebacksrv      s    & LUW{,r&   c                 "    t        | |d|       y)a  Send the tracebacks of an eager execution call to debug server(s).

  Args:
    destinations: gRPC destination addresses, a `str` or a `list` of `str`s,
      e.g., "localhost:4242". If a `list`, gRPC requests containing the same
    origin_stack: The traceback of the eager operation invocation.
    send_source: Whether the source files involved in the op tracebacks but
      outside the TensorFlow library are to be sent.
  T)rg   ri   Nrt   )rf   r-   ri   s      r   send_eager_tracebacksrx      s     LTr&   )FNNT)T)__doc__r   ra   tensorflow.core.debugr   tensorflow.core.protobufr   tensorflow.python.debug.libr   r   r   tensorflow.python.platformr   tensorflow.python.profilerr	   r   r%   r9   rH   rr   rv   rx   r<   r&   r   <module>r      sc    B   3 . . > 4 , 4
	9.0 .3#' $&*K+d '+	,4 '+r&   