Class CaselessDict
This class is a wrapper around a dictionary, where all keys are
treated lower case (where applicable). If a 'notFoundError' exception is
passed in the classes' constructor this exception will be raised on
access to a non-existing key. The first argument of the exception is the
key, followed by all arguments described by 'exceptionArgs' of the
constructor.
| Method Summary |
| |
__init__(self,
notFoundError,
*exceptionArgs)
|
| |
__delitem__(self,
key)
This function removes a given element from the dictionary. |
| |
__getitem__(self,
key)
This function returns the item of the dictionary with the given
key. |
| |
__len__(self)
Return number of items in the dictionary |
| |
__repr__(self)
This function returns a string representation of the dictionary |
| |
__setitem__(self,
key,
value)
This function sets or adds a key with a given value to the
dictionary. |
| |
clear(self)
This function clears the wrapped dictionary. |
| |
fromkeys(self,
keys,
value)
This function is a class method taht returns a new dictionary, having
all keys listed in the given sequence. |
| |
get(self,
key,
default)
|
| |
has_key(self,
key)
This function returns True if a given key exists in the dictionary,
False otherwise. |
| |
items(self)
Return sequence with all key-value pairs of the dictionary |
| |
iteritems(self)
This function returns an iterator over (key, value) pairs. |
| |
iterkeys(self)
This function returns an iterator over the mapping's keys. |
| |
itervalues(self)
This function returns an iterator over the mapping's values. |
| |
keys(self)
Return sequence with all keys of the dictionary |
| |
pop(self,
key,
*default)
This function returns the value for a given key and if it exists
removes it from the dictionary. |
| |
popitem(self)
This function returns an arbitrary (key, value) pair and removes it
from the dictionary. |
| |
setdefault(self,
key,
default)
This function returns the current value of the given key. |
| |
update(self,
data)
This function updates the wrapped dictionary with the given
dictionary |
| |
values(self)
Return sequence with all values of the dictionary |
__init__(self,
notFoundError=None,
*exceptionArgs)
(Constructor)
-
- Parameters:
notFoundError -
exception raised instead of a KeyError
exceptionArgs -
arguments for the notFoundError exception
|
__delitem__(self,
key)
(Index deletion operator)
This function removes a given element from the dictionary.
-
- Parameters:
key -
the key of the element to be removed
|
__getitem__(self,
key)
(Indexing operator)
This function returns the item of the dictionary with the given key.
If no such key exists, a 'notFoundError' or a KeyError will be
raised.
-
- Parameters:
key -
the key to look for
- Returns:
-
the dictionary element with the given key
|
__len__(self)
(Length operator)
-
- Returns:
-
number of items in the dictionary
|
__repr__(self)
(Representation operator)
This function returns a string representation of the dictionary
-
- Returns:
-
the wrapped dictionary as string
|
__setitem__(self,
key,
value)
(Index assignment operator)
This function sets or adds a key with a given value to the
dictionary.
-
- Parameters:
key -
key to be set
value -
the value to be set for the key
|
clear(self)
This function clears the wrapped dictionary.
-
|
fromkeys(self,
keys,
value=None)
This function is a class method taht returns a new dictionary,
having all keys listed in the given sequence. If a value is given, all
keys will have this value.
-
- Parameters:
keys -
sequence of keys of the new dictionary
value -
value of all keys in the new dictionary
- Returns:
-
new dictionary wrapper instance with the same
notFoundError
|
get(self,
key,
default=None)
-
|
has_key(self,
key)
This function returns True if a given key exists in the dictionary,
False otherwise.
-
- Parameters:
key -
key to be looked for
- Returns:
-
True if key is in the dictionary, False otherwise
|
items(self)
-
- Returns:
-
sequence with all key-value pairs of the dictionary
|
iteritems(self)
This function returns an iterator over (key, value) pairs. If Python
version is below 2.2 this function raises a NotImplementedError.
-
- Returns:
-
iterator object for (key, value) pairs
|
iterkeys(self)
This function returns an iterator over the mapping's keys. If Python
version is below 2.2 this function raises a NotImplementedError.
-
- Returns:
-
iterator object for keys
|
itervalues(self)
This function returns an iterator over the mapping's values. If
Python version is below 2.2 this function raises a
NotImplementedError.
-
- Returns:
-
iterator object for values
|
keys(self)
-
- Returns:
-
sequence with all keys of the dictionary
|
pop(self,
key,
*default)
This function returns the value for a given key and if it exists
removes it from the dictionary. If the key does not exist and a default
is given, this default will be returned. If no default is given a
KeyError or a notFoundError will be raised.
-
- Parameters:
key -
the key to return the value for (will be removed
afterwards)
default -
default value to return if the key does not exist
- Returns:
-
value for key or default (if given)
|
popitem(self)
This function returns an arbitrary (key, value) pair and removes it
from the dictionary. This is useful to destructively iterate over the
dictionary. If called on an empty dictionary a KeyError will be
raised.
-
- Returns:
-
arbitrary (key, value) pair
|
setdefault(self,
key,
default=None)
This function returns the current value of the given key. If the
dictionary has no such key, it will be added using the given default
value.
-
- Parameters:
key -
the key to return the value from
default -
value to set for the key if it's not available in the
dictionary already
- Returns:
-
current value of the given key
|
update(self,
data)
This function updates the wrapped dictionary with the given
dictionary
-
- Parameters:
data -
dictionary to update from
|
values(self)
-
- Returns:
-
sequence with all values of the dictionary
|