
    ~ g
                     ,    S SK r S SKJr   " S S5      rg)    N)Lockc                   \    \ rS rSrSr/ r/ rSrSrSr	S r
S rS rS rS	 rS
 rS rS rSrg)SoSMap   zStandardized way to store items with their obfuscated counterparts.

Each type of sanitization that SoSCleaner supports should have a
corresponding SoSMap() object, to allow for easy retrieval of obfuscated
items.
TFc                 \    0 U l         [        5       U l        / U l        [	        5       U l        g )N)datasetset_regexes_madecompiled_regexesr   lock)selfs    ?/usr/lib/python3/dist-packages/sos/cleaner/mappings/__init__.py__init__SoSMap.__init__   s$     U "F	    c                 *   U(       aL  XR                   ;   d=  XR                  R                  5       ;   d   U R                  (       a  [	        U5      S::  a  gU R
                   H/  n[        R                  " X![        R                  5      (       d  M/    g   g)zpSome items need to be completely ignored, for example link-local or
loopback addresses should not be obfuscated
   TF)		skip_keysr   valuesignore_short_itemslenignore_matchesrematchI)r   itemskips      r   ignore_itemSoSMap.ignore_item%   se     t~~-9L9L9N1N++D	Q''DxxBDD)) ( r   c                    U R                  U5      (       a  U$ U R                     U R                  U5      U R                  U'   U R                  (       a  U R                  U5        U R                  U   sSSS5        $ ! , (       d  f       g= f)zAdd a particular item to the map, generating an obfuscated pair
for it.

Positional arguments:

    :param item:        The plaintext object to obfuscate
N)r   r   sanitize_itemr   compile_regexesadd_regex_itemr   r   s     r   add
SoSMap.add1   sg     D!!KYY!%!3!3D!9DLL####D)<<%	 YYs   AA>>
Bc                    U R                  U5      (       a  gXR                  ;  ab  U R                  R                  U5        U R                  R	                  XR                  U5      45        U R                  R                  S SS9  gg)zAdd an item to the regexes dict and then re-sort the list that the
parsers will use during parse_line()

:param item:    The unobfuscated item to generate a regex for
:type item:     ``str``
Nc                     [        U S   5      $ )Nr   )r   )xs    r   <lambda>'SoSMap.add_regex_item.<locals>.<lambda>V   s    S1Yr   T)keyreverse)r   r
   r%   r   appendget_regex_resultsortr$   s     r   r#   SoSMap.add_regex_itemA   s}     D!!)))
 ""4( !!(($0E0Ed0K)LM!!&&+>&M *r   c                     U R                   (       a  S[        R                  " U5       S3nO[        R                  " U5      n[        R                  " U[        R                  5      $ )a  Generate the object/value that is used by the parser when iterating
over pre-generated regexes during parse_line(). For most parsers this
will simply be a ``re.Pattern()`` object, but for more complex parsers
this can be overridden to provide a different object, e.g. a tuple,
for that parer's specific iteration needs.

:param item:    The unobfuscated string to generate the regex for
:type item:     ``str``

:returns:       A compiled regex pattern for the item
:rtype:         ``re.Pattern``
z(?<![a-z0-9])z
(?=\b|_|-))match_full_words_onlyr   escapecompiler   r$   s     r   r/   SoSMap.get_regex_resultX   sF     %%#BIIdO#4J?D99T?Dzz$%%r   c                     U$ )zPerform the obfuscation relevant to the item being added to the map.

This should be overridden by each type of map that subclasses SoSMap

Positional arguments:

    :param item:        The plaintext object to obfuscate
 r$   s     r   r!   SoSMap.sanitize_itemk   s	     r   c                     U R                  U5      (       a  U$ XR                  ;  a  U R                  U5      $ U R                  U   $ )zRetrieve an item's obfuscated counterpart from the map. If the item
does not yet exist in the map, add it by generating one on the fly
)r   r   r%   r$   s     r   get
SoSMap.getv   sA     D!!K||#88D>!||D!!r   c                 :    U R                   R                  U5        g)zUpdate the map using information from a previous run to ensure that
we have consistent obfuscation between reports

Positional arguments:

    :param config:    A dict of mappings with the form of
                      {clean_entry: 'obfuscated_entry'}
N)r   update)r   configs     r   conf_updateSoSMap.conf_update   s     	F#r   )r
   r   r   r   N)__name__
__module____qualname____firstlineno____doc__r   r   r"   r   r3   r   r   r%   r#   r/   r!   r;   r@   __static_attributes__r8   r   r   r   r      sM     NIO!
& N.&&	"	$r   r   )r   	threadingr   r   r8   r   r   <module>rI      s    
 y$ y$r   