
    fchm:                     d    S r SSKrSSKJr  SSKJr  SSKJ	r
  SS/rSrS	rS
rSrSS jrSrSS jrg)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.
    N)OrderedDict)	iskeyword)
itemgetter	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
 [/        X5        X   n [4        R6                  " S5      nUR8                  R;                  SS 5      Ul        U$ s  snf ! [0         a   n[1        UR2                  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     2lib/python3.13/site-packages/boltons/namedutils.py	<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   r+   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)indexr+   N)_imm_field_tmplr.   r   r6   r+   s      r   r   r      s(      %P8N &5%;%;%%;%S8N   "$
field_defsznamedtuple_%s)_itemgetter__name__r   	_property_tuple:
Nr<   __main__ ) 
isinstancestrreplacesplitset	enumerateall
_iskeywordisdigit
startswithadd
ValueErrortuplelenreprjoin_namedtuple_tmplr.   printdictr;   r   propertyexecSyntaxErrormsg_sys	_getframe	f_globalsget
__module__AttributeError)r    r!   verboserenamexseenr6   r+   fmt_kwclass_definition	namespaceeresultframes                 r   r   r   {   s   2 +s##!))#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  <!%%%-*::;;< 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 -  [*        [,        [.        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 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>9  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   rk   B  r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   c              3   H   #    U  H  n[         R                  US 9v   M     g7fr*   r,   r/   s     r   r   rk   Z  r0   r1   r2   r3   c              3   L   #    U  H  u  p[         R                  XS 9v   M     g7fr5   )_m_field_tmplr.   r8   s      r   r   rk   \  s(      %P8N &3%9%9%9%Q8Nr9   r:   c                    ^  U 4S jnU$ )Nc                    > XT'   g )NrA   )objvaluekeys     r   _itemsetter3namedlist.<locals>._itemsetter.<locals>._itemsetterd  s
    H    rA   )rt   ru   s   ` r   ru   namedlist.<locals>._itemsetterc  s    	rw   znamedlist_%s)r;   ru   r<   r   r=   _listr?   Nr<   r@   rA   )!rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   _namedlist_tmplr.   rS   rT   r;   r   rU   listrV   rW   rX   rY   rZ   r[   r\   r]   r^   )r    r!   r_   r`   ra   rb   r6   r+   rc   rd   ru   re   rf   rg   rh   s                  r   r   r     s%   2 +s##!))#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  <!%%%-*::;;< J' Ms/   K&K+ -7L +
L5LLL,+L,)FF)__doc__sysrY   collectionsr   keywordr   rI   operatorr   r;   __all__r-   r7   ro   rR   r   rz   r   rA   rw   r   <module>r      sW   >$  # + . 
% 
0 d`N5pgrw   