Browse Source

----------------------------------------------------------------------

Modified Files:
 	WSDLTools.py
        XMLSchema.py

    -- Fixed [ 808505 ] ZSI fails with <xs:include ... />
       Now schema include statements should be handled correctly.

    -- Also fixed a problem with relative uri handling for XMLSchema
       and SchemaReader.

 ----------------------------------------------------------------------
main
Joshua Boverhof 21 years ago
parent
commit
fad7098bee
2 changed files with 28 additions and 21 deletions
  1. +7
    -7
      WSDLTools.py
  2. +21
    -14
      XMLSchema.py

+ 7
- 7
WSDLTools.py View File

@@ -152,15 +152,15 @@ class WSDL:
location = DOM.getAttr(element, 'location') location = DOM.getAttr(element, 'location')
imported[location] = 1 imported[location] = 1


reader = SchemaReader()
reader = SchemaReader(base_url=self.location)
for element in DOM.getElements(definitions, None, None): for element in DOM.getElements(definitions, None, None):
localName = element.localName localName = element.localName


if not DOM.nsUriMatch(element.namespaceURI, NS_WSDL): if not DOM.nsUriMatch(element.namespaceURI, NS_WSDL):
if localName == 'schema': if localName == 'schema':
self.types.addSchema(
reader.loadFromNode(WSDLToolsAdapter(self), element)
)
schema = reader.loadFromNode(WSDLToolsAdapter(self), element)
schema.setBaseUrl(self.location)
self.types.addSchema(schema)
else: else:
self.extensions.append(element) self.extensions.append(element)
continue continue
@@ -209,9 +209,9 @@ class WSDL:
self.types.documentation = GetDocumentation(element) self.types.documentation = GetDocumentation(element)
for item in DOM.getElements(element, None, None): for item in DOM.getElements(element, None, None):
if item.localName == 'schema': if item.localName == 'schema':
self.types.addSchema(
reader.loadFromNode(WSDLToolsAdapter(self), item)
)
schema = reader.loadFromNode(WSDLToolsAdapter(self), item)
schema.setBaseUrl(self.location)
self.types.addSchema(schema)
else: else:
self.types.addExtension(item) self.types.addExtension(item)
continue continue


+ 21
- 14
XMLSchema.py View File

@@ -62,9 +62,11 @@ def GetSchema(component):
class SchemaReader: class SchemaReader:
"""A SchemaReader creates XMLSchema objects from urls and xml data. """A SchemaReader creates XMLSchema objects from urls and xml data.
""" """
def __init__(self, domReader=None):
def __init__(self, domReader=None, base_url=None):
"""domReader -- class must implement DOMAdapterInterface """domReader -- class must implement DOMAdapterInterface
base_url -- base url string
""" """
self.__base_url = base_url
self.__readerClass = domReader self.__readerClass = domReader
if not self.__readerClass: if not self.__readerClass:
self.__readerClass = DOMAdapter self.__readerClass = DOMAdapter
@@ -105,6 +107,7 @@ class SchemaReader:
schema = XMLSchema(parent) schema = XMLSchema(parent)
#HACK to keep a reference #HACK to keep a reference
schema.wsdl = parent schema.wsdl = parent
schema.setBaseUrl(self.__base_url)
schema.load(reader) schema.load(reader)
return schema return schema
@@ -115,6 +118,7 @@ class SchemaReader:
reader = self.__readerClass() reader = self.__readerClass()
reader.loadDocument(file) reader.loadDocument(file)
schema = XMLSchema() schema = XMLSchema()
schema.setBaseUrl(self.__base_url)
schema.load(reader) schema.load(reader)
self.__setIncludes(schema) self.__setIncludes(schema)
self.__setImports(schema) self.__setImports(schema)
@@ -133,8 +137,11 @@ class SchemaReader:
if not url.endswith('xsd'): if not url.endswith('xsd'):
raise SchemaError, 'unknown file type %s' %url raise SchemaError, 'unknown file type %s' %url
reader = self.__readerClass() reader = self.__readerClass()
if self.__base_url:
url = urllib.basejoin(self.__base_url,url)
reader.loadFromURL(url) reader.loadFromURL(url)
schema = XMLSchema() schema = XMLSchema()
schema.setBaseUrl(self.__base_url)
schema.load(reader) schema.load(reader)
self.__setIncludes(schema) self.__setIncludes(schema)
self.__setImports(schema) self.__setImports(schema)
@@ -944,7 +951,8 @@ class XMLSchema(XMLSchemaComponent):
'attr_decl','attr_groups','model_groups','notations']: 'attr_decl','attr_groups','model_groups','notations']:
for k,v in getattr(schema,collection).items(): for k,v in getattr(schema,collection).items():
if not getattr(self,collection).has_key(k): if not getattr(self,collection).has_key(k):
setattr(self,collection,v)
v._parent = weakref.ref(self)
getattr(self,collection)[k] = v


elif component == 'import': elif component == 'import':
tp = self.__class__.Import(self) tp = self.__class__.Import(self)
@@ -1065,14 +1073,11 @@ class XMLSchema(XMLSchemaComponent):
if not schema: if not schema:
if not self.attributes.has_key('schemaLocation'): if not self.attributes.has_key('schemaLocation'):
raise SchemaError, 'namespace(%s) is unknown' %ns raise SchemaError, 'namespace(%s) is unknown' %ns

url = urllib.basejoin(self._parent().getBaseUrl(),\
self.attributes['schemaLocation'])
reader = SchemaReader()
base_url = self._parent().getBaseUrl()
reader = SchemaReader(base_url=base_url)
reader._imports = self._parent().getImportSchemas() reader._imports = self._parent().getImportSchemas()
reader._includes = self._parent().getIncludeSchemas() reader._includes = self._parent().getIncludeSchemas()
self._schema = reader.loadFromURL(url) self._schema = reader.loadFromURL(url)
self._schema.setBaseUrl(url)
return self._schema or schema return self._schema or schema




@@ -1114,17 +1119,19 @@ class XMLSchema(XMLSchemaComponent):
and create a new Schema class instance. and create a new Schema class instance.
""" """
if not self._schema: if not self._schema:
schema = self._parent()._parent()
self._schema = schema.getIncludeSchemas(\
self.attributes['schemaLocation'])
#schema = self._parent()._parent()
schema = self._parent()
#self._schema = schema.getIncludeSchemas(\
# self.attributes['schemaLocation'])
self._schema = schema.getIncludeSchemas().get(\
self.attributes['schemaLocation']
)
if not self._schema: if not self._schema:
url = BaseUriResolver().normalize(\
self.attributes['schemaLocation'], schema.getBaseUrl())
reader = SchemaReader()
url = self.attributes['schemaLocation']
reader = SchemaReader(base_url=schema.getBaseUrl())
reader._imports = schema.getImportSchemas() reader._imports = schema.getImportSchemas()
reader._includes = schema.getIncludeSchemas() reader._includes = schema.getIncludeSchemas()
self._schema = reader.loadFromURL(url) self._schema = reader.loadFromURL(url)
self._schema.setBaseUrl(url)
return self._schema return self._schema






Loading…
Cancel
Save