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 | Public Attributes | Private Member Functions | List of all members
lsst.pex.config.choiceField.ChoiceField Class Reference
Inheritance diagram for lsst.pex.config.choiceField.ChoiceField:

Public Member Functions

def __init__
 

Public Attributes

 allowed
 
 source
 

Private Member Functions

def _validateValue
 

Detailed Description

Defines a Config Field which allows only a set of values
All allowed must be of the same type.
Allowed values should be provided as a dict of value, doc string pairs

Definition at line 28 of file choiceField.py.

Constructor & Destructor Documentation

def lsst.pex.config.choiceField.ChoiceField.__init__ (   self,
  doc,
  dtype,
  allowed,
  default = None,
  optional = True 
)

Definition at line 35 of file choiceField.py.

35 
36  def __init__(self, doc, dtype, allowed, default=None, optional=True):
37  self.allowed = dict(allowed)
38  if optional and None not in self.allowed:
39  self.allowed[None]="Field is optional"
40 
41  if len(self.allowed)==0:
42  raise ValueError("ChoiceFields must allow at least one choice")
43 
44  doc += "\nAllowed values:\n"
45  for choice, choiceDoc in self.allowed.iteritems():
46  if choice is not None and not isinstance(choice, dtype):
47  raise ValueError("ChoiceField's allowed choice %s is of incorrect type %s. Expected %s"%\
48  (choice, _typeStr(choice), _typeStr(dtype)))
49  doc += "\t%s\t%s\n"%(str(choice), choiceDoc)
50 
51  Field.__init__(self, doc=doc, dtype=dtype, default=default,
52  check=None, optional=optional)
53  self.source = traceback.extract_stack(limit=2)[0]

Member Function Documentation

def lsst.pex.config.choiceField.ChoiceField._validateValue (   self,
  value 
)
private

Definition at line 54 of file choiceField.py.

54 
55  def _validateValue(self, value):
56  Field._validateValue(self, value)
57  if value not in self.allowed:
58  allowedStr = "{%s"%self.allowed.keys()[0]
59  for x in self.allowed:
60  allowedStr += ", %s"%x
61  allowedStr+="}"
62  msg = "Value %s is not allowed.\n\tAllowed values: %s"%\
63  (value, allowedStr)
64  raise ValueError(msg)

Member Data Documentation

lsst.pex.config.choiceField.ChoiceField.allowed

Definition at line 36 of file choiceField.py.

lsst.pex.config.choiceField.ChoiceField.source

Definition at line 52 of file choiceField.py.


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