
    NgS                          d Z dZg dZddlZej        dd         Zd ej        D             e_        ddlZee_        d Zd ZddZ	d	 Z
d
 Zd Zd Zd Zed             ZdS )a  
Decorator module by Michele Simionato <michelesimionato@libero.it>
Copyright Michele Simionato, distributed under the terms of the BSD License (see below).
http://www.phyast.pitt.edu/~micheles/python/documentation.html

Included in NLTK for its support of a nice memoization decorator.
zrestructuredtext en)	decoratornew_wrappergetinfo    Nc                 8    g | ]}|d t          |          v|S )nltk)str).0ps     K/var/www/html/ai-engine/env/lib/python3.11/site-packages/nltk/decorators.py
<listcomp>r      s-    >>>!1>s1vv)=)=A)=)=)=    c                 p   t          |           dd                             d          }t          |          D ]h\  }}|                    d          dk    r3|d|                    d                                                   ||<   Q|                                ||<   id                    |          S )z
    For retrocompatibility reasons, we don't use a standard Signature.
    Instead, we use the string generated by this method.
    Basically, from a Signature we create a string and remove the default values.
       ,=r   z, )r   split	enumeratecountindexstripjoin)	signaturelistsignaturecounterparams       r   __legacysignaturer      s     	NN1R4(..s33M#M22 3 3;;sa%*1u{{3/?/?+?%@%F%F%H%HM'""%*[[]]M'""99]###r   c                    t          j        |           st          j        |           sJ t          j        |           }|dd         \  }}}t	          |          }|r|                    |           |r|                    |           t          j        |           }t          |          }t          | d          r| j	        }| j
        }	n| j        }| j        }	t          | j        |||| j        | j        | j        | j        |	|
  
        S )a  
    Returns an info dictionary containing:
    - name (the name of the function : str)
    - argnames (the names of the arguments : list)
    - defaults (the values of the default arguments : tuple)
    - signature (the signature : str)
    - fullsignature (the full signature : Signature)
    - doc (the docstring : str)
    - module (the module name : str)
    - dict (the function __dict__ : str)

    >>> def f(self, x=1, y=2, *args, **kw): pass

    >>> info = getinfo(f)

    >>> info["name"]
    'f'
    >>> info["argnames"]
    ['self', 'x', 'y', 'args', 'kw']

    >>> info["defaults"]
    (1, 2)

    >>> info["signature"]
    'self, x, y, *args, **kw'

    >>> info["fullsignature"]
    <Signature (self, x=1, y=2, *args, **kw)>
    N   __closure__)
nameargnamesr   fullsignaturedefaultsdocmoduledictglobalsclosure)inspectismethod
isfunctiongetfullargspeclistappendr   r   hasattrr    __globals__func_closurefunc_globalsr'   __name____defaults____doc__
__module____dict__)
funcargspecregargsvarargs	varkwargsr"   r#   r   _closure_globalss
             r   r   r   ,   s!   < D!!=W%7%=%====$T**G")"1"+GWiG}}H !    #	"""%d++M!-00I t]## %##$$]#"L]   r   c                     |pt          |          }|d         | _        |d         | _        |d         | _        | j                            |d                    |d         | _        || _        | S )z akin to functools.update_wrapperr!   r%   r&   r'   r$   )r   r4   r6   r7   r8   updater5   undecorated)wrappermodelinfodicts      r   update_wrapperrF   l   sm    )75>>H'GuoGO!(+GHV,---#J/GGNr   c                     t          |t                    r|}nt          |          }d|d         vs
J d            d|z  }t          |t          |                     }t	          |||          S )aA  
    An improvement over functools.update_wrapper. The wrapper is a generic
    callable object. It works by generating a copy of the wrapper with the
    right signature and by updating the copy, not the original.
    Moreovoer, 'model' can be a dictionary with keys 'name', 'doc', 'module',
    'dict', 'defaults'.
    	_wrapper_r"   z("_wrapper_" is a reserved argument name!z.lambda %(signature)s: _wrapper_(%(signature)s))rH   )
isinstancer'   r   evalrF   )rC   rD   rE   srcfuncopys        r   r   r   x   s     % "5>>8J////1 0//
:X
EC3w///00G'5(333r   c                 .     t           fd          S )Nc                  &     j         g| R i |S N)call)akr9   selfs     r   <lambda>z__call__.<locals>.<lambda>   s#    yty'?'?'?'?Q'?'? r   )r   )rS   r9   s   ``r   __call__rU      s!    ?????FFFr   c                     t          t          |                     }d|v rt          d          d|vrt          d          t          | _        | S )z
    Take a class with a ``.caller`` method and return a callable decorator
    object. It works by adding a suitable __call__ method to the class;
    it raises a TypeError if the class already has a nontrivial __call__
    method.
    rU   z=You cannot decorate a class with a nontrivial __call__ methodrP   z2You cannot decorate a class without a .call method)setdir	TypeErrorrU   )clsattrss     r   decorator_factoryr\      s]     CMMEUN
 
 	
 UOPPPCLJr   c                 t     t          j                   rt                     S  fd}t          |           S )a  
    General purpose decorator factory: takes a caller function as
    input and returns a decorator with the same attributes.
    A caller function is any function like this::

     def caller(func, *args, **kw):
         # do something
         return func(*args, **kw)

    Here is an example of usage:

    >>> @decorator
    ... def chatty(f, *args, **kw):
    ...     print("Calling %r" % f.__name__)
    ...     return f(*args, **kw)

    >>> chatty.__name__
    'chatty'

    >>> @chatty
    ... def f(): pass
    ...
    >>> f()
    Calling 'f'

    decorator can also take in input a class with a .caller method; in this
    case it converts the class into a factory of callable decorator objects.
    See the documentation for an example.
    c                     t          |           }|d         }d|v sd|v r
J d            d|z  }t          |t          |                     }t          || |          S )Nr"   _call__func_z2You cannot use _call_ or _func_ as argument names!z3lambda %(signature)s: _call_(_func_, %(signature)s))r`   r_   )r   rJ   r'   rF   )r9   rE   r"   rK   dec_funccallers        r   
_decoratorzdecorator.<locals>._decorator   sv    4==J'  H$8$8$8? %9$8$8ChNTf===>>hh777r   )r*   isclassr\   rF   )rb   rc   s   ` r   r   r      sP    < v ) (((	8 	8 	8 	8 	8 *f---r   c                 ~    	 t          | |          S # t          $ r   |            }t          | ||           |cY S w xY w)z'Similar to .setdefault in dictionaries.)getattrAttributeErrorsetattr)objr!   default_thunkdefaults       r   getattr_rl      sX    sD!!!   -//T7###s    '<<c                 ^    t          | dt                    }||v r||         S  | | }|||<   |S )Nmemoize_dic)rl   r'   )r9   argsdicresults       r   memoizerr      s?    
4
-
-Cs{{4yT4[FCIMr   rO   )r6   __docformat____all__syspathOLD_SYS_PATHr*   r   r   rF   r   rU   r\   r   rl   rr    r   r   <module>ry      s    & 2
1
1 



 x{>>sx>>> $ $ $= = =@	 	 	 	4 4 4*G G G  $,. ,. ,.^       r   