[Zope-CVS] CVS: Packages/WebService - XMLSchema.py:1.2
Brian Lloyd
brian@digicool.com
Thu, 29 Nov 2001 14:42:51 -0500
Update of /cvs-repository/Packages/WebService
In directory cvs.zope.org:/tmp/cvs-serv9069
Modified Files:
XMLSchema.py
Log Message:
Minor schema noodling and docs sync up.
=== Packages/WebService/XMLSchema.py 1.1 => 1.2 ===
"""Return an XMLSchema instance loaded from a file object."""
document = DOM.loadDocument(file)
- return self.loadFromDOM(document)
+ schema = XMLSchema()
+ schema.load(document)
+ return schema
def loadFromString(self, data):
"""Return an XMLSchema instance loaded from an xml string."""
@@ -28,8 +30,10 @@
def loadFromURL(self, url):
"""Return an XMLSchema instance loaded from the given url."""
file = urlopen(url)
- try: schema = self.loadFromStream(file)
+ try: document = DOM.loadDocument(file)
finally: file.close()
+ schema = XMLSchema()
+ schema.load(document)
return schema
def loadFromFile(self, filename):
@@ -65,6 +69,16 @@
self.idConstraints=None
self.modelGroups = None
self.notations = None
+ self.extensions = []
+
+ targetNamespace = None
+ attributeFormDefault = 'unqualified'
+ elementFormDefault = 'unqualified'
+ blockDefault = None
+ finalDefault = None
+ location = None
+ version = None
+ id = None
def load(self, document):
if document.nodeType == document.DOCUMENT_NODE:
@@ -74,43 +88,40 @@
if schema is None:
raise SchemaError('Missing <schema> element.')
- # Check nsuri here
+ self.namespace = namespace = schema.namespaceURI
+ if not namespace in DOM.NS_XSD_ALL:
+ raise SchemaError(
+ 'Unknown XML schema namespace: %s.' % self.namespace
+ )
- self.namespace = schema.namespaceURI
- self.attributeFormDefault = DOM.getAttr(
- schema, 'attributeFormDefault', None, 'unqualified'
- )
- self.elementFormDefault = DOM.getAttr(
- schema, 'elementFormDefault', None, 'unqualified'
- )
-
- self.targetNamespace = DOM.getAttr(schema, 'targetNamespace',
- None, None)
- self.name = DOM.getAttr(definitions, 'name', None, None)
- self.documentation = GetDocumentation(definitions)
-
- # Resolve (recursively) any import elements in the document.
- imported = {}
- while 1:
- imports = []
- for element in DOM.getElements(definitions, 'import', NS_WSDL):
- location = DOM.getAttr(element, 'location')
- if not imported.has_key(location):
- imports.append(element)
- if not imports:
- break
- for element in imports:
- self._import(document, element)
- imported[location] = 1
+ for attrname in (
+ 'targetNamespace', 'attributeFormDefault', 'elementFormDefault',
+ 'blockDefault', 'finalDefault', 'version', 'id'
+ ):
+ value = DOM.getAttr(schema, attrname, None, None)
+ if attr is not None:
+ setattr(self, attrname, value)
+
+
+ # Resolve imports and includes here?
+## imported = {}
+## while 1:
+## imports = []
+## for element in DOM.getElements(definitions, 'import', NS_WSDL):
+## location = DOM.getAttr(element, 'location')
+## if not imported.has_key(location):
+## imports.append(element)
+## if not imports:
+## break
+## for element in imports:
+## self._import(document, element)
+## imported[location] = 1
- for element in DOM.getElements(definitions, None, None):
+ for element in DOM.getElements(schema, None, None):
localName = element.localName
- if not DOM.nsUriMatch(element.namespaceURI, NS_WSDL):
- if localName == 'schema':
- self.types.addSchema(XMLSchema(element))
- else:
- self.extensions.append(element)
+ if not DOM.nsUriMatch(element.namespaceURI, namespace):
+ self.extensions.append(element)
continue
elif localName == 'message':
@@ -121,47 +132,6 @@
message.load(parts)
continue
- elif localName == 'portType':
- name = DOM.getAttr(element, 'name')
- docs = GetDocumentation(element)
- ptype = self.addPortType(name, docs)
- operations = DOM.getElements(element, 'operation', NS_WSDL)
- ptype.load(operations)
- continue
-
- elif localName == 'binding':
- name = DOM.getAttr(element, 'name')
- type = DOM.getAttr(element, 'type', default=None)
- if type is None:
- raise WSDLError(
- 'Missing type attribute for binding %s.' % name
- )
- type = type.split(':', 1)[-1]
- docs = GetDocumentation(element)
- binding = self.addBinding(name, type, docs)
- operations = DOM.getElements(element, 'operation', NS_WSDL)
- binding.load(operations)
- binding.load_ex(GetExtensions(element))
- continue
-
- elif localName == 'service':
- name = DOM.getAttr(element, 'name')
- docs = GetDocumentation(element)
- service = self.addService(name, docs)
- ports = DOM.getElements(element, 'port', NS_WSDL)
- service.load(ports)
- service.load_ex(GetExtensions(element))
- continue
-
- elif localName == 'types':
- self.types.documentation = GetDocumentation(element)
- for item in DOM.getElements(element, None, None):
- if item.localName == 'schema':
- self.types.addSchema(XMLSchema(item))
- else:
- self.types.addExtension(item)
- continue
-
def _import(self, document, element):
namespace = DOM.getAttr(element, 'namespace', default=None)
location = DOM.getAttr(element, 'location', default=None)
@@ -216,6 +186,15 @@
importdoc.unlink()
+class Element:
+ """Common base class for element representation classes."""
+ def __init__(self, name=None, documentation=''):
+ self.name = name
+ self.documentation = documentation
+ self.extensions = []
+
+ def addExtension(self, item):
+ self.extensions.append(item)
class SimpleTypeDefinition:
@@ -229,6 +208,32 @@
class ElementDeclaration:
"""Represents an xml schema element declaration."""
+ def __init__(self, name, type=None, targetNamespace=None):
+ self.name = name
+
+ targetNamespace = None
+ annotation = None
+ nillable = 0
+ abstract = 0
+ default = None
+ fixed = None
+ scope = 'global'
+ type = None
+ form = 0
+ # Things we will not worry about for now.
+ id_constraint_defs = None
+ sub_group_exclude = None
+ sub_group_affils = None
+ disallowed_subs = None
+
+
+
+
+
+
+
+
+
class AttributeGroupDefinition:
"""Represents an xml schema attribute group definition."""