����JFIF���������
1#@!#!123s
D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
python34
/
lib64
/
python3.4
/
lib2to3
/
__pycache__
/
Filename :
btm_utils.cpython-34.pyc
back
Copy
� i f�&������������������@���s����d��Z��d�d�l�m�Z�d�d�l�m�Z�m�Z�d�d�l�m�Z�m�Z�e�Z �e�Z �e�j�Z�e�Z �d�Z�d�Z�d�Z�Gd�d����d�e���Z�d �d �d���Z�d�d ����Z�d�d����Z�d �S)z0Utility functions used by the btm_matcher module����)�pytree)�grammar�token)�pattern_symbols�python_symbols��������c���������������@���sX���e��Z�d��Z�d�Z�d�d�d�d���Z�d�d����Z�d�d����Z�d �d ����Z�d�d����Z�d�S) �MinNodez�This class serves as an intermediate representation of the pattern tree during the conversion to sets of leaf-to-root subpatternsNc�������������C���sC���|�|��_��|�|��_�g��|��_�d�|��_�d��|��_�g��|��_�g��|��_�d��S)NF)�type�name�children�leaf�parent�alternatives�group)�selfr ���r�����r����6/opt/alt/python34/lib64/python3.4/lib2to3/btm_utils.py�__init__���s���� zMinNode.__init__c�������������C���s���t��|��j���d�t��|��j���S)N� )�strr ���r���)r���r���r���r����__repr__���s����zMinNode.__repr__c�������������C���sU��|��}�g��}�xB|�rP|�j��t�k�r��|�j�j�|���t�|�j���t�|�j���k�r|�t�|�j���g�}�g��|�_�|�j�}�q�q��|�j�}�d�}�Pn��|�j��t�k�r|�j �j�|���t�|�j ���t�|�j���k�r��t �|�j ���}�g��|�_ �|�j�}�q�q|�j�}�d�}�Pn��|�j��t�j�k�r4|�j �r4|�j�|�j ���n�|�j�|�j����|�j�}�q�W|�S)z�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)r ����TYPE_ALTERNATIVESr����append�lenr����tupler���� TYPE_GROUPr����get_characteristic_subpattern�token_labels�NAMEr���)r����node�subpr���r���r����leaf_to_root!���s8���� zMinNode.leaf_to_rootc�������������C���s1���x*�|��j�����D]�}�|�j����}�|�r �|�Sq �Wd�S)a���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)�leavesr"���)r����lr!���r���r���r����get_linear_subpatternK���s����zMinNode.get_linear_subpatternc�������������c���s8���x �|��j��D]�}�|�j����Dd�Hq �W|��j��s4�|��Vn��d�S)z-Generator that returns the leaves of the treeN)r���r#���)r����childr���r���r���r#���`���s���� zMinNode.leaves) �__name__� __module__�__qualname__�__doc__r���r���r"���r%���r#���r���r���r���r���r ������s��� *r ���Nc������� ������C���s��d�}�|��j��t�j�k�r(�|��j�d�}��n��|��j��t�j�k�r��t�|��j���d�k�rh�t�|��j�d�|���}�q�t�d�t���}�x�|��j�D]P�}�|��j�j �|���d�r��q��n��t�|�|���}�|�d�k �r��|�j�j �|���q��q��Wn'|��j��t�j�k�rxt�|��j���d�k�r_t�d�t���}�x9�|��j�D].�}�t�|�|���}�|�r|�j�j �|���qqW|�j�sud�}�quq�t�|��j�d�|���}�n�|��j��t�j �k�r�t�|��j�d�t�j���r�|��j�d�j�d�k�r�t�|��j�d�|���St�|��j�d�t�j���r�|��j�d�j�d�k�s=t�|��j���d�k�rAt�|��j�d�d���rA|��j�d�j�d�k�rAd�Sd �}�d�}�d�}�d �}�d�} �d �} �x��|��j�D]��}�|�j��t�j�k�r�d �}�|�}�n<�|�j��t�j�k�r�d �}�|�} �n�|�j��t�j�k�r�|�}�n��t�|�d���ro|�j�d�k�rod �} �qoqoW| �rA|��j�d�}�t�|�d���rN|�j�d�k�rN|��j�d�}�qNn �|��j�d�}�|�j��t�j�k�r�|�j�d �k�r�t�d�t���}�qTt�t�|�j���r�t�d�t�t�|�j�����}�qTt�d�t�t�|�j�����}�n��|�j��t�j�k�r0|�j�j�d���}�|�t�k�rt�d�t�|���}�qTt�d�t�j�d�|���}�n$�|�j��t�j�k�rTt�|�|���}�n��|�r�| �j�d�j�d�k�ryd�}�q�| �j�d�j�d�k�r�q�t���n��|�r�|�d�k �r�xL�|�j�d�d���D]4�}�t�|�|���}�|�d�k �r�|�j�j �|���q�q�Wq�n��|�r|�|�_�n��|�S)z� 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*). N�����r���r ���r����(�[�valueTF�=r����any�'r����*�+���)r ����symsZMatcherr���ZAlternativesr����reduce_treer ���r����indexr���ZAlternativer���ZUnit� isinstancer���ZLeafr.����hasattrZDetailsZRepeaterr���r����TYPE_ANY�getattr�pysyms�STRING�strip�tokens�NotImplementedErrorr���) r ���r���Znew_noder&���Zreducedr ���Zdetails_nodeZalternatives_nodeZhas_repeaterZ repeater_nodeZhas_variable_nameZ name_leafr���r���r���r���r6���g���s����� r6���c����������������s5��t��|��t���s�|��St�|����d�k�r-�|��d�Sg��}�g��}�d�d�d�d�d�g���g��}�d����x��|��D]��}�t�t�|�d �d ��������ra�t�t�|����f�d�d ��������r��|�j�|���q��t�t�|���f�d�d ��������r��|�j�|���q��|�j�|���qa�qa�W|�r|�}��n�|�r|�}��n�|�r%|�}��n��t�|��d �t��S)z�Picks the most characteristic from a list of linear patterns Current order used is: names > common_names > common_chars r���r+����in�for�if�not�Nonez[]().,:c�������������S���s���t��|����t�k�S)N)r ���r���)�xr���r���r����<lambda>����s����z/get_characteristic_subpattern.<locals>.<lambda>c����������������s���t��|��t���o�|�����k�S)N)r8���r���)rF���)�common_charsr���r���rG������s����c����������������s���t��|��t���o�|�����k�S)N)r8���r���)rF���)�common_namesr���r���rG�����s�����key)r8����listr���r0����rec_testr����max)ZsubpatternsZsubpatterns_with_namesZsubpatterns_with_common_namesZsubpatterns_with_common_chars� subpatternr���)rH���rI���r���r�������s2���� r���c�������������c���sJ���xC�|��D];�}�t��|�t�t�f���r7�t�|�|���Dd�Hq�|�|���Vq�Wd�S)zPTests test_func on all items of sequence and items of included sub-iterablesN)r8���rK���r���rL���)ZsequenceZ test_funcrF���r���r���r���rL�����s���� rL���r4���������)r*�����r���Zpgen2r���r���Zpygramr���r���r5���r<���Zopmapr?���r���r:���r���r����objectr ���r6���r���rL���r���r���r���r����<module>���s��� W�%