CasperSecurity

Current Path : /usr/lib/python3.10/lib2to3/__pycache__/
Upload File :
Current File : //usr/lib/python3.10/lib2to3/__pycache__/btm_utils.cpython-310.pyc

o

��bc�&�@s|dZddlmZddlmZmZddlmZmZeZ	eZ
ejZeZ
dZdZdZGdd	�d	e�Zddd�Zd
d�Zdd�Zd
S)z0Utility functions used by the btm_matcher module�)�pytree)�grammar�token)�pattern_symbols�python_symbols���������c@s:eZdZdZd
dd�Zdd�Zdd�Zd	d
�Zdd�ZdS)�MinNodez�This class serves as an intermediate representation of the
    pattern tree during the conversion to sets of leaf-to-root
    subpatternsNcCs.||_||_g|_d|_d|_g|_g|_dS)NF)�type�name�children�leaf�parent�alternatives�group)�selfrr�r�(/usr/lib/python3.10/lib2to3/btm_utils.py�__init__s
zMinNode.__init__cCst|j�dt|j�S)N� )�strrr)rrrr�__repr__szMinNode.__repr__cCs�|}g}|rt|jtkr0|j�|�t|j�t|j�kr(t|j�g}g|_|j}q|j}d}	|S|jtkrY|j	�|�t|j	�t|j�krQt
|j	�}g|_	|j}q|j}d}	|S|jtjkri|j
ri|�|j
�n|�|j�|j}|s|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�subprrr�leaf_to_root!s>

�
	��"zMinNode.leaf_to_rootcCs&|��D]}|��}|r|SqdS)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"rrr�get_linear_subpatternKs��zMinNode.get_linear_subpatternccs0�|jD]	}|��EdHq|js|VdSdS)z-Generator that returns the leaves of the treeN)r
r$)r�childrrrr$`s�

�zMinNode.leaves)NN)	�__name__�
__module__�__qualname__�__doc__rrr#r&r$rrrrr
s
	*r
Nc
Cs�d}|jtjkr
|jd}|jtjkrIt|j�dkr$t|jd|�}�n�ttd�}|jD]}|j�	|�dr7q,t||�}|durF|j�
|�q,�nw|jtjkrt|j�dkruttd�}|jD]}t||�}|rm|j�
|�q^|jssd}�nKt|jd|�}�nA|jtj
k�r�t|jdtj�r�|jdjdkr�t|jd|�St|jdtj�r�|jdjdks�t|j�dkr�t|jdd�r�|jdjdkr�dSd	}d}d}d
}d}	d
}
|jD].}|jtjkr�d
}|}n|jtjkr�d	}|}	n|jtjkr�|}t|d��r|jdk�rd	}
q�|
�r!|jd}t|d��r |jdk�r |jd}n|jd}|jtjk�rT|jd
k�r9ttd�}nItt|j��rJttt|j�d�}n8ttt|j�d�}n.|jtjk�rv|j�d�}|tv�rntt|d�}nttj|d�}n|jtjk�r�t||�}|�r�|	jdjdk�r�d}n|	jdjdk�r�nt�|�r�|du�r�|jdd�D]}t||�}|du�r�|j�
|��q�|�r�||_|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��)rr�(�[�valueTF�=��any�')rr�*�+r)r�syms�Matcherr
�Alternativesr�reduce_treer
r�indexr�Alternativer�Unit�
isinstancer�Leafr0�hasattr�Details�Repeaterrr �TYPE_ANY�getattr�pysyms�STRING�strip�tokens�NotImplementedErrorr)
r!r�new_noder'�reducedr�details_node�alternatives_node�has_repeater�
repeater_node�has_variable_name�	name_leafrrrrr:gs�



��


���
�

�




�r:cs�t|t�s|St|�dkr|dSg}g}gd��g}d�|D]2}tt|dd���rQtt|�fdd���r;|�|�qtt|�fdd���rL|�|�q|�|�q|rW|}n	|r\|}n|r`|}t|td	�S)
z�Picks the most characteristic from a list of linear patterns
    Current order used is:
    names > common_names > common_chars
    rr,)�in�for�if�not�Nonez[]().,:cSst|�tuS�N)rr��xrrr�<lambda>�sz/get_characteristic_subpattern.<locals>.<lambda>c�t|t�o|�vSrW�r>rrX)�common_charsrrrZ�cr[rWr\rX)�common_namesrrrZr^)�key)r>�listrr3�rec_testr�max)�subpatterns�subpatterns_with_names�subpatterns_with_common_names�subpatterns_with_common_chars�
subpatternr)r]r_rr�s8

�
�
�rccs:�|D]}t|ttf�rt||�EdHq||�VqdS)zPTests test_func on all items of sequence and items of included
    sub-iterablesN)r>rarrb)�sequence�	test_funcrYrrrrbs��rbrW)r+�r�pgen2rr�pygramrrr7rE�opmaprHrrCrr�objectr
r:rrbrrrr�<module>s 
W%
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY