o
    *b-                     @   s&   d dl Z d dlmZ G dd dZdS )    N)Lockc                   @   sP   e Zd ZdZg Zg Zdd Zdd Zdd Zdd	 Z	d
d Z
dd Zdd ZdS )SoSMapzStandardized 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.
    c                 C   s   i | _ t | _d S N)datasetr   lock)self r   ?/usr/lib/python3/dist-packages/sos/cleaner/mappings/__init__.py__init__   s   zSoSMap.__init__c                 C   s"   | j D ]}t||r dS qdS )zSome items need to be completely ignored, for example link-local or
        loopback addresses should not be obfuscated
        TN)ignore_matchesrematch)r   itemskipr   r   r	   ignore_item    s
   
zSoSMap.ignore_itemc                 C   s   || j  v S r   )r   valuesr   r   r   r   r	   item_in_dataset_values(   s   zSoSMap.item_in_dataset_valuesc                 C   sZ   | j   |s|W  d   S | || j|< | j| W  d   S 1 s&w   Y  dS )zAdd a particular item to the map, generating an obfuscated pair
        for it.

        Positional arguments:

            :param item:        The plaintext object to obfuscate
        N)r   sanitize_itemr   r   r   r   r	   add+   s   $z
SoSMap.addc                 C   s   |S )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   r   r   r   r	   r   9   s   	zSoSMap.sanitize_itemc                 C   s:   |r|  |s| |r|S || jvr| |S | j| S )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   r   r   r   r	   getD   s   


z
SoSMap.getc                 C   s   | j | dS )a)  Update the map using information from a previous run to ensure that
        we have consistent obfuscation between reports

        Positional arguments:

            :param map_dict:    A dict of mappings with the form of
                                {clean_entry: 'obfuscated_entry'}
        N)r   update)r   Zmap_dictr   r   r	   conf_updateO   s   	zSoSMap.conf_updateN)__name__
__module____qualname____doc__r   Z	skip_keysr
   r   r   r   r   r   r   r   r   r   r	   r      s    r   )r   Z	threadingr   r   r   r   r   r	   <module>   s   
