AlkantarClanX12

Your IP : 18.191.202.48


Current Path : /opt/alt/python33/lib64/python3.3/lib2to3/__pycache__/
Upload File :
Current File : //opt/alt/python33/lib64/python3.3/lib2to3/__pycache__/btm_utils.cpython-33.pyc

�
��f'c@s�dZddlmZddlmZmZddlmZmZeZ	eZ
ejZeZ
dZdZdZGdd�de�Zdd	d
�Zdd�Zd
d�ZdS(u0Utility functions used by the btm_matcher modulei(upytree(ugrammarutoken(upattern_symbolsupython_symbolsiicBs\|EeZdZdZdddd�Zdd�Zdd�Zdd	�Zd
d�Z	dS(
uMinNodeu�This class serves as an intermediate representation of the
    pattern tree during the conversion to sets of leaf-to-root
    subpatternscCsC||_||_g|_d|_d|_g|_g|_dS(NF(	utypeunameuchildrenuFalseuleafuNoneuparentualternativesugroup(uselfutypeuname((u6/opt/alt/python33/lib64/python3.3/lib2to3/btm_utils.pyu__init__s						uMinNode.__init__cCst|j�dt|j�S(Nu (ustrutypeuname(uself((u6/opt/alt/python33/lib64/python3.3/lib2to3/btm_utils.pyu__repr__suMinNode.__repr__cCsU|}g}xB|rP|jtkr�|jj|�t|j�t|j�kr|t|j�g}g|_|j}qq�|j}d}Pn|jt	kr|j
j|�t|j
�t|j�kr�t|j
�}g|_
|j}qq|j}d}Pn|jtj
kr4|jr4|j|j�n|j|j�|j}qW|S(u�Internal method. Returns a characteristic path of the
        pattern tree. This method must be run for all leaves until the
        linear subpatterns are merged into a singleN(utypeuTYPE_ALTERNATIVESualternativesuappendulenuchildrenutupleuparentuNoneu
TYPE_GROUPugroupuget_characteristic_subpatternutoken_labelsuNAMEuname(uselfunodeusubp((u6/opt/alt/python33/lib64/python3.3/lib2to3/btm_utils.pyuleaf_to_root!s8							
uMinNode.leaf_to_rootcCs1x*|j�D]}|j�}|r
|Sq
WdS(u�Drives the leaf_to_root method. The reason that
        leaf_to_root must be run multiple times is because we need to
        reject 'group' matches; for example the alternative form
        (a | b c) creates a group [b c] that needs to be matched. Since
        matching multiple linear patterns overcomes the automaton's
        capabilities, leaf_to_root merges each group into a single
        choice based on 'characteristic'ity,

        i.e. (a|b c) -> (a|b) if b more characteristic than c

        Returns: The most 'characteristic'(as defined by
          get_characteristic_subpattern) path for the compiled pattern
          tree.
        N(uleavesuleaf_to_root(uselfulusubp((u6/opt/alt/python33/lib64/python3.3/lib2to3/btm_utils.pyuget_linear_subpatternKsuMinNode.get_linear_subpatternccsEx-|jD]"}x|j�D]}|VqWq
W|jsA|VndS(u-Generator that returns the leaves of the treeN(uchildrenuleaves(uselfuchildux((u6/opt/alt/python33/lib64/python3.3/lib2to3/btm_utils.pyuleaves`s

	uMinNode.leavesN(
u__name__u
__module__u__qualname__u__doc__uNoneu__init__u__repr__uleaf_to_rootuget_linear_subpatternuleaves(u
__locals__((u6/opt/alt/python33/lib64/python3.3/lib2to3/btm_utils.pyuMinNodes	*uMinNodec
Csd}|jtjkr(|jd}n|jtjkr�t|j�dkrht|jd|�}q�tdt	�}x�|jD]P}|jj
|�dr�q�nt||�}|dk	r�|jj|�q�q�Wn'|jtjkrxt|j�dkr_tdt
�}x9|jD].}t||�}|r|jj|�qqW|jsud}quq�t|jd|�}n�|jtjkr�t|jdtj�r�|jdjdkr�t|jd|�St|jdtj�r�|jdjdks=t|j�dkrAt|jdd�rA|jdjdkrAdSd}d}d}d}d}	d}
x�|jD]�}|jtjkr�d}|}n<|jtjkr�d}|}	n|jtjkr�|}nt|d�ro|jdkrod}
qoqoW|
rA|jd}t|d�rN|jdkrN|jd	}qNn
|jd}|jtjkr�|jd
kr�tdt�}qTtt|j�r�tdtt|j��}qTtdtt|j��}n�|jtjkr0|jjd�}|tkrtdt|�}qTtdtjd|�}n$|jtjkrTt||�}n|r�|	jdjd
kryd}q�|	jdjdkr�q�t �n|r�|dk	r�xL|jdd�D]4}t||�}|dk	r�|jj|�q�q�Wq�n|r||_!n|S(u�
    Internal function. Reduces a compiled pattern tree to an
    intermediate representation suitable for feeding the
    automaton. This also trims off any optional pattern elements(like
    [a], a*).
    iiutypeiu(u[uvalueu=iuanyu'unameu*u+NTFi����("uNoneutypeusymsuMatcheruchildrenuAlternativesulenureduce_treeuMinNodeuTYPE_ALTERNATIVESuindexuappenduAlternativeu
TYPE_GROUPuUnitu
isinstanceupytreeuLeafuvalueuhasattruTrueuFalseuDetailsuRepeaterutoken_labelsuNAMEuTYPE_ANYugetattrupysymsuSTRINGustriputokensuNotImplementedErroruparent(
unodeuparentunew_nodeuchildureduceduleafudetails_nodeualternatives_nodeuhas_repeateru
repeater_nodeuhas_variable_nameu	name_leafuname((u6/opt/alt/python33/lib64/python3.3/lib2to3/btm_utils.pyureduce_treehs�				


	ureduce_treecs5t|t�s|St|�dkr-|dSg}g}dddddg�g}d�x�|D]�}tt|d	d
���ratt|�fdd
���r�|j|�q�tt|�fdd
���r�|j|�q�|j|�qaqaW|r|}n|r|}n|r%|}nt|d
t�S(u�Picks the most characteristic from a list of linear patterns
    Current order used is:
    names > common_names > common_chars
    iiuinuforuifunotuNoneu[]().,:cSst|�tkS(N(utypeustr(ux((u6/opt/alt/python33/lib64/python3.3/lib2to3/btm_utils.pyu<lambda>�su/get_characteristic_subpattern.<locals>.<lambda>cst|t�o|�kS(N(u
isinstanceustr(ux(ucommon_chars(u6/opt/alt/python33/lib64/python3.3/lib2to3/btm_utils.pyu<lambda>scst|t�o|�kS(N(u
isinstanceustr(ux(ucommon_names(u6/opt/alt/python33/lib64/python3.3/lib2to3/btm_utils.pyu<lambda>sukey(u
isinstanceulistulenuanyurec_testuappendumax(usubpatternsusubpatterns_with_namesusubpatterns_with_common_namesusubpatterns_with_common_charsu
subpattern((ucommon_charsucommon_namesu6/opt/alt/python33/lib64/python3.3/lib2to3/btm_utils.pyuget_characteristic_subpattern�s2
					uget_characteristic_subpatternccsWxP|D]H}t|ttf�rDx*t||�D]}|Vq2Wq||�VqWdS(uPTests test_func on all items of sequence and items of included
    sub-iterablesN(u
isinstanceulistutupleurec_test(usequenceu	test_funcuxuy((u6/opt/alt/python33/lib64/python3.3/lib2to3/btm_utils.pyurec_tests

urec_testNi����i����i����(u__doc__uupytreeupgen2ugrammarutokenupygramupattern_symbolsupython_symbolsusymsupysymsuopmaputokensutoken_labelsuTYPE_ANYuTYPE_ALTERNATIVESu
TYPE_GROUPuobjectuMinNodeuNoneureduce_treeuget_characteristic_subpatternurec_test(((u6/opt/alt/python33/lib64/python3.3/lib2to3/btm_utils.pyu<module>s	X�%