bronx.stdtypes.dictionaries

Structure or dictionary like classes for miscellaneous usage.

Classes

class bronx.stdtypes.dictionaries.Foo(**kw)[source]

Bases: object

Protected C-struct like class… for gathering anything. Internal dict methods could be called through i_*methodname* protection.

as_dict()[source]

Returns the object’s content as a dictionary.

class bronx.stdtypes.dictionaries.LowerCaseDict(*kargs, **kwargs)[source]

Bases: SpecialDict

A dictionary with only lower case keys.

Example:

>>> lcdict = LowerCaseDict()
>>> len(lcdict)
0
>>> lcdict['Ab'] = 1
>>> lcdict['cD'] = 2
>>> 'ab' in lcdict
True
>>> 'AB' in lcdict
True
>>> 'Ab' in lcdict
True
>>> 'abc' in lcdict
False
>>> print(','.join(sorted(lcdict.keys())))
ab,cd
>>> lcdict.show()
+ ab                       = 1
+ cd                       = 2
remap(key)[source]

Return a lower case value of the actual key.

class bronx.stdtypes.dictionaries.ReadOnlyDict(data=None)[source]

Bases: Mapping

A type of read-only dictionary.

Example:

>>> rodict = ReadOnlyDict()
>>> len(rodict)
0
>>> rodict['a'] = 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'ReadOnlyDict' object does not support item assignment

>>> rodict = ReadOnlyDict(dict(a=1, b=2))
>>> len(rodict)
2
>>> rodict['a']
1
>>> print(','.join(rodict))
a,b
>>> print(','.join([str(x) for k, x in sorted(rodict.items())]))
1,2
class bronx.stdtypes.dictionaries.SpecialDict(*kargs, **kwargs)[source]

Bases: dict

Add some special features to std dict especially the ability to remap keys on the fly.

This class behaves like a usual dictionary, to be useful, it should be subclassed and the method remap() should be redefined in order to implement a customised key remaping

remap(key)[source]

Return a new value for the actual key. Default is identity.

show(ljust=24)[source]

Print the actual values of the dictionary.

update(*args, **kw)[source]

Extended dictionary update with args as dict and extra keywords.

class bronx.stdtypes.dictionaries.UpperCaseDict(*kargs, **kwargs)[source]

Bases: SpecialDict

A dictionary with only upper case keys.

remap(key)[source]

Return a upper case value of the actual key.