Package pyxmpp :: Module expdict :: Class ExpiringDictionary |
[hide private]

# Class ExpiringDictionary

source code

    object --+
             |
          dict --+
                 |
                ExpiringDictionary

An extension to standard Python dictionary objects which implements item expiration.

Each item in ExpiringDictionary has its expiration time assigned, after which the item is removed from the mapping.

Instance Methods | [hide private]
    new empty dictionary
__init__(self, default_timeout=300) Initialize an ExpiringDictionary object. | source code
__delitem__(self, key) del x[y] | source code
__getitem__(self, key) x[y] | source code
v, remove specified key and return the corresponding value |
pop(self, key, default=sentinel) If key is not found, d is returned if given, otherwise KeyError is raised | source code
__setitem__(self, key, value) x[i]=y | source code
set_item(self, key, value, timeout=None, timeout_callback=None) Set item of the dictionary. | source code
expire(self) Do the expiration of dictionary items. | source code
_expire_item(self, key) Do the expiration of a dictionary item. | source code
Inherited from `dict`: `__cmp__`, `__contains__`, `__eq__`, `__ge__`, `__getattribute__`, `__gt__`, `__iter__`, `__le__`, `__len__`, `__lt__`, `__ne__`, `__new__`, `__repr__`, `__sizeof__`, `clear`, `copy`, `fromkeys`, `get`, `has_key`, `items`, `iteritems`, `iterkeys`, `itervalues`, `keys`, `popitem`, `setdefault`, `update`, `values`, `viewitems`, `viewkeys`, `viewvalues` Inherited from `object`: `__delattr__`, `__format__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__str__`, `__subclasshook__`

Class Variables | [hide private]
Inherited from `dict`: `__hash__`

Instance Variables | [hide private]
: `int` | _default_timeout : the default timeout value (in seconds from now).
: `threading.RLock` | _lock : access synchronization lock.
: `dict` | _timeouts : a dictionary with timeout values and timeout callback for stored objects.

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, default_timeout=300) (Constructor) | source code
Initialize an ExpiringDictionary object. Parameters: `default_timeout` (: `int`) - : default timeout value for stored objects. Returns:
    new empty dictionary
Overrides: object.__init__

### __delitem__(self, key) (Index deletion operator) | source code
del x[y] Overrides: dict.__delitem__ (inherited documentation)

### __getitem__(self, key) (Indexing operator) | source code
x[y] Overrides: dict.__getitem__ (inherited documentation)

### pop(self, key, default=sentinel) | source code
If key is not found, d is returned if given, otherwise KeyError is raised Returns: v, remove specified key and return the corresponding value Overrides: dict.pop (inherited documentation)

### __setitem__(self, key, value) (Index assignment operator) | source code
x[i]=y Overrides: dict.__setitem__ (inherited documentation)

### set_item(self, key, value, timeout=None, timeout_callback=None) | source code
Set item of the dictionary. Parameters: `key` (: any hashable value) - : the key. `value` (: any python object) - : the object to store. `timeout` (: `int`) - : timeout value for the object (in seconds from now). `timeout_callback` (: callable) - : function to be called when the item expires. The callback should accept none, one (the key) or two (the key and the value) arguments.

### expire(self) | source code
Do the expiration of dictionary items. Remove items that expired by now from the dictionary.

### _expire_item(self, key) | source code
Do the expiration of a dictionary item. Remove the item if it has expired by now. Parameters: `key` (: any hashable value) - : key to the object.