Package pyxmpp2 :: Module expdict :: Class ExpiringDictionary
[hide private]

Class 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.0)
Initialize an ExpiringDictionary object.
 
__delitem__(self, key)
del x[y]
 
__getitem__(self, key)
x[y]
v, remove specified key and return the corresponding value
pop(self, key, default=_NO_DEFAULT)
If key is not found, d is returned if given, otherwise KeyError is raised
 
__setitem__(self, key, value)
x[i]=y
 
set_item(self, key, value, timeout=None, timeout_callback=None)
Set item of the dictionary.
float
expire(self)
Do the expiration of dictionary items.
None
clear(self)
Remove all items from D.
 
_expire_item(self, key)
Do the expiration of a dictionary item.

Inherited from dict: __cmp__, __contains__, __eq__, __ge__, __getattribute__, __gt__, __iter__, __le__, __len__, __lt__, __ne__, __new__, __repr__, __sizeof__, 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]
float _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.0)
(Constructor)

 
Initialize an ExpiringDictionary object.
Parameters:
  • default_timeout (float) - default timeout value (in seconds) for stored objects.
Returns:
new empty dictionary

Overrides: object.__init__

__delitem__(self, key)
(Index deletion operator)

 
del x[y]
Overrides: dict.__delitem__
(inherited documentation)

__getitem__(self, key)
(Indexing operator)

 
x[y]
Overrides: dict.__getitem__
(inherited documentation)

pop(self, key, default=_NO_DEFAULT)

 
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)

 
x[i]=y
Overrides: dict.__setitem__
(inherited documentation)

set_item(self, key, value, timeout=None, timeout_callback=None)

 
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)

 

Do the expiration of dictionary items.

Remove items that expired by now from the dictionary.

Returns: float
time, in seconds, when the next item expires or None

clear(self)

 
Remove all items from D.
Returns: None
Overrides: dict.clear
(inherited documentation)

_expire_item(self, key)

 

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.