Modified Files:
Utility.py
-- created a new func "basejoin" for python2.3, because python2.3
and python2.4 have different implementations(python2.3 is broke in
it's handling of current directory ./ ).
WSDLTools.py
-- fixed problem with wsdl:imports in WSDLTools.load, need to
_import all <wsdl:import>'s then check again if any <wsdl:import>'s
were added to main document and do again and again. Also fixed
problem with assigning base locations to these <wsdl:import>'s.
-- Remove all <wsdl:import>'s after they have been processed, or
deemed to be redundant.
-- grab basejoin from wstools.Utility
XMLSchema.py
-- grab basejoin from wstools.Utility
----------------------------------------------------------------------
main
| @@ -9,8 +9,7 @@ | |||||
| ident = "$Id$" | ident = "$Id$" | ||||
| import types | |||||
| import string, httplib, smtplib, urllib, socket, weakref | |||||
| import sys, types, httplib, smtplib, urllib, socket, weakref | |||||
| from os.path import isfile | from os.path import isfile | ||||
| from string import join, strip, split | from string import join, strip, split | ||||
| from UserDict import UserDict | from UserDict import UserDict | ||||
| @@ -54,6 +53,18 @@ except: | |||||
| return | return | ||||
| return tuple(l) | return tuple(l) | ||||
| # | |||||
| # python2.3 urllib.basejoin does not remove current directory ./ | |||||
| # from path and this causes problems on subsequent basejoins. | |||||
| # | |||||
| basejoin = urllib.basejoin | |||||
| if sys.version_info[0:2] < (2, 4, 0, 'final', 0)[0:2]: | |||||
| #basejoin = lambda base,url: urllib.basejoin(base,url.lstrip('./')) | |||||
| token = './' | |||||
| def basejoin(base, url): | |||||
| if url.startswith(token) is True: | |||||
| return urllib.basejoin(base,url[2:]) | |||||
| return urllib.basejoin(base,url) | |||||
| class NamespaceError(Exception): | class NamespaceError(Exception): | ||||
| """Used to indicate a Namespace Error.""" | """Used to indicate a Namespace Error.""" | ||||
| @@ -116,6 +127,7 @@ class TimeoutHTTPS(HTTPSConnection): | |||||
| ssl = socket.ssl(realsock, self.key_file, self.cert_file) | ssl = socket.ssl(realsock, self.key_file, self.cert_file) | ||||
| self.sock = httplib.FakeSocket(sock, ssl) | self.sock = httplib.FakeSocket(sock, ssl) | ||||
| def urlopen(url, timeout=20, redirects=None): | def urlopen(url, timeout=20, redirects=None): | ||||
| """A minimal urlopen replacement hack that supports timeouts for http. | """A minimal urlopen replacement hack that supports timeouts for http. | ||||
| Note that this supports GET only.""" | Note that this supports GET only.""" | ||||
| @@ -9,10 +9,10 @@ | |||||
| ident = "$Id$" | ident = "$Id$" | ||||
| import urllib, weakref | |||||
| import weakref | |||||
| from cStringIO import StringIO | from cStringIO import StringIO | ||||
| from Namespaces import OASIS, XMLNS, WSA200408, WSA200403, WSA200303 | from Namespaces import OASIS, XMLNS, WSA200408, WSA200403, WSA200303 | ||||
| from Utility import Collection, CollectionNS, DOM, ElementProxy | |||||
| from Utility import Collection, CollectionNS, DOM, ElementProxy, basejoin | |||||
| from XMLSchema import XMLSchema, SchemaReader, WSDLToolsAdapter | from XMLSchema import XMLSchema, SchemaReader, WSDLToolsAdapter | ||||
| @@ -183,16 +183,36 @@ class WSDL: | |||||
| self.name = DOM.getAttr(definitions, 'name', None, None) | self.name = DOM.getAttr(definitions, 'name', None, None) | ||||
| self.documentation = GetDocumentation(definitions) | self.documentation = GetDocumentation(definitions) | ||||
| # Resolve (recursively) any import elements in the document. | |||||
| imported = {} | |||||
| # | |||||
| # Retrieve all <wsdl:import>'s, append all children of imported | |||||
| # document to main document. First iteration grab all original | |||||
| # <wsdl:import>'s from document, second iteration grab all | |||||
| # "imported" <wsdl:imports> from document, etc break out when | |||||
| # no more <wsdl:import>'s. | |||||
| # | |||||
| imported = [] | |||||
| base_location = self.location | base_location = self.location | ||||
| while len(DOM.getElements(definitions, 'import', NS_WSDL)): | |||||
| do_it = True | |||||
| while do_it: | |||||
| do_it = False | |||||
| for element in DOM.getElements(definitions, 'import', NS_WSDL): | for element in DOM.getElements(definitions, 'import', NS_WSDL): | ||||
| location = DOM.getAttr(element, 'location') | location = DOM.getAttr(element, 'location') | ||||
| location = urllib.basejoin(base_location, location) | |||||
| self._import(self.document, element, base_location) | |||||
| if base_location is not None: | |||||
| location = basejoin(base_location, location) | |||||
| #reader = SchemaReader(base_url=self.location) | |||||
| if location not in imported: | |||||
| do_it = True | |||||
| self._import(document, element, base_location) | |||||
| imported.append(location) | |||||
| else: | |||||
| definitions.removeChild(element) | |||||
| base_location = None | |||||
| # | |||||
| # No more <wsdl:import>'s, now load up all other | |||||
| # WSDL information items. | |||||
| # | |||||
| for element in DOM.getElements(definitions, None, None): | for element in DOM.getElements(definitions, None, None): | ||||
| targetNamespace = DOM.getAttr(element, 'targetNamespace') | targetNamespace = DOM.getAttr(element, 'targetNamespace') | ||||
| localName = element.localName | localName = element.localName | ||||
| @@ -289,7 +309,7 @@ class WSDL: | |||||
| 'Invalid import element (missing namespace or location).' | 'Invalid import element (missing namespace or location).' | ||||
| ) | ) | ||||
| if base_location: | if base_location: | ||||
| location = urllib.basejoin(base_location, location) | |||||
| location = basejoin(base_location, location) | |||||
| element.setAttributeNS(None, 'location', location) | element.setAttributeNS(None, 'location', location) | ||||
| obimport = self.addImport(namespace, location) | obimport = self.addImport(namespace, location) | ||||
| @@ -334,7 +354,7 @@ class WSDL: | |||||
| #XXX Quick Hack, should be in WSDL Namespace. | #XXX Quick Hack, should be in WSDL Namespace. | ||||
| if child.localName == 'import': | if child.localName == 'import': | ||||
| rlocation = child.getAttributeNS(None, 'location') | rlocation = child.getAttributeNS(None, 'location') | ||||
| alocation = urllib.basejoin(location, rlocation) | |||||
| alocation = basejoin(location, rlocation) | |||||
| child.setAttribute('location', alocation) | child.setAttribute('location', alocation) | ||||
| elif child.localName == 'types': | elif child.localName == 'types': | ||||
| child.setAttribute('base-location', location) | child.setAttribute('base-location', location) | ||||
| @@ -14,10 +14,10 @@ | |||||
| ident = "$Id$" | ident = "$Id$" | ||||
| import types, weakref, urllib, sys | |||||
| import types, weakref, sys | |||||
| from threading import RLock | from threading import RLock | ||||
| from Namespaces import XMLNS | from Namespaces import XMLNS | ||||
| from Utility import DOM, DOMException, Collection, SplitQName | |||||
| from Utility import DOM, DOMException, Collection, SplitQName, basejoin | |||||
| from StringIO import StringIO | from StringIO import StringIO | ||||
| def GetSchema(component): | def GetSchema(component): | ||||
| @@ -107,7 +107,7 @@ class SchemaReader: | |||||
| """ | """ | ||||
| reader = self.__readerClass() | reader = self.__readerClass() | ||||
| if self.__base_url: | if self.__base_url: | ||||
| url = urllib.basejoin(self.__base_url,url) | |||||
| url = basejoin(self.__base_url,url) | |||||
| reader.loadFromURL(url) | reader.loadFromURL(url) | ||||
| schema = XMLSchema() | schema = XMLSchema() | ||||
| schema.setBaseUrl(url) | schema.setBaseUrl(url) | ||||
| @@ -121,7 +121,7 @@ class SchemaReader: | |||||
| filename -- name of file to open | filename -- name of file to open | ||||
| """ | """ | ||||
| if self.__base_url: | if self.__base_url: | ||||
| filename = urllib.basejoin(self.__base_url,filename) | |||||
| filename = basejoin(self.__base_url,filename) | |||||
| file = open(filename, 'rb') | file = open(filename, 'rb') | ||||
| try: | try: | ||||
| schema = self.loadFromStream(file, filename) | schema = self.loadFromStream(file, filename) | ||||