3 ܓi!@s6ddlZddlZddlZddlmZGdddZdS)N)Pathc@seZdZdZgZgZdZdZdZddZ ddZ dd Z d d Z d d Z ddZddZddZddZddZddZddZdS)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. TFcCsJi|_t|_g|_|jjj|_||_t j j |jd|j|_ |j dS)NZ cleaner_cache)datasetset _regexes_madecompiled_regexes __class____name__lowerZcnameworkdirospathjoin cache_dir load_entries)selfr r/usr/lib/python3.6/__init__.py__init__ s  zSoSMap.__init__cCs"t|jjddd|jddS)ai Load cached entries from the disk. This method must be called when we initialize a Map instance and whenever we want to retrieve self.dataset (e.g. to store default_mapping file). The later is essential since a concurrent Map can add more objects to the cache, so we need to update self.dataset up to date. Keep in mind that size of self.dataset is usually bigger than number of files in the corresponding cleaner's directory: directory contains just whole items (e.g. IP addresses) while dataset contains more derived objects (e.g. subnets). T)parentsexist_okN)rrmkdirload_new_entries_from_dir)rrrrr,s zSoSMap.load_entriescCs\| s0||jks0||jjks0|jr4t|dkr4dSx"|jD]}tj||tjrsz'SoSMap.add_regex_item..T)keyreverse)r%rr r=rappendget_regex_resultsort)rr#rrrr+s   zSoSMap.add_regex_itemcCs2|jrdtj|d}n tj|}tj|tjS)a9Generate 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 (? s