• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

contrib/opal/ZSI/ZSI/TCnumbers.py

00001 #! /usr/bin/env python
00002 # $Header$
00003 '''Typecodes for numbers.
00004 '''
00005 import types
00006 from ZSI import _copyright, _inttypes, _floattypes, _seqtypes, \
00007         EvaluateException
00008 from ZSI.TC import TypeCode, Integer, Decimal
00009 from ZSI.wstools.Namespaces import SCHEMA
00010 
00011 class IunsignedByte(Integer):
00012     '''Unsigned 8bit value.
00013     '''
00014     type = (SCHEMA.XSD3, "unsignedByte")
00015     parselist = [ (None, "unsignedByte") ]
00016     seriallist = [ ]
00017 
00018 class IunsignedShort(Integer):
00019     '''Unsigned 16bit value.
00020     '''
00021     type = (SCHEMA.XSD3, "unsignedShort")
00022     parselist = [ (None, "unsignedShort") ]
00023     seriallist = [ ]
00024 
00025 class IunsignedInt(Integer):
00026     '''Unsigned 32bit value.
00027     '''
00028     type = (SCHEMA.XSD3, "unsignedInt")
00029     parselist = [ (None, "unsignedInt") ]
00030     seriallist = [ ]
00031 
00032 class IunsignedLong(Integer):
00033     '''Unsigned 64bit value.
00034     '''
00035     type = (SCHEMA.XSD3, "unsignedLong")
00036     parselist = [ (None, "unsignedLong") ]
00037     seriallist = [ ]
00038 
00039 class Ibyte(Integer):
00040     '''Signed 8bit value.
00041     '''
00042     type = (SCHEMA.XSD3, "byte")
00043     parselist = [ (None, "byte") ]
00044     seriallist = [ ]
00045 
00046 class Ishort(Integer):
00047     '''Signed 16bit value.
00048     '''
00049     type = (SCHEMA.XSD3, "short")
00050     parselist = [ (None, "short") ]
00051     seriallist = [ ]
00052 
00053 class Iint(Integer):
00054     '''Signed 32bit value.
00055     '''
00056     type = (SCHEMA.XSD3, "int")
00057     parselist = [ (None, "int") ]
00058     seriallist = [ types.IntType ]
00059 
00060 class Ilong(Integer):
00061     '''Signed 64bit value.
00062     '''
00063     type = (SCHEMA.XSD3, "long")
00064     parselist = [(None, "long")]
00065     seriallist = [ types.LongType ]
00066 
00067 class InegativeInteger(Integer):
00068     '''Value less than zero.
00069     '''
00070     type = (SCHEMA.XSD3, "negativeInteger")
00071     parselist = [ (None, "negativeInteger") ]
00072     seriallist = [ ]
00073 
00074 class InonPositiveInteger(Integer):
00075     '''Value less than or equal to zero.
00076     '''
00077     type = (SCHEMA.XSD3, "nonPositiveInteger")
00078     parselist = [ (None, "nonPositiveInteger") ]
00079     seriallist = [ ]
00080 
00081 class InonNegativeInteger(Integer):
00082     '''Value greater than or equal to zero.
00083     '''
00084     type = (SCHEMA.XSD3, "nonNegativeInteger")
00085     parselist = [ (None, "nonNegativeInteger") ]
00086     seriallist = [ ]
00087 
00088 class IpositiveInteger(Integer):
00089     '''Value greater than zero.
00090     '''
00091     type = (SCHEMA.XSD3, "positiveInteger")
00092     parselist = [ (None, "positiveInteger") ]
00093     seriallist = [ ]
00094 
00095 class Iinteger(Integer):
00096     '''Integer value.
00097     '''
00098     type = (SCHEMA.XSD3, "integer")
00099     parselist = [ (None, "integer") ]
00100     seriallist = [ ]
00101 
00102 class IEnumeration(Integer):
00103     '''Integer value, limited to a specified set of values.
00104     '''
00105 
00106     def __init__(self, choices, pname=None, **kw):
00107         Integer.__init__(self, pname, **kw)
00108         self.choices = choices
00109         t = type(choices)
00110         if t in _seqtypes:
00111             self.choices = tuple(choices)
00112         elif TypeCode.typechecks:
00113             raise TypeError(
00114                 'Enumeration choices must be list or sequence, not ' + str(t))
00115         if TypeCode.typechecks:
00116             for c in self.choices:
00117                 if type(c) not in _inttypes:
00118                     raise TypeError('Enumeration choice "' +
00119                             str(c) + '" is not an integer')
00120 
00121     def parse(self, elt, ps):
00122         val = Integer.parse(self, elt, ps)
00123         if val not in self.choices:
00124             raise EvaluateException('Value "' + str(val) + \
00125                         '" not in enumeration list',
00126                     ps.Backtrace(elt))
00127         return val
00128 
00129     def serialize(self, elt, sw, pyobj, name=None, orig=None, **kw):
00130         if pyobj not in self.choices:
00131             raise EvaluateException('Value not in int enumeration list',
00132                     ps.Backtrace(elt))
00133         Integer.serialize(self, elt, sw, pyobj, name=name, orig=orig, **kw)
00134 
00135 
00136 class FPfloat(Decimal):
00137     '''IEEE 32bit floating point value.
00138     '''
00139     type = (SCHEMA.XSD3, "float")
00140     parselist = [ (None, "float") ]
00141     seriallist = [ types.FloatType ]
00142 
00143 class FPdouble(Decimal):
00144     '''IEEE 64bit floating point value.
00145     '''
00146     type = (SCHEMA.XSD3, "double")
00147     parselist = [ (None, "double") ]
00148     seriallist = [ ]
00149 
00150 class FPEnumeration(FPfloat):
00151     '''Floating point value, limited to a specified set of values.
00152     '''
00153 
00154     def __init__(self, choices, pname=None, **kw):
00155         FPfloat.__init__(self, pname, **kw)
00156         self.choices = choices
00157         t = type(choices)
00158         if t in _seqtypes:
00159             self.choices = tuple(choices)
00160         elif TypeCode.typechecks:
00161             raise TypeError(
00162                 'Enumeration choices must be list or sequence, not ' + str(t))
00163         if TypeCode.typechecks:
00164             for c in self.choices:
00165                 if type(c) not in _floattypes:
00166                     raise TypeError('Enumeration choice "' +
00167                             str(c) + '" is not floating point number')
00168 
00169     def parse(self, elt, ps):
00170         val = Decimal.parse(self, elt, ps)
00171         if val not in self.choices:
00172             raise EvaluateException('Value "' + str(val) + \
00173                         '" not in enumeration list',
00174                     ps.Backtrace(elt))
00175         return val
00176     
00177     def serialize(self, elt, sw, pyobj, name=None, orig=None, **kw):
00178         if pyobj not in self.choices:
00179             raise EvaluateException('Value not in int enumeration list',
00180                     ps.Backtrace(elt))
00181         Decimal.serialize(self, elt, sw, pyobj, name=name, orig=orig, **kw)
00182     
00183 
00184 if __name__ == '__main__': print _copyright

Generated on Wed Oct 20 2010 11:12:16 for APBS by  doxygen 1.7.2