ok

Mini Shell

Direktori : /lib64/python3.6/lib2to3/__pycache__/
Upload File :
Current File : //lib64/python3.6/lib2to3/__pycache__/pytree.cpython-36.opt-1.pyc

3


 \�m�@s�dZdZddlZddlZddlmZdZiadd�ZGdd	�d	e	�Z
Gd
d�de
�ZGdd
�d
e
�Zdd�Z
Gdd�de	�ZGdd�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���cCsHts<ddlm}x*|jj�D]\}}t|�tkr|t|<qWtj||�S)N�)�python_symbols)�_type_reprsZpygramr�__dict__�items�type�int�
setdefault)Ztype_numr�name�val�r
�&/usr/lib64/python3.6/lib2to3/pytree.py�	type_reprsrc@s�eZdZdZdZdZfZdZdZdd�Z	dd�Z
dZdd	�Zd
d�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.
    NFcOs
tj|�S)z7Constructor that prevents Base from being instantiated.)�object�__new__)�cls�args�kwdsr
r
rr2szBase.__new__cCs|j|jk	rtS|j|�S)zW
        Compare two nodes for equality.

        This calls the method _eq().
        )�	__class__�NotImplemented�_eq)�self�otherr
r
r�__eq__7s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)�NotImplementedError)rrr
r
rrCs	zBase._eqcCst�dS)zr
        Return a cloned (deep) copy of self.

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

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

        This must be implemented by the concrete subclass.
        N)r)rr
r
r�	pre_order^szBase.pre_ordercCs�t|t�s|g}g}d}x:|jjD].}||krF|dk	r@|j|�d}q"|j|�q"W|jj�||j_x|D]}|j|_qlWd|_dS)z/Replace this node with a new one in the parent.FNT)�
isinstance�list�parent�children�extend�append�changed)r�newZ
l_children�found�ch�xr
r
r�replacefs



zBase.replacecCs.|}x"t|t�s&|jsdS|jd}qW|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|jj�d|_dS)NT)r"r&�was_changed)rr
r
rr&�s
zBase.changedcCsJ|jrFx>t|jj�D].\}}||kr|jj�|jj|=d|_|SqWdS)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�ir.r
r
r�remove�s

zBase.removecCsZ|jdkrdSxFt|jj�D]6\}}||kry|jj|dStk
rPdSXqWdS)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"r1r#�
IndexError)rr2�childr
r
r�next_sibling�s
zBase.next_siblingcCsP|jdkrdSx<t|jj�D],\}}||kr|dkr8dS|jj|dSqWdS)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"r1r#)rr2r5r
r
r�prev_sibling�s
zBase.prev_siblingccs"x|jD]}|j�EdHqWdS)N)r#�leaves)rr5r
r
rr8�szBase.leavescCs|jdkrdSd|jj�S)Nrr)r"�depth)rr
r
rr9�s
z
Base.depthcCs|j}|dkrdS|jS)z�
        Return the string immediately following the invocant node. This is
        effectively equivalent to node.next_sibling.prefix
        N�)r6�prefix)rZnext_sibr
r
r�
get_suffix�szBase.get_suffix�rcCst|�jd�S)N�ascii)�str�encode)rr
r
r�__str__�szBase.__str__)r=r)�__name__�
__module__�__qualname__�__doc__rr"r#r0Zwas_checkedrr�__hash__rrrrr+r/r&r3�propertyr6r7r8r9r<�sys�version_inforAr
r
r
rr s0	
	


rc@s�eZdZdZddd�Zdd�Zdd�Zejdkr4eZ	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zeee�Zdd�Zdd�Zdd�ZdS)�Nodez+Concrete implementation for interior nodes.NcCsR||_t|�|_x|jD]
}||_qW|dk	r4||_|rH|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"r;�fixers_applied)rrr#�contextr;rKr)r
r
r�__init__�s


z
Node.__init__cCsd|jjt|j�|jfS)z)Return a canonical string representation.z
%s(%s, %r))rrBrrr#)rr
r
r�__repr__�sz
Node.__repr__cCsdjtt|j��S)zk
        Return a pretty string representation.

        This reproduces the input source exactly.
        r:)�join�mapr?r#)rr
r
r�__unicode__�szNode.__unicode__r=rcCs|j|jf|j|jfkS)zCompare two nodes for equality.)rr#)rrr
r
rr�szNode._eqcCst|jdd�|jD�|jd�S)z$Return a cloned (deep) copy of self.cSsg|]}|j��qSr
)r)�.0r)r
r
r�
<listcomp>szNode.clone.<locals>.<listcomp>)rK)rJrr#rK)rr
r
rrsz
Node.cloneccs(x|jD]}|j�EdHqW|VdS)z*Return a post-order iterator for the tree.N)r#r)rr5r
r
rrszNode.post_orderccs(|Vx|jD]}|j�EdHqWdS)z)Return a pre-order iterator for the tree.N)r#r)rr5r
r
rr
szNode.pre_ordercCs|js
dS|jdjS)zO
        The whitespace and comments preceding this node in the input.
        r:r)r#r;)rr
r
r�_prefix_getterszNode._prefix_gettercCs|jr||jd_dS)Nr)r#r;)rr;r
r
r�_prefix_setterszNode._prefix_settercCs(||_d|j|_||j|<|j�dS)z�
        Equivalent to 'node.children[i] = child'. This method also sets the
        child's parent attribute appropriately.
        N)r"r#r&)rr2r5r
r
r�	set_child!s
zNode.set_childcCs ||_|jj||�|j�dS)z�
        Equivalent to 'node.children.insert(i, child)'. This method also sets
        the child's parent attribute appropriately.
        N)r"r#�insertr&)rr2r5r
r
r�insert_child+szNode.insert_childcCs||_|jj|�|j�dS)z�
        Equivalent to 'node.children.append(child)'. This method also sets the
        child's parent attribute appropriately.
        N)r"r#r%r&)rr5r
r
r�append_child4szNode.append_child)NNN)r=r)rBrCrDrErMrNrQrHrIrArrrrrTrUrGr;rVrXrYr
r
r
rrJ�s$



	rJc@s�eZdZdZdZdZdZddgfdd�Zdd�Zd	d
�Z	e
jdkrFe	Zdd
�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zeee�ZdS)r,z'Concrete implementation for leaf nodes.r:rNcCsF|dk	r|\|_\|_|_||_||_|dk	r4||_|dd�|_dS)z�
        Initializer.

        Takes a type constant (a token number < 256), a string value, and an
        optional context keyword argument.
        N)�_prefixr-�columnr�valuerK)rrr\rLr;rKr
r
rrMGsz
Leaf.__init__cCsd|jj|j|jfS)z)Return a canonical string representation.z
%s(%r, %r))rrBrr\)rr
r
rrNZsz
Leaf.__repr__cCs|jt|j�S)zk
        Return a pretty string representation.

        This reproduces the input source exactly.
        )r;r?r\)rr
r
rrQ`szLeaf.__unicode__r=cCs|j|jf|j|jfkS)zCompare two nodes for equality.)rr\)rrr
r
rrkszLeaf._eqcCs$t|j|j|j|j|jff|jd�S)z$Return a cloned (deep) copy of self.)rK)r,rr\r;r-r[rK)rr
r
rros
z
Leaf.cloneccs
|VdS)Nr
)rr
r
rr8uszLeaf.leavesccs
|VdS)z*Return a post-order iterator for the tree.Nr
)rr
r
rrxszLeaf.post_orderccs
|VdS)z)Return a pre-order iterator for the tree.Nr
)rr
r
rr|szLeaf.pre_ordercCs|jS)zP
        The whitespace and comments preceding this token in the input.
        )rZ)rr
r
rrT�szLeaf._prefix_gettercCs|j�||_dS)N)r&rZ)rr;r
r
rrU�szLeaf._prefix_setter)r=r)rBrCrDrErZr-r[rMrNrQrHrIrArrr8rrrTrUrGr;r
r
r
rr,>s&
r,cCsN|\}}}}|s||jkr<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)rLN)Z
number2symbol�lenrJr,)ZgrZraw_noderr\rLr#r
r
r�convert�sr^c@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
tj|�S)z>Constructor that prevents BasePattern from being instantiated.)rr)rrrr
r
rr�szBasePattern.__new__cCsLt|j�|j|jg}x|r.|ddkr.|d=qWd|jjdjtt|��fS)Nrz%s(%s)z, ���r`)	rr�contentrrrBrOrP�repr)rrr
r
rrN�s
zBasePattern.__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
)rr
r
r�optimize�szBasePattern.optimizecCsn|jdk	r|j|jkrdS|jdk	rRd}|dk	r4i}|j||�sDdS|rR|j|�|dk	rj|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)rra�	_submatch�updater)rr.�results�rr
r
r�match�s


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

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

        Default implementation for non-wildcard patterns.
        rrN)rh)rrirgr
r
r�generate_matches�szBasePattern.generate_matches)N)N)
rBrCrDrErrarrrNrcrhrjrkr
r
r
rr_�s


r_c@s*eZdZddd�Zd	dd�Zd
dd�ZdS)�LeafPatternNcCs&|dk	r|dk	r||_||_||_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.
        N)rrar)rrrarr
r
rrM�s
zLeafPattern.__init__cCst|t�sdStj|||�S)z*Override match() to insist on a leaf node.F)r r,r_rh)rr.rfr
r
rrhs
zLeafPattern.matchcCs|j|jkS)a�
        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.
        )rar\)rr.rfr
r
rrds
zLeafPattern._submatch)NNN)N)N)rBrCrDrMrhrdr
r
r
rrl�s

rlc@s$eZdZdZddd�Zddd�ZdS)	�NodePatternFNcCsT|dk	r|dk	r>t|�}x$t|�D]\}}t|t�r"d|_q"W||_||_||_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.
        NT)r!r1r �WildcardPattern�	wildcardsrrar)rrrarr2�itemr
r
rrM%s

zNodePattern.__init__cCs�|jrJx>t|j|j�D],\}}|t|j�kr|dk	r>|j|�dSqWdSt|j�t|j�krbdSx*t|j|j�D]\}}|j||�srdSqrWdS)a�
        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.
        NTF)rorkrar#r]re�ziprh)rr.rf�crg�
subpatternr5r
r
rrdBs

zNodePattern._submatch)NNN)N)rBrCrDrorMrdr
r
r
rrm!s
rmc@s^eZdZdZddedfdd�Zdd�Zddd	�Zdd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)rna
    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@|dk	r$ttt|��}x|D]}qW||_||_||_||_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)*
        N)�tuplerPra�min�maxr)rrarurvr�altr
r
rrMls
zWildcardPattern.__init__cCs�d}|jdk	r<t|j�dkr<t|jd�dkr<|jdd}|jdkr�|jdkr�|jdkrft|jd�S|dk	r�|j|jkr�|j�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)	rar]rurvrmrrcr rn)rrsr
r
rrc�s 
 


zWildcardPattern.optimizecCs|j|g|�S)z'Does this pattern exactly match a node?)rj)rr.rfr
r
rrh�szWildcardPattern.matchcCsRxL|j|�D]>\}}|t|�kr|dk	rF|j|�|jrFt|�||j<dSqWdS)z4Does this pattern exactly match a sequence of nodes?NTF)rkr]rerr!)rrirfrrrgr
r
rrj�s
zWildcardPattern.match_seqccs:|jdkrXxJt|jdtt|�|j��D]*}i}|jrH|d|�||j<||fVq(Wn�|jdkrp|j|�Vn�ttd�r�tj	}t
�t_	z�y@x:|j|d�D]*\}}|jr�|d|�||j<||fVq�WWnRtk
�rx:|j
|�D],\}}|j�r
|d|�||j<||fVq�WYnXWdttd��r4|t_	XdS)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)ra�rangerur]rvr�_bare_name_matches�hasattrrH�stderrr�_recursive_matches�RuntimeError�_iterative_matches)rri�countrgZsave_stderrr
r
rrk�s.
"

z WildcardPattern.generate_matchesccst|�}d|jkrdifVg}x>|jD]4}x.t||�D] \}}||fV|j||f�q8Wq(Wx�|�rg}x�|D]�\}}	||krr||jkrrxn|jD]d}x^t|||d��D]H\}
}|
dkr�i}|j|	�|j|�||
|fV|j||
|f�q�Wq�WqrW|}qbWdS)z(Helper to iteratively yield the matches.rN)r]rurarkr%rvre)rriZnodelenrfrwrrrgZnew_results�c0�r0�c1�r1r
r
rr�s*




z"WildcardPattern._iterative_matchescCsxd}i}d}t|�}xH|r\||kr\d}x0|jD]&}|dj|||�r0|d7}d}Pq0WqW|d|�||j<||fS)z(Special optimized matcher for bare_name.rFTrN)r]rarhr)rrir�rg�donervZleafr
r
rrz�s
z"WildcardPattern._bare_name_matchesc	cs�||jkrdifV||jkr�xr|jD]h}xbt||�D]T\}}xJ|j||d�|d�D].\}}i}|j|�|j|�|||fVqXWq6Wq&WdS)z(Helper to recursively yield the matches.rNr)rurvrarkr}re)	rrir�rwr�r�r�r�rgr
r
rr}s


"

z"WildcardPattern._recursive_matches)N)N)
rBrCrDrE�HUGErMrcrhrjrkrrzr}r
r
r
rrn^s#

-rnc@s.eZdZd
dd�Zdd�Zdd�Zdd	�ZdS)�NegatedPatternNcCs|dk	r||_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)ra)rrar
r
rrMs	zNegatedPattern.__init__cCsdS)NFr
)rr.r
r
rrh)szNegatedPattern.matchcCst|�dkS)Nr)r])rrir
r
rrj-szNegatedPattern.match_seqccsL|jdkr"t|�dkrHdifVn&x|jj|�D]
\}}dSWdifVdS)Nr)rar]rk)rrirrrgr
r
rrk1s
zNegatedPattern.generate_matches)N)rBrCrDrMrhrjrkr
r
r
rr�s

r�c	cs�|sdifVn�|d|dd�}}xl|j|�D]^\}}|sJ||fVq2xDt|||d��D].\}}i}|j|�|j|�|||fVq^Wq2WdS)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)rkre)	Zpatternsri�p�restr�r�r�r�rgr
r
rrk=s


rk)rE�
__author__rH�warnings�iorr�rrrrrJr,r^r_rlrmrnr�rkr
r
r
r�<module>s&
1nNV,==#

Zerion Mini Shell 1.0