Utils¶
Just a set of helpful utility methods (HHAC/IP to str, file helpers, log utils).
Network Utils¶
File Utils¶
File utilities that might be useful
-
chains.utils.file_utils.
all_files_in_directory
(path)[source]¶ Recursively list all files under a directory
Parameters: path – the path of the directory to traverse Returns: a list of all the files contained withint the directory
-
chains.utils.file_utils.
file_dir
(file_path)[source]¶ Root directory for a file_path
Parameters: file_path – a fully qualified file path Returns: the directory which contains the file
Log Utils¶
Log utilities that might be useful
Data Utils¶
Data utilities that might be useful
-
chains.utils.data_utils.
make_dict
(obj)[source]¶ This method creates a dictionary out of a non-builtin object
-
chains.utils.data_utils.
get_value
(data, key)[source]¶ Follow the dot notation to get the proper field, then perform the action
Parameters: - data – the data as a dictionary (required to be a dictionary)
- key –
the key (as dot notation) into the data that gives the field (IP.src)
- Returns:
- the value of the field(subfield) if it exist, otherwise None
Cache¶
Cache class for key/value pairs
-
class
chains.utils.cache.
Cache
(max_size=1000, timeout=None)[source]¶ Bases:
object
In process memory cache. Not thread safe. Usage:
cache = Cache(max_size=5, timeout=10) cache.set(‘foo’, ‘bar’) cache.get(‘foo’) >>> bar time.sleep(11) cache.get(‘foo’) >>> None cache.clear()-
set
(key, value)[source]¶ Add an item to the cache :param key: item key :param value: the value associated with this key
-