pdk.Variables ($Date: 2002/12/04 10:13:05 $)
index
pdk/Variables.py

Variable classes.

Variables are values with a type, a default, and possibly a restricted range. They also can carry documentation and know how to convert a literal into a valid variable value.

This code incorporates ideas taken from Graphite, which was originally written by Joseph and Michelle Strout in 1999.

FOG 03/2000,08/2001

 
Classes
            
pdk.Base.OptionHandler
Variable
ArrayVariable
BooleanVariable
CharVariable
DateTimeVariable
EnumVariable
FunctionVariable
InstanceVariable
MappingVariable
MappingVariable
NumberVariable
FloatVariable
IntVariable
PositionVariable
RectangleVariable
SequenceVariable
TupleVariable
SequenceVariable
TupleVariable
StringVariable
VariableGroup
__builtin__.object
__builtin__.class
 
class ArrayVariable(Variable)
     
Purpose:implements an array variable
Detail:MINDIM and MAXDIM determine the minimum and maximum dimension of the array. TYPECODE provides a NumPy typecode the array is typecasted to.

 
  
Method resolution order:
ArrayVariable
Variable
pdk.Base.OptionHandler

Methods defined here:
asType(self, value)
checkValue(self, value)
getMaximalDimension(self)
getMinimalDimension(self)
getTypeCode(self)
getTypestring(self)
setMaximalDimension(self, maximalDimension)
setMinimalDimension(self, minimalDimension)
setTypeCode(self, typeCode)

Data and non-method functions defined here:
OPTIONS = {'MAXDIM': 3, 'MINDIM': 1, 'TYPECODE': 'd'}
 
class BooleanVariable(Variable)
     
Purpose:implements a boolean variable
Detail:accepted values for a Boolean value are 0,1 (integers), "true","false","yes","no" (all case-insensitive) and "0","1". All valid input is converted to False or True.

 
  
Method resolution order:
BooleanVariable
Variable
pdk.Base.OptionHandler

Methods defined here:
checkValue(self, value)

Static methods defined here:
asType(value, allowNA=0)
 
class CharVariable(Variable)
     
Purpose:implements a char variable

 
  
Method resolution order:
CharVariable
Variable
pdk.Base.OptionHandler

Methods defined here:
checkLiteral(self, literal)
checkValue(self, value)
convertFromLiteral(self, literal)
convertToLiteral(self, value, width=None)

Static methods defined here:
asType(value, allowNA=0)
 
class DateTimeVariable(Variable)
     
Purpose:implements a date/time variable

 
  
Method resolution order:
DateTimeVariable
Variable
pdk.Base.OptionHandler

Methods defined here:
asType(self, value, allowNA=0)
checkLiteral(self, literal)
checkValue(self, value)
convertFromLiteral = asType(self, value, allowNA=0)
convertToLiteral(self, value)
getInFormat(self)
getOutFormat(self)
setInFormat(self, formatString)
setOutFormat(self, formatString)

Data and non-method functions defined here:
CHARS = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-.:/'
OPTIONS = {'INFORMAT': '%b %d %Y %H:%M:%S', 'OUTFORMAT': '%b %d %Y %H:%M:%S'}
 
DictionaryVariable = class MappingVariable(Variable)
     
Purpose:implements a mapping variable
Detail:relies on operator.isMappingType to determine the validity of a candidate value. KEYTYPE and VALUETYPE may be set to types that will then ensure the keys and values of this mapping will conform to them.

 
  
Method resolution order:
MappingVariable
Variable
pdk.Base.OptionHandler

Methods defined here:
acceptable(self, value)
getTypeString(self)

Data and non-method functions defined here:
OPTIONS = {'KEYTYPE': None, 'VALUETYPE': None}
 
class EnumVariable(Variable)
     
Purpose:implements an enumeration variable
Detail:an enumeration variable contains any of a finite set of constants. values is either a list of allowed values or a dictionary mapping allowed values to documentation strings describing the meaning of each of the values. Note that, by default, acceptable values defined in base classes of an EnumVariable are added to the list of acceptable values (via the .extend method).

 
  
Method resolution order:
EnumVariable
Variable
pdk.Base.OptionHandler

Methods defined here:
__init__(self, defaultValue, values, **optionD)
acceptable(self, value)
extend(self, value)
getHelpString(self)
getTypeString(self)
getValueInfoList(self)
getValueList(self)

Data and non-method functions defined here:
OPTIONS = {'EXTEND': 1}
 
class FloatVariable(NumberVariable)
     
Purpose:implements a float variable

 
  
Method resolution order:
FloatVariable
NumberVariable
Variable
pdk.Base.OptionHandler

Methods defined here:
convertFromLiteral(self, literal)
convertToLiteral(self, value, width=None, precision=3, exp=0)
getTypestring(self)

Static methods defined here:
asType(value, allowNA=0)

Data and non-method functions defined here:
CHARS = '0123456789eE+-.'
OPTIONS = {'MAXVAL': 2147483647, 'MINVAL': -2147483648}
REGEX = <_sre.SRE_Pattern object>
 
class FunctionVariable(Variable)
     
Purpose:implements a function variable

 
  
Method resolution order:
FunctionVariable
Variable
pdk.Base.OptionHandler

Methods defined here:
acceptable(self, value)
 
class InstanceVariable(Variable)
     
Purpose:implements a class variable
Detail:allowed values are a class, instances of a class (or of derived classes), or None.

 
  
Method resolution order:
InstanceVariable
Variable
pdk.Base.OptionHandler

Methods defined here:
__init__(self, defaultValue, initClass, **optionD)
acceptable(self, value)
getTypestring(self)
 
class IntVariable(NumberVariable)
     
Purpose:implements an integer variable
Detail:note that this class subsumes the two Python types int and long (i.e., if a value/literal is too big for a plain int, it is automatically converted to a long).

 
  
Method resolution order:
IntVariable
NumberVariable
Variable
pdk.Base.OptionHandler

Methods defined here:
convertFromLiteral(self, literal)
convertToLiteral(self, value, width=None)
getTypestring(self)

Static methods defined here:
asType(value, allowNA=0)

Data and non-method functions defined here:
CHARS = '0123456789+-'
OPTIONS = {'MAXVAL': 2147483647, 'MINVAL': -2147483648}
REGEX = <_sre.SRE_Pattern object>
 
ListVariable = class SequenceVariable(Variable)
     
Purpose:implements a sequence variable
Detail:MINQTY and MAXQTY determine the minimum and maximum length of the sequence. With ELEMTYPE, a variable class can be provided which then requires the sequence elements to conform to this variable.

 
  
Method resolution order:
SequenceVariable
Variable
pdk.Base.OptionHandler

Methods defined here:
checkValue(self, valueL)
getElementType(self)
getMaximumQuantity(self)
getMinimumQuantity(self)
getTypestring(self)
setElementType(self, elementType)
setMaximumQuantity(self, maxQty)
setMininmumQuantity(self, minQty)

Static methods defined here:
asType(value)

Data and non-method functions defined here:
OPTIONS = {'ELEMTYPE': None, 'MAXQTY': 32767, 'MINQTY': 0}
 
class MappingVariable(Variable)
     
Purpose:implements a mapping variable
Detail:relies on operator.isMappingType to determine the validity of a candidate value. KEYTYPE and VALUETYPE may be set to types that will then ensure the keys and values of this mapping will conform to them.

 
  
Method resolution order:
MappingVariable
Variable
pdk.Base.OptionHandler

Methods defined here:
acceptable(self, value)
getTypeString(self)

Data and non-method functions defined here:
OPTIONS = {'KEYTYPE': None, 'VALUETYPE': None}
 
class NumberVariable(Variable)
     
Purpose:implements a number variable

 
  
Method resolution order:
NumberVariable
Variable
pdk.Base.OptionHandler

Methods defined here:
checkLiteral(self, literal)
checkValue(self, value)
getMaxValue(self)
getMinValue(self)
getRange(self)
setMaxValue(self, maxValue)
setMinValue(self, minValue)
setRange(self, minValue, maxValue)

Data and non-method functions defined here:
CHARS = '0123456789'
OPTIONS = {'MAXVAL': None, 'MINVAL': None}
REGEX = <_sre.SRE_Pattern object>
 
class PositionVariable(Variable)
     
Purpose:specifies a position in 2D- or 3D-space
Detail:a position has two or three coordinates. Each coordinate (x,y,z) can have range restrictions imposed on it (options MINX,`MAXX`,`MINY`,`MAXY`,`MINZ`,`MAXZ`). Note that the position data are kept in a Numeric Array to allow simple arithmetics on the variable value.

 
  
Method resolution order:
PositionVariable
Variable
pdk.Base.OptionHandler

Methods defined here:
acceptable(self, value)
getLimits(self)
getMaximumX(self)
getMaximumY(self)
getMaximumZ(self)
getMinimumX(self)
getMinimumY(self)
getMinimumZ(self)
setLimits(self, (minX, maxX, minY, maxY, minZ, maxZ))
setMaximumX(self, maxX)
setMaximumY(self, maxY)
setMaximumZ(self, maxZ)
setMinimumX(self, minX)
setMinimumY(self, minY)
setMinimumZ(self, minZ)

Data and non-method functions defined here:
OPTIONS = {'MAXX': None, 'MAXY': None, 'MAXZ': None, 'MINX': None, 'MINY': None, 'MINZ': None}
 
class RectangleVariable(Variable)
     
Purpose:specifies a rectangle with a x,y-position and width/height
Detail:

a rectangle has a position (x- and y-coordinates of the upper left corner) and a width and a height. Minimum/maximum width/heihgt values can be set with the options MINWIDTH, MAXWIDTH, MINHEIGHT, MAXHEIGHT. The position is defined relative to the rectangle spanned by the maximum width/height values. Valid values for this variable are either a 2-sequence of integers

(<width>,<height>)

with the position tacitly set to (0,0), or a 4-sequence of integers

(<left pos. x>,<top pos. y>,<width>,<height>)

Note that the sum of the x-coordinate/y-coordinate of the position and the current width/height cannot exceed the maximum width/height.


 
  
Method resolution order:
RectangleVariable
Variable
pdk.Base.OptionHandler

Methods defined here:
acceptable(self, value)
getMaximumHeight(self)
getMaximumWidth(self)
getMinimumHeight(self)
getMinimumWidth(self)
setMaximumHeight(self, maxHeight)
setMaximumWidth(self, maxWidth)
setMinimumHeight(self, minHeight)
setMinimumWidth(self, minWidth)

Data and non-method functions defined here:
OPTIONS = {'MAXHEIGHT': None, 'MAXWIDTH': None, 'MINHEIGHT': 0, 'MINWIDTH': 0}
 
class SequenceVariable(Variable)
     
Purpose:implements a sequence variable
Detail:MINQTY and MAXQTY determine the minimum and maximum length of the sequence. With ELEMTYPE, a variable class can be provided which then requires the sequence elements to conform to this variable.

 
  
Method resolution order:
SequenceVariable
Variable
pdk.Base.OptionHandler

Methods defined here:
checkValue(self, valueL)
getElementType(self)
getMaximumQuantity(self)
getMinimumQuantity(self)
getTypestring(self)
setElementType(self, elementType)
setMaximumQuantity(self, maxQty)
setMininmumQuantity(self, minQty)

Static methods defined here:
asType(value)

Data and non-method functions defined here:
OPTIONS = {'ELEMTYPE': None, 'MAXQTY': 32767, 'MINQTY': 0}
 
class StringVariable(Variable)
     
Purpose:implements a string variable

 
  
Method resolution order:
StringVariable
Variable
pdk.Base.OptionHandler

Methods defined here:
checkLiteral(self, literal)
all strings are a valid literal of a string...

Static methods defined here:
asType(value, allowNA=0)
 
class TupleVariable(SequenceVariable)
     
Purpose:implements a tuple variable

 
  
Method resolution order:
TupleVariable
SequenceVariable
Variable
pdk.Base.OptionHandler

Methods defined here:
checkValue(self, valueT)

Static methods defined here:
asType(value)
 
class Variable(pdk.Base.OptionHandler)
       
   Methods defined here:
__init__(self, defaultValue, **optionD)
__or__(self, otherVariable)
__ror__ = __or__(self, otherVariable)
acceptable(self, value)
checks whether value is acceptable as value for this variable. Returns two values: first is 0/1 unacceptable/acceptable, second is the value modified as needed to fit the value type or an error string explaining the problem.
asType(value, allowNA=0)
a static method that tries to convert value (any input value) to the value type of the class. Raises a ValueError if the conversion fails. If allowNA is True, None is treated as an allowed value.
checkChar(self, char)
checks whether char is a valid char for a literal representation of this variable class. Returns a boolean.
checkLiteral(self, literal)
checks whether literal is a valid literal representation of this variable class. Returns INVALID (invalid literal), VALID (valid literal), or PARTIAL (may be completed into a valid literal).
checkValue(self, value)
checks if value (which is of the expected value type) conforms to whatever options are set for this variable instance. Returns a 2-tuple (a boolean indicating success and a [possibly converted] value on success or an error message on failure).
convertFromLiteral(self, literal)
convertToLiteral(self, value)
getDefaultValue(self)
returns the current setting for the default value.
getHelpDescription(self)
returns a string describing the variable.
getHelpString(self)
returns a string describing the variable and its value.
getHelpValue(self)
returns a string describing the value of this variable.
getTypestring(self)
returns a short string indicating the type of this variable.
setDefaultValue(self, newDefaultValue)
sets the default value to %newDefaultValue%.

Class methods defined here:
asTypeOrNA = asTypeOrNA(cl, value) from __builtin__.class

Data and non-method functions defined here:
CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
OPTIONS = {'INFO': ('no help available', '')}
REGEX = <_sre.SRE_Pattern object>
 
class VariableGroup(Variable)
     
Purpose:implements "or" operations on variables
Detail:

use this to express that a value may be of more than one type, e.g.

a = IntVariable(0, MAXVAL=255) | CharVariable("0")

 
  
Method resolution order:
VariableGroup
Variable
pdk.Base.OptionHandler

Methods defined here:
__init__(self, *variableT)
acceptable(self, value)
getVariableInstances(self)
 
class class(object)
       
   Methods defined here:
__call__(...)
x.__call__(...) <==> x(...)
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__str__(...)
x.__str__() <==> str(x)

Data and non-method functions defined here:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T
 
Functions
            
as_array_or_NA(value)
as_bool = asType(value, allowNA=0)
as_bool_or_NA = asTypeOrNA(cl, value) class method of BooleanVariable instance
as_char = asType(value, allowNA=0)
as_char_or_NA = asTypeOrNA(cl, value) class method of CharVariable instance
as_datetime(value, formatString=None, allowNA=0)
allowed input values for date/time variables are:
  • a time.struct_time instance
  • a 9-tuple of integers (use to instantiate time.struct_time)
  • a string (convert with time.strptime using the formatString argument)
as_datetime_or_NA(value, formatString=None)
as_float = asType(value, allowNA=0)
as_float_or_NA = asTypeOrNA(cl, value) class method of FloatVariable instance
as_int = asType(value, allowNA=0)
as_int_or_NA = asTypeOrNA(cl, value) class method of IntVariable instance
as_list = asType(value)
as_tuple = asType(value)
set_date_format = setDateFormat(format)
use this to change the default date format for all following DateTime instances
 
Data
             INVALID = 0
PARTIAL = 2
VALID = 1
 
Author
            
$Author: gathmann $