Current File : //proc/self/root/lib/python3/dist-packages/sos/cleaner/parsers/__pycache__/__init__.cpython-312.pyc |
�
-�_gq � � � d dl Z G d� d� Zy)� Nc �b � e Zd ZdZdZg Zg Zg Zg ZdZ dZ
i g fd�Zd� Zd� Z
d� Zd � 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 |v r(| j j || j � || _ | j � y )N)�map_file_key�mapping�conf_update�skip_cleaning_files�_generate_skip_regexes)�self�configr
s �>/usr/lib/python3/dist-packages/sos/cleaner/parsers/__init__.py�__init__zSoSCleanerParser.__init__4 sA � �����&��L�L�$�$�V�D�,=�,=�%>�?�#6�� ��#�#�%� c � � g | _ | j | j z D ]0 }| j j t j
|� � �2 y)z�Generate the regexes for the parser's configured parser_skip_files
or global skip_cleaning_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�parser_skip_filesr
�append�re�compile)r �ps r r z'SoSCleanerParser._generate_skip_regexes: sH � �
����'�'�$�*B�*B�B� 5�A����%�%�b�j�j��m�4� 5r c � � | j sy| j j D ] }| j j |� � 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_regexesC s; � � �#�#���l�l�*�*� 0�F��L�L�'�'��/� 0r c � � d}| j D ]- }t j ||t j � s�)||fc S | j r| 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_lineO s� � � �� �3�3� #�L��x�x��d�B�D�D�1��U�{�"� #� ��� �B�B�4�H�M�D�'��W��E��'�'��-���f�
�����U�{�r c �� � d}| j j D ]X \ }}|j |� s�|j | j j |j � � |� \ }}||z
}�Z ||fS )ah Check 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)r r$ r% �item�regr( s r r"