LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Properties | Private Attributes | List of all members
lsst.pex.config.dictField.Dict Class Reference
Inheritance diagram for lsst.pex.config.dictField.Dict:

Public Member Functions

def __init__
 
def __getitem__
 
def __len__
 
def __iter__
 
def __contains__
 
def __setitem__
 
def __delitem__
 
def __repr__
 
def __str__
 
def __setattr__
 

Properties

 history = property(lambda x: x._history)
 

Private Attributes

 _field
 
 _config
 
 _dict
 
 _history
 
 __doc__
 

Detailed Description

Config-Internal mapping container
Emulates a dict, but adds validation and provenance.

Definition at line 30 of file dictField.py.

Constructor & Destructor Documentation

def lsst.pex.config.dictField.Dict.__init__ (   self,
  config,
  field,
  value,
  at,
  label,
  setHistory = True 
)

Definition at line 36 of file dictField.py.

36 
37  def __init__(self, config, field, value, at, label, setHistory=True):
38  self._field = field
39  self._config = config
40  self._dict = {}
41  self._history = self._config._history.setdefault(self._field.name, [])
42  self.__doc__=field.doc
43  if value is not None:
44  try:
45  for k in value:
46  #do not set history per-item
47  self.__setitem__(k, value[k], at=at, label=label, setHistory=False)
48  except TypeError:
49  msg = "Value %s is of incorrect type %s. Mapping type expected."%\
50  (value, _typeStr(value))
51  raise FieldValidationError(self._field, self._config, msg)
52  if setHistory:
53  self._history.append((dict(self._dict), at, label))
54 

Member Function Documentation

def lsst.pex.config.dictField.Dict.__contains__ (   self,
  k 
)

Definition at line 66 of file dictField.py.

66 
67  def __contains__(self, k): return k in self._dict
def lsst.pex.config.dictField.Dict.__delitem__ (   self,
  k,
  at = None,
  label = "delitem",
  setHistory = True 
)

Definition at line 105 of file dictField.py.

106  def __delitem__(self, k, at=None, label="delitem", setHistory=True):
107  if self._config._frozen:
108  raise FieldValidationError(self._field, self._config,
109  "Cannot modify a frozen Config")
110 
111  del self._dict[k]
112  if setHistory:
113  if at is None:
114  at = traceback.extract_stack()[:-1]
115  self._history.append((dict(self._dict), at, label))
def lsst.pex.config.dictField.Dict.__getitem__ (   self,
  k 
)

Definition at line 60 of file dictField.py.

60 
61  def __getitem__(self, k): return self._dict[k]
def lsst.pex.config.dictField.Dict.__iter__ (   self)

Definition at line 64 of file dictField.py.

64 
65  def __iter__(self): return iter(self._dict)
def lsst.pex.config.dictField.Dict.__len__ (   self)

Definition at line 62 of file dictField.py.

62 
63  def __len__(self): return len(self._dict)
def lsst.pex.config.dictField.Dict.__repr__ (   self)

Definition at line 116 of file dictField.py.

117  def __repr__(self): return repr(self._dict)
def lsst.pex.config.dictField.Dict.__setattr__ (   self,
  attr,
  value,
  at = None,
  label = "assignment" 
)

Definition at line 120 of file dictField.py.

121  def __setattr__(self, attr, value, at=None, label="assignment"):
122  if hasattr(getattr(self.__class__, attr, None), '__set__'):
123  # This allows properties to work.
124  object.__setattr__(self, attr, value)
125  elif attr in self.__dict__ or attr in ["_field", "_config", "_history", "_dict", "__doc__"]:
126  # This allows specific private attributes to work.
127  object.__setattr__(self, attr, value)
128  else:
129  # We throw everything else.
130  msg = "%s has no attribute %s"%(_typeStr(self._field), attr)
131  raise FieldValidationError(self._field, self._config, msg)
132 
def lsst.pex.config.dictField.Dict.__setitem__ (   self,
  k,
  x,
  at = None,
  label = "setitem",
  setHistory = True 
)

Definition at line 68 of file dictField.py.

68 
69  def __setitem__(self, k, x, at=None, label="setitem", setHistory=True):
70  if self._config._frozen:
71  msg = "Cannot modify a frozen Config. "\
72  "Attempting to set item at key %r to value %s"%(k, x)
73  raise FieldValidationError(self._field, self._config, msg)
74 
75  #validate keytype
76  k = _autocast(k, self._field.keytype)
77  if type(k) != self._field.keytype:
78  msg = "Key %r is of type %s, expected type %s"%\
79  (k, _typeStr(k), _typeStr(self._field.keytype))
80  raise FieldValidationError(self._field, self._config, msg)
81 
82  #validate itemtype
83  x = _autocast(x, self._field.itemtype)
84  if self._field.itemtype is None:
85  if type(x) not in self._field.supportedTypes and x is not None:
86  msg ="Value %s at key %r is of invalid type %s" % (x, k, _typeStr(x))
87  raise FieldValidationError(self._field, self._config, msg)
88  else:
89  if type(x) != self._field.itemtype and x is not None:
90  msg ="Value %s at key %r is of incorrect type %s. Expected type %s"%\
91  (x, k, _typeStr(x), _typeStr(self._field.itemtype))
92  raise FieldValidationError(self._field, self._config, msg)
93 
94  #validate item using itemcheck
95  if self._field.itemCheck is not None and not self._field.itemCheck(x):
96  msg="Item at key %r is not a valid value: %s"%(k, x)
97  raise FieldValidationError(self._field, self._config, msg)
98 
99  if at is None:
100  at = traceback.extract_stack()[:-1]
101 
102  self._dict[k]=x
103  if setHistory:
104  self._history.append((dict(self._dict), at, label))
def lsst.pex.config.dictField.Dict.__str__ (   self)

Definition at line 118 of file dictField.py.

119  def __str__(self): return str(self._dict)

Member Data Documentation

lsst.pex.config.dictField.Dict.__doc__
private

Definition at line 41 of file dictField.py.

lsst.pex.config.dictField.Dict._config
private

Definition at line 38 of file dictField.py.

lsst.pex.config.dictField.Dict._dict
private

Definition at line 39 of file dictField.py.

lsst.pex.config.dictField.Dict._field
private

Definition at line 37 of file dictField.py.

lsst.pex.config.dictField.Dict._history
private

Definition at line 40 of file dictField.py.

Property Documentation

lsst.pex.config.dictField.Dict.history = property(lambda x: x._history)
static

Definition at line 58 of file dictField.py.


The documentation for this class was generated from the following file: