home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / ZSI / wstools / XMLSchema.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2010-11-24  |  76.5 KB  |  2,706 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. ident = '$Id: XMLSchema.py 1434 2007-11-01 22:42:47Z boverhof $'
  5. import types
  6. import weakref
  7. import sys
  8. import warnings
  9. from Namespaces import SCHEMA, XMLNS, SOAP
  10. from Utility import DOM, DOMException, Collection, SplitQName, basejoin, isfile
  11. from StringIO import StringIO
  12.  
  13. try:
  14.     from threading import RLock
  15. except ImportError:
  16.     
  17.     class RLock:
  18.         
  19.         def acquire():
  20.             pass
  21.  
  22.         
  23.         def release():
  24.             pass
  25.  
  26.  
  27.  
  28. TYPES = 'types'
  29. ATTRIBUTE_GROUPS = 'attr_groups'
  30. ATTRIBUTES = 'attr_decl'
  31. ELEMENTS = 'elements'
  32. MODEL_GROUPS = 'model_groups'
  33. BUILT_IN_NAMESPACES = [
  34.     SOAP.ENC,
  35.     SOAP.ENC12] + SCHEMA.XSD_LIST
  36.  
  37. def GetSchema(component):
  38.     parent = component
  39.     while not isinstance(parent, XMLSchema):
  40.         parent = parent._parent()
  41.     return parent
  42.  
  43.  
  44. class SchemaReader:
  45.     namespaceToSchema = { }
  46.     
  47.     def __init__(self, domReader = None, base_url = None):
  48.         self._SchemaReader__base_url = base_url
  49.         self._SchemaReader__readerClass = domReader
  50.         if not self._SchemaReader__readerClass:
  51.             self._SchemaReader__readerClass = DOMAdapter
  52.         
  53.         self._includes = { }
  54.         self._imports = { }
  55.  
  56.     
  57.     def __setImports(self, schema):
  58.         for ns, val in schema.imports.items():
  59.             if self._imports.has_key(ns):
  60.                 schema.addImportSchema(self._imports[ns])
  61.                 continue
  62.         
  63.  
  64.     
  65.     def __setIncludes(self, schema):
  66.         for schemaLocation, val in schema.includes.items():
  67.             if self._includes.has_key(schemaLocation):
  68.                 schema.addIncludeSchema(schemaLocation, self._imports[schemaLocation])
  69.                 continue
  70.         
  71.  
  72.     
  73.     def addSchemaByLocation(self, location, schema):
  74.         self._includes[location] = schema
  75.  
  76.     
  77.     def addSchemaByNamespace(self, schema):
  78.         self._imports[schema.targetNamespace] = schema
  79.  
  80.     
  81.     def loadFromNode(self, parent, element):
  82.         reader = self._SchemaReader__readerClass(element)
  83.         schema = XMLSchema(parent)
  84.         schema.wsdl = parent
  85.         schema.setBaseUrl(self._SchemaReader__base_url)
  86.         schema.load(reader)
  87.         return schema
  88.  
  89.     
  90.     def loadFromStream(self, file, url = None):
  91.         reader = self._SchemaReader__readerClass()
  92.         reader.loadDocument(file)
  93.         schema = XMLSchema()
  94.         if url is not None:
  95.             schema.setBaseUrl(url)
  96.         
  97.         schema.load(reader)
  98.         self._SchemaReader__setIncludes(schema)
  99.         self._SchemaReader__setImports(schema)
  100.         return schema
  101.  
  102.     
  103.     def loadFromString(self, data):
  104.         return self.loadFromStream(StringIO(data))
  105.  
  106.     
  107.     def loadFromURL(self, url, schema = None):
  108.         reader = self._SchemaReader__readerClass()
  109.         if self._SchemaReader__base_url:
  110.             url = basejoin(self._SchemaReader__base_url, url)
  111.         
  112.         reader.loadFromURL(url)
  113.         if not schema:
  114.             pass
  115.         schema = XMLSchema()
  116.         schema.setBaseUrl(url)
  117.         schema.load(reader)
  118.         self._SchemaReader__setIncludes(schema)
  119.         self._SchemaReader__setImports(schema)
  120.         return schema
  121.  
  122.     
  123.     def loadFromFile(self, filename):
  124.         if self._SchemaReader__base_url:
  125.             filename = basejoin(self._SchemaReader__base_url, filename)
  126.         
  127.         file = open(filename, 'rb')
  128.         
  129.         try:
  130.             schema = self.loadFromStream(file, filename)
  131.         finally:
  132.             file.close()
  133.  
  134.         return schema
  135.  
  136.  
  137.  
  138. class SchemaError(Exception):
  139.     pass
  140.  
  141.  
  142. class NoSchemaLocationWarning(Exception):
  143.     pass
  144.  
  145.  
  146. class DOMAdapterInterface:
  147.     
  148.     def hasattr(self, attr, ns = None):
  149.         raise NotImplementedError, 'adapter method not implemented'
  150.  
  151.     
  152.     def getContentList(self, *contents):
  153.         raise NotImplementedError, 'adapter method not implemented'
  154.  
  155.     
  156.     def setAttributeDictionary(self, attributes):
  157.         raise NotImplementedError, 'adapter method not implemented'
  158.  
  159.     
  160.     def getAttributeDictionary(self):
  161.         raise NotImplementedError, 'adapter method not implemented'
  162.  
  163.     
  164.     def getNamespace(self, prefix):
  165.         raise NotImplementedError, 'adapter method not implemented'
  166.  
  167.     
  168.     def getTagName(self):
  169.         raise NotImplementedError, 'adapter method not implemented'
  170.  
  171.     
  172.     def getParentNode(self):
  173.         raise NotImplementedError, 'adapter method not implemented'
  174.  
  175.     
  176.     def loadDocument(self, file):
  177.         raise NotImplementedError, 'adapter method not implemented'
  178.  
  179.     
  180.     def loadFromURL(self, url):
  181.         raise NotImplementedError, 'adapter method not implemented'
  182.  
  183.  
  184.  
  185. class DOMAdapter(DOMAdapterInterface):
  186.     
  187.     def __init__(self, node = None):
  188.         if hasattr(node, 'documentElement'):
  189.             self._DOMAdapter__node = node.documentElement
  190.         else:
  191.             self._DOMAdapter__node = node
  192.         self._DOMAdapter__attributes = None
  193.  
  194.     
  195.     def getNode(self):
  196.         return self._DOMAdapter__node
  197.  
  198.     
  199.     def hasattr(self, attr, ns = None):
  200.         if not self._DOMAdapter__attributes:
  201.             self.setAttributeDictionary()
  202.         
  203.         if ns:
  204.             return self._DOMAdapter__attributes.get(ns, { }).has_key(attr)
  205.         return self._DOMAdapter__attributes.has_key(attr)
  206.  
  207.     
  208.     def getContentList(self, *contents):
  209.         nodes = []
  210.         ELEMENT_NODE = self._DOMAdapter__node.ELEMENT_NODE
  211.         for child in DOM.getElements(self._DOMAdapter__node, None):
  212.             if child.nodeType == ELEMENT_NODE and SplitQName(child.tagName)[1] in contents:
  213.                 nodes.append(child)
  214.                 continue
  215.         
  216.         return map(self.__class__, nodes)
  217.  
  218.     
  219.     def setAttributeDictionary(self):
  220.         self._DOMAdapter__attributes = { }
  221.         for v in self._DOMAdapter__node._attrs.values():
  222.             self._DOMAdapter__attributes[v.nodeName] = v.nodeValue
  223.         
  224.  
  225.     
  226.     def getAttributeDictionary(self):
  227.         if not self._DOMAdapter__attributes:
  228.             self.setAttributeDictionary()
  229.         
  230.         return self._DOMAdapter__attributes
  231.  
  232.     
  233.     def getTagName(self):
  234.         return self._DOMAdapter__node.tagName
  235.  
  236.     
  237.     def getParentNode(self):
  238.         if self._DOMAdapter__node.parentNode.nodeType == self._DOMAdapter__node.ELEMENT_NODE:
  239.             return DOMAdapter(self._DOMAdapter__node.parentNode)
  240.  
  241.     
  242.     def getNamespace(self, prefix):
  243.         namespace = None
  244.         if prefix == 'xmlns':
  245.             namespace = DOM.findDefaultNS(prefix, self._DOMAdapter__node)
  246.         else:
  247.             
  248.             try:
  249.                 namespace = DOM.findNamespaceURI(prefix, self._DOMAdapter__node)
  250.             except DOMException:
  251.                 ex = None
  252.                 if prefix != 'xml':
  253.                     raise SchemaError, '%s namespace not declared for %s' % (prefix, self._DOMAdapter__node._get_tagName())
  254.                 prefix != 'xml'
  255.                 namespace = XMLNS.XML
  256.  
  257.         return namespace
  258.  
  259.     
  260.     def loadDocument(self, file):
  261.         self._DOMAdapter__node = DOM.loadDocument(file)
  262.         if hasattr(self._DOMAdapter__node, 'documentElement'):
  263.             self._DOMAdapter__node = self._DOMAdapter__node.documentElement
  264.         
  265.  
  266.     
  267.     def loadFromURL(self, url):
  268.         self._DOMAdapter__node = DOM.loadFromURL(url)
  269.         if hasattr(self._DOMAdapter__node, 'documentElement'):
  270.             self._DOMAdapter__node = self._DOMAdapter__node.documentElement
  271.         
  272.  
  273.  
  274.  
  275. class XMLBase:
  276.     tag = None
  277.     __indent = 0
  278.     __rlock = RLock()
  279.     
  280.     def __str__(self):
  281.         XMLBase._XMLBase__rlock.acquire()
  282.         XMLBase._XMLBase__indent += 1
  283.         tmp = '<' + str(self.__class__) + '>\n'
  284.         for k, v in self.__dict__.items():
  285.             tmp += '%s* %s = %s\n' % (XMLBase._XMLBase__indent * '  ', k, v)
  286.         
  287.         XMLBase._XMLBase__indent -= 1
  288.         XMLBase._XMLBase__rlock.release()
  289.         return tmp
  290.  
  291.  
  292.  
  293. class DefinitionMarker:
  294.     pass
  295.  
  296.  
  297. class DeclarationMarker:
  298.     pass
  299.  
  300.  
  301. class AttributeMarker:
  302.     pass
  303.  
  304.  
  305. class AttributeGroupMarker:
  306.     pass
  307.  
  308.  
  309. class WildCardMarker:
  310.     pass
  311.  
  312.  
  313. class ElementMarker:
  314.     pass
  315.  
  316.  
  317. class ReferenceMarker:
  318.     pass
  319.  
  320.  
  321. class ModelGroupMarker:
  322.     pass
  323.  
  324.  
  325. class AllMarker(ModelGroupMarker):
  326.     pass
  327.  
  328.  
  329. class ChoiceMarker(ModelGroupMarker):
  330.     pass
  331.  
  332.  
  333. class SequenceMarker(ModelGroupMarker):
  334.     pass
  335.  
  336.  
  337. class ExtensionMarker:
  338.     pass
  339.  
  340.  
  341. class RestrictionMarker:
  342.     facets = [
  343.         'enumeration',
  344.         'length',
  345.         'maxExclusive',
  346.         'maxInclusive',
  347.         'maxLength',
  348.         'minExclusive',
  349.         'minInclusive',
  350.         'minLength',
  351.         'pattern',
  352.         'fractionDigits',
  353.         'totalDigits',
  354.         'whiteSpace']
  355.  
  356.  
  357. class SimpleMarker:
  358.     pass
  359.  
  360.  
  361. class ListMarker:
  362.     pass
  363.  
  364.  
  365. class UnionMarker:
  366.     pass
  367.  
  368.  
  369. class ComplexMarker:
  370.     pass
  371.  
  372.  
  373. class LocalMarker:
  374.     pass
  375.  
  376.  
  377. class MarkerInterface:
  378.     
  379.     def isDefinition(self):
  380.         return isinstance(self, DefinitionMarker)
  381.  
  382.     
  383.     def isDeclaration(self):
  384.         return isinstance(self, DeclarationMarker)
  385.  
  386.     
  387.     def isAttribute(self):
  388.         return isinstance(self, AttributeMarker)
  389.  
  390.     
  391.     def isAttributeGroup(self):
  392.         return isinstance(self, AttributeGroupMarker)
  393.  
  394.     
  395.     def isElement(self):
  396.         return isinstance(self, ElementMarker)
  397.  
  398.     
  399.     def isReference(self):
  400.         return isinstance(self, ReferenceMarker)
  401.  
  402.     
  403.     def isWildCard(self):
  404.         return isinstance(self, WildCardMarker)
  405.  
  406.     
  407.     def isModelGroup(self):
  408.         return isinstance(self, ModelGroupMarker)
  409.  
  410.     
  411.     def isAll(self):
  412.         return isinstance(self, AllMarker)
  413.  
  414.     
  415.     def isChoice(self):
  416.         return isinstance(self, ChoiceMarker)
  417.  
  418.     
  419.     def isSequence(self):
  420.         return isinstance(self, SequenceMarker)
  421.  
  422.     
  423.     def isExtension(self):
  424.         return isinstance(self, ExtensionMarker)
  425.  
  426.     
  427.     def isRestriction(self):
  428.         return isinstance(self, RestrictionMarker)
  429.  
  430.     
  431.     def isSimple(self):
  432.         return isinstance(self, SimpleMarker)
  433.  
  434.     
  435.     def isComplex(self):
  436.         return isinstance(self, ComplexMarker)
  437.  
  438.     
  439.     def isLocal(self):
  440.         return isinstance(self, LocalMarker)
  441.  
  442.     
  443.     def isList(self):
  444.         return isinstance(self, ListMarker)
  445.  
  446.     
  447.     def isUnion(self):
  448.         return isinstance(self, UnionMarker)
  449.  
  450.  
  451.  
  452. class XMLSchemaComponent(XMLBase, MarkerInterface):
  453.     required = []
  454.     attributes = { }
  455.     contents = { }
  456.     xmlns_key = ''
  457.     xmlns = 'xmlns'
  458.     xml = 'xml'
  459.     
  460.     def __init__(self, parent = None):
  461.         self.attributes = None
  462.         self._parent = parent
  463.         if self._parent:
  464.             self._parent = weakref.ref(parent)
  465.         
  466.         if not (self.__class__ == XMLSchemaComponent):
  467.             if type(self.__class__.required) == type(XMLSchemaComponent.required) and type(self.__class__.attributes) == type(XMLSchemaComponent.attributes):
  468.                 pass
  469.             if not (type(self.__class__.contents) == type(XMLSchemaComponent.contents)):
  470.                 raise RuntimeError, 'Bad type for a class variable in %s' % self.__class__
  471.         not (type(self.__class__.contents) == type(XMLSchemaComponent.contents))
  472.  
  473.     
  474.     def getItemTrace(self):
  475.         (item, path, name, ref) = (self, [], 'name', 'ref')
  476.         while not isinstance(item, XMLSchema) and not isinstance(item, WSDLToolsAdapter):
  477.             attr = item.getAttribute(name)
  478.             if not attr:
  479.                 attr = item.getAttribute(ref)
  480.                 if not attr:
  481.                     path.append('<%s>' % item.tag)
  482.                 else:
  483.                     path.append('<%s ref="%s">' % (item.tag, attr))
  484.             else:
  485.                 path.append('<%s name="%s">' % (item.tag, attr))
  486.             item = item._parent()
  487.         
  488.         try:
  489.             tns = item.getTargetNamespace()
  490.         except:
  491.             tns = ''
  492.  
  493.         path.append('<%s targetNamespace="%s">' % (item.tag, tns))
  494.         path.reverse()
  495.         return ''.join(path)
  496.  
  497.     
  498.     def getTargetNamespace(self):
  499.         parent = self
  500.         targetNamespace = 'targetNamespace'
  501.         tns = self.attributes.get(targetNamespace)
  502.         while not tns and parent and parent._parent is not None:
  503.             parent = parent._parent()
  504.             tns = parent.attributes.get(targetNamespace)
  505.         if not tns:
  506.             pass
  507.         return ''
  508.  
  509.     
  510.     def getAttributeDeclaration(self, attribute):
  511.         return self.getQNameAttribute(ATTRIBUTES, attribute)
  512.  
  513.     
  514.     def getAttributeGroup(self, attribute):
  515.         return self.getQNameAttribute(ATTRIBUTE_GROUPS, attribute)
  516.  
  517.     
  518.     def getTypeDefinition(self, attribute):
  519.         return self.getQNameAttribute(TYPES, attribute)
  520.  
  521.     
  522.     def getElementDeclaration(self, attribute):
  523.         return self.getQNameAttribute(ELEMENTS, attribute)
  524.  
  525.     
  526.     def getModelGroup(self, attribute):
  527.         return self.getQNameAttribute(MODEL_GROUPS, attribute)
  528.  
  529.     
  530.     def getQNameAttribute(self, collection, attribute):
  531.         tdc = self.getAttributeQName(attribute)
  532.         if not tdc:
  533.             return None
  534.         obj = self.getSchemaItem(collection, tdc.getTargetNamespace(), tdc.getName())
  535.         if obj:
  536.             return obj
  537.  
  538.     
  539.     def getSchemaItem(self, collection, namespace, name):
  540.         parent = GetSchema(self)
  541.         if parent.targetNamespace == namespace:
  542.             
  543.             try:
  544.                 obj = getattr(parent, collection)[name]
  545.             except KeyError:
  546.                 ex = None
  547.                 raise KeyError, 'targetNamespace(%s) collection(%s) has no item(%s)' % (namespace, collection, name)
  548.  
  549.             return obj
  550.         if not parent.imports.has_key(namespace):
  551.             if namespace in BUILT_IN_NAMESPACES:
  552.                 return None
  553.             raise SchemaError, 'schema "%s" does not import namespace "%s"' % (parent.targetNamespace, namespace)
  554.         parent.imports.has_key(namespace)
  555.         schema = parent.imports[namespace]
  556.         if not isinstance(schema, XMLSchema):
  557.             schema = schema.getSchema()
  558.             if schema is not None:
  559.                 parent.imports[namespace] = schema
  560.             
  561.         
  562.         if schema is None:
  563.             if namespace in BUILT_IN_NAMESPACES:
  564.                 return None
  565.             raise SchemaError, 'no schema instance for imported namespace (%s).' % namespace
  566.         schema is None
  567.         if not isinstance(schema, XMLSchema):
  568.             raise TypeError, 'expecting XMLSchema instance not "%r"' % schema
  569.         isinstance(schema, XMLSchema)
  570.         
  571.         try:
  572.             obj = getattr(schema, collection)[name]
  573.         except KeyError:
  574.             ex = None
  575.             raise KeyError, 'targetNamespace(%s) collection(%s) has no item(%s)' % (namespace, collection, name)
  576.  
  577.         return obj
  578.  
  579.     
  580.     def getXMLNS(self, prefix = None):
  581.         if prefix == XMLSchemaComponent.xml:
  582.             return XMLNS.XML
  583.         parent = self
  584.         if not prefix:
  585.             pass
  586.         ns = self.attributes[XMLSchemaComponent.xmlns].get(XMLSchemaComponent.xmlns_key)
  587.         while not ns:
  588.             parent = parent._parent()
  589.             if not prefix:
  590.                 pass
  591.             ns = parent.attributes[XMLSchemaComponent.xmlns].get(XMLSchemaComponent.xmlns_key)
  592.             if not ns and isinstance(parent, WSDLToolsAdapter):
  593.                 if prefix is None:
  594.                     return ''
  595.                 raise SchemaError, 'unknown prefix %s' % prefix
  596.             isinstance(parent, WSDLToolsAdapter)
  597.             continue
  598.             prefix == XMLSchemaComponent.xml
  599.         return ns
  600.  
  601.     
  602.     def getAttribute(self, attribute):
  603.         if type(attribute) in (list, tuple):
  604.             if len(attribute) != 2:
  605.                 raise LookupError, 'To access attributes must use name or (namespace,name)'
  606.             len(attribute) != 2
  607.             ns_dict = self.attributes.get(attribute[0])
  608.             if ns_dict is None:
  609.                 return None
  610.             return ns_dict.get(attribute[1])
  611.         return self.attributes.get(attribute)
  612.  
  613.     
  614.     def getAttributeQName(self, attribute):
  615.         qname = self.getAttribute(attribute)
  616.         if isinstance(qname, TypeDescriptionComponent) is True:
  617.             return qname
  618.         if qname is None:
  619.             return None
  620.         (prefix, ncname) = SplitQName(qname)
  621.         namespace = self.getXMLNS(prefix)
  622.         return TypeDescriptionComponent((namespace, ncname))
  623.  
  624.     
  625.     def getAttributeName(self):
  626.         return self.getAttribute('name')
  627.  
  628.     
  629.     def setAttributes(self, node):
  630.         self.attributes = {
  631.             XMLSchemaComponent.xmlns: { } }
  632.         for k, v in node.getAttributeDictionary().items():
  633.             (prefix, value) = SplitQName(k)
  634.             if value == XMLSchemaComponent.xmlns:
  635.                 if not prefix:
  636.                     pass
  637.                 self.attributes[value][XMLSchemaComponent.xmlns_key] = v
  638.                 continue
  639.             if prefix:
  640.                 ns = node.getNamespace(prefix)
  641.                 if not ns:
  642.                     raise SchemaError, 'no namespace for attribute prefix %s' % prefix
  643.                 ns
  644.                 if not self.attributes.has_key(ns):
  645.                     self.attributes[ns] = { }
  646.                 elif self.attributes[ns].has_key(value):
  647.                     raise SchemaError, 'attribute %s declared multiple times in %s' % (value, ns)
  648.                 
  649.                 self.attributes[ns][value] = v
  650.                 continue
  651.             if not self.attributes.has_key(value):
  652.                 self.attributes[value] = v
  653.                 continue
  654.             raise SchemaError, 'attribute %s declared multiple times' % value
  655.         
  656.         if not isinstance(self, WSDLToolsAdapter):
  657.             self._XMLSchemaComponent__checkAttributes()
  658.         
  659.         self._XMLSchemaComponent__setAttributeDefaults()
  660.         for k in [
  661.             'type',
  662.             'element',
  663.             'base',
  664.             'ref',
  665.             'substitutionGroup',
  666.             'itemType']:
  667.             if self.attributes.has_key(k):
  668.                 (prefix, value) = SplitQName(self.attributes.get(k))
  669.                 self.attributes[k] = TypeDescriptionComponent((self.getXMLNS(prefix), value))
  670.                 continue
  671.         
  672.         for k in [
  673.             'memberTypes']:
  674.             if self.attributes.has_key(k):
  675.                 qnames = self.attributes[k]
  676.                 self.attributes[k] = []
  677.                 for qname in qnames.split():
  678.                     (prefix, value) = SplitQName(qname)
  679.                     self.attributes['memberTypes'].append(TypeDescriptionComponent((self.getXMLNS(prefix), value)))
  680.                 
  681.         
  682.  
  683.     
  684.     def getContents(self, node):
  685.         return node.getContentList(*self.__class__.contents['xsd'])
  686.  
  687.     
  688.     def __setAttributeDefaults(self):
  689.         for k, v in self.__class__.attributes.items():
  690.             if v is not None and self.attributes.has_key(k) is False:
  691.                 if isinstance(v, types.FunctionType):
  692.                     self.attributes[k] = v(self)
  693.                 else:
  694.                     self.attributes[k] = v
  695.             isinstance(v, types.FunctionType)
  696.         
  697.  
  698.     
  699.     def __checkAttributes(self):
  700.         for a in self.__class__.required:
  701.             if not self.attributes.has_key(a):
  702.                 raise SchemaError, 'class instance %s, missing required attribute %s' % (self.__class__, a)
  703.             self.attributes.has_key(a)
  704.         
  705.         for a, v in self.attributes.items():
  706.             if type(v) is dict:
  707.                 continue
  708.             
  709.             if a in (XMLSchemaComponent.xmlns, XMLNS.XML):
  710.                 continue
  711.             
  712.             if a not in self.__class__.attributes.keys():
  713.                 if self.isAttribute():
  714.                     pass
  715.                 if not self.isReference():
  716.                     raise SchemaError, '%s, unknown attribute(%s,%s)' % (self.getItemTrace(), a, self.attributes[a])
  717.             not self.isReference()
  718.         
  719.  
  720.  
  721.  
  722. class WSDLToolsAdapter(XMLSchemaComponent):
  723.     attributes = {
  724.         'name': None,
  725.         'targetNamespace': None }
  726.     tag = 'definitions'
  727.     
  728.     def __init__(self, wsdl):
  729.         XMLSchemaComponent.__init__(self, parent = wsdl)
  730.         self.setAttributes(DOMAdapter(wsdl.document))
  731.  
  732.     
  733.     def getImportSchemas(self):
  734.         return self._parent().types
  735.  
  736.  
  737.  
  738. class Notation(XMLSchemaComponent):
  739.     required = [
  740.         'name',
  741.         'public']
  742.     attributes = {
  743.         'id': None,
  744.         'name': None,
  745.         'public': None,
  746.         'system': None }
  747.     contents = {
  748.         'xsd': 'annotation' }
  749.     tag = 'notation'
  750.     
  751.     def __init__(self, parent):
  752.         XMLSchemaComponent.__init__(self, parent)
  753.         self.annotation = None
  754.  
  755.     
  756.     def fromDom(self, node):
  757.         self.setAttributes(node)
  758.         contents = self.getContents(node)
  759.         for i in contents:
  760.             component = SplitQName(i.getTagName())[1]
  761.             if component == 'annotation' and not (self.annotation):
  762.                 self.annotation = Annotation(self)
  763.                 self.annotation.fromDom(i)
  764.                 continue
  765.             raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  766.         
  767.  
  768.  
  769.  
  770. class Annotation(XMLSchemaComponent):
  771.     attributes = {
  772.         'id': None }
  773.     contents = {
  774.         'xsd': ('documentation', 'appinfo') }
  775.     tag = 'annotation'
  776.     
  777.     def __init__(self, parent):
  778.         XMLSchemaComponent.__init__(self, parent)
  779.         self.content = None
  780.  
  781.     
  782.     def fromDom(self, node):
  783.         self.setAttributes(node)
  784.         contents = self.getContents(node)
  785.         content = []
  786.         for i in contents:
  787.             component = SplitQName(i.getTagName())[1]
  788.             if component == 'documentation':
  789.                 continue
  790.                 continue
  791.             if component == 'appinfo':
  792.                 continue
  793.                 continue
  794.             raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  795.         
  796.         self.content = tuple(content)
  797.  
  798.     
  799.     class Documentation(XMLSchemaComponent):
  800.         attributes = {
  801.             'source': None,
  802.             'xml:lang': None }
  803.         contents = {
  804.             'xsd': ('mixed', 'any') }
  805.         tag = 'documentation'
  806.         
  807.         def __init__(self, parent):
  808.             XMLSchemaComponent.__init__(self, parent)
  809.             self.content = None
  810.  
  811.         
  812.         def fromDom(self, node):
  813.             self.setAttributes(node)
  814.             contents = self.getContents(node)
  815.             content = []
  816.             for i in contents:
  817.                 component = SplitQName(i.getTagName())[1]
  818.                 if component == 'mixed':
  819.                     continue
  820.                     continue
  821.                 if component == 'any':
  822.                     continue
  823.                     continue
  824.                 raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  825.             
  826.             self.content = tuple(content)
  827.  
  828.  
  829.     
  830.     class Appinfo(XMLSchemaComponent):
  831.         attributes = {
  832.             'source': None,
  833.             'anyURI': None }
  834.         contents = {
  835.             'xsd': ('mixed', 'any') }
  836.         tag = 'appinfo'
  837.         
  838.         def __init__(self, parent):
  839.             XMLSchemaComponent.__init__(self, parent)
  840.             self.content = None
  841.  
  842.         
  843.         def fromDom(self, node):
  844.             self.setAttributes(node)
  845.             contents = self.getContents(node)
  846.             content = []
  847.             for i in contents:
  848.                 component = SplitQName(i.getTagName())[1]
  849.                 if component == 'mixed':
  850.                     continue
  851.                     continue
  852.                 if component == 'any':
  853.                     continue
  854.                     continue
  855.                 raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  856.             
  857.             self.content = tuple(content)
  858.  
  859.  
  860.  
  861.  
  862. class XMLSchemaFake:
  863.     
  864.     def __init__(self, element):
  865.         self.targetNamespace = DOM.getAttr(element, 'targetNamespace')
  866.         self.element = element
  867.  
  868.  
  869.  
  870. class XMLSchema(XMLSchemaComponent):
  871.     attributes = {
  872.         'id': None,
  873.         'version': None,
  874.         'xml:lang': None,
  875.         'targetNamespace': None,
  876.         'attributeFormDefault': 'unqualified',
  877.         'elementFormDefault': 'unqualified',
  878.         'blockDefault': None,
  879.         'finalDefault': None }
  880.     contents = {
  881.         'xsd': ('include', 'import', 'redefine', 'annotation', 'attribute', 'attributeGroup', 'complexType', 'element', 'group', 'notation', 'simpleType', 'annotation') }
  882.     empty_namespace = ''
  883.     tag = 'schema'
  884.     
  885.     def __init__(self, parent = None):
  886.         self._XMLSchema__node = None
  887.         self.targetNamespace = None
  888.         XMLSchemaComponent.__init__(self, parent)
  889.         
  890.         f = lambda k: k.attributes['name']
  891.         
  892.         ns = lambda k: k.attributes['namespace']
  893.         
  894.         sl = lambda k: k.attributes['schemaLocation']
  895.         self.includes = Collection(self, key = sl)
  896.         self.imports = Collection(self, key = ns)
  897.         self.elements = Collection(self, key = f)
  898.         self.types = Collection(self, key = f)
  899.         self.attr_decl = Collection(self, key = f)
  900.         self.attr_groups = Collection(self, key = f)
  901.         self.model_groups = Collection(self, key = f)
  902.         self.notations = Collection(self, key = f)
  903.         self._imported_schemas = { }
  904.         self._included_schemas = { }
  905.         self._base_url = None
  906.  
  907.     
  908.     def getNode(self):
  909.         return self._XMLSchema__node
  910.  
  911.     
  912.     def addImportSchema(self, schema):
  913.         if not isinstance(schema, XMLSchema):
  914.             raise TypeError, 'expecting a Schema instance'
  915.         isinstance(schema, XMLSchema)
  916.         if schema.targetNamespace != self.targetNamespace:
  917.             self._imported_schemas[schema.targetNamespace] = schema
  918.         else:
  919.             raise SchemaError, 'import schema bad targetNamespace'
  920.         return schema.targetNamespace != self.targetNamespace
  921.  
  922.     
  923.     def addIncludeSchema(self, schemaLocation, schema):
  924.         if not isinstance(schema, XMLSchema):
  925.             raise TypeError, 'expecting a Schema instance'
  926.         isinstance(schema, XMLSchema)
  927.         if not (schema.targetNamespace) or schema.targetNamespace == self.targetNamespace:
  928.             self._included_schemas[schemaLocation] = schema
  929.         else:
  930.             raise SchemaError, 'include schema bad targetNamespace'
  931.         return schema.targetNamespace == self.targetNamespace
  932.  
  933.     
  934.     def setImportSchemas(self, schema_dict):
  935.         self._imported_schemas = schema_dict
  936.  
  937.     
  938.     def getImportSchemas(self):
  939.         return self._imported_schemas
  940.  
  941.     
  942.     def getSchemaNamespacesToImport(self):
  943.         return tuple(self.includes.keys())
  944.  
  945.     
  946.     def setIncludeSchemas(self, schema_dict):
  947.         self._included_schemas = schema_dict
  948.  
  949.     
  950.     def getIncludeSchemas(self):
  951.         return self._included_schemas
  952.  
  953.     
  954.     def getBaseUrl(self):
  955.         return self._base_url
  956.  
  957.     
  958.     def setBaseUrl(self, url):
  959.         self._base_url = url
  960.  
  961.     
  962.     def getElementFormDefault(self):
  963.         return self.attributes.get('elementFormDefault')
  964.  
  965.     
  966.     def isElementFormDefaultQualified(self):
  967.         return self.attributes.get('elementFormDefault') == 'qualified'
  968.  
  969.     
  970.     def getAttributeFormDefault(self):
  971.         return self.attributes.get('attributeFormDefault')
  972.  
  973.     
  974.     def getBlockDefault(self):
  975.         return self.attributes.get('blockDefault')
  976.  
  977.     
  978.     def getFinalDefault(self):
  979.         return self.attributes.get('finalDefault')
  980.  
  981.     
  982.     def load(self, node, location = None):
  983.         self._XMLSchema__node = node
  984.         pnode = node.getParentNode()
  985.         if pnode:
  986.             pname = SplitQName(pnode.getTagName())[1]
  987.             if pname == 'types':
  988.                 attributes = { }
  989.                 self.setAttributes(pnode)
  990.                 attributes.update(self.attributes)
  991.                 self.setAttributes(node)
  992.                 for k, v in attributes['xmlns'].items():
  993.                     if not self.attributes['xmlns'].has_key(k):
  994.                         self.attributes['xmlns'][k] = v
  995.                         continue
  996.                 
  997.             else:
  998.                 self.setAttributes(node)
  999.         else:
  1000.             self.setAttributes(node)
  1001.         self.targetNamespace = self.getTargetNamespace()
  1002.         for childNode in self.getContents(node):
  1003.             component = SplitQName(childNode.getTagName())[1]
  1004.             if component == 'include':
  1005.                 tp = self.__class__.Include(self)
  1006.                 tp.fromDom(childNode)
  1007.                 sl = tp.attributes['schemaLocation']
  1008.                 schema = tp.getSchema()
  1009.                 if not self.getIncludeSchemas().has_key(sl):
  1010.                     self.addIncludeSchema(sl, schema)
  1011.                 
  1012.                 self.includes[sl] = tp
  1013.                 pn = childNode.getParentNode().getNode()
  1014.                 pn.removeChild(childNode.getNode())
  1015.                 for child in schema.getNode().getNode().childNodes:
  1016.                     pn.appendChild(child.cloneNode(1))
  1017.                 
  1018.                 for collection in [
  1019.                     'imports',
  1020.                     'elements',
  1021.                     'types',
  1022.                     'attr_decl',
  1023.                     'attr_groups',
  1024.                     'model_groups',
  1025.                     'notations']:
  1026.                     for k, v in getattr(schema, collection).items():
  1027.                         if not getattr(self, collection).has_key(k):
  1028.                             v._parent = weakref.ref(self)
  1029.                             getattr(self, collection)[k] = v
  1030.                             continue
  1031.                         warnings.warn('Not keeping schema component.')
  1032.                     
  1033.                 
  1034.             if component == 'import':
  1035.                 slocd = SchemaReader.namespaceToSchema
  1036.                 tp = self.__class__.Import(self)
  1037.                 tp.fromDom(childNode)
  1038.                 if not tp.getAttribute('namespace'):
  1039.                     pass
  1040.                 import_ns = self.__class__.empty_namespace
  1041.                 schema = slocd.get(import_ns)
  1042.                 if schema is None:
  1043.                     schema = XMLSchema()
  1044.                     slocd[import_ns] = schema
  1045.                     
  1046.                     try:
  1047.                         tp.loadSchema(schema)
  1048.                     except NoSchemaLocationWarning:
  1049.                         ex = None
  1050.                         del slocd[import_ns]
  1051.                         continue
  1052.                     except SchemaError:
  1053.                         ex = None
  1054.                         warnings.warn('<import namespace="%s">, %s' % (import_ns, 'failed to load schema instance, resort to lazy eval when necessary'))
  1055.                         del slocd[import_ns]
  1056.                         
  1057.                         class _LazyEvalImport('_LazyEvalImport', (str,)):
  1058.                             
  1059.                             def getSchema(namespace):
  1060.                                 schema = slocd.get(namespace)
  1061.                                 if schema is None:
  1062.                                     parent = self._parent()
  1063.                                     wstypes = parent
  1064.                                     if isinstance(parent, WSDLToolsAdapter):
  1065.                                         wstypes = parent.getImportSchemas()
  1066.                                     
  1067.                                     schema = wstypes.get(namespace)
  1068.                                 
  1069.                                 if isinstance(schema, XMLSchema):
  1070.                                     self.imports[namespace] = schema
  1071.                                     return schema
  1072.  
  1073.  
  1074.                         self.imports[import_ns] = _LazyEvalImport(import_ns)
  1075.                         continue
  1076.                     except:
  1077.                         None<EXCEPTION MATCH>NoSchemaLocationWarning
  1078.                     
  1079.  
  1080.                 None<EXCEPTION MATCH>NoSchemaLocationWarning
  1081.                 tp._schema = schema
  1082.                 if self.getImportSchemas().has_key(import_ns):
  1083.                     warnings.warn('Detected multiple imports of the namespace "%s" ' % import_ns)
  1084.                 
  1085.                 self.addImportSchema(schema)
  1086.                 self.imports[import_ns] = tp
  1087.                 continue
  1088.             if component == 'redefine':
  1089.                 warnings.warn('redefine is ignored')
  1090.                 continue
  1091.             if component == 'annotation':
  1092.                 warnings.warn('annotation is ignored')
  1093.                 continue
  1094.             if component == 'attribute':
  1095.                 tp = AttributeDeclaration(self)
  1096.                 tp.fromDom(childNode)
  1097.                 self.attr_decl[tp.getAttribute('name')] = tp
  1098.                 continue
  1099.             if component == 'attributeGroup':
  1100.                 tp = AttributeGroupDefinition(self)
  1101.                 tp.fromDom(childNode)
  1102.                 self.attr_groups[tp.getAttribute('name')] = tp
  1103.                 continue
  1104.             if component == 'element':
  1105.                 tp = ElementDeclaration(self)
  1106.                 tp.fromDom(childNode)
  1107.                 self.elements[tp.getAttribute('name')] = tp
  1108.                 continue
  1109.             if component == 'group':
  1110.                 tp = ModelGroupDefinition(self)
  1111.                 tp.fromDom(childNode)
  1112.                 self.model_groups[tp.getAttribute('name')] = tp
  1113.                 continue
  1114.             if component == 'notation':
  1115.                 tp = Notation(self)
  1116.                 tp.fromDom(childNode)
  1117.                 self.notations[tp.getAttribute('name')] = tp
  1118.                 continue
  1119.             if component == 'complexType':
  1120.                 tp = ComplexType(self)
  1121.                 tp.fromDom(childNode)
  1122.                 self.types[tp.getAttribute('name')] = tp
  1123.                 continue
  1124.             if component == 'simpleType':
  1125.                 tp = SimpleType(self)
  1126.                 tp.fromDom(childNode)
  1127.                 self.types[tp.getAttribute('name')] = tp
  1128.                 continue
  1129.         
  1130.  
  1131.     
  1132.     class Import(XMLSchemaComponent):
  1133.         attributes = {
  1134.             'id': None,
  1135.             'namespace': None,
  1136.             'schemaLocation': None }
  1137.         contents = {
  1138.             'xsd': [
  1139.                 'annotation'] }
  1140.         tag = 'import'
  1141.         
  1142.         def __init__(self, parent):
  1143.             XMLSchemaComponent.__init__(self, parent)
  1144.             self.annotation = None
  1145.             self._schema = None
  1146.  
  1147.         
  1148.         def fromDom(self, node):
  1149.             self.setAttributes(node)
  1150.             contents = self.getContents(node)
  1151.             if self.attributes['namespace'] == self.getTargetNamespace():
  1152.                 raise SchemaError, 'namespace of schema and import match'
  1153.             self.attributes['namespace'] == self.getTargetNamespace()
  1154.             for i in contents:
  1155.                 component = SplitQName(i.getTagName())[1]
  1156.                 if component == 'annotation' and not (self.annotation):
  1157.                     self.annotation = Annotation(self)
  1158.                     self.annotation.fromDom(i)
  1159.                     continue
  1160.                 raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  1161.             
  1162.  
  1163.         
  1164.         def getSchema(self):
  1165.             if not self._schema:
  1166.                 ns = self.attributes['namespace']
  1167.                 schema = self._parent().getImportSchemas().get(ns)
  1168.                 if not schema and self._parent()._parent:
  1169.                     schema = self._parent()._parent().getImportSchemas().get(ns)
  1170.                 
  1171.                 if not schema:
  1172.                     url = self.attributes.get('schemaLocation')
  1173.                     if not url:
  1174.                         raise SchemaError, 'namespace(%s) is unknown' % ns
  1175.                     url
  1176.                     base_url = self._parent().getBaseUrl()
  1177.                     reader = SchemaReader(base_url = base_url)
  1178.                     reader._imports = self._parent().getImportSchemas()
  1179.                     reader._includes = self._parent().getIncludeSchemas()
  1180.                     self._schema = reader.loadFromURL(url)
  1181.                 
  1182.             
  1183.             if not self._schema:
  1184.                 pass
  1185.             return schema
  1186.  
  1187.         
  1188.         def loadSchema(self, schema):
  1189.             base_url = self._parent().getBaseUrl()
  1190.             reader = SchemaReader(base_url = base_url)
  1191.             reader._imports = self._parent().getImportSchemas()
  1192.             reader._includes = self._parent().getIncludeSchemas()
  1193.             self._schema = schema
  1194.             if not self.attributes.has_key('schemaLocation'):
  1195.                 raise NoSchemaLocationWarning('no schemaLocation attribute in import')
  1196.             self.attributes.has_key('schemaLocation')
  1197.             
  1198.             try:
  1199.                 reader.loadFromFile(self.attributes.get('schemaLocation'), schema)
  1200.             except Exception:
  1201.                 reader.loadFromURL(self.attributes.get('schemaLocation'), schema)
  1202.  
  1203.  
  1204.  
  1205.     
  1206.     class Include(XMLSchemaComponent):
  1207.         required = [
  1208.             'schemaLocation']
  1209.         attributes = {
  1210.             'id': None,
  1211.             'schemaLocation': None }
  1212.         contents = {
  1213.             'xsd': [
  1214.                 'annotation'] }
  1215.         tag = 'include'
  1216.         
  1217.         def __init__(self, parent):
  1218.             XMLSchemaComponent.__init__(self, parent)
  1219.             self.annotation = None
  1220.             self._schema = None
  1221.  
  1222.         
  1223.         def fromDom(self, node):
  1224.             self.setAttributes(node)
  1225.             contents = self.getContents(node)
  1226.             for i in contents:
  1227.                 component = SplitQName(i.getTagName())[1]
  1228.                 if component == 'annotation' and not (self.annotation):
  1229.                     self.annotation = Annotation(self)
  1230.                     self.annotation.fromDom(i)
  1231.                     continue
  1232.                 raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  1233.             
  1234.  
  1235.         
  1236.         def getSchema(self):
  1237.             if not self._schema:
  1238.                 schema = self._parent()
  1239.                 self._schema = schema.getIncludeSchemas().get(self.attributes['schemaLocation'])
  1240.                 if not self._schema:
  1241.                     url = self.attributes['schemaLocation']
  1242.                     reader = SchemaReader(base_url = schema.getBaseUrl())
  1243.                     reader._imports = schema.getImportSchemas()
  1244.                     reader._includes = schema.getIncludeSchemas()
  1245.                     self._schema = XMLSchema(schema)
  1246.                     reader.loadFromURL(url, self._schema)
  1247.                 
  1248.             
  1249.             return self._schema
  1250.  
  1251.  
  1252.  
  1253.  
  1254. class AttributeDeclaration(XMLSchemaComponent, AttributeMarker, DeclarationMarker):
  1255.     required = [
  1256.         'name']
  1257.     attributes = {
  1258.         'id': None,
  1259.         'name': None,
  1260.         'type': None,
  1261.         'default': None,
  1262.         'fixed': None }
  1263.     contents = {
  1264.         'xsd': [
  1265.             'annotation',
  1266.             'simpleType'] }
  1267.     tag = 'attribute'
  1268.     
  1269.     def __init__(self, parent):
  1270.         XMLSchemaComponent.__init__(self, parent)
  1271.         self.annotation = None
  1272.         self.content = None
  1273.  
  1274.     
  1275.     def fromDom(self, node):
  1276.         self.setAttributes(node)
  1277.         contents = self.getContents(node)
  1278.         for i in contents:
  1279.             component = SplitQName(i.getTagName())[1]
  1280.             if component == 'annotation' and not (self.annotation):
  1281.                 self.annotation = Annotation(self)
  1282.                 self.annotation.fromDom(i)
  1283.                 continue
  1284.             if component == 'simpleType':
  1285.                 self.content = AnonymousSimpleType(self)
  1286.                 self.content.fromDom(i)
  1287.                 continue
  1288.             raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  1289.         
  1290.  
  1291.  
  1292.  
  1293. class LocalAttributeDeclaration(AttributeDeclaration, AttributeMarker, LocalMarker, DeclarationMarker):
  1294.     required = [
  1295.         'name']
  1296.     attributes = {
  1297.         'id': None,
  1298.         'name': None,
  1299.         'type': None,
  1300.         'form': (lambda self: GetSchema(self).getAttributeFormDefault()),
  1301.         'use': 'optional',
  1302.         'default': None,
  1303.         'fixed': None }
  1304.     contents = {
  1305.         'xsd': [
  1306.             'annotation',
  1307.             'simpleType'] }
  1308.     
  1309.     def __init__(self, parent):
  1310.         AttributeDeclaration.__init__(self, parent)
  1311.         self.annotation = None
  1312.         self.content = None
  1313.  
  1314.     
  1315.     def fromDom(self, node):
  1316.         self.setAttributes(node)
  1317.         contents = self.getContents(node)
  1318.         for i in contents:
  1319.             component = SplitQName(i.getTagName())[1]
  1320.             if component == 'annotation' and not (self.annotation):
  1321.                 self.annotation = Annotation(self)
  1322.                 self.annotation.fromDom(i)
  1323.                 continue
  1324.             if component == 'simpleType':
  1325.                 self.content = AnonymousSimpleType(self)
  1326.                 self.content.fromDom(i)
  1327.                 continue
  1328.             raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  1329.         
  1330.  
  1331.  
  1332.  
  1333. class AttributeWildCard(XMLSchemaComponent, AttributeMarker, DeclarationMarker, WildCardMarker):
  1334.     attributes = {
  1335.         'id': None,
  1336.         'namespace': '##any',
  1337.         'processContents': 'strict' }
  1338.     contents = {
  1339.         'xsd': [
  1340.             'annotation'] }
  1341.     tag = 'anyAttribute'
  1342.     
  1343.     def __init__(self, parent):
  1344.         XMLSchemaComponent.__init__(self, parent)
  1345.         self.annotation = None
  1346.  
  1347.     
  1348.     def fromDom(self, node):
  1349.         self.setAttributes(node)
  1350.         contents = self.getContents(node)
  1351.         for i in contents:
  1352.             component = SplitQName(i.getTagName())[1]
  1353.             if component == 'annotation' and not (self.annotation):
  1354.                 self.annotation = Annotation(self)
  1355.                 self.annotation.fromDom(i)
  1356.                 continue
  1357.             raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  1358.         
  1359.  
  1360.  
  1361.  
  1362. class AttributeReference(XMLSchemaComponent, AttributeMarker, ReferenceMarker):
  1363.     required = [
  1364.         'ref']
  1365.     attributes = {
  1366.         'id': None,
  1367.         'ref': None,
  1368.         'use': 'optional',
  1369.         'default': None,
  1370.         'fixed': None }
  1371.     contents = {
  1372.         'xsd': [
  1373.             'annotation'] }
  1374.     tag = 'attribute'
  1375.     
  1376.     def __init__(self, parent):
  1377.         XMLSchemaComponent.__init__(self, parent)
  1378.         self.annotation = None
  1379.  
  1380.     
  1381.     def getAttributeDeclaration(self, attribute = 'ref'):
  1382.         return XMLSchemaComponent.getAttributeDeclaration(self, attribute)
  1383.  
  1384.     
  1385.     def fromDom(self, node):
  1386.         self.setAttributes(node)
  1387.         contents = self.getContents(node)
  1388.         for i in contents:
  1389.             component = SplitQName(i.getTagName())[1]
  1390.             if component == 'annotation' and not (self.annotation):
  1391.                 self.annotation = Annotation(self)
  1392.                 self.annotation.fromDom(i)
  1393.                 continue
  1394.             raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  1395.         
  1396.  
  1397.  
  1398.  
  1399. class AttributeGroupDefinition(XMLSchemaComponent, AttributeGroupMarker, DefinitionMarker):
  1400.     required = [
  1401.         'name']
  1402.     attributes = {
  1403.         'id': None,
  1404.         'name': None }
  1405.     contents = {
  1406.         'xsd': [
  1407.             'annotation',
  1408.             'attribute',
  1409.             'attributeGroup',
  1410.             'anyAttribute'] }
  1411.     tag = 'attributeGroup'
  1412.     
  1413.     def __init__(self, parent):
  1414.         XMLSchemaComponent.__init__(self, parent)
  1415.         self.annotation = None
  1416.         self.attr_content = None
  1417.  
  1418.     
  1419.     def getAttributeContent(self):
  1420.         return self.attr_content
  1421.  
  1422.     
  1423.     def fromDom(self, node):
  1424.         self.setAttributes(node)
  1425.         contents = self.getContents(node)
  1426.         content = []
  1427.         for indx in range(len(contents)):
  1428.             component = SplitQName(contents[indx].getTagName())[1]
  1429.             if component == 'annotation' and not indx:
  1430.                 self.annotation = Annotation(self)
  1431.                 self.annotation.fromDom(contents[indx])
  1432.                 continue
  1433.             if component == 'attribute':
  1434.                 if contents[indx].hasattr('name'):
  1435.                     content.append(LocalAttributeDeclaration(self))
  1436.                 elif contents[indx].hasattr('ref'):
  1437.                     content.append(AttributeReference(self))
  1438.                 else:
  1439.                     raise SchemaError, 'Unknown attribute type'
  1440.                 contents[indx].hasattr('name')[-1].fromDom(contents[indx])
  1441.                 continue
  1442.             if component == 'attributeGroup':
  1443.                 content.append(AttributeGroupReference(self))
  1444.                 content[-1].fromDom(contents[indx])
  1445.                 continue
  1446.             if component == 'anyAttribute':
  1447.                 if len(contents) != indx + 1:
  1448.                     raise SchemaError, 'anyAttribute is out of order in %s' % self.getItemTrace()
  1449.                 len(contents) != indx + 1
  1450.                 content.append(AttributeWildCard(self))
  1451.                 content[-1].fromDom(contents[indx])
  1452.                 continue
  1453.             raise SchemaError, 'Unknown component (%s)' % contents[indx].getTagName()
  1454.         
  1455.         self.attr_content = tuple(content)
  1456.  
  1457.  
  1458.  
  1459. class AttributeGroupReference(XMLSchemaComponent, AttributeGroupMarker, ReferenceMarker):
  1460.     required = [
  1461.         'ref']
  1462.     attributes = {
  1463.         'id': None,
  1464.         'ref': None }
  1465.     contents = {
  1466.         'xsd': [
  1467.             'annotation'] }
  1468.     tag = 'attributeGroup'
  1469.     
  1470.     def __init__(self, parent):
  1471.         XMLSchemaComponent.__init__(self, parent)
  1472.         self.annotation = None
  1473.  
  1474.     
  1475.     def getAttributeGroup(self, attribute = 'ref'):
  1476.         return XMLSchemaComponent.getAttributeGroup(self, attribute)
  1477.  
  1478.     
  1479.     def fromDom(self, node):
  1480.         self.setAttributes(node)
  1481.         contents = self.getContents(node)
  1482.         for i in contents:
  1483.             component = SplitQName(i.getTagName())[1]
  1484.             if component == 'annotation' and not (self.annotation):
  1485.                 self.annotation = Annotation(self)
  1486.                 self.annotation.fromDom(i)
  1487.                 continue
  1488.             raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  1489.         
  1490.  
  1491.  
  1492.  
  1493. class IdentityConstrants(XMLSchemaComponent):
  1494.     
  1495.     def __init__(self, parent):
  1496.         XMLSchemaComponent.__init__(self, parent)
  1497.         self.selector = None
  1498.         self.fields = None
  1499.         self.annotation = None
  1500.  
  1501.     
  1502.     def fromDom(self, node):
  1503.         self.setAttributes(node)
  1504.         contents = self.getContents(node)
  1505.         fields = []
  1506.         for i in contents:
  1507.             component = SplitQName(i.getTagName())[1]
  1508.             if component in self.__class__.contents['xsd']:
  1509.                 if component == 'annotation' and not (self.annotation):
  1510.                     self.annotation = Annotation(self)
  1511.                     self.annotation.fromDom(i)
  1512.                 elif component == 'selector':
  1513.                     self.selector = self.Selector(self)
  1514.                     self.selector.fromDom(i)
  1515.                     continue
  1516.                 elif component == 'field':
  1517.                     fields.append(self.Field(self))
  1518.                     fields[-1].fromDom(i)
  1519.                     continue
  1520.                 else:
  1521.                     raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  1522.             not (self.annotation)
  1523.             raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  1524.             self.fields = tuple(fields)
  1525.         
  1526.  
  1527.     
  1528.     class Constraint(XMLSchemaComponent):
  1529.         
  1530.         def __init__(self, parent):
  1531.             XMLSchemaComponent.__init__(self, parent)
  1532.             self.annotation = None
  1533.  
  1534.         
  1535.         def fromDom(self, node):
  1536.             self.setAttributes(node)
  1537.             contents = self.getContents(node)
  1538.             for i in contents:
  1539.                 component = SplitQName(i.getTagName())[1]
  1540.                 if component in self.__class__.contents['xsd']:
  1541.                     if component == 'annotation' and not (self.annotation):
  1542.                         self.annotation = Annotation(self)
  1543.                         self.annotation.fromDom(i)
  1544.                     else:
  1545.                         raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  1546.                 not (self.annotation)
  1547.                 raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  1548.             
  1549.  
  1550.  
  1551.     
  1552.     class Selector(Constraint):
  1553.         required = [
  1554.             'xpath']
  1555.         attributes = {
  1556.             'id': None,
  1557.             'xpath': None }
  1558.         contents = {
  1559.             'xsd': [
  1560.                 'annotation'] }
  1561.         tag = 'selector'
  1562.  
  1563.     
  1564.     class Field(Constraint):
  1565.         required = [
  1566.             'xpath']
  1567.         attributes = {
  1568.             'id': None,
  1569.             'xpath': None }
  1570.         contents = {
  1571.             'xsd': [
  1572.                 'annotation'] }
  1573.         tag = 'field'
  1574.  
  1575.  
  1576.  
  1577. class Unique(IdentityConstrants):
  1578.     required = [
  1579.         'name']
  1580.     attributes = {
  1581.         'id': None,
  1582.         'name': None }
  1583.     contents = {
  1584.         'xsd': [
  1585.             'annotation',
  1586.             'selector',
  1587.             'field'] }
  1588.     tag = 'unique'
  1589.  
  1590.  
  1591. class Key(IdentityConstrants):
  1592.     required = [
  1593.         'name']
  1594.     attributes = {
  1595.         'id': None,
  1596.         'name': None }
  1597.     contents = {
  1598.         'xsd': [
  1599.             'annotation',
  1600.             'selector',
  1601.             'field'] }
  1602.     tag = 'key'
  1603.  
  1604.  
  1605. class KeyRef(IdentityConstrants):
  1606.     required = [
  1607.         'name',
  1608.         'refer']
  1609.     attributes = {
  1610.         'id': None,
  1611.         'name': None,
  1612.         'refer': None }
  1613.     contents = {
  1614.         'xsd': [
  1615.             'annotation',
  1616.             'selector',
  1617.             'field'] }
  1618.     tag = 'keyref'
  1619.  
  1620.  
  1621. class ElementDeclaration(XMLSchemaComponent, ElementMarker, DeclarationMarker):
  1622.     required = [
  1623.         'name']
  1624.     attributes = {
  1625.         'id': None,
  1626.         'name': None,
  1627.         'type': None,
  1628.         'default': None,
  1629.         'fixed': None,
  1630.         'nillable': 0,
  1631.         'abstract': 0,
  1632.         'substitutionGroup': None,
  1633.         'block': (lambda self: self._parent().getBlockDefault()),
  1634.         'final': (lambda self: self._parent().getFinalDefault()) }
  1635.     contents = {
  1636.         'xsd': [
  1637.             'annotation',
  1638.             'simpleType',
  1639.             'complexType',
  1640.             'key',
  1641.             'keyref',
  1642.             'unique'] }
  1643.     tag = 'element'
  1644.     
  1645.     def __init__(self, parent):
  1646.         XMLSchemaComponent.__init__(self, parent)
  1647.         self.annotation = None
  1648.         self.content = None
  1649.         self.constraints = ()
  1650.  
  1651.     
  1652.     def isQualified(self):
  1653.         return True
  1654.  
  1655.     
  1656.     def getAttribute(self, attribute):
  1657.         value = XMLSchemaComponent.getAttribute(self, attribute)
  1658.         if attribute != 'type' or value is not None:
  1659.             return value
  1660.         if self.content is not None:
  1661.             return None
  1662.         parent = self
  1663.         while None:
  1664.             nsdict = parent.attributes[XMLSchemaComponent.xmlns]
  1665.             for k, v in nsdict.items():
  1666.                 return TypeDescriptionComponent((v, 'anyType'))
  1667.             
  1668.             if isinstance(parent, WSDLToolsAdapter) or not hasattr(parent, '_parent'):
  1669.                 break
  1670.             
  1671.             parent = parent._parent()
  1672.             continue
  1673.             raise SchemaError, 'failed to locate the XSD namespace'
  1674.             return None
  1675.  
  1676.     
  1677.     def getElementDeclaration(self, attribute):
  1678.         raise Warning, 'invalid operation for <%s>' % self.tag
  1679.  
  1680.     
  1681.     def getTypeDefinition(self, attribute = None):
  1682.         if attribute:
  1683.             return XMLSchemaComponent.getTypeDefinition(self, attribute)
  1684.         gt = XMLSchemaComponent.getTypeDefinition(self, 'type')
  1685.         if gt:
  1686.             return gt
  1687.         return self.content
  1688.  
  1689.     
  1690.     def getConstraints(self):
  1691.         return self._constraints
  1692.  
  1693.     
  1694.     def setConstraints(self, constraints):
  1695.         self._constraints = tuple(constraints)
  1696.  
  1697.     constraints = property(getConstraints, setConstraints, None, 'tuple of key, keyref, unique constraints')
  1698.     
  1699.     def fromDom(self, node):
  1700.         self.setAttributes(node)
  1701.         contents = self.getContents(node)
  1702.         constraints = []
  1703.         for i in contents:
  1704.             component = SplitQName(i.getTagName())[1]
  1705.             if component in self.__class__.contents['xsd']:
  1706.                 if component == 'annotation' and not (self.annotation):
  1707.                     self.annotation = Annotation(self)
  1708.                     self.annotation.fromDom(i)
  1709.                 elif component == 'simpleType' and not (self.content):
  1710.                     self.content = AnonymousSimpleType(self)
  1711.                     self.content.fromDom(i)
  1712.                 elif component == 'complexType' and not (self.content):
  1713.                     self.content = LocalComplexType(self)
  1714.                     self.content.fromDom(i)
  1715.                 elif component == 'key':
  1716.                     constraints.append(Key(self))
  1717.                     constraints[-1].fromDom(i)
  1718.                 elif component == 'keyref':
  1719.                     constraints.append(KeyRef(self))
  1720.                     constraints[-1].fromDom(i)
  1721.                 elif component == 'unique':
  1722.                     constraints.append(Unique(self))
  1723.                     constraints[-1].fromDom(i)
  1724.                 else:
  1725.                     raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  1726.             not (self.content)
  1727.             raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  1728.         
  1729.         self.constraints = constraints
  1730.  
  1731.  
  1732.  
  1733. class LocalElementDeclaration(ElementDeclaration, LocalMarker):
  1734.     required = [
  1735.         'name']
  1736.     attributes = {
  1737.         'id': None,
  1738.         'name': None,
  1739.         'form': (lambda self: GetSchema(self).getElementFormDefault()),
  1740.         'type': None,
  1741.         'minOccurs': '1',
  1742.         'maxOccurs': '1',
  1743.         'default': None,
  1744.         'fixed': None,
  1745.         'nillable': 0,
  1746.         'abstract': 0,
  1747.         'block': (lambda self: GetSchema(self).getBlockDefault()) }
  1748.     contents = {
  1749.         'xsd': [
  1750.             'annotation',
  1751.             'simpleType',
  1752.             'complexType',
  1753.             'key',
  1754.             'keyref',
  1755.             'unique'] }
  1756.     
  1757.     def isQualified(self):
  1758.         form = self.getAttribute('form')
  1759.         if form == 'qualified':
  1760.             return True
  1761.         if form == 'unqualified':
  1762.             return False
  1763.         raise SchemaError, 'Bad form (%s) for element: %s' % (form, self.getItemTrace())
  1764.  
  1765.  
  1766.  
  1767. class ElementReference(XMLSchemaComponent, ElementMarker, ReferenceMarker):
  1768.     required = [
  1769.         'ref']
  1770.     attributes = {
  1771.         'id': None,
  1772.         'ref': None,
  1773.         'minOccurs': '1',
  1774.         'maxOccurs': '1' }
  1775.     contents = {
  1776.         'xsd': [
  1777.             'annotation'] }
  1778.     tag = 'element'
  1779.     
  1780.     def __init__(self, parent):
  1781.         XMLSchemaComponent.__init__(self, parent)
  1782.         self.annotation = None
  1783.  
  1784.     
  1785.     def getElementDeclaration(self, attribute = None):
  1786.         if attribute:
  1787.             return XMLSchemaComponent.getElementDeclaration(self, attribute)
  1788.         return XMLSchemaComponent.getElementDeclaration(self, 'ref')
  1789.  
  1790.     
  1791.     def fromDom(self, node):
  1792.         self.annotation = None
  1793.         self.setAttributes(node)
  1794.         for i in self.getContents(node):
  1795.             component = SplitQName(i.getTagName())[1]
  1796.             if component in self.__class__.contents['xsd']:
  1797.                 if component == 'annotation' and not (self.annotation):
  1798.                     self.annotation = Annotation(self)
  1799.                     self.annotation.fromDom(i)
  1800.                 else:
  1801.                     raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  1802.             not (self.annotation)
  1803.         
  1804.  
  1805.  
  1806.  
  1807. class ElementWildCard(LocalElementDeclaration, WildCardMarker):
  1808.     required = []
  1809.     attributes = {
  1810.         'id': None,
  1811.         'minOccurs': '1',
  1812.         'maxOccurs': '1',
  1813.         'namespace': '##any',
  1814.         'processContents': 'strict' }
  1815.     contents = {
  1816.         'xsd': [
  1817.             'annotation'] }
  1818.     tag = 'any'
  1819.     
  1820.     def __init__(self, parent):
  1821.         XMLSchemaComponent.__init__(self, parent)
  1822.         self.annotation = None
  1823.  
  1824.     
  1825.     def isQualified(self):
  1826.         return GetSchema(self).isElementFormDefaultQualified()
  1827.  
  1828.     
  1829.     def getAttribute(self, attribute):
  1830.         return XMLSchemaComponent.getAttribute(self, attribute)
  1831.  
  1832.     
  1833.     def getTypeDefinition(self, attribute):
  1834.         raise Warning, 'invalid operation for <%s>' % self.tag
  1835.  
  1836.     
  1837.     def fromDom(self, node):
  1838.         self.annotation = None
  1839.         self.setAttributes(node)
  1840.         for i in self.getContents(node):
  1841.             component = SplitQName(i.getTagName())[1]
  1842.             if component in self.__class__.contents['xsd']:
  1843.                 if component == 'annotation' and not (self.annotation):
  1844.                     self.annotation = Annotation(self)
  1845.                     self.annotation.fromDom(i)
  1846.                 else:
  1847.                     raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  1848.             not (self.annotation)
  1849.         
  1850.  
  1851.  
  1852.  
  1853. class Sequence(XMLSchemaComponent, SequenceMarker):
  1854.     attributes = {
  1855.         'id': None,
  1856.         'minOccurs': '1',
  1857.         'maxOccurs': '1' }
  1858.     contents = {
  1859.         'xsd': [
  1860.             'annotation',
  1861.             'element',
  1862.             'group',
  1863.             'choice',
  1864.             'sequence',
  1865.             'any'] }
  1866.     tag = 'sequence'
  1867.     
  1868.     def __init__(self, parent):
  1869.         XMLSchemaComponent.__init__(self, parent)
  1870.         self.annotation = None
  1871.         self.content = None
  1872.  
  1873.     
  1874.     def fromDom(self, node):
  1875.         self.setAttributes(node)
  1876.         contents = self.getContents(node)
  1877.         content = []
  1878.         for i in contents:
  1879.             component = SplitQName(i.getTagName())[1]
  1880.             if component in self.__class__.contents['xsd']:
  1881.                 if component == 'annotation' and not (self.annotation):
  1882.                     self.annotation = Annotation(self)
  1883.                     self.annotation.fromDom(i)
  1884.                     continue
  1885.                 elif component == 'element':
  1886.                     if i.hasattr('ref'):
  1887.                         content.append(ElementReference(self))
  1888.                     else:
  1889.                         content.append(LocalElementDeclaration(self))
  1890.                 elif component == 'group':
  1891.                     content.append(ModelGroupReference(self))
  1892.                 elif component == 'choice':
  1893.                     content.append(Choice(self))
  1894.                 elif component == 'sequence':
  1895.                     content.append(Sequence(self))
  1896.                 elif component == 'any':
  1897.                     content.append(ElementWildCard(self))
  1898.                 else:
  1899.                     raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  1900.                 not (self.annotation)[-1].fromDom(i)
  1901.                 continue
  1902.             raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  1903.         
  1904.         self.content = tuple(content)
  1905.  
  1906.  
  1907.  
  1908. class All(XMLSchemaComponent, AllMarker):
  1909.     attributes = {
  1910.         'id': None,
  1911.         'minOccurs': '1',
  1912.         'maxOccurs': '1' }
  1913.     contents = {
  1914.         'xsd': [
  1915.             'annotation',
  1916.             'element'] }
  1917.     tag = 'all'
  1918.     
  1919.     def __init__(self, parent):
  1920.         XMLSchemaComponent.__init__(self, parent)
  1921.         self.annotation = None
  1922.         self.content = None
  1923.  
  1924.     
  1925.     def fromDom(self, node):
  1926.         self.setAttributes(node)
  1927.         contents = self.getContents(node)
  1928.         content = []
  1929.         for i in contents:
  1930.             component = SplitQName(i.getTagName())[1]
  1931.             if component in self.__class__.contents['xsd']:
  1932.                 if component == 'annotation' and not (self.annotation):
  1933.                     self.annotation = Annotation(self)
  1934.                     self.annotation.fromDom(i)
  1935.                     continue
  1936.                 elif component == 'element':
  1937.                     if i.hasattr('ref'):
  1938.                         content.append(ElementReference(self))
  1939.                     else:
  1940.                         content.append(LocalElementDeclaration(self))
  1941.                 else:
  1942.                     raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  1943.                 not (self.annotation)[-1].fromDom(i)
  1944.                 continue
  1945.             raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  1946.         
  1947.         self.content = tuple(content)
  1948.  
  1949.  
  1950.  
  1951. class Choice(XMLSchemaComponent, ChoiceMarker):
  1952.     attributes = {
  1953.         'id': None,
  1954.         'minOccurs': '1',
  1955.         'maxOccurs': '1' }
  1956.     contents = {
  1957.         'xsd': [
  1958.             'annotation',
  1959.             'element',
  1960.             'group',
  1961.             'choice',
  1962.             'sequence',
  1963.             'any'] }
  1964.     tag = 'choice'
  1965.     
  1966.     def __init__(self, parent):
  1967.         XMLSchemaComponent.__init__(self, parent)
  1968.         self.annotation = None
  1969.         self.content = None
  1970.  
  1971.     
  1972.     def fromDom(self, node):
  1973.         self.setAttributes(node)
  1974.         contents = self.getContents(node)
  1975.         content = []
  1976.         for i in contents:
  1977.             component = SplitQName(i.getTagName())[1]
  1978.             if component in self.__class__.contents['xsd']:
  1979.                 if component == 'annotation' and not (self.annotation):
  1980.                     self.annotation = Annotation(self)
  1981.                     self.annotation.fromDom(i)
  1982.                     continue
  1983.                 elif component == 'element':
  1984.                     if i.hasattr('ref'):
  1985.                         content.append(ElementReference(self))
  1986.                     else:
  1987.                         content.append(LocalElementDeclaration(self))
  1988.                 elif component == 'group':
  1989.                     content.append(ModelGroupReference(self))
  1990.                 elif component == 'choice':
  1991.                     content.append(Choice(self))
  1992.                 elif component == 'sequence':
  1993.                     content.append(Sequence(self))
  1994.                 elif component == 'any':
  1995.                     content.append(ElementWildCard(self))
  1996.                 else:
  1997.                     raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  1998.                 not (self.annotation)[-1].fromDom(i)
  1999.                 continue
  2000.             raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  2001.         
  2002.         self.content = tuple(content)
  2003.  
  2004.  
  2005.  
  2006. class ModelGroupDefinition(XMLSchemaComponent, ModelGroupMarker, DefinitionMarker):
  2007.     required = [
  2008.         'name']
  2009.     attributes = {
  2010.         'id': None,
  2011.         'name': None }
  2012.     contents = {
  2013.         'xsd': [
  2014.             'annotation',
  2015.             'all',
  2016.             'choice',
  2017.             'sequence'] }
  2018.     tag = 'group'
  2019.     
  2020.     def __init__(self, parent):
  2021.         XMLSchemaComponent.__init__(self, parent)
  2022.         self.annotation = None
  2023.         self.content = None
  2024.  
  2025.     
  2026.     def fromDom(self, node):
  2027.         self.setAttributes(node)
  2028.         contents = self.getContents(node)
  2029.         for i in contents:
  2030.             component = SplitQName(i.getTagName())[1]
  2031.             if component in self.__class__.contents['xsd']:
  2032.                 if component == 'annotation' and not (self.annotation):
  2033.                     self.annotation = Annotation(self)
  2034.                     self.annotation.fromDom(i)
  2035.                     continue
  2036.                 elif component == 'all' and not (self.content):
  2037.                     self.content = All(self)
  2038.                 elif component == 'choice' and not (self.content):
  2039.                     self.content = Choice(self)
  2040.                 elif component == 'sequence' and not (self.content):
  2041.                     self.content = Sequence(self)
  2042.                 else:
  2043.                     raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  2044.                 (not (self.content)).content.fromDom(i)
  2045.                 continue
  2046.             raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  2047.         
  2048.  
  2049.  
  2050.  
  2051. class ModelGroupReference(XMLSchemaComponent, ModelGroupMarker, ReferenceMarker):
  2052.     required = [
  2053.         'ref']
  2054.     attributes = {
  2055.         'id': None,
  2056.         'ref': None,
  2057.         'minOccurs': '1',
  2058.         'maxOccurs': '1' }
  2059.     contents = {
  2060.         'xsd': [
  2061.             'annotation'] }
  2062.     tag = 'group'
  2063.     
  2064.     def __init__(self, parent):
  2065.         XMLSchemaComponent.__init__(self, parent)
  2066.         self.annotation = None
  2067.  
  2068.     
  2069.     def getModelGroupReference(self):
  2070.         return self.getModelGroup('ref')
  2071.  
  2072.     
  2073.     def fromDom(self, node):
  2074.         self.setAttributes(node)
  2075.         contents = self.getContents(node)
  2076.         for i in contents:
  2077.             component = SplitQName(i.getTagName())[1]
  2078.             if component in self.__class__.contents['xsd']:
  2079.                 if component == 'annotation' and not (self.annotation):
  2080.                     self.annotation = Annotation(self)
  2081.                     self.annotation.fromDom(i)
  2082.                 else:
  2083.                     raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  2084.             not (self.annotation)
  2085.             raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  2086.         
  2087.  
  2088.  
  2089.  
  2090. class ComplexType(XMLSchemaComponent, DefinitionMarker, ComplexMarker):
  2091.     required = [
  2092.         'name']
  2093.     attributes = {
  2094.         'id': None,
  2095.         'name': None,
  2096.         'mixed': 0,
  2097.         'abstract': 0,
  2098.         'block': (lambda self: self._parent().getBlockDefault()),
  2099.         'final': (lambda self: self._parent().getFinalDefault()) }
  2100.     contents = {
  2101.         'xsd': [
  2102.             'annotation',
  2103.             'simpleContent',
  2104.             'complexContent',
  2105.             'group',
  2106.             'all',
  2107.             'choice',
  2108.             'sequence',
  2109.             'attribute',
  2110.             'attributeGroup',
  2111.             'anyAttribute',
  2112.             'any'] }
  2113.     tag = 'complexType'
  2114.     
  2115.     def __init__(self, parent):
  2116.         XMLSchemaComponent.__init__(self, parent)
  2117.         self.annotation = None
  2118.         self.content = None
  2119.         self.attr_content = None
  2120.  
  2121.     
  2122.     def isMixed(self):
  2123.         m = self.getAttribute('mixed')
  2124.         if m == 0 or m == False:
  2125.             return False
  2126.         raise SchemaError, 'invalid value for attribute mixed(%s): %s' % (m, self.getItemTrace())
  2127.  
  2128.     
  2129.     def getAttributeContent(self):
  2130.         return self.attr_content
  2131.  
  2132.     
  2133.     def getElementDeclaration(self, attribute):
  2134.         raise Warning, 'invalid operation for <%s>' % self.tag
  2135.  
  2136.     
  2137.     def getTypeDefinition(self, attribute):
  2138.         raise Warning, 'invalid operation for <%s>' % self.tag
  2139.  
  2140.     
  2141.     def fromDom(self, node):
  2142.         self.setAttributes(node)
  2143.         contents = self.getContents(node)
  2144.         indx = 0
  2145.         num = len(contents)
  2146.         if not num:
  2147.             return None
  2148.         component = SplitQName(contents[indx].getTagName())[1]
  2149.         if component == 'annotation':
  2150.             self.annotation = Annotation(self)
  2151.             self.annotation.fromDom(contents[indx])
  2152.             indx += 1
  2153.             component = SplitQName(contents[indx].getTagName())[1]
  2154.         
  2155.         self.content = None
  2156.         if component == 'simpleContent':
  2157.             self.content = self.__class__.SimpleContent(self)
  2158.             self.content.fromDom(contents[indx])
  2159.         elif component == 'complexContent':
  2160.             self.content = self.__class__.ComplexContent(self)
  2161.             self.content.fromDom(contents[indx])
  2162.         elif component == 'all':
  2163.             self.content = All(self)
  2164.         elif component == 'choice':
  2165.             self.content = Choice(self)
  2166.         elif component == 'sequence':
  2167.             self.content = Sequence(self)
  2168.         elif component == 'group':
  2169.             self.content = ModelGroupReference(self)
  2170.         
  2171.         if self.content:
  2172.             self.content.fromDom(contents[indx])
  2173.             indx += 1
  2174.         
  2175.         self.attr_content = []
  2176.         while indx < num:
  2177.             component = SplitQName(contents[indx].getTagName())[1]
  2178.             if component == 'attribute':
  2179.                 if contents[indx].hasattr('ref'):
  2180.                     self.attr_content.append(AttributeReference(self))
  2181.                 else:
  2182.                     self.attr_content.append(LocalAttributeDeclaration(self))
  2183.             elif component == 'attributeGroup':
  2184.                 self.attr_content.append(AttributeGroupReference(self))
  2185.             elif component == 'anyAttribute':
  2186.                 self.attr_content.append(AttributeWildCard(self))
  2187.             else:
  2188.                 raise SchemaError, 'Unknown component (%s): %s' % (contents[indx].getTagName(), self.getItemTrace())
  2189.             (component == 'attribute').attr_content[-1].fromDom(contents[indx])
  2190.             indx += 1
  2191.  
  2192.     
  2193.     class _DerivedType(XMLSchemaComponent):
  2194.         
  2195.         def __init__(self, parent):
  2196.             XMLSchemaComponent.__init__(self, parent)
  2197.             self.annotation = None
  2198.             self.derivation = None
  2199.             self.content = None
  2200.  
  2201.         
  2202.         def fromDom(self, node):
  2203.             self.setAttributes(node)
  2204.             contents = self.getContents(node)
  2205.             for i in contents:
  2206.                 component = SplitQName(i.getTagName())[1]
  2207.                 if component in self.__class__.contents['xsd']:
  2208.                     if component == 'annotation' and not (self.annotation):
  2209.                         self.annotation = Annotation(self)
  2210.                         self.annotation.fromDom(i)
  2211.                         continue
  2212.                     elif component == 'restriction' and not (self.derivation):
  2213.                         self.derivation = self.__class__.Restriction(self)
  2214.                     elif component == 'extension' and not (self.derivation):
  2215.                         self.derivation = self.__class__.Extension(self)
  2216.                     else:
  2217.                         raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  2218.                 not (self.derivation)
  2219.                 raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  2220.                 self.derivation.fromDom(i)
  2221.             
  2222.             self.content = self.derivation
  2223.  
  2224.  
  2225.     
  2226.     class ComplexContent(_DerivedType, ComplexMarker):
  2227.         attributes = {
  2228.             'id': None,
  2229.             'mixed': 0 }
  2230.         contents = {
  2231.             'xsd': [
  2232.                 'annotation',
  2233.                 'restriction',
  2234.                 'extension'] }
  2235.         tag = 'complexContent'
  2236.         
  2237.         def isMixed(self):
  2238.             m = self.getAttribute('mixed')
  2239.             if m == 0 or m == False:
  2240.                 return False
  2241.             raise SchemaError, 'invalid value for attribute mixed(%s): %s' % (m, self.getItemTrace())
  2242.  
  2243.         
  2244.         class _DerivationBase(XMLSchemaComponent):
  2245.             required = [
  2246.                 'base']
  2247.             attributes = {
  2248.                 'id': None,
  2249.                 'base': None }
  2250.             contents = {
  2251.                 'xsd': [
  2252.                     'annotation',
  2253.                     'group',
  2254.                     'all',
  2255.                     'choice',
  2256.                     'sequence',
  2257.                     'attribute',
  2258.                     'attributeGroup',
  2259.                     'anyAttribute'] }
  2260.             
  2261.             def __init__(self, parent):
  2262.                 XMLSchemaComponent.__init__(self, parent)
  2263.                 self.annotation = None
  2264.                 self.content = None
  2265.                 self.attr_content = None
  2266.  
  2267.             
  2268.             def getAttributeContent(self):
  2269.                 return self.attr_content
  2270.  
  2271.             
  2272.             def fromDom(self, node):
  2273.                 self.setAttributes(node)
  2274.                 contents = self.getContents(node)
  2275.                 indx = 0
  2276.                 num = len(contents)
  2277.                 if not num:
  2278.                     return None
  2279.                 component = SplitQName(contents[indx].getTagName())[1]
  2280.                 if component == 'annotation':
  2281.                     self.annotation = Annotation(self)
  2282.                     self.annotation.fromDom(contents[indx])
  2283.                     indx += 1
  2284.                     component = SplitQName(contents[indx].getTagName())[1]
  2285.                 
  2286.                 if component == 'all':
  2287.                     self.content = All(self)
  2288.                     self.content.fromDom(contents[indx])
  2289.                     indx += 1
  2290.                 elif component == 'choice':
  2291.                     self.content = Choice(self)
  2292.                     self.content.fromDom(contents[indx])
  2293.                     indx += 1
  2294.                 elif component == 'sequence':
  2295.                     self.content = Sequence(self)
  2296.                     self.content.fromDom(contents[indx])
  2297.                     indx += 1
  2298.                 elif component == 'group':
  2299.                     self.content = ModelGroupReference(self)
  2300.                     self.content.fromDom(contents[indx])
  2301.                     indx += 1
  2302.                 else:
  2303.                     self.content = None
  2304.                 self.attr_content = []
  2305.                 while indx < num:
  2306.                     component = SplitQName(contents[indx].getTagName())[1]
  2307.                     if component == 'attribute':
  2308.                         if contents[indx].hasattr('ref'):
  2309.                             self.attr_content.append(AttributeReference(self))
  2310.                         else:
  2311.                             self.attr_content.append(LocalAttributeDeclaration(self))
  2312.                     elif component == 'attributeGroup':
  2313.                         if contents[indx].hasattr('ref'):
  2314.                             self.attr_content.append(AttributeGroupReference(self))
  2315.                         else:
  2316.                             self.attr_content.append(AttributeGroupDefinition(self))
  2317.                     elif component == 'anyAttribute':
  2318.                         self.attr_content.append(AttributeWildCard(self))
  2319.                     else:
  2320.                         raise SchemaError, 'Unknown component (%s)' % contents[indx].getTagName()
  2321.                     (component == 'attribute').attr_content[-1].fromDom(contents[indx])
  2322.                     indx += 1
  2323.  
  2324.  
  2325.         
  2326.         class Extension(_DerivationBase, ExtensionMarker):
  2327.             tag = 'extension'
  2328.  
  2329.         
  2330.         class Restriction(_DerivationBase, RestrictionMarker):
  2331.             tag = 'restriction'
  2332.  
  2333.  
  2334.     
  2335.     class SimpleContent(_DerivedType, SimpleMarker):
  2336.         attributes = {
  2337.             'id': None }
  2338.         contents = {
  2339.             'xsd': [
  2340.                 'annotation',
  2341.                 'restriction',
  2342.                 'extension'] }
  2343.         tag = 'simpleContent'
  2344.         
  2345.         class Extension(XMLSchemaComponent, ExtensionMarker):
  2346.             required = [
  2347.                 'base']
  2348.             attributes = {
  2349.                 'id': None,
  2350.                 'base': None }
  2351.             contents = {
  2352.                 'xsd': [
  2353.                     'annotation',
  2354.                     'attribute',
  2355.                     'attributeGroup',
  2356.                     'anyAttribute'] }
  2357.             tag = 'extension'
  2358.             
  2359.             def __init__(self, parent):
  2360.                 XMLSchemaComponent.__init__(self, parent)
  2361.                 self.annotation = None
  2362.                 self.attr_content = None
  2363.  
  2364.             
  2365.             def getAttributeContent(self):
  2366.                 return self.attr_content
  2367.  
  2368.             
  2369.             def fromDom(self, node):
  2370.                 self.setAttributes(node)
  2371.                 contents = self.getContents(node)
  2372.                 indx = 0
  2373.                 num = len(contents)
  2374.                 if num:
  2375.                     component = SplitQName(contents[indx].getTagName())[1]
  2376.                     if component == 'annotation':
  2377.                         self.annotation = Annotation(self)
  2378.                         self.annotation.fromDom(contents[indx])
  2379.                         indx += 1
  2380.                         component = SplitQName(contents[indx].getTagName())[1]
  2381.                     
  2382.                 
  2383.                 content = []
  2384.                 while indx < num:
  2385.                     component = SplitQName(contents[indx].getTagName())[1]
  2386.                     if component == 'attribute':
  2387.                         if contents[indx].hasattr('ref'):
  2388.                             content.append(AttributeReference(self))
  2389.                         else:
  2390.                             content.append(LocalAttributeDeclaration(self))
  2391.                     elif component == 'attributeGroup':
  2392.                         content.append(AttributeGroupReference(self))
  2393.                     elif component == 'anyAttribute':
  2394.                         content.append(AttributeWildCard(self))
  2395.                     else:
  2396.                         raise SchemaError, 'Unknown component (%s)' % contents[indx].getTagName()
  2397.                     component == 'attribute'[-1].fromDom(contents[indx])
  2398.                     indx += 1
  2399.                 self.attr_content = tuple(content)
  2400.  
  2401.  
  2402.         
  2403.         class Restriction(XMLSchemaComponent, RestrictionMarker):
  2404.             required = [
  2405.                 'base']
  2406.             attributes = {
  2407.                 'id': None,
  2408.                 'base': None }
  2409.             contents = {
  2410.                 'xsd': [
  2411.                     'annotation',
  2412.                     'simpleType',
  2413.                     'attribute',
  2414.                     'attributeGroup',
  2415.                     'anyAttribute'] + RestrictionMarker.facets }
  2416.             tag = 'restriction'
  2417.             
  2418.             def __init__(self, parent):
  2419.                 XMLSchemaComponent.__init__(self, parent)
  2420.                 self.annotation = None
  2421.                 self.content = None
  2422.                 self.attr_content = None
  2423.  
  2424.             
  2425.             def getAttributeContent(self):
  2426.                 return self.attr_content
  2427.  
  2428.             
  2429.             def fromDom(self, node):
  2430.                 self.content = []
  2431.                 self.setAttributes(node)
  2432.                 contents = self.getContents(node)
  2433.                 indx = 0
  2434.                 num = len(contents)
  2435.                 component = SplitQName(contents[indx].getTagName())[1]
  2436.                 if component == 'annotation':
  2437.                     self.annotation = Annotation(self)
  2438.                     self.annotation.fromDom(contents[indx])
  2439.                     indx += 1
  2440.                     component = SplitQName(contents[indx].getTagName())[1]
  2441.                 
  2442.                 content = []
  2443.                 while indx < num:
  2444.                     component = SplitQName(contents[indx].getTagName())[1]
  2445.                     if component == 'attribute':
  2446.                         if contents[indx].hasattr('ref'):
  2447.                             content.append(AttributeReference(self))
  2448.                         else:
  2449.                             content.append(LocalAttributeDeclaration(self))
  2450.                     elif component == 'attributeGroup':
  2451.                         content.append(AttributeGroupReference(self))
  2452.                     elif component == 'anyAttribute':
  2453.                         content.append(AttributeWildCard(self))
  2454.                     elif component == 'simpleType':
  2455.                         self.content.append(AnonymousSimpleType(self))
  2456.                         self.content[-1].fromDom(contents[indx])
  2457.                     else:
  2458.                         raise SchemaError, 'Unknown component (%s)' % contents[indx].getTagName()
  2459.                     component == 'attribute'[-1].fromDom(contents[indx])
  2460.                     indx += 1
  2461.                 self.attr_content = tuple(content)
  2462.  
  2463.  
  2464.  
  2465.  
  2466.  
  2467. class LocalComplexType(ComplexType, LocalMarker):
  2468.     required = []
  2469.     attributes = {
  2470.         'id': None,
  2471.         'mixed': 0 }
  2472.     tag = 'complexType'
  2473.  
  2474.  
  2475. class SimpleType(XMLSchemaComponent, DefinitionMarker, SimpleMarker):
  2476.     required = [
  2477.         'name']
  2478.     attributes = {
  2479.         'id': None,
  2480.         'name': None,
  2481.         'final': (lambda self: self._parent().getFinalDefault()) }
  2482.     contents = {
  2483.         'xsd': [
  2484.             'annotation',
  2485.             'restriction',
  2486.             'list',
  2487.             'union'] }
  2488.     tag = 'simpleType'
  2489.     
  2490.     def __init__(self, parent):
  2491.         XMLSchemaComponent.__init__(self, parent)
  2492.         self.annotation = None
  2493.         self.content = None
  2494.  
  2495.     
  2496.     def getElementDeclaration(self, attribute):
  2497.         raise Warning, 'invalid operation for <%s>' % self.tag
  2498.  
  2499.     
  2500.     def getTypeDefinition(self, attribute):
  2501.         raise Warning, 'invalid operation for <%s>' % self.tag
  2502.  
  2503.     
  2504.     def fromDom(self, node):
  2505.         self.setAttributes(node)
  2506.         contents = self.getContents(node)
  2507.         for child in contents:
  2508.             component = SplitQName(child.getTagName())[1]
  2509.             if component == 'annotation':
  2510.                 self.annotation = Annotation(self)
  2511.                 self.annotation.fromDom(child)
  2512.                 continue
  2513.             
  2514.         else:
  2515.             return None
  2516.         if None == 'restriction':
  2517.             self.content = self.__class__.Restriction(self)
  2518.         elif component == 'list':
  2519.             self.content = self.__class__.List(self)
  2520.         elif component == 'union':
  2521.             self.content = self.__class__.Union(self)
  2522.         else:
  2523.             raise SchemaError, 'Unknown component (%s)' % component
  2524.         (None == 'restriction').content.fromDom(child)
  2525.  
  2526.     
  2527.     class Restriction(XMLSchemaComponent, RestrictionMarker):
  2528.         attributes = {
  2529.             'id': None,
  2530.             'base': None }
  2531.         contents = {
  2532.             'xsd': [
  2533.                 'annotation',
  2534.                 'simpleType'] + RestrictionMarker.facets }
  2535.         tag = 'restriction'
  2536.         
  2537.         def __init__(self, parent):
  2538.             XMLSchemaComponent.__init__(self, parent)
  2539.             self.annotation = None
  2540.             self.content = None
  2541.             self.facets = None
  2542.  
  2543.         
  2544.         def getAttributeBase(self):
  2545.             return XMLSchemaComponent.getAttribute(self, 'base')
  2546.  
  2547.         
  2548.         def getTypeDefinition(self, attribute = 'base'):
  2549.             return XMLSchemaComponent.getTypeDefinition(self, attribute)
  2550.  
  2551.         
  2552.         def getSimpleTypeContent(self):
  2553.             for el in self.content:
  2554.                 if el.isSimple():
  2555.                     return el
  2556.             
  2557.  
  2558.         
  2559.         def fromDom(self, node):
  2560.             self.facets = []
  2561.             self.setAttributes(node)
  2562.             contents = self.getContents(node)
  2563.             content = []
  2564.             for indx in range(len(contents)):
  2565.                 component = SplitQName(contents[indx].getTagName())[1]
  2566.                 if component == 'annotation' and not indx:
  2567.                     self.annotation = Annotation(self)
  2568.                     self.annotation.fromDom(contents[indx])
  2569.                     continue
  2570.                     continue
  2571.                 if component == 'simpleType':
  2572.                     if not indx or indx == 1:
  2573.                         content.append(AnonymousSimpleType(self))
  2574.                         content[-1].fromDom(contents[indx])
  2575.                         continue
  2576.                 if component in RestrictionMarker.facets:
  2577.                     self.facets.append(contents[indx])
  2578.                     continue
  2579.                 raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  2580.             
  2581.             self.content = tuple(content)
  2582.  
  2583.  
  2584.     
  2585.     class Union(XMLSchemaComponent, UnionMarker):
  2586.         attributes = {
  2587.             'id': None,
  2588.             'memberTypes': None }
  2589.         contents = {
  2590.             'xsd': [
  2591.                 'annotation',
  2592.                 'simpleType'] }
  2593.         tag = 'union'
  2594.         
  2595.         def __init__(self, parent):
  2596.             XMLSchemaComponent.__init__(self, parent)
  2597.             self.annotation = None
  2598.             self.content = None
  2599.  
  2600.         
  2601.         def fromDom(self, node):
  2602.             self.setAttributes(node)
  2603.             contents = self.getContents(node)
  2604.             content = []
  2605.             for indx in range(len(contents)):
  2606.                 component = SplitQName(contents[indx].getTagName())[1]
  2607.                 if component == 'annotation' and not indx:
  2608.                     self.annotation = Annotation(self)
  2609.                     self.annotation.fromDom(contents[indx])
  2610.                     continue
  2611.                 if component == 'simpleType':
  2612.                     content.append(AnonymousSimpleType(self))
  2613.                     content[-1].fromDom(contents[indx])
  2614.                     continue
  2615.                 raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  2616.             
  2617.             self.content = tuple(content)
  2618.  
  2619.  
  2620.     
  2621.     class List(XMLSchemaComponent, ListMarker):
  2622.         attributes = {
  2623.             'id': None,
  2624.             'itemType': None }
  2625.         contents = {
  2626.             'xsd': [
  2627.                 'annotation',
  2628.                 'simpleType'] }
  2629.         tag = 'list'
  2630.         
  2631.         def __init__(self, parent):
  2632.             XMLSchemaComponent.__init__(self, parent)
  2633.             self.annotation = None
  2634.             self.content = None
  2635.  
  2636.         
  2637.         def getItemType(self):
  2638.             return self.attributes.get('itemType')
  2639.  
  2640.         
  2641.         def getTypeDefinition(self, attribute = 'itemType'):
  2642.             tp = XMLSchemaComponent.getTypeDefinition(self, attribute)
  2643.             if not tp:
  2644.                 pass
  2645.             return self.content
  2646.  
  2647.         
  2648.         def fromDom(self, node):
  2649.             self.annotation = None
  2650.             self.content = None
  2651.             self.setAttributes(node)
  2652.             contents = self.getContents(node)
  2653.             for indx in range(len(contents)):
  2654.                 component = SplitQName(contents[indx].getTagName())[1]
  2655.                 if component == 'annotation' and not indx:
  2656.                     self.annotation = Annotation(self)
  2657.                     self.annotation.fromDom(contents[indx])
  2658.                     continue
  2659.                 if component == 'simpleType':
  2660.                     self.content = AnonymousSimpleType(self)
  2661.                     self.content.fromDom(contents[indx])
  2662.                     break
  2663.                     continue
  2664.                 raise SchemaError, 'Unknown component (%s)' % i.getTagName()
  2665.             
  2666.  
  2667.  
  2668.  
  2669.  
  2670. class AnonymousSimpleType(SimpleType, SimpleMarker, LocalMarker):
  2671.     required = []
  2672.     attributes = {
  2673.         'id': None }
  2674.     tag = 'simpleType'
  2675.  
  2676.  
  2677. class Redefine:
  2678.     tag = 'redefine'
  2679.  
  2680. if sys.version_info[:2] >= (2, 2):
  2681.     tupleClass = tuple
  2682. else:
  2683.     import UserTuple
  2684.     tupleClass = UserTuple.UserTuple
  2685.  
  2686. class TypeDescriptionComponent(tupleClass):
  2687.     
  2688.     def __init__(self, args):
  2689.         if len(args) != 2:
  2690.             raise TypeError, 'expecting tuple (namespace, name), got %s' % args
  2691.         len(args) != 2
  2692.         if args[1].find(':') >= 0:
  2693.             args = (args[0], SplitQName(args[1])[1])
  2694.         
  2695.         tupleClass.__init__(self, args)
  2696.  
  2697.     
  2698.     def getTargetNamespace(self):
  2699.         return self[0]
  2700.  
  2701.     
  2702.     def getName(self):
  2703.         return self[1]
  2704.  
  2705.  
  2706.