
    c<                         d Z ddlmZ ddlZ	 ddlmZ ddl	m
Z ddlmZ 	 e d Zd	d
gZdZdZdZdZddZdZddZy# e$ r eZY 2w xY w# e$ r
 eefZd ZY 2w xY w)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                     t        d       y )Nzexec code in global_envexeccode
global_envs     2lib/python3.12/site-packages/boltons/namedutils.pyexec_r   ?   s    &'    c                     t        | |       y 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                    t        |t              r |j                  dd      j                         }|D cg c]  }t	        |       }}|r}t               }t        |      D ]e  \  }}t        d |D              r5t        |      s*|r(|d   j                         s|j                  d      s||v rd|z  ||<   |j                  |       g | g|z   D ]\  }t        d |D              st        d|z        t        |      rt        d	|z        |d   j                         sPt        d
|z         t               }|D ]F  }|j                  d      r|st        d|z        ||v rt        d|z        |j                  |       H d| i}t        |      |d<   t        |      |d<   t        t        |            j                  dd      dd |d<   dj!                  d |D              |d<   dj!                  d t        |      D              |d<   t#        j$                  d!i |}	|rt'        |	       t)        t*        d| z  t,        t.        t              }
	 t1        |	|
       |
|    }	 t7        j8                  d      }|j:                  j=                  dd       |_        |S c c}w # t2        $ r }t3        |j4                  dz   |	z         d}~ww xY w# t@        t        f$ r Y |S w xY w)"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   J   K   | ]  }|j                         xs |d k(    yw_Nisalnum.0cs     r   	<genexpr>znamedtuple.<locals>.<genexpr>   "     >A		/qCx/>   !#r   r   _%dc              3   J   K   | ]  }|j                         xs |d k(    ywr   r   r   s     r   r   znamedtuple.<locals>.<genexpr>   "     9q199;*!s(*9r!   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   K   | ]  }t         j                  |         yw)nameN
_repr_tmplformatr   r5   s     r   r   znamedtuple.<locals>.<genexpr>   &      #<'+ $.#4#4$#4#? #<    "repr_fmt
c              3   P   K   | ]  \  }}t         j                  ||          yw)indexr5   N)_imm_field_tmplr8   r   r@   r5   s      r   r   znamedtuple.<locals>.<genexpr>   s.      %P)4 &5%;%;%d%;%S %P   $&
field_defsznamedtuple_%s)_itemgetter__name__r   	_property_tuple:
NrF   __main__ )!
isinstance
basestringreplacesplitstrset	enumerateall
_iskeywordisdigit
startswithadd
ValueErrortuplelenreprjoin_namedtuple_tmplr8   printdictrE   r   propertyr   SyntaxErrormessage_sys	_getframe	f_globalsget
__module__AttributeError)r*   r+   verboserenamexseenr@   r5   fmt_kwclass_definition	namespaceeresultframes                 r   r   r      s    2 +z*!))#s399;#./a3q6/K/u$[1 	KE4>>>d#7??$??3'4<%*U]E"HHTN	 
[( 
49D99 K#$ % % d +-12 3 37?? ,.23 4 4
4 5D ??3 "$() * *4<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
@	* x Fq!!OO//
JG MK 0n  @!))e+.>>??@ J' Ms/   JJ  #6K  	K	)KK	KK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                    t        |t              r |j                  dd      j                         }|D cg c]  }t	        |       }}|r}t               }t        |      D ]e  \  }}t        d |D              r5t        |      s*|r(|d   j                         s|j                  d      s||v rd|z  ||<   |j                  |       g | g|z   D ]\  }t        d |D              st        d|z        t        |      rt        d	|z        |d   j                         sPt        d
|z         t               }|D ]F  }|j                  d      r|st        d|z        ||v rt        d|z        |j                  |       H d| i}t        |      |d<   t        |      |d<   t        t        |            j                  dd      dd |d<   dj!                  d |D              |d<   dj!                  d t        |      D              |d<   t#        j$                  d"i |}	|rt'        |	       d }
t)        t*        |
d| z  t,        t.        t0              }	 t3        |	|       ||    }	 t9        j:                  d      }|j<                  j?                  d d!      |_         |S c c}w # t4        $ r }t5        |j6                  dz   |	z         d}~ww xY w# tB        t        f$ r Y |S w xY w)#a7  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   J   K   | ]  }|j                         xs |d k(    ywr   r   r   s     r   r   znamedlist.<locals>.<genexpr>H  r    r!   r   r   r"   c              3   J   K   | ]  }|j                         xs |d k(    ywr   r   r   s     r   r   znamedlist.<locals>.<genexpr>Q  r$   r!   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   c              3   H   K   | ]  }t         j                  |         ywr4   r6   r9   s     r   r   znamedlist.<locals>.<genexpr>i  r:   r;   r<   r=   c              3   P   K   | ]  \  }}t         j                  ||          ywr?   )_m_field_tmplr8   rB   s      r   r   znamedlist.<locals>.<genexpr>k  s.      %P)4 &3%9%9D%9%Q %PrC   rD   c                       fd}|S )Nc                     || <   y r   rK   )objvaluekeys     r   _itemsetterz3namedlist.<locals>._itemsetter.<locals>._itemsetters  s    CHr   rK   )r}   r~   s   ` r   r~   znamedlist.<locals>._itemsetterr  s    	r   znamedlist_%s)rE   r~   rF   r   rG   _listrI   NrF   rJ   rK   )"rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   _namedlist_tmplr8   r^   r_   rE   r   r`   listr   ra   rb   rc   rd   re   rf   rg   rh   )r*   r+   ri   rj   rk   rl   r@   r5   rm   rn   r~   ro   rp   rq   rr   s                  r   r   r   )  s(   2 +z*!))#s399;#./a3q6/K/u$[1 	KE4>>>d#7??$??3'4<%*U]E"HHTN	 
[( 
49D99 K#$ % % d +-12 3 37?? ,.23 4 4
4 5D ??3 "$() * *4<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@	* x Fq!!OO//
JG MY 0z  @!))e+.>>??@ J' Ms/   JJ$ '6K $	K-KKK#"K#)FF)__doc__
__future__r   sysrc   collectionsr   ImportErrorr_   keywordr   rT   operatorr   rE   rM   r   	NameErrorrP   bytes__all__r7   rA   rx   r]   r   r   r   rK   r   r   <module>r      s   B" & ' , .( 
% 
0 d`N5pge  K  uJs    = A
 AA
AA