From e2d7be315216faaab08655512db99789a041035a Mon Sep 17 00:00:00 2001 From: "Ivan R. Judson" Date: Fri, 11 Mar 2005 20:28:38 +0000 Subject: [PATCH] Changed some simple formatting things in XMLSchema.py. Updated WSDLTools.py so nested schema imports work (I probably broke it before). --- WSDLTools.py | 11 +++++++---- XMLSchema.py | 46 +++++++++++++++++++++++++--------------------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/WSDLTools.py b/WSDLTools.py index 2d0d663..1723d2f 100755 --- a/WSDLTools.py +++ b/WSDLTools.py @@ -197,9 +197,10 @@ class WSDL: do_it = False for element in DOM.getElements(definitions, 'import', NS_WSDL): location = DOM.getAttr(element, 'location') + if base_location is not None: location = basejoin(base_location, location) - + if location not in imported: do_it = True self._import(document, element, base_location) @@ -219,9 +220,11 @@ class WSDL: if not DOM.nsUriMatch(element.namespaceURI, NS_WSDL): if localName == 'schema': - reader = SchemaReader(base_url=self.location) - schema = reader.loadFromNode(WSDLToolsAdapter(self), element) - schema.setBaseUrl(self.location) + tns = DOM.getAttr(element, 'targetNamespace') + reader = SchemaReader(base_url=self.imports[tns].location) + schema = reader.loadFromNode(WSDLToolsAdapter(self), + element) +# schema.setBaseUrl(self.location) self.types.addSchema(schema) else: self.extensions.append(element) diff --git a/XMLSchema.py b/XMLSchema.py index e29f30a..35896d4 100755 --- a/XMLSchema.py +++ b/XMLSchema.py @@ -108,6 +108,7 @@ class SchemaReader: reader = self.__readerClass() if self.__base_url: url = basejoin(self.__base_url,url) + reader.loadFromURL(url) schema = XMLSchema() schema.setBaseUrl(url) @@ -900,9 +901,10 @@ class XMLSchema(XMLSchemaComponent): 'elementFormDefault':'unqualified', 'blockDefault':None, 'finalDefault':None} - contents = {'xsd':('include', 'import', 'redefine', 'annotation', 'attribute',\ - 'attributeGroup', 'complexType', 'element', 'group',\ - 'notation', 'simpleType', 'annotation')} + contents = {'xsd':('include', 'import', 'redefine', 'annotation', + 'attribute', 'attributeGroup', 'complexType', + 'element', 'group', 'notation', 'simpleType', + 'annotation')} empty_namespace = '' tag = 'schema' @@ -1042,7 +1044,7 @@ class XMLSchema(XMLSchemaComponent): """ return self.attributes.get('finalDefault') - def load(self, node): + def load(self, node, location=None): self.__node = node pnode = node.getParentNode() @@ -1078,12 +1080,10 @@ class XMLSchema(XMLSchemaComponent): self.includes[sl] = tp - # This is the test code pn = childNode.getParentNode().getNode() pn.removeChild(childNode.getNode()) for child in schema.getNode().getNode().childNodes: pn.appendChild(child.cloneNode(1)) - # end of test code for collection in ['imports','elements','types', 'attr_decl','attr_groups','model_groups', @@ -1733,19 +1733,21 @@ class ElementDeclaration(XMLSchemaComponent,\ self.constraints = () def isQualified(self): - '''Global elements are always qualified. - ''' + """ +Global elements are always qualified. + """ return True def getElementDeclaration(self, attribute): raise Warning, 'invalid operation for <%s>' %self.tag def getTypeDefinition(self, attribute=None): - '''If attribute is None, "type" is assumed, return the corresponding + """ +If attribute is None, "type" is assumed, return the corresponding representation of the global type definition (TypeDefinition), or the local definition if don't find "type". To maintain backwards compat, if attribute is provided call base class method. - ''' + """ if attribute: return XMLSchemaComponent.getTypeDefinition(self, attribute) gt = XMLSchemaComponent.getTypeDefinition(self, 'type') @@ -1827,10 +1829,11 @@ class LocalElementDeclaration(ElementDeclaration,\ 'keyref', 'unique']} def isQualified(self): - '''Local elements can be qualified or unqualifed according + """ +Local elements can be qualified or unqualifed according to the attribute form, or the elementFormDefault. By default local elements are unqualified. - ''' + """ form = self.getAttribute('form') if form == 'qualified': return True @@ -1866,10 +1869,10 @@ class ElementReference(XMLSchemaComponent,\ self.annotation = None def getElementDeclaration(self, attribute=None): - '''If attribute is None, "ref" is assumed, return the corresponding + """If attribute is None, "ref" is assumed, return the corresponding representation of the global element declaration (ElementDeclaration), To maintain backwards compat, if attribute is provided call base class method. - ''' + """ if attribute: return XMLSchemaComponent.getElementDeclaration(self, attribute) return XMLSchemaComponent.getElementDeclaration(self, 'ref') @@ -1887,8 +1890,7 @@ class ElementReference(XMLSchemaComponent,\ raise SchemaError, 'Unknown component (%s)' %(i.getTagName()) -class ElementWildCard(LocalElementDeclaration,\ - WildCardMarker): +class ElementWildCard(LocalElementDeclaration, WildCardMarker): """ parents: choice, sequence @@ -1916,13 +1918,14 @@ class ElementWildCard(LocalElementDeclaration,\ self.annotation = None def isQualified(self): - '''Global elements are always qualified, but if processContents + """ + Global elements are always qualified, but if processContents are not strict could have dynamically generated local elements. - ''' + """ return GetSchema(self).isElementFormDefaultQualified() def getTypeDefinition(self, attribute): - raise Warning, 'invalid operation for <%s>' %self.tag + raise Warning, 'invalid operation for <%s>' % self.tag def fromDom(self, node): self.annotation = None @@ -2800,10 +2803,11 @@ class SimpleType(XMLSchemaComponent,\ return self.attributes.get('itemType') def getTypeDefinition(self, attribute='itemType'): - '''return the type refered to by itemType attribute or + """ + return the type refered to by itemType attribute or the simpleType content. If returns None, then the type refered to by itemType is primitive. - ''' + """ tp = XMLSchemaComponent.getTypeDefinition(self, attribute) return tp or self.content