IGitt.Utils package¶
Module contents¶
Provides useful stuff, generally!
-
class
IGitt.Utils.
Cache
[source]¶ Bases:
object
A class to manage cache with IGitt and any other external application.
The cache mechanism should be able to process raw JSON data. The response data from external requests is stored in the cache with the API URL of the associated IGitt object as the key and the data is stored along with its entity tag header, which is used alongside If-None-Match header for further queries using conditional requests. When an incoming webhook is received, the timestamp of reception is cached and any queries later on the same URL use the If-Modified-Since HTTP Header and the reception time using conditional requests, since the ETag Header is no longer valid. Note that conditional requests do not add up to rate limits on APIs.
To use IGitt’s caching mechanism for external request management, simply add the following code to your application before using IGitt.
>>> from IGitt.Utils import Cache >>> Cache.use(read_from, write_to)
If not provided, IGitt uses a default in-memory cache. For further details follow the specific method documentation below.
-
classmethod
get
(key) → Optional[dict][source]¶ Retrieves the entry from cache if present, otherwise None.
-
classmethod
update
(key, new_value)[source]¶ Updates the existing entry with new data, if present, otherwise creates a new entry in cache.
-
classmethod
use
(read_from: Callable, write_to: Callable)[source]¶ Connects the cache read, write functions to Cache class.
Parameters: - read_from – The method to be called to fetch data from cache. It should be able to receive only one parameter, key, which is used to identify an entry uniquely in the cache.
- write_to – The method to be called to write data to cache. It should be able to receive two parameters, key (used to identify the entry in cache) and the item to be stored in cache, in the specified respective order.
-
classmethod
validate
(item: dict) → dict[source]¶ Checks if the given item has valid data and adds missing fields with default values. Expected fields are as follows.
Returns: The item dictionary after validation without any missing fields. Also removes any additional unrelated fields from the given dictionary. Raises: TypeError, if the field does not match the expected type. ValueError, if the type is correct, but the value is invalid.
-
classmethod
-
class
IGitt.Utils.
CachedDataMixin
[source]¶ Bases:
object
You provide:
- self._get_data for getting your data
You can also create an IGitt instance with your own data using from_data classmethod.
-
data
¶ Retrieves the data, if needed from the network.
-
default_data
= {}¶
-
class
IGitt.Utils.
LimitedSizeDict
(*args, **kwargs)[source]¶ Bases:
collections.OrderedDict
LimitedSizeDict pops items from the first if the size of dictionary exceeds the specified limit.