From bb9668489185776401399cf2d25aeb2dc7eb0ea9 Mon Sep 17 00:00:00 2001 From: Joshua Boverhof Date: Mon, 1 Oct 2007 19:56:26 +0000 Subject: [PATCH] M XMLSchema.py -- lazy evaluation of known namespace bombing when that schema is not passed in. It should be ignored, esp if it is a well known schema like SOAPENC or XSD --- XMLSchema.py | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/XMLSchema.py b/XMLSchema.py index c00bf87..07f2cf4 100755 --- a/XMLSchema.py +++ b/XMLSchema.py @@ -158,6 +158,9 @@ class SchemaReader: class SchemaError(Exception): pass +class NoSchemaLocationWarning(Exception): + pass + ########################### # DOM Utility Adapters @@ -512,12 +515,15 @@ class XMLSchemaComponent(XMLBase, MarkerInterface): item, path, name, ref = self, [], 'name', 'ref' while not isinstance(item,XMLSchema) and not isinstance(item,WSDLToolsAdapter): attr = item.getAttribute(name) - if attr is None: + if not attr: attr = item.getAttribute(ref) - if attr is None: path.append('<%s>' %(item.tag)) - else: path.append('<%s ref="%s">' %(item.tag, attr)) + if not attr: + path.append('<%s>' %(item.tag)) + else: + path.append('<%s ref="%s">' %(item.tag, attr)) else: path.append('<%s name="%s">' %(item.tag,attr)) + item = item._parent() try: tns = item.getTargetNamespace() @@ -661,10 +667,14 @@ class XMLSchemaComponent(XMLBase, MarkerInterface): """return requested attribute value or None """ if type(attribute) in (list, tuple): - if len(attribute) != 2: + if len(attribute) != 2: raise LookupError, 'To access attributes must use name or (namespace,name)' - return self.attributes.get(attribute[0]).get(attribute[1]) + ns_dict = self.attributes.get(attribute[0]) + if ns_dict is None: + return None + + return ns_dict.get(attribute[1]) return self.attributes.get(attribute) @@ -1201,16 +1211,23 @@ class XMLSchema(XMLSchemaComponent): slocd[import_ns] = schema try: tp.loadSchema(schema) - except SchemaError: + except NoSchemaLocationWarning, ex: # Dependency declaration, hopefully implementation # is aware of this namespace (eg. SOAP,WSDL,?) + print "IMPORT: ", import_ns + print ex + del slocd[import_ns] + continue + except SchemaError, ex: #warnings.warn(\ # ', %s'\ # %(import_ns, 'failed to load schema instance') #) + print ex del slocd[import_ns] - class LazyEval(str): + class _LazyEvalImport(str): '''Lazy evaluation of import, replace entry in self.imports.''' + #attributes = dict(namespace=import_ns) def getSchema(namespace): schema = slocd.get(namespace) if schema is None: @@ -1225,7 +1242,7 @@ class XMLSchema(XMLSchemaComponent): return None - self.imports[import_ns] = LazyEval(import_ns) + self.imports[import_ns] = _LazyEvalImport(import_ns) continue else: tp._schema = schema @@ -1344,7 +1361,8 @@ class XMLSchema(XMLSchemaComponent): self._schema = schema if not self.attributes.has_key('schemaLocation'): - raise SchemaError, 'no schemaLocation' + raise NoSchemaLocationWarning('no schemaLocation attribute in import') + reader.loadFromURL(self.attributes.get('schemaLocation'), schema)