def __init__(self, pyclass, ofwhat, pname=None, inorder=0, inline=0, mutable=1, hasextras=0, **kw): '''pyclass -- the Python class to hold the fields ofwhat -- a list of fields to be in the struct hasextras -- ignore extra input fields inorder -- fields must be in exact order or not inline -- don't href/id when serializing mutable -- object could change between multiple serializations type -- the (URI,localname) of the datatype ''' TypeCode.__init__(self, pname, **kw) self.pyclass = pyclass self.inorder = inorder self.inline = inline self.mutable = mutable if self.mutable: self.inline = 1 self.hasextras = hasextras self.type = kw.get('type') t = type(ofwhat) if t not in _seqtypes: raise TypeError( 'Struct ofwhat must be list or sequence, not ' + str(t)) self.ofwhat = tuple(ofwhat) if pname is None and kw.has_key('typed'): Any.parsemap[self.type] = self t = kw['typed'] for w in self.ofwhat: w.typed = t if TypeCode.typechecks: if self.pyclass is not None and type(self.pyclass) != types.ClassType: raise TypeError('pyclass must be None or a class, not ' + str(type(self.pyclass))) _check_typecode_list(self.ofwhat, 'Struct')
def __init__(self, atype, ofwhat, pname=None, dimensions=1, fill=None, sparse=False, mutable=False, size=None, nooffset=0, undeclared=False, childnames=None, **kw): TypeCode.__init__(self, pname, **kw) self.dimensions = dimensions self.atype = atype if undeclared is False and self.atype[1].endswith(']') is False: self.atype = (self.atype[0], '%s[]' % self.atype[1]) # Support multiple dimensions if self.dimensions != 1: raise TypeError("Only single-dimensioned arrays supported") self.fill = fill self.sparse = sparse #if self.sparse: ofwhat.minOccurs = 0 self.mutable = mutable self.size = size self.nooffset = nooffset self.undeclared = undeclared self.childnames = childnames if self.size: t = type(self.size) if isinstance(self.size, _inttypes): self.size = (self.size, ) elif isinstance(self.size, _seqtypes): self.size = tuple(self.size) elif TypeCode.typechecks: raise TypeError('Size must be integer or list, not ' + str(t)) # by default use Any ofwhat = ofwhat or Any() if TypeCode.typechecks: if self.undeclared is False and not isinstance( atype, _seqtypes) and len(atype) == 2: raise TypeError("Array type must be a sequence of len 2.") if not isinstance(ofwhat, TypeCode): raise TypeError( 'Array ofwhat outside the TypeCode hierarchy, ' + str(ofwhat.__class__)) if self.size: if len(self.size) != self.dimensions: raise TypeError('Array dimension/size mismatch') for s in self.size: if not isinstance(s, _inttypes): raise TypeError('Array size "' + str(s) + '" is not an integer.') self.ofwhat = ofwhat
def __init__(self, ofwhat, pname=None, **kw): '''choices -- list of typecodes; exactly one must be match ''' TypeCode.__init__(self, pname, **kw) t = type(ofwhat) if t not in _seqtypes: raise TypeError( 'Struct ofwhat must be list or sequence, not ' + str(t)) self.ofwhat = tuple(ofwhat) if len(self.ofwhat) == 0: raise TypeError('Empty choice') _check_typecode_list(self.ofwhat, 'Choice')
def __init__(self, atype, ofwhat, pname=None, dimensions=1, fill=None, sparse=0, mutable=0, size=None, nooffset=0, undeclared=0, childnames=None, **kw): TypeCode.__init__(self, pname, **kw) self.dimensions = dimensions self.atype = atype if not undeclared and self.atype[-1] != ']': self.atype = self.atype + '[]' # Support multiple dimensions if self.dimensions != 1: raise TypeError("Only single-dimensioned arrays supported") self.fill = fill self.sparse = sparse if self.sparse: ofwhat.optional = 1 self.mutable = mutable self.size = size self.nooffset = nooffset self.undeclared = undeclared self.childnames = childnames if self.size: t = type(self.size) if t in _inttypes: self.size = (self.size,) elif t in _seqtypes: self.size = tuple(self.size) elif TypeCode.typechecks: raise TypeError('Size must be integer or list, not ' + str(t)) if TypeCode.typechecks: if not self.undeclared and type(atype) not in _stringtypes: raise TypeError("Array type must be a string or None.") t = type(ofwhat) if t != types.InstanceType: raise TypeError( 'Array ofwhat must be an instance, not ' + str(t)) if not isinstance(ofwhat, TypeCode): raise TypeError( 'Array ofwhat outside the TypeCode hierarchy, ' + str(ofwhat.__class__)) if self.size: if len(self.size) != self.dimensions: raise TypeError('Array dimension/size mismatch') for s in self.size: if type(s) not in _inttypes: raise TypeError('Array size "' + str(s) + '" is not an integer.') self.ofwhat = ofwhat
def __init__(self, pyclass, ofwhat, pname=None, inorder=False, inline=False, mutable=True, mixed=False, mixed_aname='_text', **kw): """pyclass -- the Python class to hold the fields ofwhat -- a list of fields to be in the complexType inorder -- fields must be in exact order or not inline -- don't href/id when serializing mutable -- object could change between multiple serializations type -- the (URI,localname) of the datatype mixed -- mixed content model? True/False mixed_aname -- if mixed is True, specify text content here. Default _text """ TypeCode.__init__(self, pname, pyclass=pyclass, **kw) self.inorder = inorder self.inline = inline self.mutable = mutable self.mixed = mixed self.mixed_aname = None if mixed is True: self.mixed_aname = mixed_aname if self.mutable is True: self.inline = True self.type = kw.get('type') or _get_xsitype(self) t = type(ofwhat) if not isinstance(ofwhat, _seqtypes): raise TypeError('Struct ofwhat must be list or sequence, not ' + str(t)) self.ofwhat = tuple(ofwhat) if TypeCode.typechecks: # XXX Not sure how to determine if new-style class.. if self.pyclass is not None and \ not isinstance(self.pyclass, type) and not isinstance(self.pyclass, object): raise TypeError( 'pyclass must be None or an old-style/new-style class, not ' + str(type(self.pyclass))) _check_typecode_list(self.ofwhat, 'ComplexType')
def __init__(self, pname=None, aslist=0, **kw): TypeCode.__init__(self, pname, **kw) self.aslist = aslist self.tc = _Struct(None, [ _Any('key'), _Any('value') ], inline=1)
def __init__(self, pname=None, format='%s', **kw): TypeCode.__init__(self, pname, **kw) self.format = format