
    Vi<                         S r SSKJr  SSKr SSKJr  SSK	J
r  SSKJr   \  S rS	S
/rSrSrSrSrSS jrSrSS jrg! \ a    \r N5f = f! \ a
    \\4rS r N6f = f)a  The ``namedutils`` module defines two lightweight container types:
:class:`namedtuple` and :class:`namedlist`. Both are subtypes of built-in
sequence types, which are very fast and efficient. They simply add
named attribute accessors for specific indexes within themselves.

The :class:`namedtuple` is identical to the built-in
:class:`collections.namedtuple`, with a couple of enhancements,
including a ``__repr__`` more suitable to inheritance.

The :class:`namedlist` is the mutable counterpart to the
:class:`namedtuple`, and is much faster and lighter-weight than
full-blown :class:`object`. Consider this if you're implementing nodes
in a tree, graph, or other mutable data structure. If you want an even
skinnier approach, you'll probably have to look to C.
    )print_functionN)OrderedDict)	iskeyword)
itemgetterc                     [        S5        g )Nzexec code in global_envexeccode
global_envs     e/home/james-whalen/.local/share/pipx/venvs/semgrep/lib/python3.13/site-packages/boltons/namedutils.pyexec_r   ?   s    &'    c                     [        X5        g Nr   r
   s     r   r   r   C   s
    Tr   	namedlist
namedtuplez	{name}=%rzP    {name} = _property(_itemgetter({index:d}), doc='Alias for field {index:d}')
zh    {name} = _property(_itemgetter({index:d}), _itemsetter({index:d}), doc='Alias for field {index:d}')
a  class {typename}(tuple):
    '{typename}({arg_list})'

    __slots__ = ()

    _fields = {field_names!r}

    def __new__(_cls, {arg_list}):  # TODO: tweak sig to make more extensible
        'Create new instance of {typename}({arg_list})'
        return _tuple.__new__(_cls, ({arg_list}))

    @classmethod
    def _make(cls, iterable, new=_tuple.__new__, len=len):
        'Make a new {typename} object from a sequence or iterable'
        result = new(cls, iterable)
        if len(result) != {num_fields:d}:
            raise TypeError('Expected {num_fields:d}'
                            ' arguments, got %d' % len(result))
        return result

    def __repr__(self):
        'Return a nicely formatted representation string'
        tmpl = self.__class__.__name__ + '({repr_fmt})'
        return tmpl % self

    def _asdict(self):
        'Return a new OrderedDict which maps field names to their values'
        return OrderedDict(zip(self._fields, self))

    def _replace(_self, **kwds):
        'Return a new {typename} object replacing field(s) with new values'
        result = _self._make(map(kwds.pop, {field_names!r}, _self))
        if kwds:
            raise ValueError('Got unexpected field names: %r' % kwds.keys())
        return result

    def __getnewargs__(self):
        'Return self as a plain tuple.  Used by copy and pickle.'
        return tuple(self)

    __dict__ = _property(_asdict)

    def __getstate__(self):
        'Exclude the OrderedDict from pickling'  # wat
        pass

{field_defs}
c                 V   [        U[        5      (       a   UR                  SS5      R                  5       nU Vs/ s H  n[	        U5      PM     nnU(       a  [        5       n[        U5       H~  u  pg[        S U 5       5      (       aJ  [        U5      (       d:  U(       a3  US   R                  5       (       d  UR                  S5      (       d  Xu;   a  SU-  X'   UR                  U5        M     U /U-    Hl  n[        S U 5       5      (       d  [        SU-  5      e[        U5      (       a  [        S	U-  5      eUS   R                  5       (       d  M`  [        S
U-  5      e   [        5       nU HR  nUR                  S5      (       a  U(       d  [        SU-  5      eXu;   a  [        SU-  5      eUR                  U5        MT     SU 0n[        U5      US'   [        U5      US'   [        [        U5      5      R                  SS5      SS US'   SR!                  S U 5       5      US'   SR!                  S [        U5       5       5      US'   ["        R$                  " S!0 UD6n	U(       a  ['        U	5        [)        [*        SU -  [,        [.        [        S9n
 [1        X5        X   n [6        R8                  " S5      nUR:                  R=                  SS 5      Ul        U$ s  snf ! [2         a   n[3        UR4                  S-   U	-   5      eSnAff = f! [@        [        4 a     U$ f = f)"a  Returns a new subclass of tuple with named fields.

>>> Point = namedtuple('Point', ['x', 'y'])
>>> Point.__doc__                   # docstring for the new class
'Point(x, y)'
>>> p = Point(11, y=22)             # instantiate with pos args or keywords
>>> p[0] + p[1]                     # indexable like a plain tuple
33
>>> x, y = p                        # unpack like a regular tuple
>>> x, y
(11, 22)
>>> p.x + p.y                       # fields also accessible by name
33
>>> d = p._asdict()                 # convert to a dictionary
>>> d['x']
11
>>> Point(**d)                      # convert from a dictionary
Point(x=11, y=22)
>>> p._replace(x=100)               # _replace() is like str.replace() but targets named fields
Point(x=100, y=22)
, c              3   X   #    U  H   oR                  5       =(       d    US :H  v   M"     g7f_Nisalnum.0cs     r   	<genexpr>namedtuple.<locals>.<genexpr>         >A		/qCx/   (*r   r   _%dc              3   X   #    U  H   oR                  5       =(       d    US :H  v   M"     g7fr   r   r   s     r   r   r             9Dq99;*!s(*Dr"   WType names and field names can only contain alphanumeric characters and underscores: %r2Type names and field names cannot be a keyword: %r9Type names and field names cannot start with a number: %r/Field names cannot start with an underscore: %r$Encountered duplicate field name: %rtypenamefield_names
num_fields'    arg_list, c              3   H   #    U  H  n[         R                  US 9v   M     g7f)nameN
_repr_tmplformatr   r6   s     r   r   r       %      #</:t $.#4#4$#4#?/:    "repr_fmt
c              3   L   #    U  H  u  p[         R                  XS 9v   M     g7f)indexr6   N)_imm_field_tmplr9   r   rA   r6   s      r   r   r       s(      %P8N &5%;%;%%;%S8N   "$
field_defsznamedtuple_%s)_itemgetter__name__r   	_property_tuple:
NrG   __main__ )!
isinstance
basestringreplacesplitstrset	enumerateall
_iskeywordisdigit
startswithadd
ValueErrortuplelenreprjoin_namedtuple_tmplr9   printdictrF   r   propertyr   SyntaxErrormessage_sys	_getframe	f_globalsget
__module__AttributeError)r+   r,   verboserenamexseenrA   r6   fmt_kwclass_definition	namespaceeresultframes                 r   r   r      s!   2 +z**!))#s399;#./;a3q6;K/u$[1KE>>>>d##7??$$??3''<%*U]"HHTN 2 
[(9D999 K#$ % % d +-12 3 37?? ,.23 4 4 ) 5D??3 "$() * *<CdJKK  (#F!+.F={+F<eK0199#rB1RHF: #</:#< <F:99 %P8A+8N%P PF<'..88 -8!,'!	#I
@*  Fq!!OO//
JG MK 0n  @!))e+.>>??@ J' Ms/   K"K' )7L '
L1LLL('L(a  class {typename}(list):
    '{typename}({arg_list})'

    __slots__ = ()

    _fields = {field_names!r}

    def __new__(_cls, {arg_list}):  # TODO: tweak sig to make more extensible
        'Create new instance of {typename}({arg_list})'
        return _list.__new__(_cls, ({arg_list}))

    def __init__(self, {arg_list}):  # tuple didn't need this but list does
        return _list.__init__(self, ({arg_list}))

    @classmethod
    def _make(cls, iterable, new=_list, len=len):
        'Make a new {typename} object from a sequence or iterable'
        # why did this function exist? why not just star the
        # iterable like below?
        result = cls(*iterable)
        if len(result) != {num_fields:d}:
            raise TypeError('Expected {num_fields:d} arguments,'
                            ' got %d' % len(result))
        return result

    def __repr__(self):
        'Return a nicely formatted representation string'
        tmpl = self.__class__.__name__ + '({repr_fmt})'
        return tmpl % tuple(self)

    def _asdict(self):
        'Return a new OrderedDict which maps field names to their values'
        return OrderedDict(zip(self._fields, self))

    def _replace(_self, **kwds):
        'Return a new {typename} object replacing field(s) with new values'
        result = _self._make(map(kwds.pop, {field_names!r}, _self))
        if kwds:
            raise ValueError('Got unexpected field names: %r' % kwds.keys())
        return result

    def __getnewargs__(self):
        'Return self as a plain list.  Used by copy and pickle.'
        return tuple(self)

    __dict__ = _property(_asdict)

    def __getstate__(self):
        'Exclude the OrderedDict from pickling'  # wat
        pass

{field_defs}
c           	      ^   [        U[        5      (       a   UR                  SS5      R                  5       nU Vs/ s H  n[	        U5      PM     nnU(       a  [        5       n[        U5       H~  u  pg[        S U 5       5      (       aJ  [        U5      (       d:  U(       a3  US   R                  5       (       d  UR                  S5      (       d  Xu;   a  SU-  X'   UR                  U5        M     U /U-    Hl  n[        S U 5       5      (       d  [        SU-  5      e[        U5      (       a  [        S	U-  5      eUS   R                  5       (       d  M`  [        S
U-  5      e   [        5       nU HR  nUR                  S5      (       a  U(       d  [        SU-  5      eXu;   a  [        SU-  5      eUR                  U5        MT     SU 0n[        U5      US'   [        U5      US'   [        [        U5      5      R                  SS5      SS US'   SR!                  S U 5       5      US'   SR!                  S [        U5       5       5      US'   ["        R$                  " S"0 UD6n	U(       a  ['        U	5        S n
[)        [*        U
SU -  [,        [.        [0        S9n [3        X5        X   n [8        R:                  " S5      nUR<                  R?                  S S!5      Ul         U$ s  snf ! [4         a   n[5        UR6                  S-   U	-   5      eSnAff = f! [B        [        4 a     U$ f = f)#a  Returns a new subclass of list with named fields.

>>> Point = namedlist('Point', ['x', 'y'])
>>> Point.__doc__                   # docstring for the new class
'Point(x, y)'
>>> p = Point(11, y=22)             # instantiate with pos args or keywords
>>> p[0] + p[1]                     # indexable like a plain list
33
>>> x, y = p                        # unpack like a regular list
>>> x, y
(11, 22)
>>> p.x + p.y                       # fields also accessible by name
33
>>> d = p._asdict()                 # convert to a dictionary
>>> d['x']
11
>>> Point(**d)                      # convert from a dictionary
Point(x=11, y=22)
>>> p._replace(x=100)               # _replace() is like str.replace() but targets named fields
Point(x=100, y=22)
r   r   c              3   X   #    U  H   oR                  5       =(       d    US :H  v   M"     g7fr   r   r   s     r   r   namedlist.<locals>.<genexpr>H  r!   r"   r   r   r#   c              3   X   #    U  H   oR                  5       =(       d    US :H  v   M"     g7fr   r   r   s     r   r   rv   Q  r%   r"   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   c              3   H   #    U  H  n[         R                  US 9v   M     g7fr5   r7   r:   s     r   r   rv   i  r;   r<   r=   r>   c              3   L   #    U  H  u  p[         R                  XS 9v   M     g7fr@   )_m_field_tmplr9   rC   s      r   r   rv   k  s(      %P8N &3%9%9%9%Q8NrD   rE   c                    ^  U 4S jnU$ )Nc                    > XT'   g r   rL   )objvaluekeys     r   _itemsetter3namedlist.<locals>._itemsetter.<locals>._itemsetters  s
    Hr   rL   )r   r   s   ` r   r   namedlist.<locals>._itemsetterr  s    	r   znamedlist_%s)rF   r   rG   r   rH   _listrJ   NrG   rK   rL   )"rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   _namedlist_tmplr9   r_   r`   rF   r   ra   listr   rb   rc   rd   re   rf   rg   rh   ri   )r+   r,   rj   rk   rl   rm   rA   r6   rn   ro   r   rp   rq   rr   rs   s                  r   r   r   )  s)   2 +z**!))#s399;#./;a3q6;K/u$[1KE>>>>d##7??$$??3''<%*U]"HHTN 2 
[(9D999 K#$ % % d +-12 3 37?? ,.23 4 4 ) 5D??3 "$() * *<CdJKK  (#F!+.F={+F<eK0199#rB1RHF: #</:#< <F:99 %P8A+8N%P PF<&--77 !,,x7!,'!I@*  Fq!!OO//
JG MY 0z  @!))e+.>>??@ J' Ms/   K&K+ -7L +
L5LLL,+L,)FF)__doc__
__future__r   sysrd   collectionsr   ImportErrorr`   keywordr   rU   operatorr   rF   rN   r   	NameErrorrQ   bytes__all__r8   rB   rz   r^   r   r   r   rL   r   r   <module>r      s   B" & ' , .( 
% 
0 d`N5pge  K  uJs    ? A A
	A
AA