%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/sos/cleaner/parsers/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/sos/cleaner/parsers/__pycache__/__init__.cpython-312.pyc

�

i��d�� �ddlZGd�d�Zy)�Nc�\�eZdZdZdZgZgZgZdZdZ	ifd�Z
d�Zd�Zd�Z
d	�Zd
�Zd�Zd�Zy
)�SoSCleanerParsera�Parsers are used to build objects that will take a line as input,
    parse it for a particular pattern (E.G. IP addresses) and then make any
    necessary subtitutions by referencing the SoSMap() associated with the
    parser.

    Ideally a new parser subclass will only need to set the class level attrs
    in order to be fully functional.

    :param conf_file: The configuration file to read from
    :type conf_file: ``str``

    :cvar name:     The parser name, used in logging errors
    :vartype name: ``str``

    :cvar regex_patterns:   A list of regex patterns to iterate over for every
                            line processed
    :vartype regex_patterns: ``list``

    :cvar mapping: Used by the parser to store and obfuscate matches
    :vartype mapping: ``SoSMap()``


    :cvar map_file_key: The key in the ``map_file`` to read when loading
                        previous obfuscation matches
    :vartype map_file_key: ``str``
    zUndefined Parser�unsetTc��|j|vr(|jj||j�|j�y)N)�map_file_key�mapping�conf_update�_generate_skip_regexes)�self�configs  �>/usr/lib/python3/dist-packages/sos/cleaner/parsers/__init__.py�__init__zSoSCleanerParser.__init__1s9������&��L�L�$�$�V�D�,=�,=�%>�?��#�#�%�c��g|_|jD]0}|jjtj|���2y)z�Generate the regexes for the parser's configured `skip_files`,
        so that we don't regenerate them on every file being examined for if
        the parser should skip a given file.
        N)�
skip_patterns�
skip_files�append�re�compile)r�ps  r
r
z'SoSCleanerParser._generate_skip_regexes6s;��
 ������	5�A����%�%�b�j�j��m�4�	5rc��|jsy|jjD]}|jj|��y)z�Generate regexes for items the parser will be searching for
        repeatedly without needing to generate them for every file and/or line
        we process

        Not used by all parsers.
        N)�compile_regexesr�dataset�add_regex_item)r�obitems  r
�generate_item_regexesz&SoSCleanerParser.generate_item_regexes?s;���#�#���l�l�*�*�	0�F��L�L�'�'��/�	0rc��d}|jD]-}tj||tj�s�)||fcS|jr|j|�\}}||z
}|j
|�\}}||z
}||fS)a�This will be called for every line in every file we process, so that
        every parser has a chance to scrub everything.

        This will first try to identify needed obfuscations for items we have
        already encountered (if the parser uses compiled regexes that is) and
        make those substitutions early on. After which, we will then parse the
        line again looking for new matches.
        r)�skip_line_patternsr�match�Ir�!_parse_line_with_compiled_regexes�_parse_line)r�line�count�skip_pattern�_rcount�_counts      r
�
parse_linezSoSCleanerParser.parse_lineKs����� �3�3�	#�L��x�x��d�B�D�D�1��U�{�"�	#���� �B�B�4�H�M�D�'��W��E��'�'��-���f�
�����U�{�rc���d}|jjD]X\}}|j|�s�|j|jj	|j��|�\}}||z
}�Z||fS)ahCheck the provided line against known items we have encountered
        before and have pre-generated regex Pattern() objects for.

        :param line:    The line to parse for possible matches for obfuscation
        :type line:     ``str``

        :returns:   The obfuscated line and the number of changes made
        :rtype:     ``str``, ``int``
        r)r�compiled_regexes�search�subn�get�lower)rr#r$�item�regr's      r
r!z2SoSCleanerParser._parse_line_with_compiled_regexes_sp�������6�6�	 �I�D�#��z�z�$��"�x�x����(8�(8�����(F��M���f�����	 ��U�{�rc���d}|jD]�}tj||tj�D�cgc]}|d��	}}|s�;|j	dt
��|t|�z
}|D]l}|j
�}||jjj�vr�:|jj|�}||k7s�[|j||�}�n��||fScc}w)aRCheck the provided line against the parser regex patterns to try
        and discover _new_ items to obfuscate

        :param line: The line to parse for possible matches for obfuscation
        :type line: ``str``

        :returns: The obfsucated line, and the number of changes made
        :rtype: ``tuple``, ``(str, int))``
        rT��reverse�key)�regex_patternsr�findallr �sort�len�striprr�valuesr-�replace)rr#r$�pattern�m�matchesr�	new_matchs        r
r"zSoSCleanerParser._parse_lineps������*�*�	>�G�%'�Z�Z���r�t�t�%D�E��q��t�E�G�E�����T�s��3���W��%��$�>�E�!�K�K�M�E����� 4� 4� ;� ;� =�=� � $��� 0� 0�� 7�I� �E�)�#�|�|�E�9�=��
>�	>��U�{���Fs�C&c��|jr]|jjD]B\}}|j|�s�|j	|jj|�|�}�D|St
|jjj�dd���D]5\}}||jjvr�||vs�$|j||�}�7|S)a�Parse a given string for instances of any obfuscated items, without
        applying the normal regex comparisons first. This is mainly used to
        obfuscate filenames that have, for example, hostnames in them.

        Rather than try to regex match the string_data, just use the builtin
        checks for substrings matching known obfuscated keys

        :param string_data: The line to be parsed
        :type string_data: ``str``

        :returns: The obfuscated line
        :rtype: ``str``
        Tc��t|d�S)Nr)r8)�xs r
�<lambda>z8SoSCleanerParser.parse_string_for_keys.<locals>.<lambda>�s��c�!�A�$�i�rr2)rrr*r+�subr-�sortedr�items�	skip_keysr;)r�string_datar/r0�k�obs      r
�parse_string_for_keysz&SoSCleanerParser.parse_string_for_keys�s������!�\�\�:�:�
O�	��c��:�:�k�*�"%�'�'�$�,�,�*:�*:�4�*@�+�"N�K�
O���
 ���� 4� 4� :� :� <�d�$7�9�
=���2�����.�.�.����#�"-�"5�"5�a��"<�K�
=��rc�.�|jjS)z�Get the contents of the mapping used by the parser

        :returns: All matches and their obfuscate counterparts
        :rtype: ``dict``
        )rr)rs r
�get_map_contentsz!SoSCleanerParser.get_map_contents�s���|�|�#�#�#rN)�__name__�
__module__�__qualname__�__doc__�namer5rrrrrr
rr(r!r"rKrM�rr
rrsS���6�D��N����J��L��O� �&�
5�
0��(�"�2�6$rr)rrrSrr
�<module>rTs��
�\$�\$r

Zerion Mini Shell 1.0