Browse Source

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

Modified Files:
 	XMLSchema.py -- fixed some default attribute handling, added a
		few get methods in XMLSchema for elementFormDefault,
		attributeFormDefault, blockDefault, finalDefault.  Also
		added a global method GetSchema.  Now default attributes
		are set correctly in all schema components.

 ----------------------------------------------------------------------
main
Joshua Boverhof 22 years ago
parent
commit
7e1f86e3e3
1 changed files with 43 additions and 18 deletions
  1. +43
    -18
      XMLSchema.py

+ 43
- 18
XMLSchema.py View File

@@ -21,7 +21,14 @@ from xml.ns import SCHEMA, XMLNS
from Utility import DOM, Collection from Utility import DOM, Collection
from StringIO import StringIO from StringIO import StringIO



def GetSchema(component):
"""convience function for finding the parent XMLSchema instance.
"""
parent = component
while not isinstance(parent, XMLSchema):
parent = parent._parent()
return parent
class SchemaReader: class SchemaReader:
"""A SchemaReader creates XMLSchema objects from urls and xml data. """A SchemaReader creates XMLSchema objects from urls and xml data.
""" """
@@ -292,9 +299,7 @@ class XMLSchemaComponent(XMLBase):
type_def = None type_def = None
tdc = self.attributes.get(attribute) tdc = self.attributes.get(attribute)
if tdc: if tdc:
parent = self parent = GetSchema(self)
while not isinstance(parent, Schema):
parent = parent._parent()
if parent.targetNamespace == tdc.getTargetNamespace(): if parent.targetNamespace == tdc.getTargetNamespace():
type_def = getattr(parent, collection)[tdc.getName()] type_def = getattr(parent, collection)[tdc.getName()]
elif parent.imports.has_key(tdc.getTargetNamespace()): elif parent.imports.has_key(tdc.getTargetNamespace()):
@@ -366,12 +371,12 @@ class XMLSchemaComponent(XMLBase):
class variable representing attribute is None, then class variable representing attribute is None, then
it must be defined as a instance variable. it must be defined as a instance variable.
""" """
for k,v in self.attributes.items(): for k,v in self.__class__.attributes.items():
if (not v) and (k != 'xmlns'): if v and not self.attributes.has_key(k):
default_attr = getattr(self.__class__.attributes, k) if isinstance(v, types.FunctionType):
if isinstance(default_attr, types.FunctionType): self.attributes[k] = v(self)
default_attr = default_attr() else:
self.attributes[k] = default_attr self.attributes[k] = v


def __checkAttributes(self): def __checkAttributes(self):
"""Checks that required attributes have been defined, """Checks that required attributes have been defined,
@@ -800,6 +805,26 @@ class XMLSchema(XMLSchemaComponent):
""" """
self._base_url = url self._base_url = url


def getElementFormDefault(self):
"""return elementFormDefault attribute
"""
return self.attributes['elementFormDefault']

def getAttributeFormDefault(self):
"""return attributeFormDefault attribute
"""
return self.attributes['attributeFormDefault']

def getBlockDefault(self):
"""return blockDefault attribute
"""
return self.attributes.get('blockDefault')

def getFinalDefault(self):
"""return finalDefault attribute
"""
return self.attributes.get('finalDefault')

def load(self, node): def load(self, node):
self.setAttributes(node) self.setAttributes(node)
self.targetNamespace = self.getTargetNamespace() self.targetNamespace = self.getTargetNamespace()
@@ -1062,7 +1087,7 @@ class LocalAttributeDeclaration(AttributeDeclaration,\
attributes = {'id':None, attributes = {'id':None,
'name':None, 'name':None,
'type':None, 'type':None,
'form':lambda: self._parent.parent().getAttributeFormDefault(), 'form':lambda self: GetSchema(self).getAttributeFormDefault(),
'use':'optional', 'use':'optional',
'default':None, 'default':None,
'fixed':None} 'fixed':None}
@@ -1420,8 +1445,8 @@ class ElementDeclaration(XMLSchemaComponent,\
'fixed':None, 'fixed':None,
'nillable':0, 'nillable':0,
'abstract':0, 'abstract':0,
'block':lambda: self.parent.parent().getBlockDefault(), 'block':lambda self: self._parent().getBlockDefault(),
'final':lambda: self.parent.parent().getFinalDefault()} 'final':lambda self: self._parent().getFinalDefault()}
contents = {'xsd':['annotation', 'simpleType', 'complexType', 'key',\ contents = {'xsd':['annotation', 'simpleType', 'complexType', 'key',\
'keyref', 'unique']} 'keyref', 'unique']}


@@ -1488,7 +1513,7 @@ class LocalElementDeclaration(ElementDeclaration,\
required = ['name'] required = ['name']
attributes = {'id':None, attributes = {'id':None,
'name':None, 'name':None,
'form':lambda: self._parent.parent().getElementFormDefault(), 'form':lambda self: GetSchema(self).getElementFormDefault(),
'type':None, 'type':None,
'minOccurs':'1', 'minOccurs':'1',
'maxOccurs':'1', 'maxOccurs':'1',
@@ -1496,7 +1521,7 @@ class LocalElementDeclaration(ElementDeclaration,\
'fixed':None, 'fixed':None,
'nillable':0, 'nillable':0,
'abstract':0, 'abstract':0,
'block':lambda: self.parent.parent().getBlockDefault()} 'block':lambda self: GetSchema(self).getBlockDefault()}
contents = {'xsd':['annotation', 'simpleType', 'complexType', 'key',\ contents = {'xsd':['annotation', 'simpleType', 'complexType', 'key',\
'keyref', 'unique']} 'keyref', 'unique']}


@@ -1831,8 +1856,8 @@ class ComplexType(XMLSchemaComponent,\
'name':None, 'name':None,
'mixed':0, 'mixed':0,
'abstract':0, 'abstract':0,
'block':lambda: self._parent.parent().getBlockDefault(), 'block':lambda self: self._parent().getBlockDefault(),
'final':lambda: self._parent.parent().getFinalDefault()} 'final':lambda self: self._parent().getFinalDefault()}
contents = {'xsd':['annotation', 'simpleContent', 'complexContent',\ contents = {'xsd':['annotation', 'simpleContent', 'complexContent',\
'group', 'all', 'choice', 'sequence', 'attribute', 'attributeGroup',\ 'group', 'all', 'choice', 'sequence', 'attribute', 'attributeGroup',\
'anyAttribute', 'any']} 'anyAttribute', 'any']}
@@ -2178,7 +2203,7 @@ class SimpleType(XMLSchemaComponent,\
required = ['name'] required = ['name']
attributes = {'id':None, attributes = {'id':None,
'name':None, 'name':None,
'final':lambda: self._parent.parent().getFinalDefault()} 'final':lambda self: self._parent().getFinalDefault()}
contents = {'xsd':['annotation', 'restriction', 'list', 'union']} contents = {'xsd':['annotation', 'restriction', 'list', 'union']}


def __init__(self, parent): def __init__(self, parent):


||||||
x
 
000:0
Loading…
Cancel
Save