Ejemplo n.º 1
0
 def doVcv(self,td):
   # only relevant for Attribute and Element
   # print ('dv',self,td,self.qname.local,td.name)
   if self.valueConstraint is None:
     shouldnt('vcv')
   elif td is None:
     self.vcv=self.valueConstraint[1]
     return self.vcv
   else:
     vct=td.simple()
     if not vct.isSimple:
       # the model type of a mixed complex type
       if not (td.contentType=="mixed" and td.emptiable()):
         self.error("value constraint not allowed for element with complex type unless its emptiable and mixed: %s"%td.contentType)
       self.vcv=self.valueConstraint[1]
     else:
       if self.xrpr is None:
         item=self                     # HACK, to provide a place for actual
                                       # value to be stored for cached sForS
       else:
         item=self.xrpr.elt.elt        # all the way to XMLInfoset
       res=validateText(vct,self.valueConstraint[1],
                        item,self,vct.facets)
       if res:
         self.error("value constraint value %s not of declared type: %s"%(self.valueConstraint[1],
                                                                          res))
         self.vcv=self.valueConstraint[1]
       else:
         try:
           self.vcv=item.actualValue   # cheat
         except AttributeError:
           self.vcv=self.valueConstraint[1]
     return self.vcv
Ejemplo n.º 2
0
 def __init__(self,sschema,xrpr,ns='ns'):
   self.sschema=sschema
   if sschema is not None:
     self.schema=sschema.current
     if ns=='ns' and (self.schema is not None) and not sschema.rebuilding:
       self.targetNamespace=self.schema.targetNS
   self.xrpr=xrpr
   if xrpr is not None:
     if xrpr.__dict__.has_key('name'):
       self.name=xrpr.name
     if xrpr.__dict__.has_key('annot') and xrpr.annot:
       if len(xrpr.annot)!=1:
         shouldnt("multi-annot: %d"%len(xrpr.annot))
       self.annotation=xrpr.annot[0].component
     if xrpr.elt is not None:
       ooba=filter(lambda a:a.nsuri,
                   xrpr.elt.actualAttrs)
       if ooba:
         ooba=map(lambda a:a.elt,ooba)
         if self.annotation is None:
           self.annotation=Annotation(self.sschema,None)
         if not self.annotation.attrs:
           self.annotation.attrs=ooba
         else:
           self.annotation.attrs=self.annotation.attrs.append(ooba)
   self.id=self.idCounter
   Component.idCounter=self.id+1
Ejemplo n.º 3
0
 def doBuiltIns(self,sschema):
   self.doAbInitios(sschema)
   # TODO: implement fixed facets
   for (bitn,basen,facets,idt) in builtinTypeNames:
     fake=simpleTypeElt(sschema,None)
     fake.name=bitn
     fake.restriction=restrictionElt(sschema,None)
     fake.restriction.init(None)
     fake.init(None)
     fake.component.basetypeName=QName(None,basen,XMLSchemaNS)
     fake.component.variety='atomic'
     fake.component.idt=idt
     bit=fake.restriction.component
     bit.builtin=1
     bit.rootName=fake.component.basetype.rootName
     self.typeTable[bitn]=fake.component
     for (fc,fv) in facets:
       nf=fc(sschema,None)
       fake.restriction.facets[fc.name]=nf
       if fc.name=="pattern":
         nf.stringValue=fv
       else:
         nf.value=fv
   for (bitn,basen,idt) in builtinLists:
     fake=simpleTypeElt(sschema,None)
     fake.name=bitn
     fake.list=listElt(sschema,None)
     fake.list.init(None)
     fake.init(None)
     fake.component.basetype=Type.urSimpleType
     fake.component.variety='list'
     fake.list.component.itemtypeName=QName(None,basen,XMLSchemaNS)
     wf=Whitespace(sschema,None)
     wf.value='collapse'
     wf.fixed=1
     mf=MinLength(sschema,None)
     mf.value=1
     fake.component.facets={'whiteSpace':wf,'minLength':mf}
     fake.component.idt=idt
     self.typeTable[bitn]=fake.component
   ap=Particle(sschema,None,
                         AnyAny(sschema,None),None)
   ap.term.processContents='lax'
   ap.occurs=(0,None)
   if not Type.urType.model.term.particles:
     Type.urType.model.term.particles.append(ap)
     au=AttributeUse(sschema,None,
                               AnyAny(sschema,None),'optional')
     au.attributeDeclaration.processContents='lax'
     Type.urType.attributeDeclarations={'#any':au}
   else:
     shouldnt('dbl ur')
   self.typeTable['anyType']=Type.urType
   Type.urSimpleType.schema=Type.urType.schema=self
   Type.urSimpleType.sschema=Type.urType.sschema=sschema
   ws=Whitespace(sschema,None)
   ws.value="preserve"
   Type.urSimpleType.facets['whiteSpace']=ws
   self.typeTable['anySimpleType']=Type.urSimpleType
Ejemplo n.º 4
0
 def __getattr__(self,name):
   if name=='equivalenceClassAffiliation':
     self.equivalenceClassAffiliation=None
     if self.equivClassName:
       #print ('eq',self.name,self.equivClassName)
       if self.schema.vElementTable.has_key(self.equivClassName):
         self.equivalenceClassAffiliation=exemplar=self.schema.vElementTable[self.equivClassName]
         if (self.typeDefinition is not None and
             exemplar.typeDefinition is not None):
           if not self.typeDefinition.isSubtype(exemplar.typeDefinition,()):
               self.error("type {%s}%s not subtype of type {%s}%s of exemplar %s"%(self.typeDefinition.targetNamespace,self.typeDefinition.name, exemplar.typeDefinition.targetNamespace,exemplar.typeDefinition.name, exemplar.qname))
       else:
         self.error("Undefined element %s referenced as equivalence class affiliation"%self.equivClassName)
     return self.equivalenceClassAffiliation
   elif name=='equivClass':
     # first access propagates everything
     if type(self.scope) is not types.StringType:
       shouldnt('not global %s'%self.name)
     for schema in self.sschema.schemas.values():
       for ed in schema.elementTable.values():
         if not ed.__dict__.has_key('equivClass'):
           ed.equivClass=[]
         if (ed.abstract!='true' and
             ed.equivalenceClassAffiliation is not None):
           ed.equivalenceClassAffiliation.addECM(ed)
     return self.equivClass
   elif name=='typeDefinition':
     self.typeDefinition=None
     if self.typeDefinitionName:
       if self.schema.vTypeTable.has_key(self.typeDefinitionName):
         self.typeDefinition=self.schema.vTypeTable[self.typeDefinitionName]
       else:
         self.error("Undefined type %s referenced as type definition of %s"%(self.typeDefinitionName, self.name))
     elif self.equivClassName:
       if self.equivalenceClassAffiliation is not None:
         self.typeDefinition=self.equivalenceClassAffiliation.typeDefinition
     else:
       shouldnt('etd')
     return self.typeDefinition
   elif name=='scope':
     if isinstance(self.scopeRepr,groupElt):
       self.scope=None
     else:
       self.scope=self.scopeRepr.component
     return self.scope
   elif name=='qname':
     # top-level get them at build time, locals may need them
     self.qname=QName(None,self.name,self.targetNamespace)
     return self.qname
   elif name=='vcv':
     # value constraint value
     return self.doVcv(self.typeDefinition)
   else:
     raise AttributeError,name
Ejemplo n.º 5
0
 def keyRebuild(self,val):
   if val is not None:
     for ic in val:
       if isinstance(ic,Key):
         self.keys.append(ic)
       elif isinstance(ic,Keyref):
         self.keyrefs.append(ic)
       elif isinstance(ic,Unique):
         self.uniques.append(ic)
       else:
         shouldnt('bogusic: %s'%ic)
Ejemplo n.º 6
0
 def merge(self,other):
   # not called anymore
   shouldnt('merge2')
   # TODO: check default/fixed -- what else?
   if self.name!=other.name or self.targetNamespace!=other.targetNamespace:
     self.error("declaration in a restriction not same name as declaration it corresponds to: {%s}%s vs. {%s}%s"%(self.targetNamespace,self.name,other.targetNamespace,other.name))
   if (self.typeDefinition is not None and
       other.typeDefinition is not None and
       not self.typeDefinition.isSubtype(other.typeDefinition,['extension']+other.typeDefinition.final)):
     self.error("type {%s}%s not subtype of type {%s}%s of {%s}%s in restriction"%(self.typeDefinition.targetNamespace,self.typeDefinition.name, other.typeDefinition.targetNamespace,other.typeDefinition.name, self.targetNamespace, self.name))
   return self
Ejemplo n.º 7
0
 def has_key(self, key):
     if key is None:
         return 0
     if not isinstance(key, QName):
         shouldnt("nk: %s" % key)
         return 0
     s = self.findSchema(key.uri, key.local)
     if s is None:
         # not an error to check, we'll record one error when we really go for it
         return 0
     return s.__dict__[self.tablename].has_key(key.local)
Ejemplo n.º 8
0
 def register(self,kind,table):
   if self.name:
     if table.has_key(self.name):
       self.schema.error("attempt to overwrite %s {%s}%s, ignored"%(kind,
                                                      self.schema.targetNS,
                                                                self.name),
                         self.xrpr.elt,
                         1)
     else:
       table[self.name]=self
       self.qname=QName(None,self.name,self.schema.targetNS)
   else:
     shouldnt('nc: %s'%self)
Ejemplo n.º 9
0
  def note(self,table):
    shouldnt('notee')
    if table.has_key(self.qname):
      if self.typeDefinition  is not  table[self.qname].typeDefinition:
	self.error("illegal redeclaration of %s" % self.qname)
      elif not (type(self.scope) is types.StringType and
                type(table[self.qname].scope) is types.StringType):
	self.error("redeclaration of %s ok - same type\n" % self.qname,1)
      return
    table[self.qname] = self
    if (type(self.scope) is types.StringType and
        'substitution' not in self.prohibitedSubstitutions):
      # check for equivalence classes
      # is this necessary -- it's quite expensive
      for decl in self.equivClass:
	table[decl.qname]=decl
Ejemplo n.º 10
0
 def __getattr__(self,name):
   if name=='term':
     self.term=None
     if self.termName:
       if self.termType=='element':
         if self.schema.vElementTable.has_key(self.termName):
           self.term=self.schema.vElementTable[self.termName]
         else:
           self.error("Undefined element %s referenced from content model"%self.termName)
       elif self.termType=='group':
         if self.schema.vGroupTable.has_key(self.termName):
           self.term=self.schema.vGroupTable[self.termName]
           if self.term.base is not None:
             # term is an as-yet-unchecked restrictive redefinition
             # build and check the fsms -- not reused yet, sigh
             (baseFSM,nd)=UniqueFSM(self.term.base)
             if not nd:
               # if nd, then it breaks UPA and we can't check subsumption
               # the UPA violation will get caught elsewhere
               (termFSM,nd)=UniqueFSM(self.term)
               if not nd:
                 # as above
                 res=termFSM.subsumed(baseFSM)
                 if res is not None:
                   termFSM.subsumptionError(self,baseFSM,res,"group",
                                            self.termName,
                                            "[original %s]"%self.termName,xsvNS)
                   self.term.error("redefined group not a restriction of its original definition")
         else:
           self.error("Undefined group %s referenced from content model"%self.termName)
       else:
         shouldnt('tnt')
     else:
       shouldnt('tn')
     return self.term
   elif name=='minOccurs':
     return str(self.occurs[0])
   elif name=='maxOccurs':
     return str(self.occurs[1] or 'unbounded')
   else:
     raise AttributeError,name
Ejemplo n.º 11
0
 def __getattr__(self,name):
   if name=='attributeDeclaration':
     if self.attributeDeclarationName and self.nameType=='attribute':
       if self.schema.vAttributeTable.has_key(self.attributeDeclarationName):
         self.attributeDeclaration=self.schema.vAttributeTable[self.attributeDeclarationName]
       else:
         self.error("Undeclared attribute %s referenced"%(self.attributeDeclarationName))
         self.attributeDeclaration=None
       return self.attributeDeclaration
     else:
       shouldnt('attrUse1')
   elif name=='attributeGroup':
     if self.attributeDeclarationName and self.nameType=='attributeGroup':
       if self.schema.vAttributeGroupTable.has_key(self.attributeDeclarationName):
         self.attributeGroup=self.schema.vAttributeGroupTable[self.attributeDeclarationName]
       else:
         self.error("Undeclared attribute group %s referenced"%(self.attributeDeclarationName))
         self.attributeGroup=None
       return self.attributeGroup
     else:
       shouldnt('attrUse2')
   elif name=='vcv':
     if self.valueConstraint is not None:
       return self.doVcv(self.attributeDeclaration.typeDefinition)
     else:
       self.vcv=self.attributeDeclaration.vcv
       return self.vcv
   elif name=='qname':
     # allow type derivation without chasing refs
     if self.attributeDeclarationName:
       self.qname=self.attributeDeclarationName
     else:
       self.qname=QName(None,self.attributeDeclaration.name,
                        self.attributeDeclaration.targetNamespace)
     return self.qname
   else:
     raise AttributeError,name
Ejemplo n.º 12
0
 def __init__(self,sschema,xrpr):
   # note that unlike other components, this one is built _before_ processing
   # the children of the elt it corresponds to
   self.xrpr=xrpr
   self.sschema=sschema
   self.errors=0
   self.locations=[]
   if xrpr is not None:
     # these are needed during schema accumulation
     self.maybeSetVar('targetNS','targetNamespace',None)
     self.maybeSetVar('elementFormDefault','elementFormDefault','unqualified')
     self.maybeSetVar('attributeFormDefault','attributeFormDefault',
                      'unqualified')
     self.maybeSetVar('finalDefault','finalDefault','')
     self.maybeSetVar('blockDefault','blockDefault','')
     if self.targetNS=="":
       self.error("Empty string is not allowed as value of targetNamespace",
                  xrpr.elt)
       self.targetNS=None
     if (sschema.processingInclude and
         self.targetNS!=sschema.targetNS and
         (not self.targetNS)):
         # chameleon include, OK
         self.targetNS=sschema.targetNS
         sschema.processingInclude=2
     sschema.targetNS=self.targetNS
     if sschema.schemas.has_key(self.targetNS):
       shouldnt('oldcopy')
       oldSchema=sschema.schemas[self.targetNS]
       # use real tables, we're ephemeral
       self.locations=oldSchema.locations       # broken
       sschema.current=oldSchema
       self.typeTable=oldSchema.typeTable
       self.elementTable=oldSchema.elementTable
       self.attributeTable=oldSchema.attributeTable
       self.groupTable=oldSchema.groupTable
       self.attributeGroupTable=oldSchema.attributeGroupTable
       self.vTypeTable=oldSchema.vTypeTable
       self.vElementTable=oldSchema.vElementTable
       self.vAttributeTable=oldSchema.vAttributeTable
       self.vGroupTable=oldSchema.vGroupTable
       self.vAttributeGroupTable=oldSchema.vAttributeGroupTable
       # copy defaults (they've been saved, will be restored)
       oldSchema.elementFormDefault=self.elementFormDefault
       oldSchema.attributeFormDefault=self.attributeFormDefault
       oldSchema.blockDefault=self.blockDefault
       oldSchema.finalDefault=self.finalDefault
       return
     else:
       sschema.schemas[self.targetNS]=self      
       sschema.current=self
   # either we're the first for this NS, or we're the FIRST
   self.typeTable={}
   self.elementTable={}
   self.attributeTable={}
   self.groupTable={}
   self.attributeGroupTable={}
   self.keyUniqueTable={}
   self.vTypeTable=VMapping(self, "typeTable")
   self.vElementTable=VMapping(self, "elementTable")
   self.vAttributeTable=VMapping(self, "attributeTable")
   self.vGroupTable=VMapping(self, "groupTable")
   self.vKeyUniqueTable=VMapping(self, "keyUniqueTable")
   self.vAttributeGroupTable=VMapping(self, "attributeGroupTable")
Ejemplo n.º 13
0
 def __getattr__(self,name):
   if name=='facets':
     newTable=self.xrpr.facets
     if newTable.has_key('pattern'):
       # special treatment -- multiple patterns are branches
       pf=newTable['pattern']
       if (not self.builtin) and len(pf.stringValue)>1:
         pf.stringValue=['|'.join(map(lambda p:'('+p+')',pf.stringValue))]
     if (self.base is None or
         self.variety=='unknown' or
         (self.variety=='atomic' and
          self.primitiveType is None)):
       # unknown means earlier error, bail out
       self.facets={}
       return {}
     oldTable=self.base.facets
     ft=self.base
     if ft.variety!=self.variety:
       self.error("type with variety %s must not have base type defn with variety %s"%(self.variety,ft.variety))
     if self.variety=='atomic':
       auth=self.primitiveType
       tname=self.base.name
     elif self.variety=='list':
       tname='List'
       auth=List
       ft=self.base
       if 'whiteSpace' not in oldTable:
         nwsf=Whitespace(self.sschema,self.base.elt)
         nwsf.value='collapse'
         nwsf.fixed=1
         oldTable['whiteSpace']=nwsf
     elif self.variety=='union':
       tname='Union'
       auth=Union
       ft=self.base
     else:
       shouldnt('bogusv: %s'%self.variety)
     self.facets=oldTable.copy()
     allowed=auth.allowedFacets
     #print ('r',newTable.keys(),oldTable.keys())
     for facetName in newTable.keys():
       if facetName in allowed:
         newF=newTable[facetName]
         newF.type=ft
         newF.auth=auth
     for facetName in newTable.keys():
       newF=newTable[facetName]
       if facetName in allowed:
         if oldTable.has_key(facetName):
           oldF=oldTable[facetName]
         else:
           oldF=None
         if oldF is not None and oldF.fixed and newF.value!=oldF.value:
           self.error("facet %s is fixed in basetype %s, cannot be changed"%(facetName,tname))
         newNew=getattr(ft,_checkFacetTable[facetName])(facetName,
                                                          oldF,
                                                          newF,
                                                          newTable,
                                                          self,
                                                        oldTable)
         if newNew is not None:
           self.facets[facetName]=newNew
       else:
         self.error("facet %s not allowed on type %s"%(facetName,tname))
     return self.facets
   elif name not in ('variety','rootName','primitiveType','memberTypes',
                     'itemType','base','validateText'):
     raise AttributeError,name
   if not self.__dict__.has_key('base'):
     if self.super.basetype is not None:
       self.base=self.super.basetype
       if isinstance(self.base,AbInitio):
         self.primitiveType=self.base
         if name=='primitiveType':
           return self.base
     else:
       # error already signalled . . .
       self.base=None
       return None
   if name=='base':
     return self.base
   elif self.base is not None:
     return getattr(self.base,name)
   else:
     return None
Ejemplo n.º 14
0
 def attributeUseRebuild(self,val):
   if self.__dict__.has_key('attributeDeclarations'):
     shouldnt('xyzzy')
   self.attributeDeclarations=val