tokio.connectors.common module¶
Common methods and classes used by connectors
-
class
tokio.connectors.common.
CacheableDict
(input_file=None)[source]¶ Bases:
dict
Generic class to support connectors that are dicts that can be cached as JSON
When deriving from this class, the child object will have to define its own
load_native()
method to be invoked wheninput_file
is not JSON.-
__init__
(input_file=None)[source]¶ Either initialize as empty or load from cache
Parameters: input_file (str) – Path to either a JSON file representing the dict or a native file that will be parsed into a JSON-compatible format
-
_save_cache
(output, **kwargs)[source]¶ Generates serialized representation of self
Parameters: output – Object with a .write()
method into which the serialized form of self will be passed
-
load
(input_file=None)[source]¶ Wrapper around the filetype-specific loader.
Infer the type of input being given, dispatch the correct loading function, and populate keys/values.
Parameters: input_file (str or None) – The input file to load. If not specified, uses whatever self.input_file is
-
load_json
(input_file=None)[source]¶ Loads input from serialized JSON
Load the serialized format of this object, encoded as a json dictionary. This is the converse of the save_cache() method.
Parameters: input_file (str or None) – The input file to load. If not specified, uses whatever self.input_file is
-
load_native
(input_file=None)[source]¶ Parse an uncached, native object
This is a stub that should be overloaded on derived classes.
Parameters: input_file (str or None) – The input file to load. If not specified, uses whatever self.input_file is
-
-
class
tokio.connectors.common.
SubprocessOutputDict
(cache_file=None, from_string=None, silent_errors=False)[source]¶ Bases:
dict
Generic class to support connectors that parse the output of a subprocess
When deriving from this class, the child object will have to
- Define subprocess_cmd after initializing this parent object
- Define self.__repr__ (if necessary)
- Define its own self.load_str
- Define any introspective analysis methods
-
load
(cache_file=None)[source]¶ Load based on initialization state of object
Parameters: cache_file (str or None) – The cached input file to load. If not specified, uses whatever self.cache_file is
-
load_cache
(cache_file=None)[source]¶ Load subprocess output from a cached text file
Parameters: cache_file (str or None) – The cached input file to load. If not specified, uses whatever self.cache_file is
-
class
tokio.connectors.common.
SubprocessOutputList
(cache_file=None, from_string=None, silent_errors=False)[source]¶ Bases:
list
Generic class to support connectors that parse the output of a subprocess
When deriving from this class, the child object will have to
- Define subprocess_cmd after initializing this parent object
- Define self.__repr__ (if necessary)
- Define its own self.load_str
- Define any introspective analysis methods
-
load
(cache_file=None)[source]¶ Load based on initialization state of object
Parameters: cache_file (str or None) – The cached input file to load. If not specified, uses whatever self.cache_file is
-
load_cache
(cache_file=None)[source]¶ Load subprocess output from a cached text file
Parameters: cache_file (str or None) – The cached input file to load. If not specified, uses whatever self.cache_file is
-
tokio.connectors.common.
walk_file_collection
(input_source)[source]¶ Walk all member files of an input source.
Iterator that visits every member of an input source (either directory or tarfile) and yields its file name, last modify time, and a file handle to its contents.
Parameters: input_source (str) – A path to either a directory containing files or a tarfile containing files.
Yields: tuple – Attributes for a member of input_source with the following data:
- str: fully qualified path corresponding to its name
- float: last modification time expressed as seconds since epoch
- file: handle to access the member’s contents