Browse Source

M XMLSchema.py

-- If one tries to grab a schema item using the helper methods, if that item doesn't exist and the namespace is not in the BUILT_IN_NAMESPACES list then throw a SchemaError.  Now failure to specify an import dependency will result in an error like:

     ZSI.wstools.XMLSchema.SchemaError: schema "urn:webservices" does not import namespace "urn:base"

when "item.getTypeDefinition()" is called and the "type" attribute value QName is in a namespace that hasn't been declared as a dependency

So basically this throws errors when can't find a schema item that is supposed to be defined, rather than just returning None most of the time,  which is always an error condition.  


M a  Utility.py

-- use M2Crypto if available for TimeOutSocket, and standard "ssl" if it's not
--
main
Joshua Boverhof 17 years ago
parent
commit
b13d16cc1e
2 changed files with 33 additions and 12 deletions
  1. +8
    -3
      Utility.py
  2. +25
    -9
      XMLSchema.py

+ 8
- 3
Utility.py View File

@@ -159,14 +159,19 @@ def urlopen(url, timeout=20, redirects=None):
# If ssl is not compiled into Python, you will not get an exception
# until a conn.endheaders() call. We need to know sooner, so use
# getattr.
if hasattr(socket, 'ssl'):
try:
import M2Crypto
except ImportError:
if not hasattr(socket, 'ssl'):
raise RuntimeError, 'no built-in SSL Support'

conn = TimeoutHTTPS(host, None, timeout)
else:
import M2Crypto
ctx = M2Crypto.SSL.Context()
ctx.set_session_timeout(timeout)
conn = M2Crypto.httpslib.HTTPSConnection(host, ssl_context=ctx)
#conn.set_debuglevel(1)
conn.set_debuglevel(1)

else:
conn = TimeoutHTTP(host, None, timeout)



+ 25
- 9
XMLSchema.py View File

@@ -15,7 +15,7 @@
ident = "$Id$"

import types, weakref, sys, warnings
from Namespaces import SCHEMA, XMLNS
from Namespaces import SCHEMA, XMLNS, SOAP
from Utility import DOM, DOMException, Collection, SplitQName, basejoin
from StringIO import StringIO

@@ -37,7 +37,7 @@ ATTRIBUTE_GROUPS = 'attr_groups'
ATTRIBUTES = 'attr_decl'
ELEMENTS = 'elements'
MODEL_GROUPS = 'model_groups'
BUILT_IN_NAMESPACES = [SOAP.ENC,] + SCHEMA.XSD_LIST

def GetSchema(component):
"""convience function for finding the parent XMLSchema instance.
@@ -574,16 +574,22 @@ class XMLSchemaComponent(XMLBase, MarkerInterface):
attribute -- an information item attribute, with a QName value.
collection -- collection in parent Schema instance to search.
"""
obj = None
tdc = self.getAttributeQName(attribute)
if tdc:
obj = self.getSchemaItem(collection, tdc.getTargetNamespace(), tdc.getName())
if not tdc:
return

return obj
obj = self.getSchemaItem(collection, tdc.getTargetNamespace(), tdc.getName())
if obj:
return obj

# raise SchemaError, 'No schema item "%s" in collection %s' %(tdc, collection)
return

def getSchemaItem(self, collection, namespace, name):
"""returns object instance representing namespace, name,
or if does not exist return None.
or if does not exist return None if built-in, else
raise SchemaError.
namespace -- namespace item defined in.
name -- name of item.
collection -- collection in parent Schema instance to search.
@@ -599,8 +605,14 @@ class XMLSchemaComponent(XMLBase, MarkerInterface):
return obj
if not parent.imports.has_key(namespace):
return None
if namespace in BUILT_IN_NAMESPACES:
# built-in just return
# WARNING: expecting import if "redefine" or add to built-in namespace.
return
raise SchemaError, 'schema "%s" does not import namespace "%s"' %(
parent.targetNamespace, namespace)
# Lazy Eval
schema = parent.imports[namespace]
if not isinstance(schema, XMLSchema):
@@ -609,6 +621,10 @@ class XMLSchemaComponent(XMLBase, MarkerInterface):
parent.imports[namespace] = schema
if schema is None:
if namespace in BUILT_IN_NAMESPACES:
# built-in just return
return
raise SchemaError, 'no schema instance for imported namespace (%s).'\
%(namespace)


Loading…
Cancel
Save