
    |h-                     ~    d Z ddlZddlZddlZddlZddlmZ  G d d      Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zy)z-Inspection utility functions for Python Fire.    N)
docstringsc                       e Zd ZdZ	 	 ddZy)FullArgSpeczBThe arguments of a function, as in Python 3's inspect.FullArgSpec.Nc                     |xs g | _         || _        || _        |xs d| _        |xs g | _        |xs i | _        |xs i | _        y)ai  Constructs a FullArgSpec with each provided attribute, or the default.

    Args:
      args: A list of the argument names accepted by the function.
      varargs: The name of the *varargs argument or None if there isn't one.
      varkw: The name of the **kwargs argument or None if there isn't one.
      defaults: A tuple of the defaults for the arguments that accept defaults.
      kwonlyargs: A list of argument names that must be passed with a keyword.
      kwonlydefaults: A dictionary of keyword only arguments and their defaults.
      annotations: A dictionary of arguments and their annotated types.
     N)argsvarargsvarkwdefaults
kwonlyargskwonlydefaultsannotations)selfr   r	   r
   r   r   r   r   s           P/var/www/html/test/engine/venv/lib/python3.12/site-packages/fire/inspectutils.py__init__zFullArgSpec.__init__   sN     
DIDLDJNDM &BDO(.BD"(bD    )NNNNNNN)__name__
__module____qualname____doc__r   r   r   r   r   r      s    JCGAE)r   r   c                 >   d}t        j                  |       rd}| |fS t        j                  |       r| j                  du}| |fS t        j                  |       r*t        | j                  t        j                        sd}| |fS t        j                  |       sd}| |fS )a  Gives information pertaining to computing the ArgSpec of fn.

  Determines if the first arg is supplied automatically when fn is called.
  This arg will be supplied automatically if fn is a bound method or a class
  with an __init__ method.

  Also returns the function who's ArgSpec should be used for determining the
  calling parameters for fn. This may be different from fn itself if fn is a
  class with an __init__ method.

  Args:
    fn: The function or class of interest.
  Returns:
    A tuple with the following two items:
      fn: The function to use for determining the arg spec of this function.
      skip_arg: Whether the first argument will be supplied automatically, and
        hence should be skipped when supplying args from a Fire command.
  FTN)	inspectisclassismethod__self__	isbuiltin
isinstancetypes
ModuleType
isfunction)fnskip_args     r   _GetArgSpecInfor#   2   s    & (__RH 
X {{$&H 
X  bkk5#3#34h 
X b!H	Xr   c           	         	 t        j                  | ddt         j                        }g }d}d}g }d}i }d}i }|j
                  |j                  ur|j
                  |d<   |j                  j                         D ](  }	|	j                  }
|	j                  }|
t         j                  u r|j                  |       n|
t         j                  u r:|j                  |       |	j                  |	j                  ur||	j                  fz  }nt|
t         j                  u r|}n_|
t         j                   u r9|j                  |       |	j                  |	j                  ur$|	j                  ||<   n|
t         j"                  u r|}|	j$                  |	j                  us|	j$                  ||<   + |sd}|sd}t        j&                  |||||||      S # t        $ r t	        d      w xY w)a  A alternative to the builtin getfullargspec.

  The builtin inspect.getfullargspec uses:
  `skip_bound_args=False, follow_wrapped_chains=False`
  in order to be backwards compatible.

  This function instead skips bound args (self) and follows wrapped chains.

  Args:
    fn: The function or class of interest.
  Returns:
    An inspect.FullArgSpec namedtuple with the full arg spec of the function.
  T)skip_bound_argfollow_wrapper_chainssigclszUnsupported callable.Nr   return)r   _signature_from_callable	Signature	Exception	TypeErrorreturn_annotationempty
parametersvalueskindname_POSITIONAL_ONLYappend_POSITIONAL_OR_KEYWORDdefault_VAR_POSITIONAL_KEYWORD_ONLY_VAR_KEYWORD
annotationr   )r!   sigr   r	   r
   r   r   r   
kwdefaultsparamr1   r2   s               r   Py3GetFullArgSpecr>   X   s    	-

*
*
"  	"C 
$'
%*(+(*#))+11K~~$$& +e::D::D w'''
kk$	'00	0
kk$	ekk	)U]]$$	'))	)g	'''	'	ekk	) ==
4	'&&	&eu{{***k$)+. 
J	H			T7E8'[
B B_ 
 - +
,,-s   'G	 	Gc           	         | }t        |       \  } }	 t        j                  dd dk\  rt        |       \  }}}}}}}	nt	        j
                  |       \  }}}}}}}	t        j                  dd d
k(  }|r|r|r|j                  d       t        |||||||	      S # t        $ rW t	        j                  |       rt        dd      cY S t        |dd      }
|
t        t        |
      	      cY S t               cY S w xY w)z4Returns a FullArgSpec describing the given callable.r      )      varskwargs)r	   r
   _fieldsN)r   )rA      )r#   sysversion_infor>   r   getfullargspecr,   r   r   getattrlistpop)r!   original_fnr"   r   r	   r
   r   r   r   r   fieldsskip_arg_requireds               r   GetFullArgSpecrP      s   + $,"h!
!&2CB2G0tWeX>; 3:2H2H2L0tWeX>;< &&q+v58HHQK	T7E8
> >? 
   x88 [)T2Fd6l++ =3s   AB +C7$C7*
C76C7c                     t        j                  |       ry	 t        j                  |       }	 t        j                  |       \  }}|dz   }||fS # t        $ r Y yw xY w# t
        t        f$ r d}Y ||fS w xY w)a#  Returns the filename and line number of component.

  Args:
    component: A component to find the source information for, usually a class
        or routine.
  Returns:
    filename: The name of the file where component is defined.
    lineno: The line number where component is defined.
  )NN   N)r   r   getsourcefiler,   
findsourceOSError
IndexError)	componentfilenameunused_code	lineindexlinenos        r   GetFileAndLiner\      s     y!$$Y/H$//	:K]F 
6	 
  :	 F	6	s"   A A 	AAA54A5c                 X   	 ddl m} |j                         }|j                  |       }|d   dk(  rd|d<   	 t        j                  |       \  }}|dz   |d<   d|v rt        j                  |d         |d<   |S # t        $ r t        |       }Y Xw xY w# t        t        f$ r d|d<   Y Qw xY w)	a  Returns a dict with information about the given component.

  The dict will have at least some of the following fields.
    type_name: The type of `component`.
    string_form: A string representation of `component`.
    file: The file in which `component` is defined.
    line: The line number at which `component` is defined.
    docstring: The docstring of `component`.
    init_docstring: The init docstring of `component`.
    class_docstring: The class docstring of `component`.
    call_docstring: The call docstring of `component`.
    length: The length of `component`.

  Args:
    component: The component to analyze.
  Returns:
    A dict with information about the component.
  r   )oinspect	docstringz<no docstring>NrR   linedocstring_info)IPython.corer^   	InspectorinfoImportError_InfoBackupr   rT   r,   rU   r   parse)rW   r^   	inspectorrd   rY   rZ   s         r   Infori      s    &	"%""$I>>)$D K,,d;$//	:Kq=DL D'--d;.?@D		+ 
 "y!D" W	 DLs"   4A8  B 8BBB)(B)c                    i }t        |       j                  |d<   t        |       |d<   t        |       \  }}||d<   ||d<   t	        j
                  |       |d<   	 t        t        |             |d<   |S # t        t        f$ r Y |S w xY w)a  Returns a dict with information about the given component.

  This function is to be called only in the case that IPython's
  oinspect module is not available. The info dict it produces may
  contain less information that contained in the info dict produced
  by oinspect.

  Args:
    component: The component to analyze.
  Returns:
    A dict with information about the component.
  	type_namestring_formfiler`   r_   length)	typer   strr\   r   getdoclenr,   AttributeError)rW   rd   rX   r[   s       r   rf   rf     s     
$9o..${I$}#I.(F$v,$v,nnY/${	Y(DN 
+ ^	$ 		+	s   A3 3BBc                 T    t        | t              syt        t        | dd            }|S )a$  Return true if the component is a namedtuple.

  Unfortunately, Python offers no native way to check for a namedtuple type.
  Instead, we need to use a simple hack which should suffice for our case.
  namedtuples are internally implemented as tuples, therefore we need to:
    1. Check if the component is an instance of tuple.
    2. Check if the component has a _fields attribute which regular tuples do
       not have.

  Args:
    component: The component to analyze.
  Returns:
    True if the component is a namedtuple or False otherwise.
  FrE   N)r   tupleboolrJ   )rW   
has_fieldss     r   IsNamedTuplerx   7  s*     
Iu	%GIy$78*	r   c                     t        j                  |       syt        j                  |       }|D ci c]  }|j                  | c}S c c}w )zEGets the attributes of the component class, as a dict with name keys.N)r   r   classify_class_attrsr2   )rW   class_attrs_list
class_attrs      r   GetClassAttrsDictr}   M  sM    		#11)< )

 ooz!
  
s   Ac                 <    	 t        j                  |       S #  Y yxY w)NF)asyncioiscoroutinefunction)r!   s    r   IsCoroutineFunctionr   X  s"    &&r**s    )r   r   r   rG   r   firer   r   r#   r>   rP   r\   ri   rf   rx   r}   r   r   r   r   <module>r      sV    4   
  ) )2#LFBV->`6'T>,r   