LSSTApplications  19.0.0-14-gb0260a2+2d714fc2ef,20.0.0+34a42eae2c,20.0.0+76f397ef0c,20.0.0+8558dd3f48,20.0.0+a6b6977b51,20.0.0+b2ea66fa67,20.0.0+cc669a8b45,20.0.0+d561663fb5,20.0.0+d778e99126,20.0.0+efe67588cf,20.0.0+f45b7d88f4,20.0.0+f7c597f720,20.0.0+fb43bee9b9,20.0.0+fb4d547e0d,20.0.0-1-g10df615+d8b88ec1b5,20.0.0-1-g253301a+a6b6977b51,20.0.0-1-g498fb60+ff88705a28,20.0.0-1-g4d801e7+ce0d01dabd,20.0.0-1-g5b95a8c+24eaf908b3,20.0.0-1-g8a53f90+2817c06967,20.0.0-1-gc96f8cb+fb4d547e0d,20.0.0-1-gd1c87d7+2817c06967,20.0.0-1-gdb27ee5+abab67204f,20.0.0-13-ge998c5c+9f8c516ffa,20.0.0-18-g08fba245+88079d2923,20.0.0-2-gec03fae+fb98bf9d97,20.0.0-3-gdd5c15c+a61313b210,20.0.0-34-gdb4d86a+b43b2c05ff,20.0.0-4-g4a2362f+f45b7d88f4,20.0.0-4-gfea843c+f45b7d88f4,20.0.0-5-gac0d578b1+a8c4e2ada3,20.0.0-5-gfcebe35+cfceff6a24,20.0.0-6-g01203fff+e332440eaf,20.0.0-8-gea2affd+48c001ce3c,20.0.0-9-gabd0d4c+abab67204f,20.0.0-9-gf3ab18e+fb4d547e0d,w.2020.33
LSSTDataManagementBasePackage
Public Member Functions | Properties | List of all members
pex.config.dictField.Dict Class Reference
Inheritance diagram for pex.config.dictField.Dict:
pex.config.configDictField.ConfigDict

Public Member Functions

def __init__ (self, config, field, value, at, label, setHistory=True)
 
def __getitem__ (self, k)
 
def __len__ (self)
 
def __iter__ (self)
 
def __contains__ (self, k)
 
def __setitem__ (self, k, x, at=None, label="setitem", setHistory=True)
 
def __delitem__ (self, k, at=None, label="delitem", setHistory=True)
 
def __repr__ (self)
 
def __str__ (self)
 
def __setattr__ (self, attr, value, at=None, label="assignment")
 

Properties

 history = property(lambda x: x._history)
 

Detailed Description

An internal mapping container.

This class emulates a `dict`, but adds validation and provenance.

Definition at line 37 of file dictField.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 43 of file dictField.py.

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

Member Function Documentation

◆ __contains__()

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

Definition at line 74 of file dictField.py.

74  def __contains__(self, k):
75  return k in self._dict
76 

◆ __delitem__()

def pex.config.dictField.Dict.__delitem__ (   self,
  k,
  at = None,
  label = "delitem",
  setHistory = True 
)

Definition at line 114 of file dictField.py.

114  def __delitem__(self, k, at=None, label="delitem", setHistory=True):
115  if self._config._frozen:
116  raise FieldValidationError(self._field, self._config,
117  "Cannot modify a frozen Config")
118 
119  del self._dict[k]
120  if setHistory:
121  if at is None:
122  at = getCallStack()
123  self._history.append((dict(self._dict), at, label))
124 

◆ __getitem__()

def pex.config.dictField.Dict.__getitem__ (   self,
  k 
)

Definition at line 65 of file dictField.py.

65  def __getitem__(self, k):
66  return self._dict[k]
67 

◆ __iter__()

def pex.config.dictField.Dict.__iter__ (   self)

Definition at line 71 of file dictField.py.

71  def __iter__(self):
72  return iter(self._dict)
73 

◆ __len__()

def pex.config.dictField.Dict.__len__ (   self)

Definition at line 68 of file dictField.py.

68  def __len__(self):
69  return len(self._dict)
70 

◆ __repr__()

def pex.config.dictField.Dict.__repr__ (   self)

Definition at line 125 of file dictField.py.

125  def __repr__(self):
126  return repr(self._dict)
127 

◆ __setattr__()

def pex.config.dictField.Dict.__setattr__ (   self,
  attr,
  value,
  at = None,
  label = "assignment" 
)

Definition at line 131 of file dictField.py.

131  def __setattr__(self, attr, value, at=None, label="assignment"):
132  if hasattr(getattr(self.__class__, attr, None), '__set__'):
133  # This allows properties to work.
134  object.__setattr__(self, attr, value)
135  elif attr in self.__dict__ or attr in ["_field", "_config", "_history", "_dict", "__doc__"]:
136  # This allows specific private attributes to work.
137  object.__setattr__(self, attr, value)
138  else:
139  # We throw everything else.
140  msg = "%s has no attribute %s" % (_typeStr(self._field), attr)
141  raise FieldValidationError(self._field, self._config, msg)
142 
143 

◆ __setitem__()

def pex.config.dictField.Dict.__setitem__ (   self,
  k,
  x,
  at = None,
  label = "setitem",
  setHistory = True 
)

Reimplemented in pex.config.configDictField.ConfigDict.

Definition at line 77 of file dictField.py.

77  def __setitem__(self, k, x, at=None, label="setitem", setHistory=True):
78  if self._config._frozen:
79  msg = "Cannot modify a frozen Config. "\
80  "Attempting to set item at key %r to value %s" % (k, x)
81  raise FieldValidationError(self._field, self._config, msg)
82 
83  # validate keytype
84  k = _autocast(k, self._field.keytype)
85  if type(k) != self._field.keytype:
86  msg = "Key %r is of type %s, expected type %s" % \
87  (k, _typeStr(k), _typeStr(self._field.keytype))
88  raise FieldValidationError(self._field, self._config, msg)
89 
90  # validate itemtype
91  x = _autocast(x, self._field.itemtype)
92  if self._field.itemtype is None:
93  if type(x) not in self._field.supportedTypes and x is not None:
94  msg = "Value %s at key %r is of invalid type %s" % (x, k, _typeStr(x))
95  raise FieldValidationError(self._field, self._config, msg)
96  else:
97  if type(x) != self._field.itemtype and x is not None:
98  msg = "Value %s at key %r is of incorrect type %s. Expected type %s" % \
99  (x, k, _typeStr(x), _typeStr(self._field.itemtype))
100  raise FieldValidationError(self._field, self._config, msg)
101 
102  # validate item using itemcheck
103  if self._field.itemCheck is not None and not self._field.itemCheck(x):
104  msg = "Item at key %r is not a valid value: %s" % (k, x)
105  raise FieldValidationError(self._field, self._config, msg)
106 
107  if at is None:
108  at = getCallStack()
109 
110  self._dict[k] = x
111  if setHistory:
112  self._history.append((dict(self._dict), at, label))
113 

◆ __str__()

def pex.config.dictField.Dict.__str__ (   self)

Definition at line 128 of file dictField.py.

128  def __str__(self):
129  return str(self._dict)
130 

Property Documentation

◆ history

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

Definition at line 61 of file dictField.py.


The documentation for this class was generated from the following file:
ast::append
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
Definition: functional.cc:33
pex.config.callStack.getCallStack
def getCallStack(skip=0)
Definition: callStack.py:175
type
table::Key< int > type
Definition: Detector.cc:163
astshim.fitsChanContinued.iter
def iter(self)
Definition: fitsChanContinued.py:88