ok

Mini Shell

Direktori : /proc/thread-self/root/opt/alt/python39/lib64/python3.9/lib2to3/__pycache__/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python39/lib64/python3.9/lib2to3/__pycache__/pytree.cpython-39.pyc

a

���eFm�@s�dZdZddlZddlmZdZiadd�ZGdd	�d	e�Z	Gd
d�de	�Z
Gdd
�d
e	�Zdd�ZGdd�de�Z
Gdd�de
�ZGdd�de
�ZGdd�de
�ZGdd�de
�Zdd�ZdS)z�
Python parse tree definitions.

This is a very concrete parse tree; we need to keep every token and
even the comments and whitespace between tokens.

There's also a pattern matching implementation here.
z#Guido van Rossum <guido@python.org>�N)�StringIOi���cCsDts8ddlm}|j��D]\}}t|�tkr|t|<qt�||�S)N�)�python_symbols)�_type_reprsZpygramr�__dict__�items�type�int�
setdefault)Ztype_numr�name�val�r
�3/opt/alt/python39/lib64/python3.9/lib2to3/pytree.py�	type_reprs
rc@s�eZdZdZdZdZdZdZdZdd�Z	dd�Z
dZd	d
�Zdd�Z
d
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zedd��Zedd��Zdd�Zdd �Zd!d"�Zejd#kr�d$d%�ZdS)&�Basez�
    Abstract base class for Node and Leaf.

    This provides some default functionality and boilerplate using the
    template pattern.

    A node may be a subnode of at most one parent.
    Nr
FcOs|tusJd��t�|�S)z7Constructor that prevents Base from being instantiated.zCannot instantiate Base)r�object�__new__��cls�args�kwdsr
r
rr1szBase.__new__cCs|j|jurtS|�|�S)zW
        Compare two nodes for equality.

        This calls the method _eq().
        )�	__class__�NotImplemented�_eq��self�otherr
r
r�__eq__6szBase.__eq__cCst�dS)a_
        Compare two nodes for equality.

        This is called by __eq__ and __ne__.  It is only called if the two nodes
        have the same type.  This must be implemented by the concrete subclass.
        Nodes should be considered equal if they have the same structure,
        ignoring the prefix string and other context information.
        N��NotImplementedErrorrr
r
rrBs	zBase._eqcCst�dS)zr
        Return a cloned (deep) copy of self.

        This must be implemented by the concrete subclass.
        Nr�rr
r
r�cloneMsz
Base.clonecCst�dS)zx
        Return a post-order iterator for the tree.

        This must be implemented by the concrete subclass.
        Nrr r
r
r�
post_orderUszBase.post_ordercCst�dS)zw
        Return a pre-order iterator for the tree.

        This must be implemented by the concrete subclass.
        Nrr r
r
r�	pre_order]szBase.pre_ordercCs�|jdusJt|���|dus"J�t|t�s2|g}g}d}|jjD]D}||ur||rdJ|jj||f��|durv|�|�d}qB|�|�qB|s�J|j||f��|j��||j_|D]}|j|_q�d|_dS)z/Replace this node with a new one in the parent.NFT)�parent�str�
isinstance�list�children�extend�append�changed)r�newZ
l_children�found�ch�xr
r
r�replacees&



zBase.replacecCs*|}t|t�s$|jsdS|jd}q|jS)z9Return the line number which generated the invocant node.Nr)r&�Leafr(�lineno�r�noder
r
r�
get_lineno|s
zBase.get_linenocCs|jr|j��d|_dS)NT)r$r+�was_changedr r
r
rr+�s
zBase.changedcCsJ|jrFt|jj�D]2\}}||ur|j��|jj|=d|_|SqdS)z�
        Remove the node from the tree. Returns the position of the node in its
        parent's children before it was removed.
        N)r$�	enumerater(r+)r�ir4r
r
r�remove�s

zBase.removec	Cs^|jdurdSt|jj�D]>\}}||urz|jj|dWStyVYdS0qdS)z�
        The node immediately following the invocant in their parent's children
        list. If the invocant does not have a next sibling, it is None
        Nr)r$r7r(�
IndexError�rr8�childr
r
r�next_sibling�s
zBase.next_siblingcCsR|jdurdSt|jj�D]2\}}||ur|dkr8dS|jj|dSqdS)z�
        The node immediately preceding the invocant in their parent's children
        list. If the invocant does not have a previous sibling, it is None.
        Nrr)r$r7r(r;r
r
r�prev_sibling�s
zBase.prev_siblingccs|jD]}|��EdHqdS�N)r(�leaves�rr<r
r
rr@�s
zBase.leavescCs|jdurdSd|j��S)Nrr)r$�depthr r
r
rrB�s
z
Base.depthcCs|j}|durdS|jS)z�
        Return the string immediately following the invocant node. This is
        effectively equivalent to node.next_sibling.prefix
        N�)r=�prefix)rZnext_sibr
r
r�
get_suffix�szBase.get_suffix��rcCst|��d�S)N�ascii)r%�encoder r
r
r�__str__�szBase.__str__)�__name__�
__module__�__qualname__�__doc__rr$r(r6Zwas_checkedrr�__hash__rr!r"r#r0r5r+r9�propertyr=r>r@rBrE�sys�version_inforJr
r
r
rrs4

	




rc@s�eZdZdZddd�Zdd�Zdd�Zejd	kr4eZ	d
d�Z
dd
�Zdd�Zdd�Z
edd��Zejdd��Zdd�Zdd�Zdd�ZdS)�Nodez+Concrete implementation for interior nodes.NcCst|dksJ|��||_t|�|_|jD] }|jdus@Jt|���||_q&|durV||_|rj|dd�|_nd|_dS)z�
        Initializer.

        Takes a type constant (a symbol number >= 256), a sequence of
        child nodes, and an optional context keyword argument.

        As a side effect, the parent pointers of the children are updated.
        �N)rr'r(r$�reprrD�fixers_applied)rrr(�contextrDrVr.r
r
r�__init__�s

z
Node.__init__cCsd|jjt|j�|jfS)�)Return a canonical string representation.z
%s(%s, %r))rrKrrr(r r
r
r�__repr__�s�z
Node.__repr__cCsd�tt|j��S)�k
        Return a pretty string representation.

        This reproduces the input source exactly.
        rC)�join�mapr%r(r r
r
r�__unicode__�szNode.__unicode__rFcCs|j|jf|j|jfkS�zCompare two nodes for equality.)rr(rr
r
rr�szNode._eqcCst|jdd�|jD�|jd�S)�$Return a cloned (deep) copy of self.cSsg|]}|���qSr
)r!)�.0r.r
r
r�
<listcomp>�zNode.clone.<locals>.<listcomp>�rV)rSrr(rVr r
r
rr!s�z
Node.cloneccs$|jD]}|��EdHq|VdS�z*Return a post-order iterator for the tree.N)r(r"rAr
r
rr"s
zNode.post_orderccs$|V|jD]}|��EdHqdS�z)Return a pre-order iterator for the tree.N)r(r#rAr
r
rr#s
zNode.pre_ordercCs|js
dS|jdjS)zO
        The whitespace and comments preceding this node in the input.
        rCr�r(rDr r
r
rrDszNode.prefixcCs|jr||jd_dS�Nrrg�rrDr
r
rrDscCs(||_d|j|_||j|<|��dS)z�
        Equivalent to 'node.children[i] = child'. This method also sets the
        child's parent attribute appropriately.
        N)r$r(r+r;r
r
r�	set_child s
zNode.set_childcCs ||_|j�||�|��dS)z�
        Equivalent to 'node.children.insert(i, child)'. This method also sets
        the child's parent attribute appropriately.
        N)r$r(�insertr+r;r
r
r�insert_child*szNode.insert_childcCs||_|j�|�|��dS)z�
        Equivalent to 'node.children.append(child)'. This method also sets the
        child's parent attribute appropriately.
        N)r$r(r*r+rAr
r
r�append_child3szNode.append_child)NNN)rKrLrMrNrXrZr^rQrRrJrr!r"r#rPrD�setterrjrlrmr
r
r
rrS�s(�




	rSc@s�eZdZdZdZdZdZddgfdd�Zdd�Zd	d
�Z	e
jdkrFe	Zdd
�Z
dd�Zdd�Zdd�Zdd�Zedd��Zejdd��ZdS)r1z'Concrete implementation for leaf nodes.rCrNcCsdd|krdksnJ|��|dur8|\|_\|_|_||_||_|durR||_|dd�|_dS)z�
        Initializer.

        Takes a type constant (a token number < 256), a string value, and an
        optional context keyword argument.
        rrTN)�_prefixr2�columnr�valuerV)rrrqrWrDrVr
r
rrXFs
z
Leaf.__init__cCsd|jj|j|jfS)rYz
%s(%r, %r))rrKrrqr r
r
rrZYs�z
Leaf.__repr__cCs|jt|j�S)r[)rDr%rqr r
r
rr^_szLeaf.__unicode__rFcCs|j|jf|j|jfkSr_)rrqrr
r
rrjszLeaf._eqcCs$t|j|j|j|j|jff|jd�S)r`rd)r1rrqrDr2rprVr r
r
rr!ns
�z
Leaf.cloneccs
|VdSr?r
r r
r
rr@tszLeaf.leavesccs
|VdSrer
r r
r
rr"wszLeaf.post_orderccs
|VdSrfr
r r
r
rr#{szLeaf.pre_ordercCs|jS)zP
        The whitespace and comments preceding this token in the input.
        )ror r
r
rrDszLeaf.prefixcCs|��||_dSr?)r+rorir
r
rrD�s)rKrLrMrNror2rprXrZr^rQrRrJrr!r@r"r#rPrDrnr
r
r
rr1=s*�


r1cCsN|\}}}}|s||jvr<t|�dkr.|dSt|||d�St|||d�SdS)z�
    Convert raw node information to a Node or Leaf instance.

    This is passed to the parser driver which calls it whenever a reduction of a
    grammar rule produces a new complete node, so that the tree is build
    strictly bottom-up.
    rr)rWN)Z
number2symbol�lenrSr1)ZgrZraw_noderrqrWr(r
r
r�convert�srsc@sPeZdZdZdZdZdZdd�Zdd�Zdd�Z	dd	d
�Z
ddd�Zd
d�ZdS)�BasePatterna�
    A pattern is a tree matching pattern.

    It looks for a specific node type (token or symbol), and
    optionally for a specific content.

    This is an abstract base class.  There are three concrete
    subclasses:

    - LeafPattern matches a single leaf node;
    - NodePattern matches a single node (usually non-leaf);
    - WildcardPattern matches a sequence of nodes of variable length.
    NcOs|tusJd��t�|�S)z>Constructor that prevents BasePattern from being instantiated.zCannot instantiate BasePattern)rtrrrr
r
rr�szBasePattern.__new__cCsHt|j�|j|jg}|r,|ddur,|d=qd|jjd�tt|��fS)N���z%s(%s)z, )	rr�contentrrrKr\r]rU)rrr
r
rrZ�szBasePattern.__repr__cCs|S)z�
        A subclass can define this as a hook for optimizations.

        Returns either self or another node with the same effect.
        r
r r
r
r�optimize�szBasePattern.optimizecCsn|jdur|j|jkrdS|jdurRd}|dur4i}|�||�sDdS|rR|�|�|durj|jrj|||j<dS)a#
        Does this pattern exactly match a node?

        Returns True if it matches, False if not.

        If results is not None, it must be a dict which will be
        updated with the nodes matching named subpatterns.

        Default implementation for non-wildcard patterns.
        NFT)rrv�	_submatch�updater)rr4�results�rr
r
r�match�s


zBasePattern.matchcCs t|�dkrdS|�|d|�S)z�
        Does this pattern exactly match a sequence of nodes?

        Default implementation for non-wildcard patterns.
        rFr)rrr|)r�nodesrzr
r
r�	match_seq�szBasePattern.match_seqccs&i}|r"|�|d|�r"d|fVdS)z}
        Generator yielding all matches for this pattern.

        Default implementation for non-wildcard patterns.
        rrN)r|)rr}r{r
r
r�generate_matches�szBasePattern.generate_matches)N)N)
rKrLrMrNrrvrrrZrwr|r~rr
r
r
rrt�s


rtc@s*eZdZddd�Zd	dd�Zd
dd�ZdS)�LeafPatternNcCsZ|dur&d|krdks&nJ|��|durDt|t�sDJt|���||_||_||_dS)ap
        Initializer.  Takes optional type, content, and name.

        The type, if given must be a token type (< 256).  If not given,
        this matches any *leaf* node; the content may still be required.

        The content, if given, must be a string.

        If a name is given, the matching node is stored in the results
        dict under that key.
        NrrT)r&r%rUrrvr)rrrvrr
r
rrX�szLeafPattern.__init__cCst|t�sdSt�|||�S)z*Override match() to insist on a leaf node.F)r&r1rtr|�rr4rzr
r
rr|
s
zLeafPattern.matchcCs|j|jkS)�
        Match the pattern's content to the node's children.

        This assumes the node type matches and self.content is not None.

        Returns True if it matches, False if not.

        If results is not None, it must be a dict which will be
        updated with the nodes matching named subpatterns.

        When returning False, the results dict may still be updated.
        )rvrqr�r
r
rrxs
zLeafPattern._submatch)NNN)N)N)rKrLrMrXr|rxr
r
r
rr��s

r�c@s$eZdZdZddd�Zddd�ZdS)	�NodePatternFNcCs�|dur|dksJ|��|durvt|t�r6Jt|���t|�}t|�D].\}}t|t�sdJ||f��t|t�rFd|_qF||_||_	||_
dS)ad
        Initializer.  Takes optional type, content, and name.

        The type, if given, must be a symbol type (>= 256).  If the
        type is None this matches *any* single node (leaf or not),
        except if content is not None, in which it only matches
        non-leaf nodes that also match the content pattern.

        The content, if not None, must be a sequence of Patterns that
        must match the node's children exactly.  If the content is
        given, the type must not be None.

        If a name is given, the matching node is stored in the results
        dict under that key.
        NrTT)r&r%rUr'r7rt�WildcardPattern�	wildcardsrrvr)rrrvrr8�itemr
r
rrX$s
zNodePattern.__init__cCs�|jrHt|j|j�D].\}}|t|j�kr|dur<|�|�dSqdSt|j�t|j�kr`dSt|j|j�D]\}}|�||�sndSqndS)r�NTF)r�rrvr(rrry�zipr|)rr4rz�cr{�
subpatternr<r
r
rrxAs

zNodePattern._submatch)NNN)N)rKrLrMr�rXrxr
r
r
rr� s
r�c@s^eZdZdZddedfdd�Zdd�Zddd	�Zdd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)r�a
    A wildcard pattern can match zero or more nodes.

    This has all the flexibility needed to implement patterns like:

    .*      .+      .?      .{m,n}
    (a b c | d e | f)
    (...)*  (...)+  (...)?  (...){m,n}

    except it always uses non-greedy matching.
    NrcCs�d|kr|krtks,nJ||f��|durtttt|��}t|�sVJt|���|D]}t|�sZJt|���qZ||_||_||_||_dS)a�
        Initializer.

        Args:
            content: optional sequence of subsequences of patterns;
                     if absent, matches one node;
                     if present, each subsequence is an alternative [*]
            min: optional minimum number of times to match, default 0
            max: optional maximum number of times to match, default HUGE
            name: optional name assigned to this match

        [*] Thus, if content is [[a, b, c], [d, e], [f, g, h]] this is
            equivalent to (a b c | d e | f g h); if content is None,
            this is equivalent to '.' in regular expression terms.
            The min and max parameters work as follows:
                min=0, max=maxint: .*
                min=1, max=maxint: .+
                min=0, max=1: .?
                min=1, max=1: .
            If content is not None, replace the dot with the parenthesized
            list of alternatives, e.g. (a b c | d e | f g h)*
        rN)	�HUGE�tupler]rrrUrv�min�maxr)rrvr�r�r�altr
r
rrXks,zWildcardPattern.__init__cCs�d}|jdur<t|j�dkr<t|jd�dkr<|jdd}|jdkr�|jdkr�|jdurft|jd�S|dur�|j|jkr�|��S|jdkr�t|t�r�|jdkr�|j|jkr�t|j|j|j|j|j|j�S|S)z+Optimize certain stacked wildcard patterns.Nrr)r)	rvrrr�r�r�rrwr&r�)rr�r
r
rrw�s.
��
�
�

�zWildcardPattern.optimizecCs|�|g|�S)z'Does this pattern exactly match a node?)r~r�r
r
rr|�szWildcardPattern.matchcCsP|�|�D]@\}}|t|�kr
|durD|�|�|jrDt|�||j<dSq
dS)z4Does this pattern exactly match a sequence of nodes?NTF)rrrryrr')rr}rzr�r{r
r
rr~�s
zWildcardPattern.match_seqc	cs<|jdurTt|jdtt|�|j��D]*}i}|jrF|d|�||j<||fVq&n�|jdkrl|�|�Vn�ttd�r�tj	}t
�t_	z�z<|�|d�D]*\}}|jr�|d|�||j<||fVq�WnJt�y|�
|�D]*\}}|jr�|d|�||j<||fVq�Yn0Wttd��r8|t_	nttd��r6|t_	0dS)a"
        Generator yielding matches for a sequence of nodes.

        Args:
            nodes: sequence of nodes

        Yields:
            (count, results) tuples where:
            count: the match comprises nodes[:count];
            results: dict containing named submatches.
        NrZ	bare_name�getrefcountr)rv�ranger�rrr�r�_bare_name_matches�hasattrrQ�stderrr�_recursive_matches�RuntimeError�_iterative_matches)rr}�countr{Zsave_stderrr
r
rr�s2
 

�z WildcardPattern.generate_matchesccs�t|�}d|jkrdifVg}|jD]0}t||�D] \}}||fV|�||f�q4q&|r�g}|D]�\}}	||krd||jkrd|jD]`}t|||d��D]H\}
}|
dkr�i}|�|	�|�|�||
|fV|�||
|f�q�q�qd|}qXdS)z(Helper to iteratively yield the matches.rN)rrr�rvrr*r�ry)rr}Znodelenrzr�r�r{Znew_results�c0�r0�c1�r1r
r
rr��s*






z"WildcardPattern._iterative_matchescCspd}i}d}t|�}|sV||krVd}|jD](}|d�|||�r*|d7}d}qq*q|d|�||j<||fS)z(Special optimized matcher for bare_name.rFTrN)rrrvr|r)rr}r�r{Zdoner�Zleafr
r
rr��s
z"WildcardPattern._bare_name_matchesc	cs�|jdusJ�||jkr"difV||jkr�|jD]`}t||�D]P\}}|�||d�|d�D].\}}i}|�|�|�|�|||fVq`q@q2dS)z(Helper to recursively yield the matches.Nrr)rvr�r�rr�ry)	rr}r�r�r�r�r�r�r{r
r
rr�
s



 

z"WildcardPattern._recursive_matches)N)N)
rKrLrMrNr�rXrwr|r~rr�r�r�r
r
r
rr�]s#

-r�c@s.eZdZd
dd�Zdd�Zdd�Zdd	�ZdS)�NegatedPatternNcCs(|durt|t�sJt|���||_dS)a
        Initializer.

        The argument is either a pattern or None.  If it is None, this
        only matches an empty sequence (effectively '$' in regex
        lingo).  If it is not None, this matches whenever the argument
        pattern doesn't have any matches.
        N)r&rtrUrv)rrvr
r
rrXs	zNegatedPattern.__init__cCsdS)NFr
r3r
r
rr|(szNegatedPattern.matchcCst|�dkSrh)rr)rr}r
r
rr~,szNegatedPattern.match_seqccsJ|jdur"t|�dkrFdifVn$|j�|�D]\}}dSdifVdSrh)rvrrr)rr}r�r{r
r
rr0s
zNegatedPattern.generate_matches)N)rKrLrMrXr|r~rr
r
r
rr�s

r�c	cs�|sdifVn||d|dd�}}|�|�D]Z\}}|sH||fVq0t|||d��D].\}}i}|�|�|�|�|||fVqZq0dS)aR
    Generator yielding matches for a sequence of patterns and nodes.

    Args:
        patterns: a sequence of patterns
        nodes: a sequence of nodes

    Yields:
        (count, results) tuples where:
        count: the entire sequence of patterns matches nodes[:count];
        results: dict containing named submatches.
        rrN)rry)	Zpatternsr}�p�restr�r�r�r�r{r
r
rr<s


r)rN�
__author__rQ�iorr�rrrrrSr1rsrtr�r�r�r�rr
r
r
r�<module>s$	
1nNV,==#

Zerion Mini Shell 1.0