
    zc                     "   d Z ddlZddlZd Zd Zd Zd Zd Zd Zej	        j
        fd	Zej	        j
        fd
Zej	        j
        fdZej	        j
        fdZedk    r0ddlZej        Z ej        de            ej        e           dS dS )a   Echo calls made to functions and methods in a module.

"Echoing" a function call means printing out the name of the function
and the values of its arguments before making the call (which is more
commonly referred to as "tracing", but Python already has a trace module).

Example: to echo calls made to functions in "my_module" do:

  import echo
  import my_module
  echo.echo_module(my_module)

Example: to echo calls made to functions in "my_module.my_class" do:

  echo.echo_class(my_module.my_class)

Alternatively, echo.echo can be used to decorate functions. Calls to the
decorated function will be echoed.

Example:

  @echo.echo
  def my_function(args):
      pass
    Nc                     | j         S )z Return an item's name. )__name__)items    3lib/python3.11/site-packages/watchdog/utils/echo.pynamer   &   s
    =    c                 <    t          j        |           o| j        |u S )z2 Determine if an instancemethod is a classmethod. )inspectismethod__self__)instancemethodklasss     r   is_classmethodr   +   s     N++P0G50PPr   c                     |                                 D ]G}t          |           |j        v r/t          |j        t          |                    t                    c S HdS )z6Returns True if method is an instance method of klass.F)mror   __dict__
isinstancestaticmethod)methodr   cs      r   is_static_methodr   0   s_    YY[[  <<1:% 	Fajf6EEEEE	F ur   c                 X    |                      d          o|                     d           S )z. Determine if a name is a class private name. __)
startswithendswith)r   s    r   is_class_private_namer   9   s*     ??4  <t)<)<%<<r   c                 ~    t          |           }t          |          rdt          | j        j                  |}|S )z Return a method's name.

    This function returns the name the method is accessed by from
    outside the class (i.e. it prefixes "private" methods appropriately).
    _)r   r   r   	__class__)r   mnames     r   method_namer!   ?   sG     LLEU## C C 9:::EEBLr   c                     | \  }}|d|S )zv Return a string representing a (name, value) pair.

    >>> format_arg_value(('x', (1, 2, 3)))
    'x=(1, 2, 3)'
    = )arg_valargvals      r   format_arg_valuer(   K   s     HCcc33r   c           
      D    ddl } j        }|j        |j        d          j        pt                      }t          t          t          t          |           d         |                              |	                                fd            }|S )z Echo calls to a function.

    Returns a decorated version of the input function which "echoes" calls
    made to it by writing out the function's name and the arguments it was
    called with.
    r   Nc                  &   t          t          t          t          t          	|                                         }fd	t	          |           d          D             }t          t          t
          | d                              }t          t          t          t                                                                        }||z   |z   |z   } t          
          dd                    |          d            
| i S )Nc                 F    g | ]}|vt          ||         f          S r$   )r(   ).0aargdefsks     r   
<listcomp>z)echo.<locals>.wrapped.<locals>.<listcomp>i   sB     ? ? ?1A:?%q'!*o66 ? ? ?r   (z, z)
)	listmapr(   ziplenrepritemsr   join)vr/   
positional	defaultednamelesskeywordargsargcountr.   argnamesfnwrites    `     r   wrappedzecho.<locals>.wrappedd   s    #.S15E5E0F0FGGHH
? ? ? ? ?&s1vvww/? ? ?	D!HII,//00s+T!''))__==>>I%07:DHHHHdiioooo6777r1{{{r   )
	functools__code__co_argcountco_varnames__defaults__r2   dictr4   r5   wraps)	rA   rB   rD   codefn_defaultsrC   r?   r.   r@   s	   ``    @@@r   echorM   U   s     ;DH		*H/+TVVK4Hc+&6&6%6%7%78+FFGGHHG__R
 
 
 
 
 
 
 
 
 Nr   c           
          t          |          }d}||v rdS t          ||           r3t          | |t          t	          |j        |                               dS t          | |t	          ||                     dS )z Change an instancemethod so that calls to it are echoed.

    Replacing a classmethod is a little more tricky.
    See: http://www.python.org/doc/current/ref/types.html
    )__str____repr__N)r!   r   setattrclassmethodrM   __func__)r   r   rB   r    
never_echos        r   echo_instancemethodrU   t   s     E'J
 3		&	& 3uk$v*F*FGGHHHHHud651122222r   c                 r   t          j        | t           j                  D ]\  }}t          | ||           t          j        | t           j                  D ]`\  }}t          ||           r:t          | t          |          t          t          ||                               Ot          | ||           adS )z6 Echo calls to class methods and static functions
    N)
r
   
getmembersr   rU   
isfunctionr   rQ   r   r   rM   )r   rB   r   r   rA   s        r   
echo_classrY      s     'w/?@@ 2 2	6E651111#E7+=>> 2 22B&& 	2E488\$r5//%B%BCCCC  r511112 2r   c           	          t          j        | t           j                  D ]$\  }}t          | |t	          ||                     %t          j        | t           j                  D ]\  }}t          ||           dS )z6 Echo calls to functions and methods in a module.
    N)r
   rW   rX   rQ   rM   isclassrY   )modrB   fnamerA   r   r   s         r   echo_moduler^      s     'W-?@@ - -	rUDUOO,,,,&sGO<< ! !55%    ! !r   __main__zechoexample.txt)optionflags)__doc__r
   sysr   r   r   r   r!   r(   stdoutrB   rM   rU   rY   r^   r   doctestELLIPSISr`   testfiletestmodr$   r   r   <module>rh      sV   2  



  
Q Q Q
  = = =	 	 	      :#    > .1Z-= 3 3 3 3   J, 2 2 2 2 :+ ! ! ! ! z -NNN"KG&K@@@@GO,,,,,,- -r   