version 1.74.2.6, 2000/10/02 13:33:28
|
version 1.74.2.7, 2000/10/13 12:48:42
|
Line 46 def readXML(url):
|
Line 46 def readXML(url):
|
except LTXMLinter.error: |
except LTXMLinter.error: |
return (None, None) |
return (None, None) |
|
|
|
def assess(element): |
|
|
|
allfull = 1 |
|
allnone = 1 |
|
nochildren = 1 |
|
for c in element.chunkedChildren: |
|
if isinstance(c, XMLInfoset.Element): |
|
nochildren = 0 |
|
validationAttempted = c.__dict__.has_key("validationAttempted") and c.validationAttempted |
|
if validationAttempted != 'full': |
|
allfull = 0 |
|
if validationAttempted and c.validationAttempted != 'none': |
|
allnone = 0 |
|
|
|
if nochildren: |
|
if element.validatedType: |
|
element.validationAttempted = 'full' |
|
else: |
|
element.validationAttempted = 'none' |
|
else: |
|
if allfull and element.validatedType: |
|
element.validationAttempted = 'full' |
|
elif allnone and not element.validatedType: |
|
element.validationAttempted = 'none' |
|
else: |
|
element.validationAttempted = 'partial' |
|
|
|
if element.errorCode: |
|
element.validity = 'invalid' |
|
else: |
|
has_losing_child = 0 |
|
has_untyped_strict_child = 0 |
|
has_non_winning_typed_child = 0 |
|
for c in element.chunkedChildren: |
|
if not isinstance(c, XMLInfoset.Element): |
|
continue |
|
strict = c.__dict__.has_key("strict") and c.strict |
|
validatedType = c.__dict__.has_key("validatedType") and c.validatedType |
|
validity = c.__dict__.has_key("validity") and c.validity |
|
if validity == 'invalid': |
|
has_losing_child = 1 |
|
if strict and not validatedType: |
|
has_untyped_strict_child = 1 |
|
if validatedType and validity != 'valid': |
|
has_non_winning_typed_child = 1 |
|
if has_losing_child or has_untyped_strict_child: |
|
element.validity = 'invalid' |
|
elif has_non_winning_typed_child: |
|
element.validity = 'unknown' |
|
else: |
|
element.validity = 'valid' |
|
|
|
if element.validatedType: |
|
element.typeDefinition=PSVInfoset.ComplexTypeDefinition(element, element.validatedType) |
|
|
def validate(element, typedef, schema, eltDecl): |
def validate(element, typedef, schema, eltDecl): |
if not hasattr(schema.factory,'errors'): |
if not hasattr(schema.factory,'errors'): |
schema.factory.errors=0 |
schema.factory.errors=0 |
Line 56 def validateElement(element, type, schem
|
Line 111 def validateElement(element, type, schem
|
global vel, vtype |
global vel, vtype |
vel = element |
vel = element |
vtype = type |
vtype = type |
# print "validating element %s against %s" % (element.originalName, ['type:',type]) |
# print "validating element %s against %s" % (element.originalName, ['type:',type]) |
|
element.validatedType = type |
PSVInfoset.convert(element) |
PSVInfoset.convert(element) |
if not eltDecl: |
if not eltDecl: |
eqn=XMLSchema.QName(None,element.localName,element.namespaceName or None) |
eqn=XMLSchema.QName(None,element.localName,element.namespaceName or None) |
Line 69 def validateElement(element, type, schem
|
Line 125 def validateElement(element, type, schem
|
verror(element, |
verror(element, |
"xsi:null specified on non-nullable element %s" % element.originalName, |
"xsi:null specified on non-nullable element %s" % element.originalName, |
schema,"cvc-elt.1.1") |
schema,"cvc-elt.1.1") |
|
print "bad nullable: eltDecl = %s" % eltDecl |
|
assess(element) |
return |
return |
nulled = (element.attributes[(xsi, "null")].normalizedValue == "true") |
nulled = (element.attributes[(xsi, "null")].normalizedValue == "true") |
if element.attributes.has_key((xsi, "type")): |
if element.attributes.has_key((xsi, "type")): |
Line 83 def validateElement(element, type, schem
|
Line 141 def validateElement(element, type, schem
|
xsitype=schema.vTypeTable[qt] |
xsitype=schema.vTypeTable[qt] |
else: |
else: |
verror(element,"xsi:type %s undefined" % qt,schema,"cvc-elt.2.2") |
verror(element,"xsi:type %s undefined" % qt,schema,"cvc-elt.2.2") |
|
assess(element) |
return |
return |
if type and not xsitype.isSubtype(type): |
if type and not xsitype.isSubtype(type): |
verror(element, |
verror(element, |
"xsi:type %s is not a subtype of the declared type %s"%(qt, |
"xsi:type %s is not a subtype of the declared type %s"%(qt, |
type.name), |
type.name), |
schema,"cvc-elt.2.3") |
schema,"cvc-elt.2.3") |
|
assess(element) |
return |
return |
if type: |
if type: |
vwarn(element, |
vwarn(element, |
Line 96 def validateElement(element, type, schem
|
Line 156 def validateElement(element, type, schem
|
else: |
else: |
vwarn(element,"using xsi:type %s" % qt) |
vwarn(element,"using xsi:type %s" % qt) |
type = xsitype |
type = xsitype |
|
element.validatedType = type |
lax = not type |
lax = not type |
# might have none in case of recursive call inside <any/>, or at top level |
# might have none in case of recursive call inside <any/>, or at top level |
if nulled: |
if nulled: |
Line 109 def validateElement(element, type, schem
|
Line 170 def validateElement(element, type, schem
|
validateElementSimple(element, type, schema) |
validateElementSimple(element, type, schema) |
if eltDecl: |
if eltDecl: |
validateKeys(eltDecl,element) |
validateKeys(eltDecl,element) |
element.validationAttempted = "full" |
assess(element) |
if not element.errorCode: |
|
element.validity='valid' |
|
else: |
|
element.validity='invalid' |
|
return |
return |
# a complexType |
# a complexType |
ad=type.attributeDeclarations |
ad=type.attributeDeclarations |
Line 135 def validateElement(element, type, schem
|
Line 192 def validateElement(element, type, schem
|
validateChildTypes(element.chunkedChildren, schema, lax) |
validateChildTypes(element.chunkedChildren, schema, lax) |
if eltDecl: |
if eltDecl: |
validateKeys(eltDecl,element) |
validateKeys(eltDecl,element) |
if lax: |
assess(element) |
element.validationAttempted = "partial" |
|
else: |
|
for c in element.chunkedChildren: |
|
if isinstance(c, XMLInfoset.Element) and c.validationAttempted != "full": |
|
element.validationAttempted = "partial" |
|
break |
|
else: |
|
element.validationAttempted = "full" |
|
if not element.errorCode: |
|
# no errors at any level |
|
if type: |
|
element.validity='complete' |
|
element.typeDefinition=PSVInfoset.ComplexTypeDefinition(element, type) |
|
|
|
def validateElementNull(element, type, schema): |
def validateElementNull(element, type, schema): |
if len(element.chunkedChildren) != 0: |
if len(element.chunkedChildren) != 0: |
verror(element,"element %s is nulled but is not empty" % element.originalName, |
verror(element,"element %s is nulled but is not empty" % element.originalName, |
Line 251 def validateContentModel(element, type,
|
Line 295 def validateContentModel(element, type,
|
# if a child matches some other kind of <any> we need to indicate |
# if a child matches some other kind of <any> we need to indicate |
# that it's not an error if we can't find its type |
# that it's not an error if we can't find its type |
|
|
# print "validating model for %s content %s" % (element.originalName, type.content) |
# print "validating model for %s content type %s" % (element.originalName, type.contentType) |
if type.contentType == "empty": |
if type.contentType == "empty": |
validateEmptyModel(element, type, schema) |
validateEmptyModel(element, type, schema) |
elif type.contentType == "textOnly": |
elif type.contentType == "textOnly": |
Line 308 def validateElementModel(element, fsm, m
|
Line 352 def validateElementModel(element, fsm, m
|
for e in n.edges: |
for e in n.edges: |
if e.label == qname: |
if e.label == qname: |
next = e.dest |
next = e.dest |
|
c.strict = 1 |
break |
break |
if isinstance(e.label, XMLSchema.Wildcard): |
if isinstance(e.label, XMLSchema.Wildcard): |
if e.label.allows(c.namespaceName): |
if e.label.allows(c.namespaceName): |
Line 316 def validateElementModel(element, fsm, m
|
Line 361 def validateElementModel(element, fsm, m
|
if not next: |
if not next: |
if anynext: |
if anynext: |
n = anynext |
n = anynext |
|
c.strict = (anylab.processContents == 'strict') |
# this is no longer an error, but something more complicated is XXX |
# this is no longer an error, but something more complicated is XXX |
# if c.type: |
# if c.type: |
# where(child.where) |
# where(child.where) |
Line 350 def validateChildTypes(children, schema,
|
Line 396 def validateChildTypes(children, schema,
|
# TODO: record impact of missing type in PSVI |
# TODO: record impact of missing type in PSVI |
validateElement(child,None,schema) # will be lax because no type |
validateElement(child,None,schema) # will be lax because no type |
else: |
else: |
|
PSVInfoset.convert(child) |
verror(child, |
verror(child, |
"undeclared element %s"% |
"undeclared element %s"% |
XMLSchema.QName(None,child.localName,child.namespaceName or None), |
XMLSchema.QName(None,child.localName,child.namespaceName or None), |
Line 655 def runit(en,rns=[],k=0):
|
Line 702 def runit(en,rns=[],k=0):
|
|
|
try: |
try: |
validate(e, t, s, ed) |
validate(e, t, s, ed) |
|
e.schemaInformation = [] |
|
# XXX get all the namespaces and schemas |
|
nsi = PSVInfoset.NamespaceSchemaInformation(e, 'dummy:namespace') |
|
e.schemaInformation.append(nsi) |
except: |
except: |
bt2=traceback.format_exception(sys.exc_type, |
bt2=traceback.format_exception(sys.exc_type, |
sys.exc_value, |
sys.exc_value, |
Line 711 def av(self,child,schema,kind,elt):
|
Line 762 def av(self,child,schema,kind,elt):
|
vwarn(elt,"allowing %s because it matched wildcard(%s)" % |
vwarn(elt,"allowing %s because it matched wildcard(%s)" % |
(q,self.allowed)) |
(q,self.allowed)) |
if self.processContents!='skip': |
if self.processContents!='skip': |
|
print "looking for decl for %s" % child.originalName |
if schema.factory.schemas.has_key(child.namespaceName): |
if schema.factory.schemas.has_key(child.namespaceName): |
# only try if we might win -- needs work |
# only try if we might win -- needs work |
try: |
try: |
Line 720 def av(self,child,schema,kind,elt):
|
Line 772 def av(self,child,schema,kind,elt):
|
e = schema.vAttributeTable[q] |
e = schema.vAttributeTable[q] |
except KeyError: |
except KeyError: |
e=None |
e=None |
|
print "decl for %s is %s" % (child.originalName, e) |
if e and e.typeDefinition: |
if e and e.typeDefinition: |
vwarn(None,"validating it against %s" % |
vwarn(None,"validating it against %s" % |
(e.typeDefinition.name or 'anonymous type')) |
(e.typeDefinition.name or 'anonymous type')) |
Line 734 def av(self,child,schema,kind,elt):
|
Line 787 def av(self,child,schema,kind,elt):
|
"can't find a type for wildcard-matching %s %s" %(kind, q), |
"can't find a type for wildcard-matching %s %s" %(kind, q), |
schema, |
schema, |
"src-resolve") |
"src-resolve") |
|
child.validatedType = None |
elif kind=='element': |
elif kind=='element': |
vwarn(None,"validating it laxly") |
vwarn(None,"validating it laxly") |
|
child.validatedType = None |
validateElement(child,None,schema) |
validateElement(child,None,schema) |
|
|
XMLSchema.Wildcard.validate=av |
XMLSchema.Wildcard.validate=av |
|
|
def tv(self,child,schema,kind,elt): |
def tv(self,child,schema,kind,elt): |
Line 869 if __name__=='__main__':
|
Line 924 if __name__=='__main__':
|
raise SchemaValidationError,res |
raise SchemaValidationError,res |
|
|
# $Log$ |
# $Log$ |
|
# Revision 1.74.2.7 2000/10/13 12:48:42 richard |
|
# more infoset contributions |
|
# |
# Revision 1.74.2.6 2000/10/02 13:33:28 richard |
# Revision 1.74.2.6 2000/10/02 13:33:28 richard |
# update values for validity property |
# update values for validity property |
# |
# |