wasp_general package¶
Subpackages¶
- wasp_general.cli package
- wasp_general.command package
- wasp_general.crypto package
- wasp_general.network package
- Subpackages
- wasp_general.network.beacon package
- wasp_general.network.clients package
- wasp_general.network.messenger package
- Submodules
- wasp_general.network.messenger.auth module
- wasp_general.network.messenger.coders module
- wasp_general.network.messenger.composer module
- wasp_general.network.messenger.envelope module
- wasp_general.network.messenger.layers module
- wasp_general.network.messenger.onion module
- wasp_general.network.messenger.packers module
- wasp_general.network.messenger.proto module
- wasp_general.network.messenger.session module
- wasp_general.network.messenger.transport module
- Module contents
- wasp_general.network.web package
- Submodules
- wasp_general.network.web.cookies module
- wasp_general.network.web.debug module
- wasp_general.network.web.headers module
- wasp_general.network.web.proto module
- wasp_general.network.web.re_statements module
- wasp_general.network.web.request module
- wasp_general.network.web.response module
- wasp_general.network.web.service module
- wasp_general.network.web.session module
- wasp_general.network.web.template_response module
- wasp_general.network.web.tornado module
- Module contents
- Submodules
- wasp_general.network.primitives module
- wasp_general.network.service module
- wasp_general.network.transport module
- wasp_general.network.upload module
- Module contents
- Subpackages
- wasp_general.os package
- wasp_general.task package
- wasp_general.types package
Submodules¶
wasp_general.cache module¶
-
class
wasp_general.cache.WCacheStorage[source]¶ Bases:
objectAbstract class for cache storage
-
class
CacheEntry(has_value=False, cached_value=None)[source]¶ Bases:
objectCache request result, is used in
WCacheStorage.get_cache()to determine if there is a cached value and what that value is.
-
exception
CacheMissedException[source]¶ Bases:
ExceptionException is raised in
WCacheStorage.get_result()and derived methods as an error for accessing cache record that doesn’t exist
-
clear(decorated_function=None)[source]¶ Remove results from this storage
Parameters: decorated_function – if specified, then results will be removed for this function only Returns: None
-
get_cache(decorated_function, *args, **kwargs)[source]¶ Get cache entry (
WCacheStorage.CacheEntry) for the specified argumentsParameters: - decorated_function – called function (original)
- args – args with which function is called
- kwargs – kwargs with which function is called
Returns: WCacheStorage.CacheEntry
-
get_result(decorated_function, *args, **kwargs)[source]¶ Get result from storage for specified function. Will raise an exception (
WCacheStorage.CacheMissedException) if there is no cached result.Parameters: - decorated_function – called function (original)
- args – args with which function is called
- kwargs – kwargs with which function is called
Returns: (any type, even None)
-
class
-
class
wasp_general.cache.WGlobalSingletonCacheStorage[source]¶ Bases:
wasp_general.cache.WCacheStorageSimple storage that acts as global singleton. Result (singleton) is saved on the very first call. It doesn’t matter with which parameters function was called, result will be the same for all the rest calls.
-
clear(decorated_function=None)[source]¶ WCacheStorage.clear()method implementation
-
get_cache(decorated_function, *args, **kwargs)[source]¶ WCacheStorage.get_cache()method implementation
-
get_result(decorated_function, *args, **kwargs)[source]¶ WCacheStorage.get_result()method implementation
-
has(decorated_function, *args, **kwargs)[source]¶ WCacheStorage.has()method implementation
-
put(result, decorated_function, *args, **kwargs)[source]¶ WCacheStorage.put()method implementation
-
-
class
wasp_general.cache.WInstanceSingletonCacheStorage(cache_record_cls=None, statistic=False)[source]¶ Bases:
wasp_general.cache.WCacheStorageThis storage acts similar to
WGlobalSingletonCacheStoragestorage, but works with bounded methods only (class methods or object method). For every object it keeps results with “cache-record” class (WInstanceSingletonCacheStorage.InstanceCacheRecord), this class (is used by default) saves the very first result and returns it every time. For example, by default if we have two object derived from the same class, and the same method is called, then this storage will keep two separate results, one for each instance.Exact behaviour can be tweaked through
WInstanceSingletonCacheStorage.InstanceCacheRecordinheritance. So derived “cache-records” classes can do things in there own way, they may save every called result, or may not save anything.This class was extended to support internal statistics with cache hits and misses. Still, this class is not thread safe, but accessing statistics from a separate thread should work. Statistics is calculated for records that was fetch through
WInstanceSingletonCacheStorage.get_cache()method onlyNote: This implementation uses weakrefs, so memory leak doesn’t happen (here). -
class
InstanceCacheRecord(result, decorated_function)[source]¶ Bases:
objectClass is used to save cached results for the specified method and for the single instance. This class saves the very first result only. This class uses
WCacheStorage.CacheEntrythe same way asWCacheStoragestorage does - it help to determine, whether there is a cached value or not.Because derived class constructor signature may differ from this class constructor signature, then in order to create cache record there should be a unified method, which is
WInstanceSingletonCacheStorage.InstanceCacheRecord.create()-
cache_entry(*args, **kwargs)[source]¶ Return cache entry for the specified arguments
Parameters: - args – args with which bounded method was called
- kwargs – kwargs with which bounded method was called
Returns: WCacheStorage.CacheEntry
-
classmethod
create(result, decorated_function, *args, **kwargs)[source]¶ Create new “cache-record” for the specified arguments
Parameters: - result – result to keep
- decorated_function – called bounded method
- args – args with which bounded method was called
- kwargs – kwargs with which bounded method was called
Returns: WInstanceSingletonCacheStorage.InstanceCacheRecord
-
-
cache_hit()[source]¶ Return cache hits (return None if class was constructed without ‘statistic’ flag)
Returns: int or None
-
cache_missed()[source]¶ Return cache misses (return None if class was constructed without ‘statistic’ flag)
Returns: int or None
-
clear(decorated_function=None)[source]¶ WCacheStorage.clear()method implementation (Clears statistics also)
-
get_cache(decorated_function, *args, **kwargs)[source]¶ WCacheStorage.get_cache()method implementation
-
put(result, decorated_function, *args, **kwargs)[source]¶ WCacheStorage.put()method implementation
-
class
-
wasp_general.cache.cache_control(validator=None, storage=None)[source]¶ Decorator that is used for caching result.
Parameters: - validator – function, that has following signature (decorated_function, *args, **kwargs), where decorated_function - original function, args - function arguments, kwargs - function keyword arguments. This function must return True if cache is valid (old result must be use if it there is one), or False - to generate and to store new result. So function that always return True can be used as singleton. And function that always return False won’t cache anything at all. By default (if no validator is specified), it presumes that cache is always valid.
- storage – storage that is used for caching results. see
WCacheStorageclass.
Returns: decorated function
wasp_general.composer module¶
-
class
wasp_general.composer.WClassComposer(*composite_keys, constructor=None)[source]¶ Bases:
wasp_general.composer.WCompositeComposer-
class
ClassConstructor(basic_cls, create_obj_fn=None)[source]¶ Bases:
wasp_general.composer.InstanceConstructor
-
class
ClassKey(key, basic_composer, has_key_fn=None, get_key_fn=None, set_key_fn=None, required=False)[source]¶ Bases:
wasp_general.composer.CompositeKey
-
class
-
class
wasp_general.composer.WCompositeComposer(*composite_keys, constructor=None)[source]¶
-
class
wasp_general.composer.WDictComposer(*composite_keys)[source]¶
wasp_general.config module¶
-
class
wasp_general.config.WConfig(defaults=None, dict_type=<class 'collections.OrderedDict'>, allow_no_value=False, *, delimiters=('=', ':'), comment_prefixes=('#', ';'), inline_comment_prefixes=None, strict=True, empty_lines_in_values=True, default_section='DEFAULT', interpolation=<object object>, converters=<object object>)[source]¶ Bases:
configparser.ConfigParserImproved ConfigParser. Has single method to merge config data (see
WConfig.merge()method) and method, that split coma-separated option value (seeWConfig.split_option()method).-
merge(config)[source]¶ Load configuration from given configuration.
Parameters: config – config to load. If config is a string type, then it’s treated as .ini filename Returns: None
-
merge_section(config, section_to, section_from=None)[source]¶ Load configuration section from other configuration. If specified section doesn’t exist in current configuration, then it will be added automatically.
Parameters: - config – source configuration
- section_to – destination section name
- section_from – source section name (if it is None, then section_to is used as source section name)
Returns: None
-
wasp_general.csv module¶
wasp_general.datetime module¶
-
wasp_general.datetime.local_datetime(dt=None, utc_value=True)[source]¶ Convert UTC datetime and/or datetime without timezone information to local datetime with timezone information
Parameters: - dt – datetime in UTC to convert. If is None, then system datetime value is used
- utc_value – whether dt is a datetime in UTC or in system timezone without timezone information
Returns: datetime for system (local) timezone with tz set
-
wasp_general.datetime.local_tz()[source]¶ Return current system timezone shift from UTC
Returns: datetime.timezone
-
wasp_general.datetime.utc_datetime(dt=None, local_value=True)[source]¶ Convert local datetime and/or datetime without timezone information to UTC datetime with timezone information.
Parameters: - dt – local datetime to convert. If is None, then system datetime value is used
- local_value – whether dt is a datetime in system timezone or UTC datetime without timezone information
Returns: datetime in UTC with tz set
wasp_general.io module¶
-
class
wasp_general.io.WAESWriter(raw, cipher)[source]¶ Bases:
_io.BufferedWriterFile-like writer with transparent encryption
-
class
wasp_general.io.WHashCalculationReader(raw, hash_name)[source]¶ Bases:
wasp_general.io.WBufferedIOReader,wasp_general.io.WHashIO
-
class
wasp_general.io.WHashCalculationWriter(raw, hash_name)[source]¶ Bases:
_io.BufferedWriter,wasp_general.io.WHashIO
-
class
wasp_general.io.WReaderChain(last_io_obj, *links)[source]¶ Bases:
wasp_general.io.WIOChain,_io.BufferedReader
-
class
wasp_general.io.WReaderChainLink(reader_cls, *args, **kwargs)[source]¶ Bases:
wasp_general.io.WIOChainLink
-
class
wasp_general.io.WResponsiveReader(raw, stop_event)[source]¶ Bases:
wasp_general.io.WBufferedIOReader,wasp_general.io.WResponsiveIO
-
class
wasp_general.io.WResponsiveWriter(raw, stop_event)[source]¶ Bases:
_io.BufferedWriter,wasp_general.io.WResponsiveIO
-
class
wasp_general.io.WThrottlingIO(throttling_to=None, maximum_timeout=None)[source]¶ Bases:
wasp_general.io.WIOCounter
-
class
wasp_general.io.WThrottlingReader(raw, throttling_to=None, maximum_timeout=None)[source]¶ Bases:
wasp_general.io.WBufferedIOReader,wasp_general.io.WThrottlingIO
-
class
wasp_general.io.WThrottlingWriter(raw, throttling_to=None, maximum_timeout=None)[source]¶ Bases:
_io.BufferedWriter,wasp_general.io.WThrottlingIO
-
class
wasp_general.io.WWriterChain(last_io_obj, *links)[source]¶ Bases:
wasp_general.io.WIOChain,_io.BufferedWriter
-
class
wasp_general.io.WWriterChainLink(writer_cls, *args, **kwargs)[source]¶ Bases:
wasp_general.io.WIOChainLink
wasp_general.mime module¶
-
wasp_general.mime.mime_type(filename)[source]¶ Guess mime type for the given file name
Note: this implementation uses python_magic package which is not thread-safe, as a workaround global lock is used for the ability to work in threaded environment
Parameters: filename – file name to guess Returns: str
wasp_general.template module¶
wasp_general.thread module¶
wasp_general.uri module¶
wasp_general.verify module¶
-
class
wasp_general.verify.SubclassVerifier(*tags, env_var=None, silent_checks=False)[source]¶ Bases:
wasp_general.verify.VerifierVerifier that is used for type verification. Checks parameter if it is class or subclass of specified class or classes. Specification accepts type or list/tuple/set of types
Example:
@verify_subclass(c=A, e=(A, D)) def foo(a, b, c, d=None, **kwargs): pass
-
check(type_spec, arg_name, decorated_function)[source]¶ Return callable that checks function parameter for class validity. Checks parameter if it is class or subclass of specified class or classes
Parameters: - type_spec – type or list/tuple/set of types
- arg_name – function parameter name
- decorated_function – target function
Returns: function
-
-
class
wasp_general.verify.TypeVerifier(*tags, env_var=None, silent_checks=False)[source]¶ Bases:
wasp_general.verify.VerifierVerifier that is used for type verification. Checks parameter if it is instance of specified class or classes. Specification accepts type or list/tuple/set of types
Example:
@verify_type(a=int, b=str, d=(int, None), e=float) def foo(a, b, c, d=None, **kwargs): pass
-
check(type_spec, arg_name, decorated_function)[source]¶ Return callable that checks function parameter for type validity. Checks parameter if it is instance of specified class or classes
Parameters: - type_spec – type or list/tuple/set of types
- arg_name – function parameter name
- decorated_function – target function
Returns: function
-
-
class
wasp_general.verify.ValueVerifier(*tags, env_var=None, silent_checks=False)[source]¶ Bases:
wasp_general.verify.VerifierVerifier that is used for value verification. Checks parameter if its value passes specified restrictions. Specification accepts function or list/tuple/set of functions. Each function must accept one parameter and must return True or False if it passed restrictions or not.
Example:
@verify_value(a=(lambda x: x > 5, lambda x: x < 10)) @verify_value(c=lambda x: x.a == 'foo', d=lambda x: x is None or x < 0) def foo(a, b, c, d=None, **kwargs): pass
-
check(value_spec, arg_name, decorated_function)[source]¶ Return callable that checks function parameter for value validity. Checks parameter if its value passes specified restrictions.
Parameters: - value_spec – function or list/tuple/set of functions. Each function must accept one parameter and must return True or False if it passed restrictions or not.
- arg_name – function parameter name
- decorated_function – target function
Returns: function
-
-
class
wasp_general.verify.Verifier(*tags, env_var=None, silent_checks=False)[source]¶ Bases:
objectBase class for verifier implementation.
Verifiers are classes, that generates decorators (which are later used for runtime function arguments checking). Derived classes (such as
TypeVerifier,SubclassVerifierandValueVerifier) check arguments for type and/or value validity. But each derived class uses its own syntax for check declaration (seeVerifier.check()).Same checks can be grouped into one sentence if they are used for different arguments. Each statement can be marked by tag or tags for runtime disabling. If statement doesn’t have tag then it always run checks.
Checks can be simple (implemented by lambda-statements) or complex (implemented by standalone functions or classes). Because target function is decorated for checking it is possible to run checks sequentially.
Example:
@verify_type(a=int, b=str, d=(int, None), e=float) @verify_subclass(c=A, args=B) @verify_value(a=(lambda x: x > 5, lambda x: x < 10), args=lambda x: x > 0) @verify_value(c=lambda x: x.a == 'foo', d=lambda x: x is None or x < 0) def foo(a, b, c, d=None, *args, **kwargs): pass
-
check(arg_spec, arg_name, decorated_function)[source]¶ Return callable object that takes single value - future argument. This callable must raise an exception if error occurs. It is recommended to return None if everything is OK
Parameters: - arg_spec – specification that is used to describe check like types, lambda-functions, list of types just anything (see
Verifier.decorator()) - arg_name – parameter name from decorated function
- decorated_function – target function (function to decorate)
Returns: None
- arg_spec – specification that is used to describe check like types, lambda-functions, list of types just anything (see
-
decorate_disabled()[source]¶ Return True if this decoration must be omitted, otherwise - False. This class searches for tags values in environment variable (
Verifier.__default_environment_var__), Derived class can implement any logicReturns: bool
-
decorator(**arg_specs)[source]¶ Return decorator that can decorate target function
Parameters: arg_specs – dictionary where keys are parameters name and values are theirs specification. Specific specification is passed as is to Verifier.check()method with corresponding parameter name.Returns: function
-
static
function_name(fn)[source]¶ Return function name in pretty style
Parameters: fn – source function Returns: str
-
help_info(exc, decorated_function, arg_name, arg_spec)[source]¶ Print debug information to stderr. (Do nothing if object was constructed with silent_checks=True)
Parameters: - exc – raised exception
- decorated_function – target function (function to decorate)
- arg_name – function parameter name
- arg_spec – function parameter specification
Returns: None
-
-
wasp_general.verify.verify_subclass(*tags, **type_kwargs)[source]¶ Shortcut for
SubclassVerifierParameters: - tags – verification tags. See
Verifier.__init__() - type_kwargs – verifier specification. See
SubclassVerifier.check()
Returns: decorator (function)
- tags – verification tags. See
-
wasp_general.verify.verify_type(*tags, **type_kwargs)[source]¶ Shortcut for
TypeVerifierParameters: - tags – verification tags. See
Verifier.__init__() - type_kwargs – verifier specification. See
TypeVerifier.check()
Returns: decorator (function)
- tags – verification tags. See
-
wasp_general.verify.verify_value(*tags, **type_kwargs)[source]¶ Shortcut for
ValueVerifierParameters: - tags – verification tags. See
Verifier.__init__() - type_kwargs – verifier specification. See
ValueVerifier.check()
Returns: decorator (function)
- tags – verification tags. See