Package gavo :: Package utils :: Module misctricks :: Class CaseSemisensitiveDict
[frames] | no frames]

Class CaseSemisensitiveDict

source code

object --+    
         |    
      dict --+
             |
            CaseSemisensitiveDict

A dictionary allowing case-insensitive access to its content.

This is used for DAL renderers which, unfortunately, are supposed to be case insensitive. Since case insensitivity is at least undesirable for service-specific keys, we go a semi-insenstitve approach here: First, we try literal matches, if that does not work, we try matching against an all-uppercase version.

Name clashes resulting from different names being mapped to the same normalized version are handled in some random way. Don't do this. And don't rely on case normalization if at all possible.

Only strings are allowed as keys here. This class is not concerned with the values. >>> d = CaseSemisensitiveDict({"a": 1, "A": 2, "b": 3}) >>> d["a"], d["A"], d["b"], d["B"] (1, 2, 3, 3) >>> d["B"] = 9; d["b"], d["B"] (3, 9) >>> del d["b"]; d["b"], d["B"] (9, 9) >>> "B" in d, "b" in d, "u" in d (True, True, False)

Instance Methods
new empty dictionary

__init__(self, *args, **kwargs)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
__getitem__(self, key)
x[y]
source code
 
__setitem__(self, key, value)
x[i]=y
source code
True if D has a key k, else False
__contains__(self, key) source code
D[k] if k in D, else d
get(self, key, default=None)
d defaults to None.
source code

Inherited from dict: __cmp__, __delitem__, __eq__, __ge__, __getattribute__, __gt__, __iter__, __le__, __len__, __lt__, __ne__, __new__, __repr__, __sizeof__, clear, copy, fromkeys, has_key, items, iteritems, iterkeys, itervalues, keys, pop, popitem, setdefault, update, values, viewitems, viewkeys, viewvalues

Inherited from object: __delattr__, __format__, __reduce__, __reduce_ex__, __setattr__, __str__, __subclasshook__

Class Variables

Inherited from dict: __hash__

Properties

Inherited from object: __class__

Method Details

__init__(self, *args, **kwargs)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Returns:
new empty dictionary

Overrides: object.__init__
(inherited documentation)

__getitem__(self, key)
(Indexing operator)

source code 

x[y]

Overrides: dict.__getitem__
(inherited documentation)

__setitem__(self, key, value)
(Index assignment operator)

source code 

x[i]=y

Overrides: dict.__setitem__
(inherited documentation)

__contains__(self, key)
(In operator)

source code 
Returns: True if D has a key k, else False
Overrides: dict.__contains__
(inherited documentation)

get(self, key, default=None)

source code 

d defaults to None.

Returns: D[k] if k in D, else d
Overrides: dict.get
(inherited documentation)