dalood package
Subpackages
Submodules
dalood.data_wrapper module
Data wrapper class.
- class dalood.data_wrapper.DataWrapper(loader, src)[source]
Bases:
objectWrapper around loaded data that stores that data and a loader reference, and tracks loading and access times.
dalood.exception module
Custom exceptions.
- class dalood.exception.ExpectedExceptionContext(*expected, error_msg=None)[source]
Bases:
objectContext manager to convert expected exceptions other exception types.
- EXCEPTION_MAP = {<class 'KeyError'>: <class 'dalood.exception.LoaderKeyError'>, <class 'OSError'>: <class 'dalood.exception.LoaderOSError'>, <class 'ValueError'>: <class 'dalood.exception.LoaderValueError'>}[source]
- __init__(*expected, error_msg=None)[source]
- Parameters:
*expected – The expected exceptions to transform into custom exceptions. These must be exception classes that are already in EXCEPTION_MAP.
error_msg – An error message to prepend to the caught exception when instantiating the custom exception. It should provide context for the exception when it is displayed to the user.
dalood.manager module
File manager class.
- class dalood.manager.Manager[source]
Bases:
objectFile manager for loading files on demand and managing memory.
- clear_cache(pattern=None, age=None, by_access_time=False, pattern_type=PatternType.REGEX)[source]
Clear cached data from memory.
- Parameters:
pattern – Same as for
register_loader(). If given, only cached items matching this pattern will be cleared.pattern_type – Same as for
register_loader().age – An optional datetime.timedelta object (or a dict of keyword arguments that can be passed to datetime.timedelta(). If the data has been loaded for longer than this time, it will be cleared.
by_access_time – If True, clear data by last access time when clearing by age, otherwise clear by load time.
- clear_cache_with_glob_pattern(pattern, age=None, by_access_time=False)[source]
Wrapper around
clear_cache()for GLOB patterns.
- clear_cache_with_literal_pattern(pattern, age=None, by_access_time=False)[source]
Wrapper around
clear_cache()for LITERAL patterns.
- clear_cache_with_regex_pattern(pattern, age=None, by_access_time=False)[source]
Wrapper around
clear_cache()for REGEX patterns.
- get(src, refresh=False, reload=False)[source]
Get the data from the given source. The data will be loaded via the loader if necessary.
- Parameters:
src – The data source.
refresh – If True, reload data if the reported modification time is newer
data. (H than the loaded)
reload – If True, force a reload.
- Returns:
The data.
- get_loader(src)[source]
Get the loader that matches the source.
- Parameters:
src – The data source (e.g. a file or URI, or whatever else the matching loader can handle).
- Raises:
ValueError – The given source is not matched by any registered regular expressions.
- get_mtime(src)[source]
Get the modification time of a source.
- Parameters:
src – The data source.
- Returns:
The modification time as a datetime.datetime object, or None.
- refresh(pattern=None, pattern_type=PatternType.REGEX)[source]
Refresh data for which the loader reports a source modification since the time the data was loaded.
- Parameters:
pattern – Same as for
register_loader(). If given, only cached items matching this pattern will be refreshed.pattern_type – Same as for
register_loader().
- register_loader(pattern, loader, *, prioritize=False, pattern_type=PatternType.REGEX)[source]
Register a loader to handle a pattern.
- Parameters:
pattern – Either a string, in which case the pattern type is determined by the pattern_type argument, or an instance of RegexPattern or one of its subclasses.
loader – A subclass of the
LoaderBase.prioritize – If True, insert this regex at the start of the list of registred regexes, otherwise it will be inserted at the end.
pattern_type – The pattern type, either as an instance of
PatternTypeor a string that is recognized byregex.PatternType.from_str()(e.g. “glob”, “literal”).
- register_loader_with_glob_pattern(pattern, loader, *, prioritize=False)[source]
Wrapper around
register_loader()for GLOB patterns.
- register_loader_with_literal_pattern(pattern, loader, *, prioritize=False)[source]
Wrapper around
register_loader()for LITERAL patterns.
- register_loader_with_regex_pattern(pattern, loader, *, prioritize=False)[source]
Wrapper around
register_loader()for REGEX patterns.
dalood.regex module
Regular expression types and functions.
- class dalood.regex.GlobPattern(pattern)[source]
Bases:
RegexPatternGlob pattern.
- class dalood.regex.LiteralPattern(pattern)[source]
Bases:
RegexPatternLiteral pattern.
- class dalood.regex.RegexPattern(pattern, flags=0)[source]
Bases:
objectRegular expression pattern.
- dalood.regex.get_extension_pattern_for_filepath(ext, escape=True)[source]
Get a regular expression pattern for filepaths that end with the given extension. This will exclude URIs, including file URIs.
- Parameters:
ext – The extention to recognize, e.g. “.txt”.
escape – If True, escape the extension for the pattern. This can be set to false whena pre-escaped pattern is passed in, e.g. r”.[tc]sv”.
- Returns:
A RegexPattern or a subclass thereof.
- dalood.regex.get_regex(pattern, pattern_type=PatternType.REGEX)[source]
Get the regular expression corresponding to the given pattern.
- Parameters:
pattern – A string containing a pattern of the specified type that should be converted to a regular expression.
pattern_type – An instance of
PatternTypeor an equivalent string.
- Returns:
An re.Pattern regular expression object.
Module contents
Package stub.