CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
betterConfigParser.AdaptedDict Class Reference
Inheritance diagram for betterConfigParser.AdaptedDict:

Public Member Functions

def __getitem__ (self, key)
 
def __init__ (self, args, kwargs)
 
def __setitem__ (self, key, value, dict_setitem=collections.OrderedDict.__setitem__)
 
def items (self)
 

Public Attributes

 validationslist
 

Detailed Description

Dictionary which handles updates of values for already existing keys
in a modified way.
adapteddict[key] returns a list of all values associated with key
This dictionary is used in the class `BetterConfigParser` instead of the
default `dict_type` of the `ConfigParser` class.

Definition at line 11 of file betterConfigParser.py.

Constructor & Destructor Documentation

def betterConfigParser.AdaptedDict.__init__ (   self,
  args,
  kwargs 
)

Definition at line 20 of file betterConfigParser.py.

20  def __init__(self, *args, **kwargs):
21  self.validationslist = []
22  collections.OrderedDict.__init__(self, *args, **kwargs)
23 
def __init__(self, args, kwargs)

Member Function Documentation

def betterConfigParser.AdaptedDict.__getitem__ (   self,
  key 
)

Definition at line 46 of file betterConfigParser.py.

References betterConfigParser.AdaptedDict.validationslist.

46  def __getitem__(self, key):
47  if key != "__name__" and "__name__" in self and self["__name__"]=="validation":
48  return [validation[1] for validation in self.validationslist if validation[0] == key]
49  else:
50  return collections.OrderedDict.__getitem__(self, key)
51 
def betterConfigParser.AdaptedDict.__setitem__ (   self,
  key,
  value,
  dict_setitem = collections.OrderedDict.__setitem__ 
)
od.__setitem__(i, y) <==> od[i]=y
Updating an existing key appends the new value to the old value
instead of replacing it.

Arguments:
- `key`: key part of the key-value pair
- `value`: value part of the key-value pair
- `dict_item`: method which is used for finally setting the item

Definition at line 24 of file betterConfigParser.py.

References betterConfigParser.AdaptedDict.validationslist.

24  def __setitem__(self, key, value, dict_setitem=collections.OrderedDict.__setitem__):
25  """
26  od.__setitem__(i, y) <==> od[i]=y
27  Updating an existing key appends the new value to the old value
28  instead of replacing it.
29 
30  Arguments:
31  - `key`: key part of the key-value pair
32  - `value`: value part of the key-value pair
33  - `dict_item`: method which is used for finally setting the item
34  """
35 
36  if key != "__name__" and "__name__" in self and self["__name__"]=="validation":
37  if isinstance(value, (str, unicode)):
38  for index, item in enumerate(self.validationslist[:]):
39  if item == (key, value.split("\n")):
40  self.validationslist[index] = (key, value)
41  return
42  self.validationslist.append((key, value))
43  else:
44  dict_setitem(self, key, value)
45 
def __setitem__(self, key, value, dict_setitem=collections.OrderedDict.__setitem__)
def betterConfigParser.AdaptedDict.items (   self)

Definition at line 52 of file betterConfigParser.py.

References betterConfigParser.AdaptedDict.validationslist.

Referenced by betterConfigParser.BetterConfigParser.exists(), crabConfigParser.CrabConfigParser.getSectionLines(), and python.rootplot.core.Options.kwarg_list().

52  def items(self):
53  if "__name__" in self and self["__name__"]=="validation":
54  return self.validationslist
55  else:
56  return collections.OrderedDict.items(self)
57 

Member Data Documentation

betterConfigParser.AdaptedDict.validationslist