From e7acae4ec0368b2a94142d60e878122ab7bbf6e0 Mon Sep 17 00:00:00 2001 From: Joshua Boverhof Date: Fri, 25 Feb 2005 22:44:51 +0000 Subject: [PATCH] ---------------------------------------------------------------------- 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 's then check again if any 's were added to main document and do again and again. Also fixed problem with assigning base locations to these 's. -- Remove all 's after they have been processed, or deemed to be redundant. -- grab basejoin from wstools.Utility XMLSchema.py -- grab basejoin from wstools.Utility ---------------------------------------------------------------------- --- Utility.py | 16 ++++++++++++++-- WSDLTools.py | 40 ++++++++++++++++++++++++++++++---------- XMLSchema.py | 8 ++++---- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/Utility.py b/Utility.py index bbd64e1..a9b04ed 100755 --- a/Utility.py +++ b/Utility.py @@ -9,8 +9,7 @@ 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 string import join, strip, split from UserDict import UserDict @@ -54,6 +53,18 @@ except: return 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): """Used to indicate a Namespace Error.""" @@ -116,6 +127,7 @@ class TimeoutHTTPS(HTTPSConnection): ssl = socket.ssl(realsock, self.key_file, self.cert_file) self.sock = httplib.FakeSocket(sock, ssl) + def urlopen(url, timeout=20, redirects=None): """A minimal urlopen replacement hack that supports timeouts for http. Note that this supports GET only.""" diff --git a/WSDLTools.py b/WSDLTools.py index f864bf9..e97c7be 100755 --- a/WSDLTools.py +++ b/WSDLTools.py @@ -9,10 +9,10 @@ ident = "$Id$" -import urllib, weakref +import weakref from cStringIO import StringIO 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 @@ -183,16 +183,36 @@ class WSDL: self.name = DOM.getAttr(definitions, 'name', None, None) self.documentation = GetDocumentation(definitions) - # Resolve (recursively) any import elements in the document. - imported = {} + # + # Retrieve all 's, append all children of imported + # document to main document. First iteration grab all original + # 's from document, second iteration grab all + # "imported" from document, etc break out when + # no more 's. + # + imported = [] 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): 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 's, now load up all other + # WSDL information items. + # for element in DOM.getElements(definitions, None, None): targetNamespace = DOM.getAttr(element, 'targetNamespace') localName = element.localName @@ -289,7 +309,7 @@ class WSDL: 'Invalid import element (missing namespace or location).' ) if base_location: - location = urllib.basejoin(base_location, location) + location = basejoin(base_location, location) element.setAttributeNS(None, 'location', location) obimport = self.addImport(namespace, location) @@ -334,7 +354,7 @@ class WSDL: #XXX Quick Hack, should be in WSDL Namespace. if child.localName == 'import': rlocation = child.getAttributeNS(None, 'location') - alocation = urllib.basejoin(location, rlocation) + alocation = basejoin(location, rlocation) child.setAttribute('location', alocation) elif child.localName == 'types': child.setAttribute('base-location', location) diff --git a/XMLSchema.py b/XMLSchema.py index d785a3e..569d06e 100755 --- a/XMLSchema.py +++ b/XMLSchema.py @@ -14,10 +14,10 @@ ident = "$Id$" -import types, weakref, urllib, sys +import types, weakref, sys from threading import RLock from Namespaces import XMLNS -from Utility import DOM, DOMException, Collection, SplitQName +from Utility import DOM, DOMException, Collection, SplitQName, basejoin from StringIO import StringIO def GetSchema(component): @@ -107,7 +107,7 @@ class SchemaReader: """ reader = self.__readerClass() if self.__base_url: - url = urllib.basejoin(self.__base_url,url) + url = basejoin(self.__base_url,url) reader.loadFromURL(url) schema = XMLSchema() schema.setBaseUrl(url) @@ -121,7 +121,7 @@ class SchemaReader: filename -- name of file to open """ if self.__base_url: - filename = urllib.basejoin(self.__base_url,filename) + filename = basejoin(self.__base_url,filename) file = open(filename, 'rb') try: schema = self.loadFromStream(file, filename)