
    gS                          d Z dZg dZddlZej                  dd Zej                  D  cg c]  } | sd e|       vs|  c} 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yc c} w )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    Nnltkc                    t        |       dd j                  d      }t        |      D ]R  \  }}|j                  d      dkD  r&|d|j	                  d       j                         ||<   @|j                         ||<   T dj                  |      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, )strsplit	enumeratecountindexstripjoin)	signaturelistsignaturecounterparams       D/var/www/openai/venv/lib/python3.12/site-packages/nltk/decorators.py__legacysignaturer      s     	N1R(..s3M#M2;;sa%*1u{{3/?%@%F%F%HM'"%*[[]M'"	 3
 99]##    c                 @   t        j                  |       st        j                  |       sJ t        j                  |       }|dd \  }}}t	        |      }|r|j                  |       |r|j                  |       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%7%===$$T*G")"1+GWiG}H 	"%%d+M!-0I t]#####$$$$]]#""LL]] r   c                     |xs t        |      }|d   | _        |d   | _        |d   | _        | j                  j                  |d          |d   | _        || _        | S )z akin to functools.update_wrapperr   r!   r"   r#   r    )r   r0   r2   r3   r4   updater1   undecorated)wrappermodelinfodicts      r   update_wrapperrB   l   sh    )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))rD   )
isinstancer#   r   evalrB   )r?   r@   rA   srcfuncopys        r   r   r   x   sc     %5>8J//212/
:X
EC3w/0G'5(33r   c                 &     t         fd      S )Nc                  0     j                   g| i |S N)call)akr5   selfs     r   <lambda>z__call__.<locals>.<lambda>   s    ytyy'?'?Q'?r   )r   )rO   r5   s   ``r   __call__rQ      s    ?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.
    rQ   z=You cannot decorate a class with a nontrivial __call__ methodrL   z2You cannot decorate a class without a .call method)setdir	TypeErrorrQ   )clsattrss     r   decorator_factoryrX      sK     CMEUN
 	
 UOPPCLJr   c                 f     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   rF   r#   rB   )r5   rA   r   rG   dec_funccallers        r   
_decoratorzdecorator.<locals>._decorator   sh    4=J' H$8	@?	@ 
 DhNTf=>hh77r   )r&   isclassrX   rB   )r^   r_   s   ` r   r   r      s0    < v ((	8 *f--r   c                 f    	 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_rh      s;    sD!! /T7#s    00c                 N    t        | dt              }||v r||   S  | | }|||<   |S )Nmemoize_dic)rh   r#   )r5   argsdicresults       r   memoizern      s8    
4
-Cs{4y4[FCIMr   rK   )r2   __docformat____all__syspathOLD_SYS_PATHr   r&   r   r   rB   r   rQ   rX   r   rh   rn   )ps   0r   <module>ru      s    & 2 
 xx{xx>x!1s1v)=Ax> $=@	4*G$,.^  M ?s   A6
A6A6