
    Vi                        S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKJ	r	J
r
   \  \	rSr \R$                  r SS	KJr  \" S
S9r SSKJr  \R6                  S:  r\(       d  SSKJr  OSSKJr  SSSS0 0 \S S S S \4S jrS0S jr S r!S1S jr"S2S jr#S r$ " S S\RJ                  5      r& " S S\RJ                  5      r'\'r%S3S jr(S4S  jr)S4S! jr*S5S" jr+S4S# jr,S$ r- " S% S&\5      r. " S' S(\/5      r0 " S) S*\/5      r1S+\24S, jr3 SS-KJ4r4  S/ r5g! \ a    S r\\4rSr Nf = f! \ a    S r Nf = f! \ a    \" 5       r GNf = f! \ a    Sr GNf = f! \ a    S. r4 NVf = f)6zPython's built-in :mod:`functools` module builds several useful
utilities on top of Python's first-class function
support. ``funcutils`` generally stays in the same vein, adding to and
correcting Python's standard metaprogramming facilities.
    )print_functionN)
MethodTypeFunctionTypeTc                     [        X5      $ N)r   )descobjobj_types      d/home/james-whalen/.local/share/pipx/venvs/semgrep/lib/python3.13/site-packages/boltons/funcutils.py<lambda>r   4   s	    j.C    Fc                     gNF )funcs    r   r   r   ?   s    r   )make_sentinel
NO_DEFAULT)var_name)partialmethod)      )formatargspec)formatannotationr   c                     SU -   $ )N*r   names    r   r   r   \   s    sTzr   c                     SU -   $ )Nz**r   r   s    r   r   r   ]   s    TD[r   c                     S[        U 5      -   $ N=)reprvalues    r   r   r   ^   s    cDK&7r   c                     SU -   $ )Nz -> r   )texts    r   r   r   _   s    v}r   c                   ^^^ UUU4S jn/ nU(       a  [        U 5      [        U5      -
  n[        U 5       H=  u  nnU" U5      nU(       a  UW:  a  UU
" UUU-
     5      -   nUR                  U5        M?     Ub  UR                  U" U" U5      5      5        OU(       a  UR                  S5        U(       a=  U H7  nU" U5      nU(       a  UU;   a  UU
" UU   5      -  nUR                  U5        M9     Ub  UR                  U	" U" U5      5      5        SSR                  U5      -   S-   nST;   a  UU" T" TS   5      5      -  nU$ )a  Copy formatargspec from python 3.7 standard library.
Python 3 has deprecated formatargspec and requested that Signature
be used instead, however this requires a full reimplementation
of formatargspec() in terms of creating Parameter objects and such.
Instead of introducing all the object-creation overhead and having
to reinvent from scratch, just copy their compatibility routine.
c                 F   > T" U 5      nU T;   a  UST" TU    5      -   -  nU$ )Nz: r   )argresultannotationsr   	formatargs     r   formatargandannotation5inspect_formatargspec.<locals>.formatargandannotationi   s3    s^Fk!$!1+c2B!CCCMr   r   (, )return)len	enumerateappendjoin)argsvarargsvarkwdefaults
kwonlyargskwonlydefaultsr+   r,   formatvarargsformatvarkwformatvalueformatreturnsr   r-   specsfirstdefaultir)   spec	kwonlyargr*   s         ``    `        r   inspect_formatargspecrF   X   s<   "	
 t9s8}4LoFAs)#.DA-k(1|3C*DEELL	 &
 LL'=g'FGHS!'	-i8!i>&AKy(ABBDT"	 (
 LL%;E%BCDtyy''#-{"m$4[5J$KLLFr   c                    [        U [        5      (       a  [        R                  U    n 0 0 p2[	        U 5       Ht  nU(       a  U" U5      (       a  M   [        X5      n UR                  nX`R                  :w  a  MC  [        U[        5      (       a  XRU'   M^  [        U5      (       d  Mp  XSU'   Mv     X#4$ ! [         a     M  f = f! [         a     M  f = f)zReturns two maps of (*types*, *funcs*) from *mod*, optionally
ignoring based on the :class:`bool` return value of the *ignore*
callable. *mod* can be a string name of a module in
:data:`sys.modules` or the module instance itself.
)
isinstance
basestringsysmodulesdirgetattr	Exception
__module__AttributeError__name__typecallable)modignoretypesfuncs	attr_nameattrattr_mod_names          r   get_module_callablesr[      s     #z""kk#r5X	fY''	3*D	 OOM LL(dD!!#)d^^#)! " <  		  		s$   B2C2
C ?C 
CCc                 b    [         R                  R                  S U R                   5       5      $ )a  Takes a type and returns an iterator over all class variables
throughout the type hierarchy (respecting the MRO).

>>> sorted(set([k for k, v in mro_items(int) if not k.startswith('__') and 'bytes' not in k and not callable(v)]))
['denominator', 'imag', 'numerator', 'real']
c              3   V   #    U  H  nUR                   R                  5       v   M!     g 7fr   )__dict__items).0cts     r   	<genexpr>mro_items.<locals>.<genexpr>   s(      )E3CR *,):):)<)<3Cs   '))	itertoolschainfrom_iterable__mro__)type_objs    r   	mro_itemsri      s2     ??(( )E3;3C3C)E E Er   c                 |    0 n[        U 5       H  n [        X5      X#'   M     U$ ! [         a    U(       a  e  M,  f = f)zReturn a dictionary of attribute names to values for a given
object. Unlike ``obj.__dict__``, this function returns all
attributes on the object, including ones on parent classes.
)rL   rM   rN   )r	   	raise_excretks       r   dir_dictrn      sJ     CX	S_CF  J  	 	s   %;;c                     [        U R                  U R                  U R                  [	        U SS5      [	        U SS5      S9nU(       a%  UR
                  R                  U R
                  5        U$ )a  Returns a shallow copy of the function, including code object,
globals, closure, etc.

>>> func = lambda: func
>>> func() is func
True
>>> func_copy = copy_function(func)
>>> func_copy() is func
True
>>> func_copy is not func
True

Args:
    orig (function): The function to be copied. Must be a
        function, not just any method or callable.
    copy_dict (bool): Also copy any attributes set on the function
        instance. Defaults to ``True``.
__defaults__N__closure__)r   argdefsclosure)r   __code____globals__rQ   rM   r^   update)orig	copy_dictrl   s      r   copy_functionry      s]    & t}}'' MM&t^TB&t]DA	CC
 DMM*Jr   c                     S nS nS n[        U S5      (       d  Xl        [        U S5      (       d  X l        [        U S5      (       d  X0l        U $ )a  Class decorator, similar to :func:`functools.total_ordering`,
except it is used to define `partial orderings`_ (i.e., it is
possible that *x* is neither greater than, equal to, or less than
*y*). It assumes the presence of the ``__le__()`` and ``__ge__()``
method, but nothing else. It will not override any existing
additional comparison methods.

.. _partial orderings: https://en.wikipedia.org/wiki/Partially_ordered_set

>>> @partial_ordering
... class MySet(set):
...     def __le__(self, other):
...         return self.issubset(other)
...     def __ge__(self, other):
...         return self.issuperset(other)
...
>>> a = MySet([1,2,3])
>>> b = MySet([1,2])
>>> c = MySet([1,2,4])
>>> b < a
True
>>> b > a
False
>>> b < c
True
>>> a < c
False
>>> c > a
False
c                 "    X:*  =(       a    X:  + $ r   r   selfothers     r   __lt__ partial_ordering.<locals>.__lt__       DM$G$6GGr   c                 "    X:  =(       a    X::  + $ r   r   r|   s     r   __gt__ partial_ordering.<locals>.__gt__   r   r   c                      X:  =(       a    X:*  $ r   r   r|   s     r   __eq__ partial_ordering.<locals>.__eq__   s    DM$CdmCr   r   r   r   )hasattrr   r   r   )clsr   r   r   s       r   partial_orderingr      sF    > HGC3!!:3!!:3!!:Jr   c                   4    \ rS rSrSr\b  \S 5       rS rSr	g)InstancePartiali	  a  :class:`functools.partial` is a huge convenience for anyone
working with Python's great first-class functions. It allows
developers to curry arguments and incrementally create simpler
callables for a variety of use cases.

Unfortunately there's one big gap in its usefulness:
methods. Partials just don't get bound as methods and
automatically handed a reference to ``self``. The
``InstancePartial`` type remedies this by inheriting from
:class:`functools.partial` and implementing the necessary
descriptor protocol. There are no other differences in
implementation or usage. :class:`CachedInstancePartial`, below,
has the same ability, but is slightly more efficient.

Nc                 \    [        U R                  /U R                  Q70 U R                  D6$ r   r   r   r7   keywordsr}   s    r   _partialmethodInstancePartial._partialmethod  #     HTYYH$--HHr   c                     [        XU5      $ r   )make_method)r}   r	   r
   s      r   __get__InstancePartial.__get__  s    4h//r   r   )
rQ   rO   __qualname____firstlineno____doc__r   propertyr   r   __static_attributes__r   r   r   r   r   	  s(      		I 
	I0r   r   c                   Z    \ rS rSrSr\b  \S 5       r\R                  S:  a  S r
S rSrg)	CachedInstancePartiali#  a  The ``CachedInstancePartial`` is virtually the same as
:class:`InstancePartial`, adding support for method-usage to
:class:`functools.partial`, except that upon first access, it
caches the bound method on the associated object, speeding it up
for future accesses, and bringing the method call overhead to
about the same as non-``partial`` methods.

See the :class:`InstancePartial` docstring for more details.
Nc                 \    [        U R                  /U R                  Q70 U R                  D6$ r   r   r   s    r   r   $CachedInstancePartial._partialmethod.  r   r   )r      c                     X l         g r   )rQ   )r}   r
   r   s      r   __set_name__"CachedInstancePartial.__set_name__3  s     Mr   c                    [        U SS 5      U l        U R                  R                  U l        U R                  R                  U l        U R                  nUc#  [        U5       H  u  pEXPL d  M  U=U l        nM     Uc  [        XU5      $  UR                  U   $ ! [         a     [        XU5      =UR                  U'   nUs $ f = f)NrQ   )	rM   rQ   r   r   rO   ri   r   r^   KeyError)r}   r	   r
   r   rm   vrl   s          r   r   CachedInstancePartial.__get__6  s      j$7yy(())..}} <!(+9+,,DMD , ;t(33	 <<%% 	'24h'GGCLLJ	s   B 'CC)r   rO   rQ   )rQ   rO   r   r   r   r   r   r   rJ   version_infor   r   r   r   r   r   r   r   #  s=      		I 
	I 6!	!r   r   c                 .   UR                  S[        5      nU(       a+  [        SSR                  UR	                  5       5      -  5      eU=(       d    0 nSR                  U Vs/ s H
  oT" U5      PM     sn5      n[        U[        5      (       a  [        U5       Vs/ s H  owX'   4PM
     nnOUnSR                  U VV	s/ s H  u  pyU< SU" U	5      < 3PM     sn	n5      n
UnU(       a  U
(       a  US-  nX-  nU < SU< S3$ s  snf s  snf s  sn	nf )aN  Given a name, positional arguments, and keyword arguments, format
a basic Python-style function call.

>>> print(format_invocation('func', args=(1, 2), kwargs={'c': 3}))
func(1, 2, c=3)
>>> print(format_invocation('a_func', args=(1,)))
a_func(1)
>>> print(format_invocation('kw_func', kwargs=[('a', 1), ('b', 2)]))
kw_func(a=1, b=2)

r"   zunexpected keyword args: %rr0   r!   r/   r1   )popr"   	TypeErrorr6   keysrH   dictsorted)r   r7   kwargskw_repraa_textrm   kwarg_itemsr   kw_textall_args_texts               r   format_invocationr   R  s     FF64 E	5		"'')8LLMM\rFYY$/$Qa$/0F&$/5f~>~!69~~>ii[I[TQAuQx0[IJGMM]++ 0> Js   #DDD
c           	         [        U 5      R                  nU=(       d    / nU=(       d    / n[        5       / pvX#-    H,  nX;   a  M
  UR                  U5        UR	                  U5        M.     Uc  S n[        U5      (       d   eU Vs/ s H  n[        XS5      PM     n	nU Vs/ s H  o[        XS5      4PM     n
nU
 VVs/ s H  u  pX;   a  U" U5      (       a  M  X4PM     n
nn[        XYU
5      $ s  snf s  snf s  snnf )at  Render an expression-style repr of an object, based on attribute
names, which are assumed to line up with arguments to an initializer.

>>> class Flag(object):
...    def __init__(self, length, width, depth=None):
...        self.length = length
...        self.width = width
...        self.depth = depth
...

That's our Flag object, here are some example reprs for it:

>>> flag = Flag(5, 10)
>>> print(format_exp_repr(flag, ['length', 'width'], [], ['depth']))
Flag(5, 10)
>>> flag2 = Flag(5, 15, 2)
>>> print(format_exp_repr(flag2, ['length'], ['width', 'depth']))
Flag(5, width=15, depth=2)

By picking the pos_names, req_names, opt_names, and opt_key, you
can fine-tune how you want the repr to look.

Args:
   obj (object): The object whose type name will be used and
      attributes will be checked
   pos_names (list): Required list of attribute names which will be
      rendered as positional arguments in the output repr.
   req_names (list): List of attribute names which will always
      appear in the keyword arguments in the output repr. Defaults to None.
   opt_names (list): List of attribute names which may appear in
      the keyword arguments in the output repr, provided they pass
      the *opt_key* check. Defaults to None.
   opt_key (callable): A function or callable which checks whether
      an opt_name should be in the repr. Defaults to a
      ``None``-check.

Nc                 
    U S L $ r   r   r   s    r   r   !format_exp_repr.<locals>.<lambda>      AIr   )rR   rQ   setaddr5   rS   rM   r   )r	   	pos_names	req_names	opt_namesopt_keycn
uniq_names	all_namesr   r7   kw_itemsvals               r   format_exp_reprr   q  s    L 
c		BRIRIE2	%t	 & %G1:;GCt$D;=FGYTws$/0YHG-5 =X	)gcl XH = Rx00 <G=s   C3#C8C=C=c           	         U R                   R                  nU=(       d    / nU=(       d    / n[        5       / peX-    H,  nXu;   a  M
  UR                  U5        UR	                  U5        M.     Uc  S n[        U5      (       d   eU Vs/ s H  ow[        XS5      4PM     nnU VV	s/ s H"  u  pyXr;   a  U" U	5      (       a  M  U< SU	< 3PM$     n
nn	U
(       d  S[        U 5      -  /n
SU< SSR                  U
5      < S3nU$ s  snf s  sn	nf )a<  Format a non-expression-style repr

Some object reprs look like object instantiation, e.g., App(r=[], mw=[]).

This makes sense for smaller, lower-level objects whose state
roundtrips. But a lot of objects contain values that don't
roundtrip, like types and functions.

For those objects, there is the non-expression style repr, which
mimic's Python's default style to make a repr like so:

>>> class Flag(object):
...    def __init__(self, length, width, depth=None):
...        self.length = length
...        self.width = width
...        self.depth = depth
...
>>> flag = Flag(5, 10)
>>> print(format_nonexp_repr(flag, ['length', 'width'], ['depth']))
<Flag length=5 width=10>

If no attributes are specified or set, utilizes the id, not unlike Python's
built-in behavior.

>>> print(format_nonexp_repr(flag))
<Flag id=...>
Nc                 
    U S L $ r   r   r   s    r   r   $format_nonexp_repr.<locals>.<lambda>  r   r   r!   zid=%s< >)		__class__rQ   r   r   r5   rS   rM   idr6   )r	   r   r   r   r   r   r   r   r_   r   labelsrl   s               r   format_nonexp_reprr     s   8 
		BRIRIE2	%t	 & %G:CD)$GCt,-)ED5: ;U	'GCL $s#UF ;BsG#$388F+
,CJ E;s   D&D	D	c                 *    [        [        4U SXS.UD6$ )a  Decorator factory to apply update_wrapper() to a wrapper function.

Modeled after built-in :func:`functools.wraps`. Returns a decorator
that invokes update_wrapper() with the decorated function as the wrapper
argument and the arguments to wraps() as the remaining arguments.
Default arguments are as for update_wrapper(). This is a convenience
function to simplify applying partial() to update_wrapper().

Same example as in update_wrapper's doc but with wraps:

    >>> from boltons.funcutils import wraps
    >>>
    >>> def print_return(func):
    ...     @wraps(func)
    ...     def wrapper(*args, **kwargs):
    ...         ret = func(*args, **kwargs)
    ...         print(ret)
    ...         return ret
    ...     return wrapper
    ...
    >>> @print_return
    ... def example():
    ...     '''docstring'''
    ...     return 'example return value'
    >>>
    >>> val = example()
    example return value
    >>> example.__name__
    'example'
    >>> example.__doc__
    'docstring'
N)r   
build_frominjectedexpected)partialupdate_wrapper)r   r   r   r   s       r   wrapsr     s(    B > ?$?;=? ?r   c                    Uc  / nO$[        U[        5      (       a  U/nO[        U5      n[        U5      n[        U[        [
        45      (       a  [        S[        USS5      < 35      eUR                  SS5      nUR                  SS5      nUR                  SS5      n	U(       a  [        S	UR                  5       -  5      e[        U [        R                  5      (       a  XR                  L a  U=(       d    U n[        R                  U=(       d    U5      n
U H  n U
R                  U5        M     U H  u  pU
R%                  X5        M     U
R&                  (       a  S
U
R)                  5       -  U
l        OSU
R)                  5       -  U
l        [-        XS9nU
R/                  XS9nU	(       a   [1        US5      (       a  UR2                  S	 U$ U	(       d  Xl        U$ ! [          a    U(       a  U
R"                  b   M  e f = f)a  Modeled after the built-in :func:`functools.update_wrapper`,
this function is used to make your wrapper function reflect the
wrapped function's:

  * Name
  * Documentation
  * Module
  * Signature

The built-in :func:`functools.update_wrapper` copies the first three, but
does not copy the signature. This version of ``update_wrapper`` can copy
the inner function's signature exactly, allowing seamless usage
and :mod:`introspection <inspect>`. Usage is identical to the
built-in version::

    >>> from boltons.funcutils import update_wrapper
    >>>
    >>> def print_return(func):
    ...     def wrapper(*args, **kwargs):
    ...         ret = func(*args, **kwargs)
    ...         print(ret)
    ...         return ret
    ...     return update_wrapper(wrapper, func)
    ...
    >>> @print_return
    ... def example():
    ...     '''docstring'''
    ...     return 'example return value'
    >>>
    >>> val = example()
    example return value
    >>> example.__name__
    'example'
    >>> example.__doc__
    'docstring'

In addition, the boltons version of update_wrapper supports
modifying the outer signature. By passing a list of
*injected* argument names, those arguments will be removed from
the outer wrapper's signature, allowing your decorator to provide
arguments that aren't passed in.

Args:

    wrapper (function) : The callable to which the attributes of
        *func* are to be copied.
    func (function): The callable whose attributes are to be copied.
    injected (list): An optional list of argument names which
        should not appear in the new wrapper's signature.
    expected (list): An optional list of argument names (or (name,
        default) pairs) representing new arguments introduced by
        the wrapper (the opposite of *injected*). See
        :meth:`FunctionBuilder.add_arg()` for more details.
    build_from (function): The callable from which the new wrapper
        is built. Defaults to *func*, unless *wrapper* is partial object
        built from *func*, in which case it defaults to *wrapper*.
        Useful in some specific cases where *wrapper* and *func* have the
        same arguments but differ on which are keyword-only and positional-only.
    update_dict (bool): Whether to copy other, non-standard
        attributes of *func* over to the wrapper. Defaults to True.
    inject_to_varkw (bool): Ignore missing arguments when a
        ``**kwargs``-type catch-all is present. Defaults to True.
    hide_wrapped (bool): Remove reference to the wrapped function(s)
        in the updated function.

In opposition to the built-in :func:`functools.update_wrapper` bolton's
version returns a copy of the function and does not modifiy anything in place.
For more in-depth wrapping of functions, see the
:class:`FunctionBuilder` type, on which update_wrapper was built.
Nz~wraps does not support wrapping classmethods and staticmethods, change the order of wrapping to wrap the underlying function: __func__update_dictTinject_to_varkwhide_wrappedFunexpected kwargs: %rzreturn await _call(%s)zreturn _call(%s))_call_func)	with_dict__wrapped__)rH   rI   list_parse_wraps_expectedclassmethodstaticmethodr   rM   r   r   	functoolsr   r   FunctionBuilder	from_func
remove_argMissingArgumentr9   add_argis_asyncget_invocation_strbodyr   get_funcr   r^   r   )wrapperr   r   r   r   r   expected_itemsr   r   r   fbr)   defaultexecdictfully_wrappeds                  r   r   r     s   N 	Hj	)	):>*84N$l344 #4T:= > 	>
 &&-Kff.5O66.%0L	/"'');<<'9,,--$,,2F*7
		"	":#5	6B	MM#  '


3  ' 
{{*R-B-B-DD$r'<'<'>>'.HKKK@M}==""=1  $(!+  	288#7	s    G!!HHc                    U c  / n O[        U [        5      (       a	  U [        4/n / n [        U 5      nU HY  n[        U[        5      (       a   X   nO Uu  pE[        U[        5      (       d  [        SU< 35      eUR                  XE45        M[     U$ ! [         a  n[        SU < SU< S35      eS nAff = f! [         a	    [        n Ntf = f! [        [
        4 a    [        S5      ef = f)Nz"expected" takes string name, sequence of string names, iterable of (name, default) pairs, or a mapping of  {name: default}, not z (got: r1   z"expected" takes string name, sequence of string names, iterable of (name, default) pairs, or a mapping of  {name: default}, not %rz-all "expected" argnames must be strings, not )rH   rI   r   iterr   
ValueErrorr5   )r   r   expected_itereargnamer   s         r   r   r     s   
 	Hj	)	)z*+NOX
 !gz**%"+
=#* 
 ':..RY[\\w01% !( 1  OAI1N O 	OO  %$% z* =  "< = ==s5   B B:C
B7B22B7:CCC,c            	          \ rS rSrSr\(       a  \S S S S.r\S 5       r	O\S S	 S
 \\
\
S.r\S 5       r	\\
S S S S \
S S.r\R                  \5        \R                  " 5       rS r\(       a	  S$S jrS rO%S$S jr\R*                  " S\R,                  5      rS r\S 5       rS%S jrS rS&S jr\(       a  \4S jrO\S4S  jrS! rS" rS#r g)'r   i  a
  The FunctionBuilder type provides an interface for programmatically
creating new functions, either based on existing functions or from
scratch.

Values are passed in at construction or set as attributes on the
instance. For creating a new function based of an existing one,
see the :meth:`~FunctionBuilder.from_func` classmethod. At any
point, :meth:`~FunctionBuilder.get_func` can be called to get a
newly compiled function, based on the values configured.

>>> fb = FunctionBuilder('return_five', doc='returns the integer 5',
...                      body='return 5')
>>> f = fb.get_func()
>>> f()
5
>>> fb.varkw = 'kw'
>>> f_kw = fb.get_func()
>>> f_kw(ignored_arg='ignored_val')
5

Note that function signatures themselves changed quite a bit in
Python 3, so several arguments are only applicable to
FunctionBuilder in Python 3. Except for *name*, all arguments to
the constructor are keyword arguments.

Args:
    name (str): Name of the function.
    doc (str): `Docstring`_ for the function, defaults to empty.
    module (str): Name of the module from which this function was
        imported. Defaults to None.
    body (str): String version of the code representing the body
        of the function. Defaults to ``'pass'``, which will result
        in a function which does nothing and returns ``None``.
    args (list): List of argument names, defaults to empty list,
        denoting no arguments.
    varargs (str): Name of the catch-all variable for positional
        arguments. E.g., "args" if the resultant function is to have
        ``*args`` in the signature. Defaults to None.
    varkw (str): Name of the catch-all variable for keyword
        arguments. E.g., "kwargs" if the resultant function is to have
        ``**kwargs`` in the signature. Defaults to None.
    defaults (tuple): A tuple containing default argument values for
        those arguments that have defaults.
    kwonlyargs (list): Argument names which are only valid as
        keyword arguments. **Python 3 only.**
    kwonlydefaults (dict): A mapping, same as normal *defaults*,
        but only for the *kwonlyargs*. **Python 3 only.**
    annotations (dict): Mapping of type hints and so
        forth. **Python 3 only.**
    filename (str): The filename that will appear in
        tracebacks. Defaults to "boltons.funcutils.FunctionBuilder".
    indent (int): Number of spaces with which to indent the
        function *body*. Values less than 1 will result in an error.
    dict (dict): Any other attributes which should be added to the
        functions compiled with this FunctionBuilder.

All of these arguments are also made available as attributes which
can be mutated as necessary.

.. _Docstring: https://en.wikipedia.org/wiki/Docstring#Python

c                      g r   r   r   r   r   r   FunctionBuilder.<lambda>      r   c                      g r   r   r   r   r   r   r        dr   c                      g r   r   r   r   r   r   r        r   r7   r8   r9   r:   c                 B    [         R                  " U5      u  p#pEUUUUS.$ )Nr  )inspect
getargspec)r   fr7   r8   r9   r:   s         r   _argspec_to_dict FunctionBuilder._argspec_to_dict  s-    -4-?-?-B*D5 &" (* *r   c                      g r   r   r   r   r   r   r     r  r   c                      g r   r   r   r   r   r   r    r  r   c                      g r   r   r   r   r   r   r    r  r   )r7   r8   r9   r:   r;   r<   r+   c                 n   ^ [         R                  " U5      m[        U4S jU R                   5       5      $ )Nc              3   @   >#    U  H  nU[        TU5      4v   M     g 7fr   )rM   )r`   rY   argspecs     r   rb   3FunctionBuilder._argspec_to_dict.<locals>.<genexpr>
  s$      ;$9D ww56$9s   )r	  getfullargspecr   _argspec_defaults)r   r  r  s     @r   r  r    s3    ,,Q/G ;$'$9$9; ; ;r   c                      gr   r   r   r   r   r   r    s    Ur   c                      g r   r   r   r   r   r   r    s    4r   c                      g)Npassr   r   r   r   r   r    s    r   c                      g)N   r   r   r   r   r   r    s    1r   c                      g)Nz!boltons.funcutils.FunctionBuilderr   r   r   r   r   r    s    %Hr   )docr   r   moduler   indentr+   filenamec                     Xl         U R                  R                  5        H-  u  p4UR                  US 5      nUc  U" 5       n[	        XU5        M/     U(       a  [        SUR                  5       -  5      eg )Nr   )r   	_defaultsr_   r   setattrr   r   )r}   r   r   r   default_factoryr   s         r   __init__FunctionBuilder.__init__  sf    	"&.."6"6"8A&&D/C{%'DS!	 #9 3bggi?@@r   c                 Z    [        U R                  U R                  U R                  / 5      $ zReturn function signature as a string.

with_annotations is ignored on Python 2.  On Python 3 signature
will omit annotations if it is set to False.
rF   r7   r8   r9   )r}   with_annotationss     r   get_sig_strFunctionBuilder.get_sig_str)  s&     )DLL)-R9 9r   c                 `    [        U R                  U R                  U R                  / 5      SS $ )N   r*  r   s    r   r   "FunctionBuilder.get_invocation_str2  s.    (DLL)-R99:2? ?r   c           	          U(       a  U R                   nO0 n[        U R                  U R                  U R                  / U R
                  0 U5      $ r)  )r+   rF   r7   r8   r9   r;   )r}   r+  r+   s      r   r,  r-  6  sH      ".. ()-)-)+)-)+)46 6r   z
        \*     # a star
        \s*    # followed by any amount of whitespace
        ,      # followed by a comma
        \s*    # followed by any amount of whitespace
        c           	         S n0 nU R                   (       a"  [        S U R                    5       5      nS US'   [        U R                  U R                  U R
                  / UU0 40 UD6nU R                  R                  SU5      nUSS $ )Nc              3   (   #    U  H  nX4v   M
     g 7fr   r   )r`   r)   s     r   rb   5FunctionBuilder.get_invocation_str.<locals>.<genexpr>T  s      $@/> &)J/>s   c                     SU -   $ r    r   r#   s    r   r   4FunctionBuilder.get_invocation_str.<locals>.<lambda>V  s    #+r   r?    r/  r0  )r;   r   rF   r7   r8   r9   _KWONLY_MARKERsub)r}   kwonly_pairs
formatterssigs       r   r   r1  P  s    LJ# $@/3$@  @,E
=)'		(,(,

(*(4(4(*6 +56C %%))"c2Cq9r   c           	      ~   [        U5      (       d  [        SU< 35      e[        U[        R                  5      (       a  [
        (       a  [        S5      eUR                  R                  UR                  R                  [        UR                  SS5      [        UR                  S0 5      [        UR                  S0 5      S.nO=UR                  UR                  [        USS5      [        US0 5      [        US0 5      S.nUR                  U R                  U5      5        [        U5      (       a  SUS	'   U " S
0 UD6$ )z{Create a new FunctionBuilder instance based on an existing
function. The original function will not be stored or
modified.
zexpected callable object, not zACannot build FunctionBuilder instances from partials in python 2.rO   N__annotations__r^   )r   r  r  r+   r   Tr   r   )rS   r   rH   r   r   _IS_PY2r   r   rQ   r   rM   rv   r  _inspect_iscoroutinefunction)r   r   r   s      r   r   FunctionBuilder.from_funcc  s    ~~$HIIdI--..w !dee"ii00!YY.. '		< F%,TYY8I2%N%diiR@	BF #mm!\\ 'lD A%,T3Db%I%dJ;	=F 	c**401'--!%F:}V}r   Nc                     U=(       d    0 nU R                   =(       d    U R                  nSnUS-  nU R                  (       a  SU-   n[        U R                   SU R                  -  5      nU R
                  R                  SS5      R                  SS5      nUR                  X`R                  SS	9U R                  US
9nU R                  Xq5        X   nU R
                  Ul        U R                  Ul        U R                  Ul        [        (       d"  U R                   Ul        U R$                  Ul        U(       a%  UR(                  R+                  U R,                  5        U R.                  Ul        U(       a  Xxl        U$ )a;  Compile and return a new function based on the current values of
the FunctionBuilder.

Args:
    execdict (dict): The dictionary representing the scope in
        which the compilation should take place. Defaults to an empty
        dict.
    add_source (bool): Whether to add the source used to a
        special ``__source__`` attribute on the resulting
        function. Defaults to True.
    with_dict (bool): Add any custom attributes, if
        applicable. Defaults to True.

To see an example of usage, see the implementation of
:func:`~boltons.funcutils.wraps`.
zdef {name}{sig_str}:z
{body}zasync r   r   _r   F)r+  )r   sig_strr  r   )r   _default_bodyr   _indentr   r   replaceformatr,  r  _compilerQ   r   r:   rp   r@  r<   __kwdefaults__r+   r?  r^   rv   r   r  rO   
__source__)	r}   r   
add_sourcer   r   tmplr   srcr   s	            r   r   FunctionBuilder.get_func  s1   " >ryy.D..%
==d?Dtyy#"34yy  c*223<kkt-=-=u-=-U"hhT  3c$~		xx MMw"&"5"5D#'#3#3D MM  +++ !Or   c                     [        [        [        [        [        U R                  5      [        U R
                  =(       d    / 5      5      5      5      5      n[        U SS5      nU(       a  UR                  U5        U$ )zPGet a dictionary of function arguments with defaults and the
respective values.
r<   N)r   reversedr   zipr7   r:   rM   rv   )r}   rl   r<   s      r   get_defaults_dict!FunctionBuilder.get_defaults_dict  sf     8DXdii%8%-dmm.Ar%B"D E F G '7>JJ~&
r   Fc                     [        U R                  5      [        [        U SS5      5      -   nU(       a3  U R                  5       n[        U Vs/ s H  oDU;  d  M
  UPM     sn5      nU$ s  snf )Nr;   r   )tupler7   rM   rT  )r}   only_required	arg_namesdefaults_dictans        r   get_arg_namesFunctionBuilder.get_arg_names  s^    $))$uWT<-L'MM	 224MIQIb=9PrIQRI Rs   	A)A)c                     XR                   ;   a  [        SU< SU R                  < S35      eU R                   R                  U5        U[        La  U R
                  =(       d    SU4-   U l        g)zOAdd an argument with optional *default* (defaults to ``funcutils.NO_DEFAULT``).arg  already in func 	 arg listr   N)r7   ExistingArgumentr   r5   r   r:   )r}   arg_namer   s      r   r   FunctionBuilder.add_arg  sW    99$&xY]YbYb'cddIIX&j(!%!4"
 Br   c                    XR                   ;   a  [        SU< SU R                  < S35      eXR                  ;   a  [        SU< SU R                  < S35      eU(       dC  U R                   R	                  U5        U[
        La  U R                  =(       d    SU4-   U l        gU R                  R	                  U5        U[
        La  X R                  U'   g)zAdd an argument with optional *default* (defaults to
``funcutils.NO_DEFAULT``). Pass *kwonly=True* to add a
keyword-only argument
r_  r`  ra  z kwonly arg listr   N)r7   rb  r   r;   r5   r   r:   r<   )r}   rc  r   kwonlys       r   r   rd    s    
 99$&xY]YbYb'cdd??*&V^`d`i`i'jkk		  **,%)]]%8bWJ$FDM
  &&x0*,4;''1r   c           
         U R                   nU R                  5       n UR                  U5        UR                  US5        [	        U Vs/ s H  oDU;   d  M
  X4   PM     sn5      U l        gs  snf ! [         ax     U R                  R                  U5        U R                  R                  US5         g! [        [        4 a*    [        SU< SU R                  < SU< 35      nXl        Uef = ff = f)a  Remove an argument from this FunctionBuilder's argument list. The
resulting function will have one less argument per call to
this function.

Args:
    arg_name (str): The name of the argument to remove.

Raises a :exc:`ValueError` if the argument is not present.

Nr_  z not found in z argument list: )r7   rT  remover   rW  r:   r   r;   r<   rP   r   r   rc  )r}   rc  r7   d_dictr   excs         r   r   FunctionBuilder.remove_arg  s     yy'')	LKK! JJx&!d"Jd6k969d"JKDM #K  
	8	8&&x0 ##''$7 	 #J/ %/7D'J K'	
	8s/   A1 
	A,A,1
C3<B5C35:C//C3c                     SU R                   [        U R                  5      4-  n [        XS5      n[	        XB5        U$ ! [
         a    e f = f)Nz<%s-%d>single)r!  next_compile_countcompileexecrN   )r}   rO  r   r!  codes        r   rJ  FunctionBuilder._compile  sX    }}d4+>+>&?AB	3(3D    		s	   ? A)r:   r   T)NTTF)!rQ   rO   r   r   r   r@  r   r  r   r  r   strr#  rv   rd   countro  r&  r,  r   rerp  VERBOSEr9  r   r   rT  r\  r   r   r   rJ  r   r   r   r   r   r     s+   =~ %)(4&2)57
 
	* 
	* &*(4&2)5+//3,02 
	; 
	;
 *''$ $HJI &'__&N
 	9	?	6&  %
 ZZ	&  @1f	 ,6 	 -7u 	&>	r   r   c                       \ rS rSrSrg)r   i  r   NrQ   rO   r   r   r   r   r   r   r   r         r   r   c                       \ rS rSrSrg)rb  i  r   Nr{  r   r   r   rb  rb    r|  r   rb  
c                     U R                  5        Vs/ s H  nU" U5      (       a  X-   OUPM     nnUR                  U5      $ s  snf )z based on boltons.strutils.indent)
splitlinesr6   )r&   marginnewlinekeylineindented_liness         r   rG  rG    sN     #'//"35"3$ ),D		v}t;"3  5<<''5s   A)total_orderingc                 x   SS 4SS 4SS 4/SS 4SS	 4SS
 4/SS 4SS 4SS 4/SS 4SS 4SS 4/S.n[        [        U 5      5      [        U5      -  nU(       d  [        S5      e[        U5      nX    H=  u  pEXB;  d  M  XEl        [        [        U5      R                  Ul        [        XU5        M?     U $ )zClass decorator that fills in missing comparators/ordering
methods. Backport of :func:`functools.total_ordering` to work
with Python 2.6.

Code from http://code.activestate.com/recipes/576685/
r   c                 *    X:  =(       d    X:H  (       + $ r   r   r|   s     r   r    total_ordering.<locals>.<lambda>.      $,*G$-%Hr   __le__c                      X:  =(       d    X:H  $ r   r   r|   s     r   r   r  0      T\%BT]%Br   __ge__c                     X:  + $ r   r   r|   s     r   r   r  2      %5r   c                 "    X::  + =(       d    X:H  $ r   r   r|   s     r   r   r  5  s    %6%G$-%Gr   r   c                 "    X:*  =(       a    X:X  + $ r   r   r|   s     r   r   r  7      T]%H47H%Hr   c                     X::  + $ r   r   r|   s     r   r   r  9      %6r   c                 *    X:  =(       d    X:H  (       + $ r   r   r|   s     r   r   r  <  r  r   c                      X:  =(       d    X:H  $ r   r   r|   s     r   r   r  >  r  r   c                     X:  + $ r   r   r|   s     r   r   r  @  r  r   c                 "    X:  + =(       d    X:H  $ r   r   r|   s     r   r   r  C  s    $&7%IDM%Ir   c                 "    X:  =(       a    X:X  + $ r   r   r|   s     r   r   r  E  r  r   c                     X:  + $ r   r   r|   s     r   r   r  G  r  r   )r   r  r   r  z6must define at least one ordering operation: < > <= >=)	r   rL   r   maxrQ   rM   intr   r$  )r   convertrootsrootopnameopfuncs         r   r  r  $  s%    HJBD578 GIHJ689 HJBD578 IKHJ689-
< CHG, * + +5z%mNF""(!(f!5!=!=V,	 ,
 
r   c                      g)au  
Simple function that should be used when no effect is desired.
An alternative to checking for  an optional function type parameter.

e.g.
def decorate(func, pre_func=None, post_func=None):
    if pre_func:
        pre_func()
    func()
    if post_func:
        post_func()

vs

def decorate(func, pre_func=noop, post_func=noop):
    pre_func()
    func()
    post_func()
Nr   )r7   r   s     r   noopr  U  s    ( r   r   ru  rt  )r8  r   N)NNN)NN)6r   
__future__r   rJ   rx  r	  r   rd   rV   r   r   xranger   r@  	NameErrorrv  bytesrI   iscoroutinefunctionrA  rP   boltons.typeutilsr   r   ImportErrorobjectr   r   _IS_PY35r   rF   r   r[   ri   rn   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   rb  boolrG  r  r  r   r   r   <module>r     s  B
 & 
 	    *	
K G6#*#>#> /5J'
 v%
 ?( dT""1074-.b:	E :'T0i'' 04)I-- )X  ,>:1z0r"?Jyx%P^f ^B	j 		z 	 #'D (3(hG!  CKuJG	  6#5 6  J
  Mp  1/1sW   D D* D9 E E D'&D'*	D65D69E
	E
EE	E('E(