pypicloud.util module¶
Utilities
-
class
pypicloud.util.
TimedCache
(cache_time: Optional[int], factory: Optional[Callable[[Any], Any]] = None)[source]¶ Bases:
dict
Dict that will store entries for a given time, then evict them
Parameters: - cache_time : int or None
The amount of time to cache entries for, in seconds. 0 will not cache. None will cache forever.
- factory : callable, optional
If provided, when the TimedCache is accessed and has no value, it will attempt to populate itself by calling this function with the key it was accessed with. This function should return a value to cache, or None if no value is found.
-
pypicloud.util.
create_matcher
(queries: List[str], query_type: str) → Callable[[str], bool][source]¶ Create a matcher for a list of queries
Parameters: - queries : list
List of queries
- query_type: str
Type of query to run: [“or”|”and”]
Returns: - Matcher function
-
pypicloud.util.
get_settings
(settings: dict, prefix: str, **kwargs) → dict[source]¶ Convenience method for fetching settings
Returns a dict; any settings that were missing from the config file will not be present in the returned dict (as opposed to being present with a None value)
Parameters: - settings : dict
The settings dict
- prefix : str
String to prefix all keys with when fetching value from settings
- **kwargs : dict
Mapping of setting name to conversion function (e.g. str or asbool)
-
pypicloud.util.
normalize_metadata
(metadata: Dict[str, Union[str, bytes]]) → Dict[str, str][source]¶ Strip non-ASCII characters from metadata values and replace “_” in metadata keys to “-”