
    qc<                         d Z ddlmZ ddlZ	 ddlmZ n# e$ r eZY nw xY wddl	m
Z ddlmZ 	 e d Zn# e$ r
 eefZd ZY nw xY wd	d
gZdZdZdZdZddZdZddZdS )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           d S )Nzexec code in global_envexeccode
global_envs     2lib/python3.11/site-packages/boltons/namedutils.pyexec_r   ?   s    &'''''    c                 &    t          | |           d S 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}
Fc                    t          |t                    r(|                    dd                                          }d |D             }|rt	                      }t          |          D ]\  }}t          d |D                       rDt          |          s5|r3|d                                         s|	                    d          s||v rd|z  ||<   |
                    |           | g|z   D ]z}t          d |D                       st          d	|z            t          |          rt          d
|z            |d                                         rt          d|z            {t	                      }|D ]V}|	                    d          r|st          d|z            ||v rt          d|z            |
                    |           Wd| i}t          |          |d<   t          |          |d<   t          t          |                                        dd          dd         |d<   d                    d |D                       |d<   d                    d t          |          D                       |d<   t!          j        d"i |}|rt%          |           t'          t(          d| z  t*          t,          t                    }		 t/          ||	           n,# t0          $ r}
t1          |
j        dz   |z             d}
~
ww xY w|	|          }	 t5          j        d          }|j                            d d!          |_        n# t>          t          f$ r Y nw xY w|S )#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                 ,    g | ]}t          |          S  str.0xs     r   
<listcomp>znamedtuple.<locals>.<listcomp>       ///a3q66///r   c              3   J   K   | ]}|                                 p|d k    V  dS _Nisalnumr   cs     r   	<genexpr>znamedtuple.<locals>.<genexpr>   3      >>A		/qCx>>>>>>r   r   r"   _%dc              3   J   K   | ]}|                                 p|d k    V  dS r!   r#   r%   s     r   r'   znamedtuple.<locals>.<genexpr>   3      99q199;;*!s(99999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   L   K   | ]}t                               |           V   dS )nameN
_repr_tmplformatr   r<   s     r   r'   znamedtuple.<locals>.<genexpr>   G       #< #<'+ $.#4#4$#4#?#? #< #< #< #< #< #<r   repr_fmt
c              3   T   K   | ]#\  }}t                               ||           V  $dS )indexr<   N)_imm_field_tmplr?   r   rF   r<   s      r   r'   znamedtuple.<locals>.<genexpr>   sU       %P %P)4 &5%;%;%d%;%S%S %P %P %P %P %P %Pr   
field_defsznamedtuple_%s)_itemgetter__name__r   	_property_tuple:
NrK   __main__r   ) 
isinstance
basestringreplacesplitset	enumerateall
_iskeywordisdigit
startswithadd
ValueErrortuplelenreprjoin_namedtuple_tmplr?   printdictrJ   r   propertyr   SyntaxErrormessage_sys	_getframe	f_globalsget
__module__AttributeError)r1   r2   verboserenameseenrF   r<   fmt_kwclass_definition	namespaceeresultframes                r   r   r      s@   2 +z** <!))#s3399;;//;///K 
uu$[11 	 	KE4>>>>>>> 3d##33 7??$$3 ??3''	3
 4<3 &+U]E"HHTNNNN
[( 
4 
499D99999 	% K#$ % % % d 	3 +-12 3 3 37?? 	4 ,.23 4 4 4	4 55D  ??3 	* 	* "$() * * *4< 	LCdJKKK (#F!+..F={++F<eK001199#rBB1R4HF: #< #</:#< #< #< < <F:99 %P %P8A+8N8N%P %P %P P PF<'.8888   -8!,'!	# # #I
@	**** @ @ @!)e+.>>???@x Fq!!!O//
JGGJ'    Ms*   K$ $
L.LL4M M"!M"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(|                    dd                                          }d |D             }|rt	                      }t          |          D ]\  }}t          d |D                       rDt          |          s5|r3|d                                         s|	                    d          s||v rd|z  ||<   |
                    |           | g|z   D ]z}t          d |D                       st          d	|z            t          |          rt          d
|z            |d                                         rt          d|z            {t	                      }|D ]V}|	                    d          r|st          d|z            ||v rt          d|z            |
                    |           Wd| i}t          |          |d<   t          |          |d<   t          t          |                                        dd          dd         |d<   d                    d |D                       |d<   d                    d t          |          D                       |d<   t!          j        d#i |}|rt%          |           d }	t'          t(          |	d| z  t*          t,          t.                    }
	 t1          ||
           n,# t2          $ r}t3          |j        dz   |z             d }~ww xY w|
|          }	 t7          j        d          }|j                            d!d"          |_        n# t@          t          f$ r Y nw xY w|S )$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                 ,    g | ]}t          |          S r   r   r   s     r   r   znamedlist.<locals>.<listcomp>D  r   r   c              3   J   K   | ]}|                                 p|d k    V  dS r!   r#   r%   s     r   r'   znamedlist.<locals>.<genexpr>H  r(   r   r   r"   r)   c              3   J   K   | ]}|                                 p|d k    V  dS r!   r#   r%   s     r   r'   znamedlist.<locals>.<genexpr>Q  r+   r   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   c              3   L   K   | ]}t                               |           V   dS r;   r=   r@   s     r   r'   znamedlist.<locals>.<genexpr>i  rA   r   rB   rC   c              3   T   K   | ]#\  }}t                               ||           V  $dS rE   )_m_field_tmplr?   rH   s      r   r'   znamedlist.<locals>.<genexpr>k  sU       %P %P)4 &3%9%9D%9%Q%Q %P %P %P %P %P %Pr   rI   c                       fd}|S )Nc                     || <   d S r   r   )objvaluekeys     r   _itemsetterz3namedlist.<locals>._itemsetter.<locals>._itemsetters  s    CHHHr   r   )r   r   s   ` r   r   znamedlist.<locals>._itemsetterr  s"    	 	 	 	 	r   znamedlist_%s)rJ   r   rK   r   rL   _listrN   NrK   rO   r   )!rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   _namedlist_tmplr?   ra   rb   rJ   r   rc   listr   rd   re   rf   rg   rh   ri   rj   rk   )r1   r2   rl   rm   rn   rF   r<   ro   rp   r   rq   rr   rs   rt   s                 r   r   r   )  sR   2 +z** <!))#s3399;;//;///K 
uu$[11 	 	KE4>>>>>>> 3d##33 7??$$3 ??3''	3
 4<3 &+U]E"HHTNNNN
[( 
4 
499D99999 	% K#$ % % % d 	3 +-12 3 3 37?? 	4 ,.23 4 4 4	4 55D  ??3 	* 	* "$() * * *4< 	LCdJKKK (#F!+..F={++F<eK001199#rBB1R4HF: #< #</:#< #< #< < <F:99 %P %P8A+8N8N%P %P %P P PF<&-7777     !,,x7!,'! ! !I@	**** @ @ @!)e+.>>???@x Fq!!!O//
JGGJ'    Ms*   K( (
L2LL4M M&%M&)FF)__doc__
__future__r   sysrf   collectionsr   ImportErrorrb   keywordr   rW   operatorr   rJ   rQ   r   	NameErrorr   bytes__all__r>   rG   r{   r`   r   r   r   r   r   r   <module>r      s^  B " & % % % % %    '''''''   KKK , + + + + + . . . . . .J( ( ( (   uJ    
 
% 
0 d` ` ` `N5pg g g g g gs    5 AA