xmlclass/xsdschema.py
changeset 1730 64d8f52bc8c8
parent 1683 57b4ac796dcb
child 1732 94ffe74e6895
equal deleted inserted replaced
1726:d51af006fa6b 1730:64d8f52bc8c8
    60             text += "{:.0f}".format(value)
    60             text += "{:.0f}".format(value)
    61         if name is not None:
    61         if name is not None:
    62             text += "</%s>\n" % name
    62             text += "</%s>\n" % name
    63         return text
    63         return text
    64     return generateXMLTextMethod
    64     return generateXMLTextMethod
    65         
    65 
    66 DEFAULT_FACETS = GenerateDictFacets(["pattern", "whiteSpace", "enumeration"])
    66 DEFAULT_FACETS = GenerateDictFacets(["pattern", "whiteSpace", "enumeration"])
    67 NUMBER_FACETS = GenerateDictFacets(DEFAULT_FACETS.keys() + ["maxInclusive", "maxExclusive", "minInclusive", "minExclusive"])
    67 NUMBER_FACETS = GenerateDictFacets(DEFAULT_FACETS.keys() + ["maxInclusive", "maxExclusive", "minInclusive", "minExclusive"])
    68 DECIMAL_FACETS = GenerateDictFacets(NUMBER_FACETS.keys() + ["totalDigits", "fractionDigits"])
    68 DECIMAL_FACETS = GenerateDictFacets(NUMBER_FACETS.keys() + ["totalDigits", "fractionDigits"])
    69 STRING_FACETS = GenerateDictFacets(DEFAULT_FACETS.keys() + ["length", "minLength", "maxLength"])
    69 STRING_FACETS = GenerateDictFacets(DEFAULT_FACETS.keys() + ["length", "minLength", "maxLength"])
    70 
    70 
    71 ALL_FACETS = ["pattern", "whiteSpace", "enumeration", "maxInclusive", 
    71 ALL_FACETS = ["pattern", "whiteSpace", "enumeration", "maxInclusive",
    72     "maxExclusive", "minInclusive", "minExclusive", "totalDigits", 
    72     "maxExclusive", "minInclusive", "minExclusive", "totalDigits",
    73     "fractionDigits", "length", "minLength", "maxLength"]
    73     "fractionDigits", "length", "minLength", "maxLength"]
    74 
    74 
    75 
    75 
    76 #-------------------------------------------------------------------------------
    76 #-------------------------------------------------------------------------------
    77 #                           Structure reducing functions
    77 #                           Structure reducing functions
    79 
    79 
    80 
    80 
    81 # Documentation elements
    81 # Documentation elements
    82 
    82 
    83 def ReduceAppInfo(factory, attributes, elements):
    83 def ReduceAppInfo(factory, attributes, elements):
    84     return {"type": "appinfo", "source": attributes.get("source", None), 
    84     return {"type": "appinfo", "source": attributes.get("source", None),
    85             "content": "\n".join(elements)}
    85             "content": "\n".join(elements)}
    86 
    86 
    87 
    87 
    88 def ReduceDocumentation(factory, attributes, elements):
    88 def ReduceDocumentation(factory, attributes, elements):
    89     return {"type": "documentation", "source": attributes.get("source", None), 
    89     return {"type": "documentation", "source": attributes.get("source", None),
    90             "language": attributes.get("lang", "any"), "content": "\n".join(elements)}
    90             "language": attributes.get("lang", "any"), "content": "\n".join(elements)}
    91 
    91 
    92 
    92 
    93 def ReduceAnnotation(factory, attributes, elements):
    93 def ReduceAnnotation(factory, attributes, elements):
    94     annotations, children = factory.ReduceElements(elements)
    94     annotations, children = factory.ReduceElements(elements)
   122 
   122 
   123 
   123 
   124 def ReduceList(factory, attributes, elements):
   124 def ReduceList(factory, attributes, elements):
   125     annotations, children = factory.ReduceElements(elements)
   125     annotations, children = factory.ReduceElements(elements)
   126     list = {"type": "list", "itemType": attributes.get("itemType", None), "doc": annotations}
   126     list = {"type": "list", "itemType": attributes.get("itemType", None), "doc": annotations}
   127     
   127 
   128     if len(children) > 0 and children[0]["type"] == SIMPLETYPE:
   128     if len(children) > 0 and children[0]["type"] == SIMPLETYPE:
   129         if list["itemType"] is None:
   129         if list["itemType"] is None:
   130             list["itemType"] = children[0]
   130             list["itemType"] = children[0]
   131         else:
   131         else:
   132             raise ValueError("Only one base type can be defined for restriction!")
   132             raise ValueError("Only one base type can be defined for restriction!")
   136 
   136 
   137 
   137 
   138 def ReduceUnion(factory, attributes, elements):
   138 def ReduceUnion(factory, attributes, elements):
   139     annotations, children = factory.ReduceElements(elements)
   139     annotations, children = factory.ReduceElements(elements)
   140     union = {"type": "union", "memberTypes": attributes.get("memberTypes", []), "doc": annotations}
   140     union = {"type": "union", "memberTypes": attributes.get("memberTypes", []), "doc": annotations}
   141     
   141 
   142     for child in children:
   142     for child in children:
   143         if child["type"] == SIMPLETYPE:
   143         if child["type"] == SIMPLETYPE:
   144             union["memberTypes"].appendchild
   144             union["memberTypes"].appendchild
   145     if len(union["memberTypes"]) == 0:
   145     if len(union["memberTypes"]) == 0:
   146         raise ValueError("No base type has been defined for union!")
   146         raise ValueError("No base type has been defined for union!")
   151     # Initialize type informations
   151     # Initialize type informations
   152     facets = {}
   152     facets = {}
   153     simpleType = {"type": SIMPLETYPE, "final": attributes.get("final", [])}
   153     simpleType = {"type": SIMPLETYPE, "final": attributes.get("final", [])}
   154     if attributes.has_key("name"):
   154     if attributes.has_key("name"):
   155         simpleType["name"] = attributes["name"]
   155         simpleType["name"] = attributes["name"]
   156     
   156 
   157     if typeinfos["type"] in ["restriction", "extension"]:
   157     if typeinfos["type"] in ["restriction", "extension"]:
   158         # Search for base type definition
   158         # Search for base type definition
   159         if isinstance(typeinfos["base"], (StringType, UnicodeType)):
   159         if isinstance(typeinfos["base"], (StringType, UnicodeType)):
   160             basetypeinfos = factory.FindSchemaElement(typeinfos["base"], SIMPLETYPE)
   160             basetypeinfos = factory.FindSchemaElement(typeinfos["base"], SIMPLETYPE)
   161             if basetypeinfos is None:
   161             if basetypeinfos is None:
   162                 raise "\"%s\" isn't defined!" % typeinfos["base"] 
   162                 raise "\"%s\" isn't defined!" % typeinfos["base"]
   163         else:
   163         else:
   164             basetypeinfos = typeinfos["base"]
   164             basetypeinfos = typeinfos["base"]
   165         
   165 
   166         # Check that base type is a simple type
   166         # Check that base type is a simple type
   167         if basetypeinfos["type"] != SIMPLETYPE:
   167         if basetypeinfos["type"] != SIMPLETYPE:
   168             raise ValueError("Base type given isn't a simpleType!")
   168             raise ValueError("Base type given isn't a simpleType!")
   169         
   169 
   170         simpleType["basename"] = basetypeinfos["basename"]
   170         simpleType["basename"] = basetypeinfos["basename"]
   171         
   171 
   172         # Check that derivation is allowed
   172         # Check that derivation is allowed
   173         if basetypeinfos.has_key("final"):
   173         if basetypeinfos.has_key("final"):
   174             if "#all" in basetypeinfos["final"]:
   174             if "#all" in basetypeinfos["final"]:
   175                 raise ValueError("Base type can't be derivated!")
   175                 raise ValueError("Base type can't be derivated!")
   176             if "restriction" in basetypeinfos["final"] and typeinfos["type"] == "restriction":
   176             if "restriction" in basetypeinfos["final"] and typeinfos["type"] == "restriction":
   177                 raise ValueError("Base type can't be derivated by restriction!")
   177                 raise ValueError("Base type can't be derivated by restriction!")
   178         
   178 
   179         # Extract simple type facets
   179         # Extract simple type facets
   180         for facet in typeinfos.get("facets", []):
   180         for facet in typeinfos.get("facets", []):
   181             facettype = facet["type"]
   181             facettype = facet["type"]
   182             if not basetypeinfos["facets"].has_key(facettype):
   182             if not basetypeinfos["facets"].has_key(facettype):
   183                 raise ValueError("\"%s\" facet can't be defined for \"%s\" type!" % (facettype, type))
   183                 raise ValueError("\"%s\" facet can't be defined for \"%s\" type!" % (facettype, type))
   284                 if facets.has_key("totalDigits") and value <= facets["totalDigits"][0]:
   284                 if facets.has_key("totalDigits") and value <= facets["totalDigits"][0]:
   285                     raise ValueError("\"fractionDigits\" must be lesser than or equal to \"totalDigits\"!")
   285                     raise ValueError("\"fractionDigits\" must be lesser than or equal to \"totalDigits\"!")
   286                 elif basevalue is not None and value > basevalue:
   286                 elif basevalue is not None and value > basevalue:
   287                     raise ValueError("\"totalDigits\" can't be greater than \"totalDigits\" defined in base type!")
   287                     raise ValueError("\"totalDigits\" can't be greater than \"totalDigits\" defined in base type!")
   288             facets[facettype] = (value, facet.get("fixed", False))
   288             facets[facettype] = (value, facet.get("fixed", False))
   289         
   289 
   290         # Report not redefined facet from base type to new created type 
   290         # Report not redefined facet from base type to new created type
   291         for facettype, facetvalue in basetypeinfos["facets"].items():
   291         for facettype, facetvalue in basetypeinfos["facets"].items():
   292             if not facets.has_key(facettype):
   292             if not facets.has_key(facettype):
   293                 facets[facettype] = facetvalue
   293                 facets[facettype] = facetvalue
   294         
   294 
   295         # Generate extract value for new created type
   295         # Generate extract value for new created type
   296         def ExtractSimpleTypeValue(attr, extract=True):
   296         def ExtractSimpleTypeValue(attr, extract=True):
   297             value = basetypeinfos["extract"](attr, extract)
   297             value = basetypeinfos["extract"](attr, extract)
   298             for facetname, (facetvalue, facetfixed) in facets.items():
   298             for facetname, (facetvalue, facetfixed) in facets.items():
   299                 if facetvalue is not None:
   299                 if facetvalue is not None:
   315                         raise ValueError("value must be lesser than %s" % str(facetvalue))
   315                         raise ValueError("value must be lesser than %s" % str(facetvalue))
   316                     elif facetname == "pattern":
   316                     elif facetname == "pattern":
   317                         model = re.compile("(?:%s)?$" % "|".join(map(lambda x: "(?:%s)" % x, facetvalue)))
   317                         model = re.compile("(?:%s)?$" % "|".join(map(lambda x: "(?:%s)" % x, facetvalue)))
   318                         result = model.match(value)
   318                         result = model.match(value)
   319                         if result is None:
   319                         if result is None:
   320                             if len(facetvalue) > 1:   
   320                             if len(facetvalue) > 1:
   321                                 raise ValueError("value doesn't follow any of the patterns %s" % ",".join(facetvalue))
   321                                 raise ValueError("value doesn't follow any of the patterns %s" % ",".join(facetvalue))
   322                             else:
   322                             else:
   323                                 raise ValueError("value doesn't follow the pattern %s" % facetvalue[0])
   323                                 raise ValueError("value doesn't follow the pattern %s" % facetvalue[0])
   324                     elif facetname == "whiteSpace":
   324                     elif facetname == "whiteSpace":
   325                         if facetvalue == "replace":
   325                         if facetvalue == "replace":
   326                             value = GetNormalizedString(value, False)
   326                             value = GetNormalizedString(value, False)
   327                         elif facetvalue == "collapse":
   327                         elif facetvalue == "collapse":
   328                             value = GetToken(value, False)
   328                             value = GetToken(value, False)
   329             return value
   329             return value
   330         
   330 
   331         def CheckSimpleTypeValue(value):
   331         def CheckSimpleTypeValue(value):
   332             for facetname, (facetvalue, facetfixed) in facets.items():
   332             for facetname, (facetvalue, facetfixed) in facets.items():
   333                 if facetvalue is not None:
   333                 if facetvalue is not None:
   334                     if facetname == "enumeration" and value not in facetvalue:
   334                     if facetname == "enumeration" and value not in facetvalue:
   335                         return False
   335                         return False
   349                         return False
   349                         return False
   350                     elif facetname == "pattern":
   350                     elif facetname == "pattern":
   351                         model = re.compile("(?:%s)?$" % "|".join(map(lambda x: "(?:%s)" % x, facetvalue)))
   351                         model = re.compile("(?:%s)?$" % "|".join(map(lambda x: "(?:%s)" % x, facetvalue)))
   352                         result = model.match(value)
   352                         result = model.match(value)
   353                         if result is None:
   353                         if result is None:
   354                             if len(facetvalue) > 1:   
   354                             if len(facetvalue) > 1:
   355                                 raise ValueError("value doesn't follow any of the patterns %s" % ",".join(facetvalue))
   355                                 raise ValueError("value doesn't follow any of the patterns %s" % ",".join(facetvalue))
   356                             else:
   356                             else:
   357                                 raise ValueError("value doesn't follow the pattern %s" % facetvalue[0])
   357                                 raise ValueError("value doesn't follow the pattern %s" % facetvalue[0])
   358             return True
   358             return True
   359         
   359 
   360         def SimpleTypeInitialValue():
   360         def SimpleTypeInitialValue():
   361             for facetname, (facetvalue, facetfixed) in facets.items():
   361             for facetname, (facetvalue, facetfixed) in facets.items():
   362                 if facetvalue is not None:
   362                 if facetvalue is not None:
   363                     if facetname == "enumeration":
   363                     if facetname == "enumeration":
   364                         return facetvalue[0]
   364                         return facetvalue[0]
   373                     elif facetname == "maxInclusive" and facetvalue < 0:
   373                     elif facetname == "maxInclusive" and facetvalue < 0:
   374                         return facetvalue
   374                         return facetvalue
   375                     elif facetname == "maxExclusive"  and facetvalue <= 0:
   375                     elif facetname == "maxExclusive"  and facetvalue <= 0:
   376                         return facetvalue - 1
   376                         return facetvalue - 1
   377             return basetypeinfos["initial"]()
   377             return basetypeinfos["initial"]()
   378         
   378 
   379         GenerateSimpleType = basetypeinfos["generate"]
   379         GenerateSimpleType = basetypeinfos["generate"]
   380         
   380 
   381     elif typeinfos["type"] == "list":
   381     elif typeinfos["type"] == "list":
   382         # Search for item type definition
   382         # Search for item type definition
   383         if isinstance(typeinfos["itemType"], (StringType, UnicodeType)):
   383         if isinstance(typeinfos["itemType"], (StringType, UnicodeType)):
   384             itemtypeinfos = factory.FindSchemaElement(typeinfos["itemType"], SIMPLETYPE)
   384             itemtypeinfos = factory.FindSchemaElement(typeinfos["itemType"], SIMPLETYPE)
   385             if itemtypeinfos is None:
   385             if itemtypeinfos is None:
   386                 raise "\"%s\" isn't defined!" % typeinfos["itemType"]
   386                 raise "\"%s\" isn't defined!" % typeinfos["itemType"]
   387         else:
   387         else:
   388             itemtypeinfos = typeinfos["itemType"]
   388             itemtypeinfos = typeinfos["itemType"]
   389         
   389 
   390         # Check that item type is a simple type
   390         # Check that item type is a simple type
   391         if itemtypeinfos["type"] != SIMPLETYPE:
   391         if itemtypeinfos["type"] != SIMPLETYPE:
   392             raise ValueError, "Item type given isn't a simpleType!"
   392             raise ValueError, "Item type given isn't a simpleType!"
   393         
   393 
   394         simpleType["basename"] = "list"
   394         simpleType["basename"] = "list"
   395         
   395 
   396         # Check that derivation is allowed
   396         # Check that derivation is allowed
   397         if itemtypeinfos.has_key("final"):
   397         if itemtypeinfos.has_key("final"):
   398             if itemtypeinfos["final"].has_key("#all"):
   398             if itemtypeinfos["final"].has_key("#all"):
   399                 raise ValueError("Item type can't be derivated!")
   399                 raise ValueError("Item type can't be derivated!")
   400             if itemtypeinfos["final"].has_key("list"):
   400             if itemtypeinfos["final"].has_key("list"):
   401                 raise ValueError("Item type can't be derivated by list!")
   401                 raise ValueError("Item type can't be derivated by list!")
   402         
   402 
   403         # Generate extract value for new created type
   403         # Generate extract value for new created type
   404         def ExtractSimpleTypeValue(attr, extract = True):
   404         def ExtractSimpleTypeValue(attr, extract = True):
   405             values = []
   405             values = []
   406             for value in GetToken(attr, extract).split(" "):
   406             for value in GetToken(attr, extract).split(" "):
   407                 values.append(itemtypeinfos["extract"](value, False))
   407                 values.append(itemtypeinfos["extract"](value, False))
   408             return values
   408             return values
   409         
   409 
   410         def CheckSimpleTypeValue(value):
   410         def CheckSimpleTypeValue(value):
   411             for item in value:
   411             for item in value:
   412                 result = itemtypeinfos["check"](item)
   412                 result = itemtypeinfos["check"](item)
   413                 if not result:
   413                 if not result:
   414                     return result
   414                     return result
   415             return True
   415             return True
   416         
   416 
   417         SimpleTypeInitialValue = lambda: []
   417         SimpleTypeInitialValue = lambda: []
   418         
   418 
   419         GenerateSimpleType = GenerateSimpleTypeXMLText(lambda x: " ".join(map(itemtypeinfos["generate"], x)))
   419         GenerateSimpleType = GenerateSimpleTypeXMLText(lambda x: " ".join(map(itemtypeinfos["generate"], x)))
   420         
   420 
   421         facets = GenerateDictFacets(["length", "maxLength", "minLength", "enumeration", "pattern"])
   421         facets = GenerateDictFacets(["length", "maxLength", "minLength", "enumeration", "pattern"])
   422         facets["whiteSpace"] = ("collapse", False)
   422         facets["whiteSpace"] = ("collapse", False)
   423     
   423 
   424     elif typeinfos["type"] == "union":
   424     elif typeinfos["type"] == "union":
   425         # Search for member types definition
   425         # Search for member types definition
   426         membertypesinfos = []
   426         membertypesinfos = []
   427         for membertype in typeinfos["memberTypes"]:
   427         for membertype in typeinfos["memberTypes"]:
   428             if isinstance(membertype, (StringType, UnicodeType)):
   428             if isinstance(membertype, (StringType, UnicodeType)):
   429                 infos = factory.FindSchemaElement(membertype, SIMPLETYPE)
   429                 infos = factory.FindSchemaElement(membertype, SIMPLETYPE)
   430                 if infos is None:
   430                 if infos is None:
   431                     raise ValueError("\"%s\" isn't defined!" % membertype)
   431                     raise ValueError("\"%s\" isn't defined!" % membertype)
   432             else:
   432             else:
   433                 infos = membertype
   433                 infos = membertype
   434             
   434 
   435             # Check that member type is a simple type
   435             # Check that member type is a simple type
   436             if infos["type"] != SIMPLETYPE:
   436             if infos["type"] != SIMPLETYPE:
   437                 raise ValueError("Member type given isn't a simpleType!")
   437                 raise ValueError("Member type given isn't a simpleType!")
   438             
   438 
   439             # Check that derivation is allowed
   439             # Check that derivation is allowed
   440             if infos.has_key("final"):
   440             if infos.has_key("final"):
   441                 if infos["final"].has_key("#all"):
   441                 if infos["final"].has_key("#all"):
   442                     raise ValueError("Item type can't be derivated!")
   442                     raise ValueError("Item type can't be derivated!")
   443                 if infos["final"].has_key("union"):
   443                 if infos["final"].has_key("union"):
   444                     raise ValueError("Member type can't be derivated by union!")
   444                     raise ValueError("Member type can't be derivated by union!")
   445             
   445 
   446             membertypesinfos.append(infos)
   446             membertypesinfos.append(infos)
   447         
   447 
   448         simpleType["basename"] = "union"
   448         simpleType["basename"] = "union"
   449         
   449 
   450         # Generate extract value for new created type
   450         # Generate extract value for new created type
   451         def ExtractSimpleTypeValue(attr, extract = True):
   451         def ExtractSimpleTypeValue(attr, extract = True):
   452             if extract:
   452             if extract:
   453                 value = GetAttributeValue(attr)
   453                 value = GetAttributeValue(attr)
   454             else:
   454             else:
   457                 try:
   457                 try:
   458                     return infos["extract"](attr, False)
   458                     return infos["extract"](attr, False)
   459                 except:
   459                 except:
   460                     pass
   460                     pass
   461             raise ValueError("\"%s\" isn't valid for type defined for union!")
   461             raise ValueError("\"%s\" isn't valid for type defined for union!")
   462         
   462 
   463         def CheckSimpleTypeValue(value):
   463         def CheckSimpleTypeValue(value):
   464             for infos in membertypesinfos:
   464             for infos in membertypesinfos:
   465                 result = infos["check"](value)
   465                 result = infos["check"](value)
   466                 if result:
   466                 if result:
   467                     return result
   467                     return result
   468             return False
   468             return False
   469         
   469 
   470         SimpleTypeInitialValue = membertypesinfos[0]["initial"]
   470         SimpleTypeInitialValue = membertypesinfos[0]["initial"]
   471         
   471 
   472         def GenerateSimpleTypeFunction(value):
   472         def GenerateSimpleTypeFunction(value):
   473             if isinstance(value, BooleanType):
   473             if isinstance(value, BooleanType):
   474                 return {True: "true", False: "false"}[value]
   474                 return {True: "true", False: "false"}[value]
   475             else:
   475             else:
   476                 return str(value)
   476                 return str(value)
   477         GenerateSimpleType = GenerateSimpleTypeXMLText(GenerateSimpleTypeFunction)
   477         GenerateSimpleType = GenerateSimpleTypeXMLText(GenerateSimpleTypeFunction)
   478         
   478 
   479         facets = GenerateDictFacets(["pattern", "enumeration"])
   479         facets = GenerateDictFacets(["pattern", "enumeration"])
   480     
   480 
   481     simpleType["facets"] = facets
   481     simpleType["facets"] = facets
   482     simpleType["extract"] = ExtractSimpleTypeValue
   482     simpleType["extract"] = ExtractSimpleTypeValue
   483     simpleType["initial"] = SimpleTypeInitialValue
   483     simpleType["initial"] = SimpleTypeInitialValue
   484     simpleType["check"] = CheckSimpleTypeValue
   484     simpleType["check"] = CheckSimpleTypeValue
   485     simpleType["generate"] = GenerateSimpleType
   485     simpleType["generate"] = GenerateSimpleType
   486     return simpleType
   486     return simpleType
   487 
   487 
   488 def ReduceSimpleType(factory, attributes, elements):
   488 def ReduceSimpleType(factory, attributes, elements):
   489     # Reduce all the simple type children
   489     # Reduce all the simple type children
   490     annotations, children = factory.ReduceElements(elements)
   490     annotations, children = factory.ReduceElements(elements)
   491     
   491 
   492     simpleType = CreateSimpleType(factory, attributes, children[0])
   492     simpleType = CreateSimpleType(factory, attributes, children[0])
   493     simpleType["doc"] = annotations
   493     simpleType["doc"] = annotations
   494     
   494 
   495     return simpleType
   495     return simpleType
   496 
   496 
   497 # Complex type
   497 # Complex type
   498 
   498 
   499 def ExtractAttributes(factory, elements, base=None):
   499 def ExtractAttributes(factory, elements, base=None):
   501     attrnames = {}
   501     attrnames = {}
   502     if base is not None:
   502     if base is not None:
   503         basetypeinfos = factory.FindSchemaElement(base)
   503         basetypeinfos = factory.FindSchemaElement(base)
   504         if not isinstance(basetypeinfos, (UnicodeType, StringType)) and basetypeinfos["type"] == COMPLEXTYPE:
   504         if not isinstance(basetypeinfos, (UnicodeType, StringType)) and basetypeinfos["type"] == COMPLEXTYPE:
   505             attrnames = dict(map(lambda x:(x["name"], True), basetypeinfos["attributes"]))
   505             attrnames = dict(map(lambda x:(x["name"], True), basetypeinfos["attributes"]))
   506         
   506 
   507     for element in elements:
   507     for element in elements:
   508         if element["type"] == ATTRIBUTE:
   508         if element["type"] == ATTRIBUTE:
   509             if attrnames.get(element["name"], False):
   509             if attrnames.get(element["name"], False):
   510                 raise ValueError("\"%s\" attribute has been defined two times!" % element["name"])
   510                 raise ValueError("\"%s\" attribute has been defined two times!" % element["name"])
   511             else:
   511             else:
   532             restriction["base"] = children.pop(0)
   532             restriction["base"] = children.pop(0)
   533         else:
   533         else:
   534             raise ValueError("Only one base type can be defined for restriction!")
   534             raise ValueError("Only one base type can be defined for restriction!")
   535     if restriction["base"] is None:
   535     if restriction["base"] is None:
   536         raise ValueError("No base type has been defined for restriction!")
   536         raise ValueError("No base type has been defined for restriction!")
   537     
   537 
   538     while len(children) > 0 and children[0]["type"] in ALL_FACETS:
   538     while len(children) > 0 and children[0]["type"] in ALL_FACETS:
   539         restriction["facets"].append(children.pop(0))
   539         restriction["facets"].append(children.pop(0))
   540     restriction["attributes"] = ExtractAttributes(factory, children, restriction["base"])
   540     restriction["attributes"] = ExtractAttributes(factory, children, restriction["base"])
   541     return restriction
   541     return restriction
   542 
   542 
   569     return extension
   569     return extension
   570 
   570 
   571 
   571 
   572 def ReduceSimpleContent(factory, attributes, elements):
   572 def ReduceSimpleContent(factory, attributes, elements):
   573     annotations, children = factory.ReduceElements(elements)
   573     annotations, children = factory.ReduceElements(elements)
   574     
   574 
   575     simpleContent = children[0].copy()
   575     simpleContent = children[0].copy()
   576     
   576 
   577     basetypeinfos = factory.FindSchemaElement(simpleContent["base"])
   577     basetypeinfos = factory.FindSchemaElement(simpleContent["base"])
   578     if basetypeinfos["type"] == SIMPLETYPE:
   578     if basetypeinfos["type"] == SIMPLETYPE:
   579         contenttypeinfos = simpleContent.copy()
   579         contenttypeinfos = simpleContent.copy()
   580         simpleContent.pop("base")
   580         simpleContent.pop("base")
   581     elif basetypeinfos["type"] == COMPLEXTYPE and \
   581     elif basetypeinfos["type"] == COMPLEXTYPE and \
   586         contenttypeinfos = simpleContent.copy()
   586         contenttypeinfos = simpleContent.copy()
   587         contenttypeinfos["base"] = basetypeinfos["elements"][0]["elmt_type"]
   587         contenttypeinfos["base"] = basetypeinfos["elements"][0]["elmt_type"]
   588     else:
   588     else:
   589         raise ValueError("No compatible base type defined for simpleContent!")
   589         raise ValueError("No compatible base type defined for simpleContent!")
   590     contenttypeinfos = CreateSimpleType(factory, attributes, contenttypeinfos)
   590     contenttypeinfos = CreateSimpleType(factory, attributes, contenttypeinfos)
   591     
   591 
   592     simpleContent["elements"] = [{"name": "content", "type": ELEMENT,
   592     simpleContent["elements"] = [{"name": "content", "type": ELEMENT,
   593                                   "elmt_type": contenttypeinfos, "doc": annotations,
   593                                   "elmt_type": contenttypeinfos, "doc": annotations,
   594                                   "minOccurs": 1, "maxOccurs": 1}]
   594                                   "minOccurs": 1, "maxOccurs": 1}]
   595     simpleContent["type"] = "simpleContent"
   595     simpleContent["type"] = "simpleContent"
   596     return simpleContent
   596     return simpleContent
   603     return complexContent
   603     return complexContent
   604 
   604 
   605 
   605 
   606 def ReduceComplexType(factory, attributes, elements):
   606 def ReduceComplexType(factory, attributes, elements):
   607     annotations, children = factory.ReduceElements(elements)
   607     annotations, children = factory.ReduceElements(elements)
   608     
   608 
   609     if len(children) > 0:
   609     if len(children) > 0:
   610         if children[0]["type"] in ["simpleContent", "complexContent"]:
   610         if children[0]["type"] in ["simpleContent", "complexContent"]:
   611             complexType = children[0].copy()
   611             complexType = children[0].copy()
   612             complexType.update(attributes)
   612             complexType.update(attributes)
   613             complexType["type"] = COMPLEXTYPE
   613             complexType["type"] = COMPLEXTYPE
   664     return {"type" : "anyAttribute"}
   664     return {"type" : "anyAttribute"}
   665 
   665 
   666 
   666 
   667 def ReduceAttribute(factory, attributes, elements):
   667 def ReduceAttribute(factory, attributes, elements):
   668     annotations, children = factory.ReduceElements(elements)
   668     annotations, children = factory.ReduceElements(elements)
   669     
   669 
   670     if attributes.has_key("default"):
   670     if attributes.has_key("default"):
   671         if attributes.has_key("fixed"):
   671         if attributes.has_key("fixed"):
   672             raise ValueError("\"default\" and \"fixed\" can't be defined at the same time!")
   672             raise ValueError("\"default\" and \"fixed\" can't be defined at the same time!")
   673         elif attributes.get("use", "optional") != "optional":
   673         elif attributes.get("use", "optional") != "optional":
   674             raise ValueError("if \"default\" present, \"use\" can only have the value \"optional\"!")
   674             raise ValueError("if \"default\" present, \"use\" can only have the value \"optional\"!")
   675     
   675 
   676     attribute = {"type": ATTRIBUTE, "attr_type": attributes.get("type", None), "doc": annotations}
   676     attribute = {"type": ATTRIBUTE, "attr_type": attributes.get("type", None), "doc": annotations}
   677     if len(children) > 0:
   677     if len(children) > 0:
   678         if attribute["attr_type"] is None:
   678         if attribute["attr_type"] is None:
   679             attribute["attr_type"] = children[0]
   679             attribute["attr_type"] = children[0]
   680         else:
   680         else:
   681             raise ValueError("Only one type can be defined for attribute!")
   681             raise ValueError("Only one type can be defined for attribute!")
   682     
   682 
   683     if attributes.has_key("ref"):
   683     if attributes.has_key("ref"):
   684         if attributes.has_key("name"):
   684         if attributes.has_key("name"):
   685             raise ValueError("\"ref\" and \"name\" can't be defined at the same time!")
   685             raise ValueError("\"ref\" and \"name\" can't be defined at the same time!")
   686         elif attributes.has_key("form"):
   686         elif attributes.has_key("form"):
   687             raise ValueError("\"ref\" and \"form\" can't be defined at the same time!")
   687             raise ValueError("\"ref\" and \"form\" can't be defined at the same time!")
   688         elif attribute["attr_type"] is not None:
   688         elif attribute["attr_type"] is not None:
   689             raise ValueError("if \"ref\" is present, no type can be defined!")
   689             raise ValueError("if \"ref\" is present, no type can be defined!")
   690     elif attribute["attr_type"] is None:
   690     elif attribute["attr_type"] is None:
   691         raise ValueError("No type has been defined for attribute \"%s\"!" % attributes["name"])
   691         raise ValueError("No type has been defined for attribute \"%s\"!" % attributes["name"])
   692     
   692 
   693     if attributes.has_key("type"):
   693     if attributes.has_key("type"):
   694         tmp_attrs = attributes.copy()
   694         tmp_attrs = attributes.copy()
   695         tmp_attrs.pop("type")
   695         tmp_attrs.pop("type")
   696         attribute.update(tmp_attrs)
   696         attribute.update(tmp_attrs)
   697     else:
   697     else:
   709 
   709 
   710 # Elements groups
   710 # Elements groups
   711 
   711 
   712 def ReduceAny(factory, attributes, elements):
   712 def ReduceAny(factory, attributes, elements):
   713     annotations, children = factory.ReduceElements(elements)
   713     annotations, children = factory.ReduceElements(elements)
   714     
   714 
   715     any = {"type": ANY, "doc": annotations}
   715     any = {"type": ANY, "doc": annotations}
   716     any.update(attributes)
   716     any.update(attributes)
   717     return any
   717     return any
   718 
   718 
   719 def ReduceElement(factory, attributes, elements):
   719 def ReduceElement(factory, attributes, elements):
   720     annotations, children = factory.ReduceElements(elements)
   720     annotations, children = factory.ReduceElements(elements)
   721     
   721 
   722     types = []
   722     types = []
   723     constraints = []
   723     constraints = []
   724     for child in children:
   724     for child in children:
   725         if child["type"] == CONSTRAINT:
   725         if child["type"] == CONSTRAINT:
   726             constraints.append(child)
   726             constraints.append(child)
   727         else:
   727         else:
   728             types.append(child)
   728             types.append(child)
   729     
   729 
   730     if attributes.has_key("default") and attributes.has_key("fixed"):
   730     if attributes.has_key("default") and attributes.has_key("fixed"):
   731         raise ValueError("\"default\" and \"fixed\" can't be defined at the same time!")
   731         raise ValueError("\"default\" and \"fixed\" can't be defined at the same time!")
   732     
   732 
   733     if attributes.has_key("ref"):
   733     if attributes.has_key("ref"):
   734         for attr in ["name", "default", "fixed", "form", "block", "type"]:
   734         for attr in ["name", "default", "fixed", "form", "block", "type"]:
   735             if attributes.has_key(attr):
   735             if attributes.has_key(attr):
   736                 raise ValueError("\"ref\" and \"%s\" can't be defined at the same time!" % attr)
   736                 raise ValueError("\"ref\" and \"%s\" can't be defined at the same time!" % attr)
   737         if attributes.has_key("nillable"):
   737         if attributes.has_key("nillable"):
   738             raise ValueError("\"ref\" and \"nillable\" can't be defined at the same time!")
   738             raise ValueError("\"ref\" and \"nillable\" can't be defined at the same time!")
   739         if len(types) > 0:
   739         if len(types) > 0:
   740             raise ValueError("No type and no constraints can be defined where \"ref\" is defined!")
   740             raise ValueError("No type and no constraints can be defined where \"ref\" is defined!")
   741     
   741 
   742         infos = factory.FindSchemaElement(attributes["ref"], ELEMENT)
   742         infos = factory.FindSchemaElement(attributes["ref"], ELEMENT)
   743         if infos is not None:
   743         if infos is not None:
   744             element = infos.copy()
   744             element = infos.copy()
   745             element["constraints"] = constraints
   745             element["constraints"] = constraints
   746             element["minOccurs"] = attributes["minOccurs"]
   746             element["minOccurs"] = attributes["minOccurs"]
   747             element["maxOccurs"] = attributes["maxOccurs"]
   747             element["maxOccurs"] = attributes["maxOccurs"]
   748             return element
   748             return element
   749         else:
   749         else:
   750             raise ValueError("\"%s\" base type isn't defined or circular referenced!" % name)
   750             raise ValueError("\"%s\" base type isn't defined or circular referenced!" % name)
   751     
   751 
   752     elif attributes.has_key("name"):
   752     elif attributes.has_key("name"):
   753         element = {"type": ELEMENT, "elmt_type": attributes.get("type", None), "constraints": constraints, "doc": annotations}
   753         element = {"type": ELEMENT, "elmt_type": attributes.get("type", None), "constraints": constraints, "doc": annotations}
   754         if len(types) > 0:
   754         if len(types) > 0:
   755             if element["elmt_type"] is None:
   755             if element["elmt_type"] is None:
   756                 element["elmt_type"] = types[0]
   756                 element["elmt_type"] = types[0]
   757             else:
   757             else:
   758                 raise ValueError("Only one type can be defined for attribute!")
   758                 raise ValueError("Only one type can be defined for attribute!")
   759         elif element["elmt_type"] is None:
   759         elif element["elmt_type"] is None:
   760             element["elmt_type"] = "tag"
   760             element["elmt_type"] = "tag"
   761             element["type"] = TAG
   761             element["type"] = TAG
   762         
   762 
   763         if attributes.has_key("type"):
   763         if attributes.has_key("type"):
   764             tmp_attrs = attributes.copy()
   764             tmp_attrs = attributes.copy()
   765             tmp_attrs.pop("type")
   765             tmp_attrs.pop("type")
   766             element.update(tmp_attrs)
   766             element.update(tmp_attrs)
   767         else:
   767         else:
   770     else:
   770     else:
   771         raise ValueError("\"Element\" must have at least a \"ref\" or a \"name\" defined!")
   771         raise ValueError("\"Element\" must have at least a \"ref\" or a \"name\" defined!")
   772 
   772 
   773 def ReduceAll(factory, attributes, elements):
   773 def ReduceAll(factory, attributes, elements):
   774     annotations, children = factory.ReduceElements(elements)
   774     annotations, children = factory.ReduceElements(elements)
   775     
   775 
   776     for child in children:
   776     for child in children:
   777         if children["maxOccurs"] == "unbounded" or children["maxOccurs"] > 1:
   777         if children["maxOccurs"] == "unbounded" or children["maxOccurs"] > 1:
   778             raise ValueError("\"all\" item can't have \"maxOccurs\" attribute greater than 1!")
   778             raise ValueError("\"all\" item can't have \"maxOccurs\" attribute greater than 1!")
   779     
   779 
   780     return {"type": "all", "elements": children, "minOccurs": attributes["minOccurs"],
   780     return {"type": "all", "elements": children, "minOccurs": attributes["minOccurs"],
   781             "maxOccurs": attributes["maxOccurs"], "order": False, "doc": annotations}
   781             "maxOccurs": attributes["maxOccurs"], "order": False, "doc": annotations}
   782 
   782 
   783 
   783 
   784 def ReduceChoice(factory, attributes, elements):
   784 def ReduceChoice(factory, attributes, elements):
   785     annotations, children = factory.ReduceElements(elements)
   785     annotations, children = factory.ReduceElements(elements)
   786     
   786 
   787     choices = []
   787     choices = []
   788     for child in children:
   788     for child in children:
   789         if child["type"] in [ELEMENT, ANY, TAG]:
   789         if child["type"] in [ELEMENT, ANY, TAG]:
   790             choices.append(child)
   790             choices.append(child)
   791         elif child["type"] == "sequence":
   791         elif child["type"] == "sequence":
   793             choices.append(child)
   793             choices.append(child)
   794             #raise ValueError("\"sequence\" in \"choice\" is not supported. Create instead a new complex type!")
   794             #raise ValueError("\"sequence\" in \"choice\" is not supported. Create instead a new complex type!")
   795         elif child["type"] == CHOICE:
   795         elif child["type"] == CHOICE:
   796             choices.extend(child["choices"])
   796             choices.extend(child["choices"])
   797         elif child["type"] == "group":
   797         elif child["type"] == "group":
   798             elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP) 
   798             elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP)
   799             if not elmtgroup.has_key("choices"):
   799             if not elmtgroup.has_key("choices"):
   800                 raise ValueError("Only group composed of \"choice\" can be referenced in \"choice\" element!")
   800                 raise ValueError("Only group composed of \"choice\" can be referenced in \"choice\" element!")
   801             choices_tmp = []
   801             choices_tmp = []
   802             for choice in elmtgroup["choices"]:
   802             for choice in elmtgroup["choices"]:
   803                 if not isinstance(choice["elmt_type"], (UnicodeType, StringType)) and choice["elmt_type"]["type"] == COMPLEXTYPE:
   803                 if not isinstance(choice["elmt_type"], (UnicodeType, StringType)) and choice["elmt_type"]["type"] == COMPLEXTYPE:
   808                     new_choice["elmt_type"] = elmt_type
   808                     new_choice["elmt_type"] = elmt_type
   809                     choices_tmp.append(new_choice)
   809                     choices_tmp.append(new_choice)
   810                 else:
   810                 else:
   811                     choices_tmp.append(choice)
   811                     choices_tmp.append(choice)
   812             choices.extend(choices_tmp)
   812             choices.extend(choices_tmp)
   813     
   813 
   814     for choice in choices:
   814     for choice in choices:
   815         attributes["minOccurs"] = min(attributes["minOccurs"], choice["minOccurs"])
   815         attributes["minOccurs"] = min(attributes["minOccurs"], choice["minOccurs"])
   816         choice["minOccurs"] = 1
   816         choice["minOccurs"] = 1
   817     
   817 
   818     return {"type": CHOICE, "choices": choices, "minOccurs": attributes["minOccurs"],
   818     return {"type": CHOICE, "choices": choices, "minOccurs": attributes["minOccurs"],
   819             "maxOccurs": attributes["maxOccurs"], "doc": annotations}
   819             "maxOccurs": attributes["maxOccurs"], "doc": annotations}
   820 
   820 
   821 
   821 
   822 def ReduceSequence(factory, attributes, elements):
   822 def ReduceSequence(factory, attributes, elements):
   823     annotations, children = factory.ReduceElements(elements)
   823     annotations, children = factory.ReduceElements(elements)
   824     
   824 
   825     sequence = []
   825     sequence = []
   826     for child in children:
   826     for child in children:
   827         if child["type"] in [ELEMENT, ANY, TAG, CHOICE]:
   827         if child["type"] in [ELEMENT, ANY, TAG, CHOICE]:
   828             sequence.append(child)
   828             sequence.append(child)
   829         elif child["type"] == "sequence":
   829         elif child["type"] == "sequence":
   842                     new_element["elmt_type"] = elmt_type
   842                     new_element["elmt_type"] = elmt_type
   843                     elements_tmp.append(new_element)
   843                     elements_tmp.append(new_element)
   844                 else:
   844                 else:
   845                     elements_tmp.append(element)
   845                     elements_tmp.append(element)
   846             sequence.extend(elements_tmp)
   846             sequence.extend(elements_tmp)
   847             
   847 
   848     return {"type": "sequence", "elements": sequence, "minOccurs": attributes["minOccurs"],
   848     return {"type": "sequence", "elements": sequence, "minOccurs": attributes["minOccurs"],
   849             "maxOccurs": attributes["maxOccurs"], "order": True, "doc": annotations}
   849             "maxOccurs": attributes["maxOccurs"], "order": True, "doc": annotations}
   850     
   850 
   851     
   851 
   852 def ReduceGroup(factory, attributes, elements):
   852 def ReduceGroup(factory, attributes, elements):
   853     annotations, children = factory.ReduceElements(elements)
   853     annotations, children = factory.ReduceElements(elements)
   854     
   854 
   855     if attributes.has_key("ref"):
   855     if attributes.has_key("ref"):
   856         return {"type": "group", "ref": attributes["ref"], "doc": annotations}
   856         return {"type": "group", "ref": attributes["ref"], "doc": annotations}
   857     else:
   857     else:
   858         element = children[0]
   858         element = children[0]
   859         group = {"type": ELEMENTSGROUP, "doc": annotations}
   859         group = {"type": ELEMENTSGROUP, "doc": annotations}
   866 
   866 
   867 # Constraint elements
   867 # Constraint elements
   868 
   868 
   869 def ReduceUnique(factory, attributes, elements):
   869 def ReduceUnique(factory, attributes, elements):
   870     annotations, children = factory.ReduceElements(elements)
   870     annotations, children = factory.ReduceElements(elements)
   871     
   871 
   872     unique = {"type": CONSTRAINT, "const_type": "unique", "selector": children[0], "fields": children[1:]}
   872     unique = {"type": CONSTRAINT, "const_type": "unique", "selector": children[0], "fields": children[1:]}
   873     unique.update(attributes)
   873     unique.update(attributes)
   874     return unique
   874     return unique
   875     
   875 
   876 def ReduceKey(factory, attributes, elements):
   876 def ReduceKey(factory, attributes, elements):
   877     annotations, children = factory.ReduceElements(elements)
   877     annotations, children = factory.ReduceElements(elements)
   878     
   878 
   879     key = {"type": CONSTRAINT, "const_type": "key", "selector": children[0], "fields": children[1:]}
   879     key = {"type": CONSTRAINT, "const_type": "key", "selector": children[0], "fields": children[1:]}
   880     key.update(attributes)
   880     key.update(attributes)
   881     return key
   881     return key
   882 
   882 
   883 def ReduceKeyRef(factory, attributes, elements):
   883 def ReduceKeyRef(factory, attributes, elements):
   884     annotations, children = factory.ReduceElements(elements)
   884     annotations, children = factory.ReduceElements(elements)
   885     
   885 
   886     keyref = {"type": CONSTRAINT, "const_type": "keyref", "selector": children[0], "fields": children[1:]}
   886     keyref = {"type": CONSTRAINT, "const_type": "keyref", "selector": children[0], "fields": children[1:]}
   887     keyref.update(attributes)
   887     keyref.update(attributes)
   888     return keyref
   888     return keyref
   889     
   889 
   890 def ReduceSelector(factory, attributes, elements):
   890 def ReduceSelector(factory, attributes, elements):
   891     annotations, children = factory.ReduceElements(elements)
   891     annotations, children = factory.ReduceElements(elements)
   892     
   892 
   893     selector = {"type": CONSTRAINT, "const_type": "selector"}
   893     selector = {"type": CONSTRAINT, "const_type": "selector"}
   894     selector.update(attributes)
   894     selector.update(attributes)
   895     return selector
   895     return selector
   896 
   896 
   897 def ReduceField(factory, attributes, elements):
   897 def ReduceField(factory, attributes, elements):
   898     annotations, children = factory.ReduceElements(elements)
   898     annotations, children = factory.ReduceElements(elements)
   899     
   899 
   900     field = {"type": CONSTRAINT, "const_type": "field"}
   900     field = {"type": CONSTRAINT, "const_type": "field"}
   901     field.update(attributes)
   901     field.update(attributes)
   902     return field
   902     return field
   903     
   903 
   904 
   904 
   905 # Inclusion elements
   905 # Inclusion elements
   906 
   906 
   907 def ReduceImport(factory, attributes, elements):
   907 def ReduceImport(factory, attributes, elements):
   908     annotations, children = factory.ReduceElements(elements)
   908     annotations, children = factory.ReduceElements(elements)
   909     raise ValueError("\"import\" element isn't supported yet!")
   909     raise ValueError("\"import\" element isn't supported yet!")
   910 
   910 
   911 def ReduceInclude(factory, attributes, elements):
   911 def ReduceInclude(factory, attributes, elements):
   912     annotations, children = factory.ReduceElements(elements)
   912     annotations, children = factory.ReduceElements(elements)
   913     
   913 
   914     if factory.FileName is None:
   914     if factory.FileName is None:
   915         raise ValueError("Include in XSD string not yet supported")
   915         raise ValueError("Include in XSD string not yet supported")
   916     filepath = attributes["schemaLocation"]
   916     filepath = attributes["schemaLocation"]
   917     if filepath is not None and not os.path.exists(filepath):
   917     if filepath is not None and not os.path.exists(filepath):
   918         filepath = os.path.join(factory.BaseFolder, filepath)
   918         filepath = os.path.join(factory.BaseFolder, filepath)
   920             raise ValueError("No file '%s' found for include" % attributes["schemaLocation"])
   920             raise ValueError("No file '%s' found for include" % attributes["schemaLocation"])
   921     xsdfile = open(filepath, 'r')
   921     xsdfile = open(filepath, 'r')
   922     include_factory = XSDClassFactory(minidom.parse(xsdfile), filepath)
   922     include_factory = XSDClassFactory(minidom.parse(xsdfile), filepath)
   923     xsdfile.close()
   923     xsdfile.close()
   924     include_factory.CreateClasses()
   924     include_factory.CreateClasses()
   925     
   925 
   926     if factory.TargetNamespace == include_factory.TargetNamespace:
   926     if factory.TargetNamespace == include_factory.TargetNamespace:
   927         factory.Namespaces[factory.TargetNamespace].update(include_factory.Namespaces[include_factory.TargetNamespace])
   927         factory.Namespaces[factory.TargetNamespace].update(include_factory.Namespaces[include_factory.TargetNamespace])
   928     else:
   928     else:
   929         factory.Namespaces[include_factory.TargetNamespace] = include_factory.Namespaces[include_factory.TargetNamespace]
   929         factory.Namespaces[include_factory.TargetNamespace] = include_factory.Namespaces[include_factory.TargetNamespace]
   930     factory.ComputedClasses.update(include_factory.ComputedClasses)
   930     factory.ComputedClasses.update(include_factory.ComputedClasses)
   931     factory.ComputedClassesLookUp.update(include_factory.ComputedClassesLookUp)
   931     factory.ComputedClassesLookUp.update(include_factory.ComputedClassesLookUp)
   932     factory.EquivalentClassesParent.update(include_factory.EquivalentClassesParent)
   932     factory.EquivalentClassesParent.update(include_factory.EquivalentClassesParent)
   933     return None
   933     return None
   934     
   934 
   935 def ReduceRedefine(factory, attributes, elements):
   935 def ReduceRedefine(factory, attributes, elements):
   936     annotations, children = factory.ReduceElements(elements)
   936     annotations, children = factory.ReduceElements(elements)
   937     raise ValueError("\"redefine\" element isn't supported yet!")
   937     raise ValueError("\"redefine\" element isn't supported yet!")
   938 
   938 
   939 
   939 
   942 def ReduceSchema(factory, attributes, elements):
   942 def ReduceSchema(factory, attributes, elements):
   943     factory.AttributeFormDefault = attributes["attributeFormDefault"]
   943     factory.AttributeFormDefault = attributes["attributeFormDefault"]
   944     factory.ElementFormDefault = attributes["elementFormDefault"]
   944     factory.ElementFormDefault = attributes["elementFormDefault"]
   945     factory.BlockDefault = attributes["blockDefault"]
   945     factory.BlockDefault = attributes["blockDefault"]
   946     factory.FinalDefault = attributes["finalDefault"]
   946     factory.FinalDefault = attributes["finalDefault"]
   947     
   947 
   948     targetNamespace = attributes.get("targetNamespace", None)
   948     targetNamespace = attributes.get("targetNamespace", None)
   949     factory.TargetNamespace = factory.DefinedNamespaces.get(targetNamespace, None)
   949     factory.TargetNamespace = factory.DefinedNamespaces.get(targetNamespace, None)
   950     if factory.TargetNamespace is not None:
   950     if factory.TargetNamespace is not None:
   951         factory.etreeNamespaceFormat = "{%s}%%s" % targetNamespace
   951         factory.etreeNamespaceFormat = "{%s}%%s" % targetNamespace
   952     factory.Namespaces[factory.TargetNamespace] = {}
   952     factory.Namespaces[factory.TargetNamespace] = {}
   953     
   953 
   954     annotations, children = factory.ReduceElements(elements, True)
   954     annotations, children = factory.ReduceElements(elements, True)
   955     
   955 
   956     for child in children:
   956     for child in children:
   957         if child.has_key("name"):
   957         if child.has_key("name"):
   958             infos = factory.GetQualifiedNameInfos(child["name"], factory.TargetNamespace, True)
   958             infos = factory.GetQualifiedNameInfos(child["name"], factory.TargetNamespace, True)
   959             if infos is None:
   959             if infos is None:
   960                 factory.Namespaces[factory.TargetNamespace][child["name"]] = child
   960                 factory.Namespaces[factory.TargetNamespace][child["name"]] = child
   985         if not isinstance(reference, FunctionType) or schema.__name__ != reference.__name__:
   985         if not isinstance(reference, FunctionType) or schema.__name__ != reference.__name__:
   986             return False
   986             return False
   987         else:
   987         else:
   988             return True
   988             return True
   989     return schema == reference
   989     return schema == reference
   990     
   990 
   991 #-------------------------------------------------------------------------------
   991 #-------------------------------------------------------------------------------
   992 #                       Base class for XSD schema extraction
   992 #                       Base class for XSD schema extraction
   993 #-------------------------------------------------------------------------------
   993 #-------------------------------------------------------------------------------
   994 
   994 
   995 
   995 
   997 
   997 
   998     def __init__(self, document, filepath=None, debug=False):
   998     def __init__(self, document, filepath=None, debug=False):
   999         ClassFactory.__init__(self, document, filepath, debug)
   999         ClassFactory.__init__(self, document, filepath, debug)
  1000         self.Namespaces["xml"] = {
  1000         self.Namespaces["xml"] = {
  1001             "lang": {
  1001             "lang": {
  1002                 "type": SYNTAXATTRIBUTE, 
  1002                 "type": SYNTAXATTRIBUTE,
  1003                 "extract": {
  1003                 "extract": {
  1004                     "default": GenerateModelNameExtraction("lang", LANGUAGE_model)
  1004                     "default": GenerateModelNameExtraction("lang", LANGUAGE_model)
  1005                 }
  1005                 }
  1006             }
  1006             }
  1007         }
  1007         }
  1008         self.Namespaces["xsi"] = {
  1008         self.Namespaces["xsi"] = {
  1009             "noNamespaceSchemaLocation": {
  1009             "noNamespaceSchemaLocation": {
  1010                 "type": SYNTAXATTRIBUTE, 
  1010                 "type": SYNTAXATTRIBUTE,
  1011                 "extract": {
  1011                 "extract": {
  1012                     "default": NotSupportedYet("noNamespaceSchemaLocation")
  1012                     "default": NotSupportedYet("noNamespaceSchemaLocation")
  1013                 }
  1013                 }
  1014             },
  1014             },
  1015             "nil": {
  1015             "nil": {
  1016                 "type": SYNTAXATTRIBUTE, 
  1016                 "type": SYNTAXATTRIBUTE,
  1017                 "extract": {
  1017                 "extract": {
  1018                     "default": NotSupportedYet("nil")
  1018                     "default": NotSupportedYet("nil")
  1019                 }
  1019                 }
  1020             },
  1020             },
  1021             "schemaLocation": {
  1021             "schemaLocation": {
  1022                 "type": SYNTAXATTRIBUTE, 
  1022                 "type": SYNTAXATTRIBUTE,
  1023                 "extract": {
  1023                 "extract": {
  1024                     "default": NotSupportedYet("schemaLocation")
  1024                     "default": NotSupportedYet("schemaLocation")
  1025                 }
  1025                 }
  1026             },
  1026             },
  1027             "type": {
  1027             "type": {
  1028                 "type": SYNTAXATTRIBUTE, 
  1028                 "type": SYNTAXATTRIBUTE,
  1029                 "extract": {
  1029                 "extract": {
  1030                     "default": NotSupportedYet("type")
  1030                     "default": NotSupportedYet("type")
  1031                 }
  1031                 }
  1032             }
  1032             }
  1033         }
  1033         }
  1034         
  1034 
  1035     def ParseSchema(self):
  1035     def ParseSchema(self):
  1036         for child in self.Document.childNodes:
  1036         for child in self.Document.childNodes:
  1037             if child.nodeType == self.Document.ELEMENT_NODE:
  1037             if child.nodeType == self.Document.ELEMENT_NODE:
  1038                 schema = child
  1038                 schema = child
  1039                 break
  1039                 break
  1065             else:
  1065             else:
  1066                 raise ValueError("\"%s\" isn't defined!" % element_name)
  1066                 raise ValueError("\"%s\" isn't defined!" % element_name)
  1067         if element_type is not None and element["type"] != element_type:
  1067         if element_type is not None and element["type"] != element_type:
  1068             raise ValueError("\"%s\" isn't of the expected type!" % element_name)
  1068             raise ValueError("\"%s\" isn't of the expected type!" % element_name)
  1069         return element
  1069         return element
  1070     
  1070 
  1071     def CreateSchemaElement(self, element_name, element_type):
  1071     def CreateSchemaElement(self, element_name, element_type):
  1072         for type, attributes, elements in self.Schema[2]:
  1072         for type, attributes, elements in self.Schema[2]:
  1073             namespace, name = DecomposeQualifiedName(type)
  1073             namespace, name = DecomposeQualifiedName(type)
  1074             if attributes.get("name", None) == element_name:
  1074             if attributes.get("name", None) == element_name:
  1075                 element_infos = None
  1075                 element_infos = None
  1089                     self.Namespaces[self.TargetNamespace][element_name] = element_infos
  1089                     self.Namespaces[self.TargetNamespace][element_name] = element_infos
  1090                     return element_infos
  1090                     return element_infos
  1091         return None
  1091         return None
  1092 
  1092 
  1093 """
  1093 """
  1094 This function opens the xsd file and generate a xml parser with class lookup from 
  1094 This function opens the xsd file and generate a xml parser with class lookup from
  1095 the xml tree
  1095 the xml tree
  1096 """
  1096 """
  1097 def GenerateParserFromXSD(filepath):
  1097 def GenerateParserFromXSD(filepath):
  1098     xsdfile = open(filepath, 'r')
  1098     xsdfile = open(filepath, 'r')
  1099     xsdstring = xsdfile.read()
  1099     xsdstring = xsdfile.read()
  1127           maxOccurs = 1 : 1
  1127           maxOccurs = 1 : 1
  1128           minOccurs = (0 | 1) : 1
  1128           minOccurs = (0 | 1) : 1
  1129           {any attributes with non-schema namespace . . .}>
  1129           {any attributes with non-schema namespace . . .}>
  1130           Content: (annotation?, element*)
  1130           Content: (annotation?, element*)
  1131         </all>""",
  1131         </all>""",
  1132         "type": SYNTAXELEMENT, 
  1132         "type": SYNTAXELEMENT,
  1133         "extract": {
  1133         "extract": {
  1134             "default": GenerateElement("all", ["id", "maxOccurs", "minOccurs"], 
  1134             "default": GenerateElement("all", ["id", "maxOccurs", "minOccurs"],
  1135                 re.compile("((?:annotation )?(?:element )*)"))
  1135                 re.compile("((?:annotation )?(?:element )*)"))
  1136         },
  1136         },
  1137         "reduce": ReduceAll
  1137         "reduce": ReduceAll
  1138     },
  1138     },
  1139 
  1139 
  1141         <annotation
  1141         <annotation
  1142           id = ID
  1142           id = ID
  1143           {any attributes with non-schema namespace . . .}>
  1143           {any attributes with non-schema namespace . . .}>
  1144           Content: (appinfo | documentation)*
  1144           Content: (appinfo | documentation)*
  1145         </annotation>""",
  1145         </annotation>""",
  1146         "type": SYNTAXELEMENT, 
  1146         "type": SYNTAXELEMENT,
  1147         "extract": {
  1147         "extract": {
  1148             "default": GenerateElement("annotation", ["id"], 
  1148             "default": GenerateElement("annotation", ["id"],
  1149                 re.compile("((?:app_info |documentation )*)"))
  1149                 re.compile("((?:app_info |documentation )*)"))
  1150         },
  1150         },
  1151         "reduce": ReduceAnnotation
  1151         "reduce": ReduceAnnotation
  1152     },
  1152     },
  1153 
  1153 
  1159           namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) )  : ##any
  1159           namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) )  : ##any
  1160           processContents = (lax | skip | strict) : strict
  1160           processContents = (lax | skip | strict) : strict
  1161           {any attributes with non-schema namespace . . .}>
  1161           {any attributes with non-schema namespace . . .}>
  1162           Content: (annotation?)
  1162           Content: (annotation?)
  1163         </any>""",
  1163         </any>""",
  1164         "type": SYNTAXELEMENT, 
  1164         "type": SYNTAXELEMENT,
  1165         "extract": {
  1165         "extract": {
  1166             "default": GenerateElement("any", 
  1166             "default": GenerateElement("any",
  1167                 ["id", "maxOccurs", "minOccurs", "namespace", "processContents"], 
  1167                 ["id", "maxOccurs", "minOccurs", "namespace", "processContents"],
  1168                 re.compile("((?:annotation )?(?:simpleType )*)"))
  1168                 re.compile("((?:annotation )?(?:simpleType )*)"))
  1169         },
  1169         },
  1170         "reduce": ReduceAny
  1170         "reduce": ReduceAny
  1171     },
  1171     },
  1172 
  1172 
  1176           namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) )  : ##any
  1176           namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) )  : ##any
  1177           processContents = (lax | skip | strict) : strict
  1177           processContents = (lax | skip | strict) : strict
  1178           {any attributes with non-schema namespace . . .}>
  1178           {any attributes with non-schema namespace . . .}>
  1179           Content: (annotation?)
  1179           Content: (annotation?)
  1180         </anyAttribute>""",
  1180         </anyAttribute>""",
  1181         "type": SYNTAXELEMENT, 
  1181         "type": SYNTAXELEMENT,
  1182         "extract": {
  1182         "extract": {
  1183             "default": GenerateElement("anyAttribute",
  1183             "default": GenerateElement("anyAttribute",
  1184                 ["id", "namespace", "processContents"], ONLY_ANNOTATION)
  1184                 ["id", "namespace", "processContents"], ONLY_ANNOTATION)
  1185         },
  1185         },
  1186         "reduce": ReduceAnyAttribute
  1186         "reduce": ReduceAnyAttribute
  1190         <appinfo
  1190         <appinfo
  1191           source = anyURI
  1191           source = anyURI
  1192           {any attributes with non-schema namespace . . .}>
  1192           {any attributes with non-schema namespace . . .}>
  1193           Content: ({any})*
  1193           Content: ({any})*
  1194         </appinfo>""",
  1194         </appinfo>""",
  1195         "type": SYNTAXELEMENT, 
  1195         "type": SYNTAXELEMENT,
  1196         "extract": {
  1196         "extract": {
  1197             "default": GenerateElement("appinfo", ["source"], re.compile("(.*)"), True)
  1197             "default": GenerateElement("appinfo", ["source"], re.compile("(.*)"), True)
  1198         },
  1198         },
  1199         "reduce": ReduceAppInfo
  1199         "reduce": ReduceAppInfo
  1200     },
  1200     },
  1210           type = QName
  1210           type = QName
  1211           use = (optional | prohibited | required) : optional
  1211           use = (optional | prohibited | required) : optional
  1212           {any attributes with non-schema namespace . . .}>
  1212           {any attributes with non-schema namespace . . .}>
  1213           Content: (annotation?, simpleType?)
  1213           Content: (annotation?, simpleType?)
  1214         </attribute>""",
  1214         </attribute>""",
  1215         "type": SYNTAXELEMENT, 
  1215         "type": SYNTAXELEMENT,
  1216         "extract": {
  1216         "extract": {
  1217             "default": GenerateElement("attribute", 
  1217             "default": GenerateElement("attribute",
  1218                 ["default", "fixed", "form", "id", "name", "ref", "type", "use"], 
  1218                 ["default", "fixed", "form", "id", "name", "ref", "type", "use"],
  1219                 re.compile("((?:annotation )?(?:simpleType )?)")),
  1219                 re.compile("((?:annotation )?(?:simpleType )?)")),
  1220             "schema": GenerateElement("attribute", 
  1220             "schema": GenerateElement("attribute",
  1221                 ["default", "fixed", "form", "id", "name", "type"], 
  1221                 ["default", "fixed", "form", "id", "name", "type"],
  1222                 re.compile("((?:annotation )?(?:simpleType )?)"))
  1222                 re.compile("((?:annotation )?(?:simpleType )?)"))
  1223         },
  1223         },
  1224         "reduce": ReduceAttribute
  1224         "reduce": ReduceAttribute
  1225     },
  1225     },
  1226 
  1226 
  1230           name = NCName
  1230           name = NCName
  1231           ref = QName
  1231           ref = QName
  1232           {any attributes with non-schema namespace . . .}>
  1232           {any attributes with non-schema namespace . . .}>
  1233           Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
  1233           Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
  1234         </attributeGroup>""",
  1234         </attributeGroup>""",
  1235         "type": SYNTAXELEMENT, 
  1235         "type": SYNTAXELEMENT,
  1236         "extract": {
  1236         "extract": {
  1237             "default": GenerateElement("attributeGroup", 
  1237             "default": GenerateElement("attributeGroup",
  1238                 ["id", "ref"], ONLY_ANNOTATION),
  1238                 ["id", "ref"], ONLY_ANNOTATION),
  1239             "schema": GenerateElement("attributeGroup",
  1239             "schema": GenerateElement("attributeGroup",
  1240                 ["id", "name"], 
  1240                 ["id", "name"],
  1241                 re.compile("((?:annotation )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))"))
  1241                 re.compile("((?:annotation )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))"))
  1242         },
  1242         },
  1243         "reduce": ReduceAttributeGroup
  1243         "reduce": ReduceAttributeGroup
  1244     },
  1244     },
  1245 
  1245 
  1249           maxOccurs = (nonNegativeInteger | unbounded)  : 1
  1249           maxOccurs = (nonNegativeInteger | unbounded)  : 1
  1250           minOccurs = nonNegativeInteger : 1
  1250           minOccurs = nonNegativeInteger : 1
  1251           {any attributes with non-schema namespace . . .}>
  1251           {any attributes with non-schema namespace . . .}>
  1252           Content: (annotation?, (element | group | choice | sequence | any)*)
  1252           Content: (annotation?, (element | group | choice | sequence | any)*)
  1253         </choice>""",
  1253         </choice>""",
  1254         "type": SYNTAXELEMENT, 
  1254         "type": SYNTAXELEMENT,
  1255         "extract": {
  1255         "extract": {
  1256             "default": GenerateElement("choice", ["id", "maxOccurs", "minOccurs"], 
  1256             "default": GenerateElement("choice", ["id", "maxOccurs", "minOccurs"],
  1257                 re.compile("((?:annotation )?(?:element |group |choice |sequence |any )*)"))
  1257                 re.compile("((?:annotation )?(?:element |group |choice |sequence |any )*)"))
  1258         },
  1258         },
  1259         "reduce": ReduceChoice
  1259         "reduce": ReduceChoice
  1260     },
  1260     },
  1261 
  1261 
  1264           id = ID
  1264           id = ID
  1265           mixed = boolean
  1265           mixed = boolean
  1266           {any attributes with non-schema namespace . . .}>
  1266           {any attributes with non-schema namespace . . .}>
  1267           Content: (annotation?, (restriction | extension))
  1267           Content: (annotation?, (restriction | extension))
  1268         </complexContent>""",
  1268         </complexContent>""",
  1269         "type": SYNTAXELEMENT, 
  1269         "type": SYNTAXELEMENT,
  1270         "extract": {
  1270         "extract": {
  1271             "default": GenerateElement("complexContent", ["id", "mixed"], 
  1271             "default": GenerateElement("complexContent", ["id", "mixed"],
  1272                 re.compile("((?:annotation )?(?:restriction |extension ))"))
  1272                 re.compile("((?:annotation )?(?:restriction |extension ))"))
  1273         },
  1273         },
  1274         "reduce": ReduceComplexContent
  1274         "reduce": ReduceComplexContent
  1275     },
  1275     },
  1276 
  1276 
  1283           mixed = boolean : false
  1283           mixed = boolean : false
  1284           name = NCName
  1284           name = NCName
  1285           {any attributes with non-schema namespace . . .}>
  1285           {any attributes with non-schema namespace . . .}>
  1286           Content: (annotation?, (simpleContent | complexContent | ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))))
  1286           Content: (annotation?, (simpleContent | complexContent | ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))))
  1287         </complexType>""",
  1287         </complexType>""",
  1288         "type": SYNTAXELEMENT, 
  1288         "type": SYNTAXELEMENT,
  1289         "extract": {
  1289         "extract": {
  1290             "default": GenerateElement("complexType", 
  1290             "default": GenerateElement("complexType",
  1291                 ["abstract", "block", "final", "id", "mixed", "name"], 
  1291                 ["abstract", "block", "final", "id", "mixed", "name"],
  1292                 re.compile("((?:annotation )?(?:simpleContent |complexContent |(?:(?:group |all |choice |sequence )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))))"))
  1292                 re.compile("((?:annotation )?(?:simpleContent |complexContent |(?:(?:group |all |choice |sequence )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))))"))
  1293         },
  1293         },
  1294         "reduce": ReduceComplexType
  1294         "reduce": ReduceComplexType
  1295     },
  1295     },
  1296 
  1296 
  1299           source = anyURI
  1299           source = anyURI
  1300           xml:lang = language
  1300           xml:lang = language
  1301           {any attributes with non-schema namespace . . .}>
  1301           {any attributes with non-schema namespace . . .}>
  1302           Content: ({any})*
  1302           Content: ({any})*
  1303         </documentation>""",
  1303         </documentation>""",
  1304         "type": SYNTAXELEMENT, 
  1304         "type": SYNTAXELEMENT,
  1305         "extract": {
  1305         "extract": {
  1306             "default": GenerateElement("documentation", 
  1306             "default": GenerateElement("documentation",
  1307                 ["source", "lang"], re.compile("(.*)"), True)
  1307                 ["source", "lang"], re.compile("(.*)"), True)
  1308         },
  1308         },
  1309         "reduce": ReduceDocumentation
  1309         "reduce": ReduceDocumentation
  1310     },
  1310     },
  1311 
  1311 
  1326           substitutionGroup = QName
  1326           substitutionGroup = QName
  1327           type = QName
  1327           type = QName
  1328           {any attributes with non-schema namespace . . .}>
  1328           {any attributes with non-schema namespace . . .}>
  1329           Content: (annotation?, ((simpleType | complexType)?, (unique | key | keyref)*))
  1329           Content: (annotation?, ((simpleType | complexType)?, (unique | key | keyref)*))
  1330         </element>""",
  1330         </element>""",
  1331         "type": SYNTAXELEMENT, 
  1331         "type": SYNTAXELEMENT,
  1332         "extract": {
  1332         "extract": {
  1333             "default": GenerateElement("element", 
  1333             "default": GenerateElement("element",
  1334                 ["abstract", "block", "default", "final", "fixed", "form", "id", "maxOccurs", "minOccurs", "name", "nillable", "ref", "substitutionGroup", "type"], 
  1334                 ["abstract", "block", "default", "final", "fixed", "form", "id", "maxOccurs", "minOccurs", "name", "nillable", "ref", "substitutionGroup", "type"],
  1335                 re.compile("((?:annotation )?(?:simpleType |complexType )?(?:unique |key |keyref )*)")),
  1335                 re.compile("((?:annotation )?(?:simpleType |complexType )?(?:unique |key |keyref )*)")),
  1336             "schema": GenerateElement("element", 
  1336             "schema": GenerateElement("element",
  1337                 ["abstract", "block", "default", "final", "fixed", "form", "id", "name", "nillable", "substitutionGroup", "type"], 
  1337                 ["abstract", "block", "default", "final", "fixed", "form", "id", "name", "nillable", "substitutionGroup", "type"],
  1338                 re.compile("((?:annotation )?(?:simpleType |complexType )?(?:unique |key |keyref )*)"))
  1338                 re.compile("((?:annotation )?(?:simpleType |complexType )?(?:unique |key |keyref )*)"))
  1339         },
  1339         },
  1340         "reduce": ReduceElement
  1340         "reduce": ReduceElement
  1341     },
  1341     },
  1342 
  1342 
  1345           id = ID
  1345           id = ID
  1346           value = anySimpleType
  1346           value = anySimpleType
  1347           {any attributes with non-schema namespace . . .}>
  1347           {any attributes with non-schema namespace . . .}>
  1348           Content: (annotation?)
  1348           Content: (annotation?)
  1349         </enumeration>""",
  1349         </enumeration>""",
  1350         "type": SYNTAXELEMENT, 
  1350         "type": SYNTAXELEMENT,
  1351         "extract": {
  1351         "extract": {
  1352             "default": GenerateElement("enumeration", ["id", "value"], ONLY_ANNOTATION)
  1352             "default": GenerateElement("enumeration", ["id", "value"], ONLY_ANNOTATION)
  1353         },
  1353         },
  1354         "reduce": GenerateFacetReducing("enumeration", False)
  1354         "reduce": GenerateFacetReducing("enumeration", False)
  1355     },
  1355     },
  1359           base = QName
  1359           base = QName
  1360           id = ID
  1360           id = ID
  1361           {any attributes with non-schema namespace . . .}>
  1361           {any attributes with non-schema namespace . . .}>
  1362           Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
  1362           Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
  1363         </extension>""",
  1363         </extension>""",
  1364         "type": SYNTAXELEMENT, 
  1364         "type": SYNTAXELEMENT,
  1365         "extract": {
  1365         "extract": {
  1366             "default": GenerateElement("extension", ["base", "id"], 
  1366             "default": GenerateElement("extension", ["base", "id"],
  1367                 re.compile("((?:annotation )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))")),
  1367                 re.compile("((?:annotation )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))")),
  1368             "complexContent": GenerateElement("extension", ["base", "id"], 
  1368             "complexContent": GenerateElement("extension", ["base", "id"],
  1369                 re.compile("((?:annotation )?(?:group |all |choice |sequence )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))"))
  1369                 re.compile("((?:annotation )?(?:group |all |choice |sequence )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))"))
  1370         },
  1370         },
  1371         "reduce": ReduceExtension
  1371         "reduce": ReduceExtension
  1372     },
  1372     },
  1373 
  1373 
  1376           id = ID
  1376           id = ID
  1377           xpath = a subset of XPath expression, see below
  1377           xpath = a subset of XPath expression, see below
  1378           {any attributes with non-schema namespace . . .}>
  1378           {any attributes with non-schema namespace . . .}>
  1379           Content: (annotation?)
  1379           Content: (annotation?)
  1380         </field>""",
  1380         </field>""",
  1381         "type": SYNTAXELEMENT, 
  1381         "type": SYNTAXELEMENT,
  1382         "extract": {
  1382         "extract": {
  1383             "default": GenerateElement("field", ["id", "xpath"], ONLY_ANNOTATION)
  1383             "default": GenerateElement("field", ["id", "xpath"], ONLY_ANNOTATION)
  1384         },
  1384         },
  1385         "reduce": ReduceField
  1385         "reduce": ReduceField
  1386     },
  1386     },
  1391           id = ID
  1391           id = ID
  1392           value = nonNegativeInteger
  1392           value = nonNegativeInteger
  1393           {any attributes with non-schema namespace . . .}>
  1393           {any attributes with non-schema namespace . . .}>
  1394           Content: (annotation?)
  1394           Content: (annotation?)
  1395         </fractionDigits>""",
  1395         </fractionDigits>""",
  1396         "type": SYNTAXELEMENT, 
  1396         "type": SYNTAXELEMENT,
  1397         "extract": {
  1397         "extract": {
  1398             "default": GenerateElement("fractionDigits", 
  1398             "default": GenerateElement("fractionDigits",
  1399                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1399                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1400         },
  1400         },
  1401         "reduce": GenerateFacetReducing("fractionDigits", True)
  1401         "reduce": GenerateFacetReducing("fractionDigits", True)
  1402     },
  1402     },
  1403 
  1403 
  1409           name = NCName
  1409           name = NCName
  1410           ref = QName
  1410           ref = QName
  1411           {any attributes with non-schema namespace . . .}>
  1411           {any attributes with non-schema namespace . . .}>
  1412           Content: (annotation?, (all | choice | sequence)?)
  1412           Content: (annotation?, (all | choice | sequence)?)
  1413         </group>""",
  1413         </group>""",
  1414         "type": SYNTAXELEMENT, 
  1414         "type": SYNTAXELEMENT,
  1415         "extract": {
  1415         "extract": {
  1416             "default": GenerateElement("group",
  1416             "default": GenerateElement("group",
  1417                 ["id", "maxOccurs", "minOccurs", "ref"], 
  1417                 ["id", "maxOccurs", "minOccurs", "ref"],
  1418                 re.compile("((?:annotation )?(?:all |choice |sequence )?)")),
  1418                 re.compile("((?:annotation )?(?:all |choice |sequence )?)")),
  1419             "schema": GenerateElement("group",
  1419             "schema": GenerateElement("group",
  1420                 ["id", "name"], 
  1420                 ["id", "name"],
  1421                 re.compile("((?:annotation )?(?:all |choice |sequence )?)"))
  1421                 re.compile("((?:annotation )?(?:all |choice |sequence )?)"))
  1422         },
  1422         },
  1423         "reduce": ReduceGroup
  1423         "reduce": ReduceGroup
  1424     },
  1424     },
  1425 
  1425 
  1429           namespace = anyURI
  1429           namespace = anyURI
  1430           schemaLocation = anyURI
  1430           schemaLocation = anyURI
  1431           {any attributes with non-schema namespace . . .}>
  1431           {any attributes with non-schema namespace . . .}>
  1432           Content: (annotation?)
  1432           Content: (annotation?)
  1433         </import>""",
  1433         </import>""",
  1434         "type": SYNTAXELEMENT, 
  1434         "type": SYNTAXELEMENT,
  1435         "extract": {
  1435         "extract": {
  1436             "default": GenerateElement("import",
  1436             "default": GenerateElement("import",
  1437                 ["id", "namespace", "schemaLocation"], ONLY_ANNOTATION)
  1437                 ["id", "namespace", "schemaLocation"], ONLY_ANNOTATION)
  1438         },
  1438         },
  1439         "reduce": ReduceImport
  1439         "reduce": ReduceImport
  1444           id = ID
  1444           id = ID
  1445           schemaLocation = anyURI
  1445           schemaLocation = anyURI
  1446           {any attributes with non-schema namespace . . .}>
  1446           {any attributes with non-schema namespace . . .}>
  1447           Content: (annotation?)
  1447           Content: (annotation?)
  1448         </include>""",
  1448         </include>""",
  1449         "type": SYNTAXELEMENT, 
  1449         "type": SYNTAXELEMENT,
  1450         "extract": {
  1450         "extract": {
  1451             "default": GenerateElement("include",
  1451             "default": GenerateElement("include",
  1452                 ["id", "schemaLocation"], ONLY_ANNOTATION)
  1452                 ["id", "schemaLocation"], ONLY_ANNOTATION)
  1453         },
  1453         },
  1454         "reduce": ReduceInclude
  1454         "reduce": ReduceInclude
  1459           id = ID
  1459           id = ID
  1460           name = NCName
  1460           name = NCName
  1461           {any attributes with non-schema namespace . . .}>
  1461           {any attributes with non-schema namespace . . .}>
  1462           Content: (annotation?, (selector, field+))
  1462           Content: (annotation?, (selector, field+))
  1463         </key>""",
  1463         </key>""",
  1464         "type": SYNTAXELEMENT, 
  1464         "type": SYNTAXELEMENT,
  1465         "extract": {
  1465         "extract": {
  1466             "default": GenerateElement("key", ["id", "name"], 
  1466             "default": GenerateElement("key", ["id", "name"],
  1467                 re.compile("((?:annotation )?(?:selector (?:field )+))"))
  1467                 re.compile("((?:annotation )?(?:selector (?:field )+))"))
  1468         },
  1468         },
  1469         "reduce": ReduceKey
  1469         "reduce": ReduceKey
  1470     },
  1470     },
  1471 
  1471 
  1475           name = NCName
  1475           name = NCName
  1476           refer = QName
  1476           refer = QName
  1477           {any attributes with non-schema namespace . . .}>
  1477           {any attributes with non-schema namespace . . .}>
  1478           Content: (annotation?, (selector, field+))
  1478           Content: (annotation?, (selector, field+))
  1479         </keyref>""",
  1479         </keyref>""",
  1480         "type": SYNTAXELEMENT, 
  1480         "type": SYNTAXELEMENT,
  1481         "extract": {
  1481         "extract": {
  1482             "default": GenerateElement("keyref", ["id", "name", "refer"], 
  1482             "default": GenerateElement("keyref", ["id", "name", "refer"],
  1483                 re.compile("((?:annotation )?(?:selector (?:field )+))"))
  1483                 re.compile("((?:annotation )?(?:selector (?:field )+))"))
  1484         },
  1484         },
  1485         "reduce": ReduceKeyRef
  1485         "reduce": ReduceKeyRef
  1486     },
  1486     },
  1487 
  1487 
  1491           id = ID
  1491           id = ID
  1492           value = nonNegativeInteger
  1492           value = nonNegativeInteger
  1493           {any attributes with non-schema namespace . . .}>
  1493           {any attributes with non-schema namespace . . .}>
  1494           Content: (annotation?)
  1494           Content: (annotation?)
  1495         </length>""",
  1495         </length>""",
  1496         "type": SYNTAXELEMENT, 
  1496         "type": SYNTAXELEMENT,
  1497         "extract": {
  1497         "extract": {
  1498             "default": GenerateElement("length", 
  1498             "default": GenerateElement("length",
  1499                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1499                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1500         },
  1500         },
  1501         "reduce": GenerateFacetReducing("length", True)
  1501         "reduce": GenerateFacetReducing("length", True)
  1502     },
  1502     },
  1503 
  1503 
  1506           id = ID
  1506           id = ID
  1507           itemType = QName
  1507           itemType = QName
  1508           {any attributes with non-schema namespace . . .}>
  1508           {any attributes with non-schema namespace . . .}>
  1509           Content: (annotation?, simpleType?)
  1509           Content: (annotation?, simpleType?)
  1510         </list>""",
  1510         </list>""",
  1511         "type": SYNTAXELEMENT, 
  1511         "type": SYNTAXELEMENT,
  1512         "extract": {
  1512         "extract": {
  1513             "default": GenerateElement("list", ["id", "itemType"], 
  1513             "default": GenerateElement("list", ["id", "itemType"],
  1514                 re.compile("((?:annotation )?(?:simpleType )?)$"))
  1514                 re.compile("((?:annotation )?(?:simpleType )?)$"))
  1515         },
  1515         },
  1516         "reduce": ReduceList
  1516         "reduce": ReduceList
  1517     },
  1517     },
  1518 
  1518 
  1522           id = ID
  1522           id = ID
  1523           value = anySimpleType
  1523           value = anySimpleType
  1524           {any attributes with non-schema namespace . . .}>
  1524           {any attributes with non-schema namespace . . .}>
  1525           Content: (annotation?)
  1525           Content: (annotation?)
  1526         </maxInclusive>""",
  1526         </maxInclusive>""",
  1527         "type": SYNTAXELEMENT, 
  1527         "type": SYNTAXELEMENT,
  1528         "extract": {
  1528         "extract": {
  1529             "default": GenerateElement("maxExclusive",
  1529             "default": GenerateElement("maxExclusive",
  1530                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1530                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1531         },
  1531         },
  1532         "reduce": GenerateFacetReducing("maxExclusive", True)
  1532         "reduce": GenerateFacetReducing("maxExclusive", True)
  1538           id = ID
  1538           id = ID
  1539           value = anySimpleType
  1539           value = anySimpleType
  1540           {any attributes with non-schema namespace . . .}>
  1540           {any attributes with non-schema namespace . . .}>
  1541           Content: (annotation?)
  1541           Content: (annotation?)
  1542         </maxExclusive>""",
  1542         </maxExclusive>""",
  1543         "type": SYNTAXELEMENT, 
  1543         "type": SYNTAXELEMENT,
  1544         "extract": {
  1544         "extract": {
  1545             "default": GenerateElement("maxInclusive", 
  1545             "default": GenerateElement("maxInclusive",
  1546                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1546                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1547         },
  1547         },
  1548         "reduce": GenerateFacetReducing("maxInclusive", True)
  1548         "reduce": GenerateFacetReducing("maxInclusive", True)
  1549     },
  1549     },
  1550 
  1550 
  1554           id = ID
  1554           id = ID
  1555           value = nonNegativeInteger
  1555           value = nonNegativeInteger
  1556           {any attributes with non-schema namespace . . .}>
  1556           {any attributes with non-schema namespace . . .}>
  1557           Content: (annotation?)
  1557           Content: (annotation?)
  1558         </maxLength>""",
  1558         </maxLength>""",
  1559         "type": SYNTAXELEMENT, 
  1559         "type": SYNTAXELEMENT,
  1560         "extract": {
  1560         "extract": {
  1561             "default": GenerateElement("maxLength", 
  1561             "default": GenerateElement("maxLength",
  1562                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1562                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1563         },
  1563         },
  1564         "reduce": GenerateFacetReducing("maxLength", True)
  1564         "reduce": GenerateFacetReducing("maxLength", True)
  1565     },
  1565     },
  1566 
  1566 
  1570           id = ID
  1570           id = ID
  1571           value = anySimpleType
  1571           value = anySimpleType
  1572           {any attributes with non-schema namespace . . .}>
  1572           {any attributes with non-schema namespace . . .}>
  1573           Content: (annotation?)
  1573           Content: (annotation?)
  1574         </minExclusive>""",
  1574         </minExclusive>""",
  1575         "type": SYNTAXELEMENT, 
  1575         "type": SYNTAXELEMENT,
  1576         "extract": {
  1576         "extract": {
  1577             "default": GenerateElement("minExclusive", 
  1577             "default": GenerateElement("minExclusive",
  1578                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1578                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1579         },
  1579         },
  1580         "reduce": GenerateFacetReducing("minExclusive", True)
  1580         "reduce": GenerateFacetReducing("minExclusive", True)
  1581     },
  1581     },
  1582 
  1582 
  1586           id = ID
  1586           id = ID
  1587           value = anySimpleType
  1587           value = anySimpleType
  1588           {any attributes with non-schema namespace . . .}>
  1588           {any attributes with non-schema namespace . . .}>
  1589           Content: (annotation?)
  1589           Content: (annotation?)
  1590         </minInclusive>""",
  1590         </minInclusive>""",
  1591         "type": SYNTAXELEMENT, 
  1591         "type": SYNTAXELEMENT,
  1592         "extract": {
  1592         "extract": {
  1593             "default": GenerateElement("minInclusive", 
  1593             "default": GenerateElement("minInclusive",
  1594                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1594                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1595         },
  1595         },
  1596         "reduce": GenerateFacetReducing("minInclusive", True)
  1596         "reduce": GenerateFacetReducing("minInclusive", True)
  1597     },
  1597     },
  1598 
  1598 
  1602           id = ID
  1602           id = ID
  1603           value = nonNegativeInteger
  1603           value = nonNegativeInteger
  1604           {any attributes with non-schema namespace . . .}>
  1604           {any attributes with non-schema namespace . . .}>
  1605           Content: (annotation?)
  1605           Content: (annotation?)
  1606         </minLength>""",
  1606         </minLength>""",
  1607         "type": SYNTAXELEMENT, 
  1607         "type": SYNTAXELEMENT,
  1608         "extract": {
  1608         "extract": {
  1609             "default": GenerateElement("minLength",
  1609             "default": GenerateElement("minLength",
  1610                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1610                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1611         },
  1611         },
  1612         "reduce": GenerateFacetReducing("minLength", True)
  1612         "reduce": GenerateFacetReducing("minLength", True)
  1617           id = ID
  1617           id = ID
  1618           value = string
  1618           value = string
  1619           {any attributes with non-schema namespace . . .}>
  1619           {any attributes with non-schema namespace . . .}>
  1620           Content: (annotation?)
  1620           Content: (annotation?)
  1621         </pattern>""",
  1621         </pattern>""",
  1622         "type": SYNTAXELEMENT, 
  1622         "type": SYNTAXELEMENT,
  1623         "extract": {
  1623         "extract": {
  1624             "default": GenerateElement("pattern", ["id", "value"], ONLY_ANNOTATION)
  1624             "default": GenerateElement("pattern", ["id", "value"], ONLY_ANNOTATION)
  1625         },
  1625         },
  1626         "reduce": GenerateFacetReducing("pattern", False)
  1626         "reduce": GenerateFacetReducing("pattern", False)
  1627     },
  1627     },
  1631           id = ID
  1631           id = ID
  1632           schemaLocation = anyURI
  1632           schemaLocation = anyURI
  1633           {any attributes with non-schema namespace . . .}>
  1633           {any attributes with non-schema namespace . . .}>
  1634           Content: (annotation | (simpleType | complexType | group | attributeGroup))*
  1634           Content: (annotation | (simpleType | complexType | group | attributeGroup))*
  1635         </redefine>""",
  1635         </redefine>""",
  1636         "type": SYNTAXELEMENT, 
  1636         "type": SYNTAXELEMENT,
  1637         "extract": {
  1637         "extract": {
  1638             "default": GenerateElement("refine", ["id", "schemaLocation"], 
  1638             "default": GenerateElement("refine", ["id", "schemaLocation"],
  1639                 re.compile("((?:annotation |(?:simpleType |complexType |group |attributeGroup ))*)"))
  1639                 re.compile("((?:annotation |(?:simpleType |complexType |group |attributeGroup ))*)"))
  1640         },
  1640         },
  1641         "reduce": ReduceRedefine
  1641         "reduce": ReduceRedefine
  1642     },
  1642     },
  1643 
  1643 
  1646           base = QName
  1646           base = QName
  1647           id = ID
  1647           id = ID
  1648           {any attributes with non-schema namespace . . .}>
  1648           {any attributes with non-schema namespace . . .}>
  1649           Content: (annotation?, (group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))
  1649           Content: (annotation?, (group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))
  1650         </restriction>""",
  1650         </restriction>""",
  1651         "type": SYNTAXELEMENT, 
  1651         "type": SYNTAXELEMENT,
  1652         "extract": {
  1652         "extract": {
  1653             "default": GenerateElement("restriction", ["base", "id"], 
  1653             "default": GenerateElement("restriction", ["base", "id"],
  1654                 re.compile("((?:annotation )?(?:(?:simpleType )?(?:(?:minExclusive |minInclusive |maxExclusive |maxInclusive |totalDigits |fractionDigits |length |minLength |maxLength |enumeration |whiteSpace |pattern )*)))")),
  1654                 re.compile("((?:annotation )?(?:(?:simpleType )?(?:(?:minExclusive |minInclusive |maxExclusive |maxInclusive |totalDigits |fractionDigits |length |minLength |maxLength |enumeration |whiteSpace |pattern )*)))")),
  1655             "simpleContent": GenerateElement("restriction", ["base", "id"], 
  1655             "simpleContent": GenerateElement("restriction", ["base", "id"],
  1656                 re.compile("((?:annotation )?(?:(?:simpleType )?(?:(?:minExclusive |minInclusive |maxExclusive |maxInclusive |totalDigits |fractionDigits |length |minLength |maxLength |enumeration |whiteSpace |pattern )*)?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?)))")),
  1656                 re.compile("((?:annotation )?(?:(?:simpleType )?(?:(?:minExclusive |minInclusive |maxExclusive |maxInclusive |totalDigits |fractionDigits |length |minLength |maxLength |enumeration |whiteSpace |pattern )*)?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?)))")),
  1657             "complexContent": GenerateElement("restriction", ["base", "id"], 
  1657             "complexContent": GenerateElement("restriction", ["base", "id"],
  1658                 re.compile("((?:annotation )?(?:(?:simpleType )?(?:group |all |choice |sequence )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?)))")),
  1658                 re.compile("((?:annotation )?(?:(?:simpleType )?(?:group |all |choice |sequence )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?)))")),
  1659         },
  1659         },
  1660         "reduce": ReduceRestriction
  1660         "reduce": ReduceRestriction
  1661     },
  1661     },
  1662 
  1662 
  1671           version = token
  1671           version = token
  1672           xml:lang = language
  1672           xml:lang = language
  1673           {any attributes with non-schema namespace . . .}>
  1673           {any attributes with non-schema namespace . . .}>
  1674           Content: ((include | import | redefine | annotation)*, (((simpleType | complexType | group | attributeGroup) | element | attribute | notation), annotation*)*)
  1674           Content: ((include | import | redefine | annotation)*, (((simpleType | complexType | group | attributeGroup) | element | attribute | notation), annotation*)*)
  1675         </schema>""",
  1675         </schema>""",
  1676         "type": SYNTAXELEMENT, 
  1676         "type": SYNTAXELEMENT,
  1677         "extract": {
  1677         "extract": {
  1678             "default": GenerateElement("schema",
  1678             "default": GenerateElement("schema",
  1679                 ["attributeFormDefault", "blockDefault", "elementFormDefault", "finalDefault", "id", "targetNamespace", "version", "lang"], 
  1679                 ["attributeFormDefault", "blockDefault", "elementFormDefault", "finalDefault", "id", "targetNamespace", "version", "lang"],
  1680                 re.compile("((?:include |import |redefine |annotation )*(?:(?:(?:simpleType |complexType |group |attributeGroup )|element |attribute |annotation )(?:annotation )*)*)"))
  1680                 re.compile("((?:include |import |redefine |annotation )*(?:(?:(?:simpleType |complexType |group |attributeGroup )|element |attribute |annotation )(?:annotation )*)*)"))
  1681         }
  1681         }
  1682     },
  1682     },
  1683 
  1683 
  1684     "selector": {"struct": """
  1684     "selector": {"struct": """
  1686           id = ID
  1686           id = ID
  1687           xpath = a subset of XPath expression, see below
  1687           xpath = a subset of XPath expression, see below
  1688           {any attributes with non-schema namespace . . .}>
  1688           {any attributes with non-schema namespace . . .}>
  1689           Content: (annotation?)
  1689           Content: (annotation?)
  1690         </selector>""",
  1690         </selector>""",
  1691         "type": SYNTAXELEMENT, 
  1691         "type": SYNTAXELEMENT,
  1692         "extract": {
  1692         "extract": {
  1693             "default": GenerateElement("selector", ["id", "xpath"], ONLY_ANNOTATION)
  1693             "default": GenerateElement("selector", ["id", "xpath"], ONLY_ANNOTATION)
  1694         },
  1694         },
  1695         "reduce": ReduceSelector
  1695         "reduce": ReduceSelector
  1696     },
  1696     },
  1701           maxOccurs = (nonNegativeInteger | unbounded)  : 1
  1701           maxOccurs = (nonNegativeInteger | unbounded)  : 1
  1702           minOccurs = nonNegativeInteger : 1
  1702           minOccurs = nonNegativeInteger : 1
  1703           {any attributes with non-schema namespace . . .}>
  1703           {any attributes with non-schema namespace . . .}>
  1704           Content: (annotation?, (element | group | choice | sequence | any)*)
  1704           Content: (annotation?, (element | group | choice | sequence | any)*)
  1705         </sequence>""",
  1705         </sequence>""",
  1706         "type": SYNTAXELEMENT, 
  1706         "type": SYNTAXELEMENT,
  1707         "extract": {
  1707         "extract": {
  1708             "default": GenerateElement("sequence", ["id", "maxOccurs", "minOccurs"], 
  1708             "default": GenerateElement("sequence", ["id", "maxOccurs", "minOccurs"],
  1709                 re.compile("((?:annotation )?(?:element |group |choice |sequence |any )*)"))
  1709                 re.compile("((?:annotation )?(?:element |group |choice |sequence |any )*)"))
  1710         },
  1710         },
  1711         "reduce": ReduceSequence
  1711         "reduce": ReduceSequence
  1712     },
  1712     },
  1713 
  1713 
  1715         <simpleContent
  1715         <simpleContent
  1716           id = ID
  1716           id = ID
  1717           {any attributes with non-schema namespace . . .}>
  1717           {any attributes with non-schema namespace . . .}>
  1718           Content: (annotation?, (restriction | extension))
  1718           Content: (annotation?, (restriction | extension))
  1719         </simpleContent>""",
  1719         </simpleContent>""",
  1720         "type": SYNTAXELEMENT, 
  1720         "type": SYNTAXELEMENT,
  1721         "extract": {
  1721         "extract": {
  1722             "default": GenerateElement("simpleContent", ["id"], 
  1722             "default": GenerateElement("simpleContent", ["id"],
  1723                 re.compile("((?:annotation )?(?:restriction |extension ))"))
  1723                 re.compile("((?:annotation )?(?:restriction |extension ))"))
  1724         },
  1724         },
  1725         "reduce": ReduceSimpleContent
  1725         "reduce": ReduceSimpleContent
  1726     },
  1726     },
  1727 
  1727 
  1731           id = ID
  1731           id = ID
  1732           name = NCName
  1732           name = NCName
  1733           {any attributes with non-schema namespace . . .}>
  1733           {any attributes with non-schema namespace . . .}>
  1734           Content: (annotation?, (restriction | list | union))
  1734           Content: (annotation?, (restriction | list | union))
  1735         </simpleType>""",
  1735         </simpleType>""",
  1736         "type": SYNTAXELEMENT, 
  1736         "type": SYNTAXELEMENT,
  1737         "extract": {
  1737         "extract": {
  1738             "default": GenerateElement("simpleType", ["final", "id", "name"], 
  1738             "default": GenerateElement("simpleType", ["final", "id", "name"],
  1739                 re.compile("((?:annotation )?(?:restriction |list |union ))"))
  1739                 re.compile("((?:annotation )?(?:restriction |list |union ))"))
  1740         },
  1740         },
  1741         "reduce": ReduceSimpleType
  1741         "reduce": ReduceSimpleType
  1742     },
  1742     },
  1743 
  1743 
  1747           id = ID
  1747           id = ID
  1748           value = positiveInteger
  1748           value = positiveInteger
  1749           {any attributes with non-schema namespace . . .}>
  1749           {any attributes with non-schema namespace . . .}>
  1750           Content: (annotation?)
  1750           Content: (annotation?)
  1751         </totalDigits>""",
  1751         </totalDigits>""",
  1752         "type": SYNTAXELEMENT, 
  1752         "type": SYNTAXELEMENT,
  1753         "extract": {
  1753         "extract": {
  1754             "default": GenerateElement("totalDigits", 
  1754             "default": GenerateElement("totalDigits",
  1755                 ["fixed", "id", "value"], ONLY_ANNOTATION),
  1755                 ["fixed", "id", "value"], ONLY_ANNOTATION),
  1756         },
  1756         },
  1757         "reduce": GenerateFacetReducing("totalDigits", True)
  1757         "reduce": GenerateFacetReducing("totalDigits", True)
  1758     },
  1758     },
  1759 
  1759 
  1762           id = ID
  1762           id = ID
  1763           memberTypes = List of QName
  1763           memberTypes = List of QName
  1764           {any attributes with non-schema namespace . . .}>
  1764           {any attributes with non-schema namespace . . .}>
  1765           Content: (annotation?, simpleType*)
  1765           Content: (annotation?, simpleType*)
  1766         </union>""",
  1766         </union>""",
  1767         "type": SYNTAXELEMENT, 
  1767         "type": SYNTAXELEMENT,
  1768         "extract": {
  1768         "extract": {
  1769             "default": GenerateElement("union", ["id", "memberTypes"], 
  1769             "default": GenerateElement("union", ["id", "memberTypes"],
  1770                 re.compile("((?:annotation )?(?:simpleType )*)"))
  1770                 re.compile("((?:annotation )?(?:simpleType )*)"))
  1771         },
  1771         },
  1772         "reduce": ReduceUnion
  1772         "reduce": ReduceUnion
  1773     },
  1773     },
  1774 
  1774 
  1777           id = ID
  1777           id = ID
  1778           name = NCName
  1778           name = NCName
  1779           {any attributes with non-schema namespace . . .}>
  1779           {any attributes with non-schema namespace . . .}>
  1780           Content: (annotation?, (selector, field+))
  1780           Content: (annotation?, (selector, field+))
  1781         </unique>""",
  1781         </unique>""",
  1782         "type": SYNTAXELEMENT, 
  1782         "type": SYNTAXELEMENT,
  1783         "extract": {
  1783         "extract": {
  1784             "default": GenerateElement("unique", ["id", "name"], 
  1784             "default": GenerateElement("unique", ["id", "name"],
  1785                 re.compile("((?:annotation )?(?:selector |(?:field )+))"))
  1785                 re.compile("((?:annotation )?(?:selector |(?:field )+))"))
  1786         },
  1786         },
  1787         "reduce": ReduceUnique
  1787         "reduce": ReduceUnique
  1788     },
  1788     },
  1789     
  1789 
  1790     "whiteSpace": {"struct" : """
  1790     "whiteSpace": {"struct" : """
  1791         <whiteSpace
  1791         <whiteSpace
  1792           fixed = boolean : false
  1792           fixed = boolean : false
  1793           id = ID
  1793           id = ID
  1794           value = (collapse | preserve | replace)
  1794           value = (collapse | preserve | replace)
  1795           {any attributes with non-schema namespace . . .}>
  1795           {any attributes with non-schema namespace . . .}>
  1796           Content: (annotation?)
  1796           Content: (annotation?)
  1797         </whiteSpace>""",
  1797         </whiteSpace>""",
  1798         "type": SYNTAXELEMENT, 
  1798         "type": SYNTAXELEMENT,
  1799         "extract": {
  1799         "extract": {
  1800             "default": GenerateElement("whiteSpace", 
  1800             "default": GenerateElement("whiteSpace",
  1801                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1801                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1802         },
  1802         },
  1803         "reduce": GenerateFacetReducing("whiteSpace", True)
  1803         "reduce": GenerateFacetReducing("whiteSpace", True)
  1804     },
  1804     },
  1805 
  1805 
  1806 #-------------------------------------------------------------------------------
  1806 #-------------------------------------------------------------------------------
  1807 #                       Syntax attributes definition
  1807 #                       Syntax attributes definition
  1808 #-------------------------------------------------------------------------------
  1808 #-------------------------------------------------------------------------------
  1809 
  1809 
  1810     "abstract": {
  1810     "abstract": {
  1811         "type": SYNTAXATTRIBUTE, 
  1811         "type": SYNTAXATTRIBUTE,
  1812         "extract": {
  1812         "extract": {
  1813             "default": GetBoolean
  1813             "default": GetBoolean
  1814         },
  1814         },
  1815         "default": {
  1815         "default": {
  1816             "default": False
  1816             "default": False
  1817         }
  1817         }
  1818     },
  1818     },
  1819 
  1819 
  1820     "attributeFormDefault": {
  1820     "attributeFormDefault": {
  1821         "type": SYNTAXATTRIBUTE, 
  1821         "type": SYNTAXATTRIBUTE,
  1822         "extract": {
  1822         "extract": {
  1823             "default": GenerateEnumeratedExtraction("member attributeFormDefault", ["qualified", "unqualified"])
  1823             "default": GenerateEnumeratedExtraction("member attributeFormDefault", ["qualified", "unqualified"])
  1824         },
  1824         },
  1825         "default": {
  1825         "default": {
  1826             "default": "unqualified"
  1826             "default": "unqualified"
  1827         }
  1827         }
  1828     },
  1828     },
  1829     
  1829 
  1830     "base": {
  1830     "base": {
  1831         "type": SYNTAXATTRIBUTE, 
  1831         "type": SYNTAXATTRIBUTE,
  1832         "extract": {
  1832         "extract": {
  1833             "default": GenerateModelNameExtraction("member base", QName_model)
  1833             "default": GenerateModelNameExtraction("member base", QName_model)
  1834         }
  1834         }
  1835     },
  1835     },
  1836     
  1836 
  1837     "block": {
  1837     "block": {
  1838         "type": SYNTAXATTRIBUTE, 
  1838         "type": SYNTAXATTRIBUTE,
  1839         "extract": {
  1839         "extract": {
  1840             "default": GenerateGetList("block", ["restriction", "extension", "substitution"])
  1840             "default": GenerateGetList("block", ["restriction", "extension", "substitution"])
  1841         }
  1841         }
  1842     },
  1842     },
  1843     
  1843 
  1844     "blockDefault": {
  1844     "blockDefault": {
  1845         "type": SYNTAXATTRIBUTE, 
  1845         "type": SYNTAXATTRIBUTE,
  1846         "extract": {
  1846         "extract": {
  1847             "default": GenerateGetList("block", ["restriction", "extension", "substitution"])
  1847             "default": GenerateGetList("block", ["restriction", "extension", "substitution"])
  1848         },
  1848         },
  1849         "default": {
  1849         "default": {
  1850             "default": ""
  1850             "default": ""
  1851         }
  1851         }
  1852     },
  1852     },
  1853     
  1853 
  1854     "default": {
  1854     "default": {
  1855         "type": SYNTAXATTRIBUTE, 
  1855         "type": SYNTAXATTRIBUTE,
  1856         "extract": {
  1856         "extract": {
  1857             "default": GetAttributeValue
  1857             "default": GetAttributeValue
  1858         }
  1858         }
  1859     },
  1859     },
  1860 
  1860 
  1861     "elementFormDefault": {
  1861     "elementFormDefault": {
  1862         "type": SYNTAXATTRIBUTE, 
  1862         "type": SYNTAXATTRIBUTE,
  1863         "extract": {
  1863         "extract": {
  1864             "default": GenerateEnumeratedExtraction("member elementFormDefault", ["qualified", "unqualified"])
  1864             "default": GenerateEnumeratedExtraction("member elementFormDefault", ["qualified", "unqualified"])
  1865         },
  1865         },
  1866         "default": {
  1866         "default": {
  1867             "default": "unqualified"
  1867             "default": "unqualified"
  1868         }
  1868         }
  1869     },
  1869     },
  1870     
  1870 
  1871     "final": {
  1871     "final": {
  1872         "type": SYNTAXATTRIBUTE, 
  1872         "type": SYNTAXATTRIBUTE,
  1873         "extract": {
  1873         "extract": {
  1874             "default": GenerateGetList("final", ["restriction", "extension", "substitution"]),
  1874             "default": GenerateGetList("final", ["restriction", "extension", "substitution"]),
  1875             "simpleType": GenerateGetList("final", ["list", "union", "restriction"])
  1875             "simpleType": GenerateGetList("final", ["list", "union", "restriction"])
  1876         }
  1876         }
  1877     },
  1877     },
  1878 
  1878 
  1879     "finalDefault": {
  1879     "finalDefault": {
  1880         "type": SYNTAXATTRIBUTE, 
  1880         "type": SYNTAXATTRIBUTE,
  1881         "extract": {
  1881         "extract": {
  1882             "default": GenerateGetList("finalDefault", ["restriction", "extension", "list", "union"])
  1882             "default": GenerateGetList("finalDefault", ["restriction", "extension", "list", "union"])
  1883         },
  1883         },
  1884         "default": {
  1884         "default": {
  1885             "default": ""
  1885             "default": ""
  1886         }
  1886         }
  1887     },
  1887     },
  1888     
  1888 
  1889     "fixed": {
  1889     "fixed": {
  1890         "type": SYNTAXATTRIBUTE, 
  1890         "type": SYNTAXATTRIBUTE,
  1891         "extract": {
  1891         "extract": {
  1892             "default": GetBoolean,
  1892             "default": GetBoolean,
  1893             "attribute": GetAttributeValue,
  1893             "attribute": GetAttributeValue,
  1894             "element": GetAttributeValue
  1894             "element": GetAttributeValue
  1895         },
  1895         },
  1899             "element": None
  1899             "element": None
  1900         }
  1900         }
  1901     },
  1901     },
  1902 
  1902 
  1903     "form": {
  1903     "form": {
  1904         "type": SYNTAXATTRIBUTE, 
  1904         "type": SYNTAXATTRIBUTE,
  1905         "extract": {
  1905         "extract": {
  1906             "default": GenerateEnumeratedExtraction("member form", ["qualified", "unqualified"])
  1906             "default": GenerateEnumeratedExtraction("member form", ["qualified", "unqualified"])
  1907         }
  1907         }
  1908     },
  1908     },
  1909 
  1909 
  1910     "id": {
  1910     "id": {
  1911         "type": SYNTAXATTRIBUTE, 
  1911         "type": SYNTAXATTRIBUTE,
  1912         "extract": {
  1912         "extract": {
  1913             "default": GenerateModelNameExtraction("member id", NCName_model)
  1913             "default": GenerateModelNameExtraction("member id", NCName_model)
  1914         }
  1914         }
  1915     },
  1915     },
  1916     
  1916 
  1917     "itemType": {
  1917     "itemType": {
  1918         "type": SYNTAXATTRIBUTE, 
  1918         "type": SYNTAXATTRIBUTE,
  1919         "extract": {
  1919         "extract": {
  1920             "default": GenerateModelNameExtraction("member itemType", QName_model)
  1920             "default": GenerateModelNameExtraction("member itemType", QName_model)
  1921         }
  1921         }
  1922     },
  1922     },
  1923 
  1923 
  1924     "memberTypes": {
  1924     "memberTypes": {
  1925         "type": SYNTAXATTRIBUTE, 
  1925         "type": SYNTAXATTRIBUTE,
  1926         "extract": {
  1926         "extract": {
  1927             "default": GenerateModelNameListExtraction("member memberTypes", QNames_model)
  1927             "default": GenerateModelNameListExtraction("member memberTypes", QNames_model)
  1928         },
  1928         },
  1929     },
  1929     },
  1930     
  1930 
  1931     "maxOccurs": {
  1931     "maxOccurs": {
  1932         "type": SYNTAXATTRIBUTE, 
  1932         "type": SYNTAXATTRIBUTE,
  1933         "extract": {
  1933         "extract": {
  1934             "default": GenerateLimitExtraction(),
  1934             "default": GenerateLimitExtraction(),
  1935             "all": GenerateLimitExtraction(1, 1, False)
  1935             "all": GenerateLimitExtraction(1, 1, False)
  1936         },
  1936         },
  1937         "default": {
  1937         "default": {
  1938             "default": 1
  1938             "default": 1
  1939         }
  1939         }
  1940     },
  1940     },
  1941 
  1941 
  1942     "minOccurs": {
  1942     "minOccurs": {
  1943         "type": SYNTAXATTRIBUTE, 
  1943         "type": SYNTAXATTRIBUTE,
  1944         "extract": {
  1944         "extract": {
  1945             "default": GenerateLimitExtraction(unbounded = False),
  1945             "default": GenerateLimitExtraction(unbounded = False),
  1946             "all": GenerateLimitExtraction(0, 1, False)
  1946             "all": GenerateLimitExtraction(0, 1, False)
  1947         },
  1947         },
  1948         "default": {
  1948         "default": {
  1949             "default": 1
  1949             "default": 1
  1950         }
  1950         }
  1951     },
  1951     },
  1952 
  1952 
  1953     "mixed": {
  1953     "mixed": {
  1954         "type": SYNTAXATTRIBUTE, 
  1954         "type": SYNTAXATTRIBUTE,
  1955         "extract": {
  1955         "extract": {
  1956             "default": GetBoolean
  1956             "default": GetBoolean
  1957         },
  1957         },
  1958         "default": {
  1958         "default": {
  1959             "default": None,
  1959             "default": None,
  1960             "complexType": False
  1960             "complexType": False
  1961         }
  1961         }
  1962     },
  1962     },
  1963     
  1963 
  1964     "name": {
  1964     "name": {
  1965         "type": SYNTAXATTRIBUTE, 
  1965         "type": SYNTAXATTRIBUTE,
  1966         "extract": {
  1966         "extract": {
  1967             "default": GenerateModelNameExtraction("member name", NCName_model)
  1967             "default": GenerateModelNameExtraction("member name", NCName_model)
  1968         }
  1968         }
  1969     },
  1969     },
  1970     
  1970 
  1971     "namespace": {
  1971     "namespace": {
  1972         "type": SYNTAXATTRIBUTE, 
  1972         "type": SYNTAXATTRIBUTE,
  1973         "extract": {
  1973         "extract": {
  1974             "default": GenerateModelNameExtraction("member namespace", URI_model),
  1974             "default": GenerateModelNameExtraction("member namespace", URI_model),
  1975             "any": GetNamespaces
  1975             "any": GetNamespaces
  1976         },
  1976         },
  1977         "default": {
  1977         "default": {
  1979             "any": "##any"
  1979             "any": "##any"
  1980         }
  1980         }
  1981     },
  1981     },
  1982 
  1982 
  1983     "nillable": {
  1983     "nillable": {
  1984         "type": SYNTAXATTRIBUTE, 
  1984         "type": SYNTAXATTRIBUTE,
  1985         "extract": {
  1985         "extract": {
  1986             "default": GetBoolean
  1986             "default": GetBoolean
  1987         },
  1987         },
  1988     },
  1988     },
  1989     
  1989 
  1990     "processContents": {
  1990     "processContents": {
  1991         "type": SYNTAXATTRIBUTE, 
  1991         "type": SYNTAXATTRIBUTE,
  1992         "extract": {
  1992         "extract": {
  1993             "default": GenerateEnumeratedExtraction("member processContents", ["lax", "skip", "strict"])
  1993             "default": GenerateEnumeratedExtraction("member processContents", ["lax", "skip", "strict"])
  1994         },
  1994         },
  1995         "default": {
  1995         "default": {
  1996             "default": "strict"
  1996             "default": "strict"
  1997         }
  1997         }
  1998     },
  1998     },
  1999     
  1999 
  2000     "ref": {
  2000     "ref": {
  2001         "type": SYNTAXATTRIBUTE, 
  2001         "type": SYNTAXATTRIBUTE,
  2002         "extract": {
  2002         "extract": {
  2003             "default": GenerateModelNameExtraction("member ref", QName_model)
  2003             "default": GenerateModelNameExtraction("member ref", QName_model)
  2004         }
  2004         }
  2005     },
  2005     },
  2006 
  2006 
  2008         "type": SYNTAXATTRIBUTE,
  2008         "type": SYNTAXATTRIBUTE,
  2009         "extract": {
  2009         "extract": {
  2010             "default": GenerateModelNameExtraction("member refer", QName_model)
  2010             "default": GenerateModelNameExtraction("member refer", QName_model)
  2011         }
  2011         }
  2012     },
  2012     },
  2013     
  2013 
  2014     "schemaLocation": {
  2014     "schemaLocation": {
  2015         "type": SYNTAXATTRIBUTE, 
  2015         "type": SYNTAXATTRIBUTE,
  2016         "extract": {
  2016         "extract": {
  2017             "default": GenerateModelNameExtraction("member schemaLocation", URI_model)
  2017             "default": GenerateModelNameExtraction("member schemaLocation", URI_model)
  2018         }
  2018         }
  2019     },
  2019     },
  2020     
  2020 
  2021     "source": {
  2021     "source": {
  2022         "type": SYNTAXATTRIBUTE,
  2022         "type": SYNTAXATTRIBUTE,
  2023         "extract": {
  2023         "extract": {
  2024             "default": GenerateModelNameExtraction("member source", URI_model)
  2024             "default": GenerateModelNameExtraction("member source", URI_model)
  2025         }
  2025         }
  2026     },
  2026     },
  2027     
  2027 
  2028     "substitutionGroup": {
  2028     "substitutionGroup": {
  2029         "type": SYNTAXATTRIBUTE, 
  2029         "type": SYNTAXATTRIBUTE,
  2030         "extract": {
  2030         "extract": {
  2031             "default": GenerateModelNameExtraction("member substitutionGroup", QName_model)
  2031             "default": GenerateModelNameExtraction("member substitutionGroup", QName_model)
  2032         }
  2032         }
  2033     },
  2033     },
  2034 
  2034 
  2035     "targetNamespace": {
  2035     "targetNamespace": {
  2036         "type": SYNTAXATTRIBUTE, 
  2036         "type": SYNTAXATTRIBUTE,
  2037         "extract": {
  2037         "extract": {
  2038             "default": GenerateModelNameExtraction("member targetNamespace", URI_model)
  2038             "default": GenerateModelNameExtraction("member targetNamespace", URI_model)
  2039         }
  2039         }
  2040     },
  2040     },
  2041     
  2041 
  2042     "type": {
  2042     "type": {
  2043         "type": SYNTAXATTRIBUTE, 
  2043         "type": SYNTAXATTRIBUTE,
  2044         "extract": {
  2044         "extract": {
  2045             "default": GenerateModelNameExtraction("member type", QName_model)
  2045             "default": GenerateModelNameExtraction("member type", QName_model)
  2046         }
  2046         }
  2047     },
  2047     },
  2048 
  2048 
  2049     "use": {
  2049     "use": {
  2050         "type": SYNTAXATTRIBUTE, 
  2050         "type": SYNTAXATTRIBUTE,
  2051         "extract": {
  2051         "extract": {
  2052             "default": GenerateEnumeratedExtraction("member usage", ["required", "optional", "prohibited"])
  2052             "default": GenerateEnumeratedExtraction("member usage", ["required", "optional", "prohibited"])
  2053         },
  2053         },
  2054         "default": {
  2054         "default": {
  2055             "default": "optional"
  2055             "default": "optional"
  2056         }
  2056         }
  2057     },
  2057     },
  2058 
  2058 
  2059     "value": {
  2059     "value": {
  2060         "type": SYNTAXATTRIBUTE, 
  2060         "type": SYNTAXATTRIBUTE,
  2061         "extract": {
  2061         "extract": {
  2062             "default": GetAttributeValue,
  2062             "default": GetAttributeValue,
  2063             "fractionDigits": GenerateIntegerExtraction(minInclusive=0),
  2063             "fractionDigits": GenerateIntegerExtraction(minInclusive=0),
  2064             "length": GenerateIntegerExtraction(minInclusive=0),
  2064             "length": GenerateIntegerExtraction(minInclusive=0),
  2065             "maxLength": GenerateIntegerExtraction(minInclusive=0),
  2065             "maxLength": GenerateIntegerExtraction(minInclusive=0),
  2075             "default": GetToken
  2075             "default": GetToken
  2076         }
  2076         }
  2077     },
  2077     },
  2078 
  2078 
  2079     "xpath": {
  2079     "xpath": {
  2080         "type": SYNTAXATTRIBUTE, 
  2080         "type": SYNTAXATTRIBUTE,
  2081         "extract": {
  2081         "extract": {
  2082 #            "default": NotSupportedYet("xpath")
  2082 #            "default": NotSupportedYet("xpath")
  2083             "default": GetAttributeValue
  2083             "default": GetAttributeValue
  2084         }
  2084         }
  2085     },
  2085     },
  2086     
  2086 
  2087 #-------------------------------------------------------------------------------
  2087 #-------------------------------------------------------------------------------
  2088 #                           Simple types definition
  2088 #                           Simple types definition
  2089 #-------------------------------------------------------------------------------
  2089 #-------------------------------------------------------------------------------
  2090 
  2090 
  2091     "string": {
  2091     "string": {
  2108         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2108         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2109     },
  2109     },
  2110 
  2110 
  2111     "token": {
  2111     "token": {
  2112         "type": SIMPLETYPE,
  2112         "type": SIMPLETYPE,
  2113         "basename": "token",  
  2113         "basename": "token",
  2114         "extract": GetToken,
  2114         "extract": GetToken,
  2115         "facets": STRING_FACETS,
  2115         "facets": STRING_FACETS,
  2116         "generate": GenerateSimpleTypeXMLText(lambda x : x),
  2116         "generate": GenerateSimpleTypeXMLText(lambda x : x),
  2117         "initial": lambda: "",
  2117         "initial": lambda: "",
  2118         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2118         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2119     },
  2119     },
  2120     
  2120 
  2121     "base64Binary": {
  2121     "base64Binary": {
  2122         "type": SIMPLETYPE, 
  2122         "type": SIMPLETYPE,
  2123         "basename": "base64Binary", 
  2123         "basename": "base64Binary",
  2124         "extract": NotSupportedYet("base64Binary"),
  2124         "extract": NotSupportedYet("base64Binary"),
  2125         "facets": STRING_FACETS,
  2125         "facets": STRING_FACETS,
  2126         "generate": GenerateSimpleTypeXMLText(str),
  2126         "generate": GenerateSimpleTypeXMLText(str),
  2127         "initial": lambda: 0,
  2127         "initial": lambda: 0,
  2128         "check": lambda x: isinstance(x, (IntType, LongType))
  2128         "check": lambda x: isinstance(x, (IntType, LongType))
  2129     },
  2129     },
  2130     
  2130 
  2131     "hexBinary": {
  2131     "hexBinary": {
  2132         "type": SIMPLETYPE,
  2132         "type": SIMPLETYPE,
  2133         "basename": "hexBinary", 
  2133         "basename": "hexBinary",
  2134         "extract": GetHexInteger,
  2134         "extract": GetHexInteger,
  2135         "facets": STRING_FACETS,
  2135         "facets": STRING_FACETS,
  2136         "generate": GenerateSimpleTypeXMLText(lambda x: ("%."+str(int(round(len("%X"%x)/2.)*2))+"X")%x),
  2136         "generate": GenerateSimpleTypeXMLText(lambda x: ("%."+str(int(round(len("%X"%x)/2.)*2))+"X")%x),
  2137         "initial": lambda: 0,
  2137         "initial": lambda: 0,
  2138         "check": lambda x: isinstance(x, (IntType, LongType))
  2138         "check": lambda x: isinstance(x, (IntType, LongType))
  2139     },
  2139     },
  2140 
  2140 
  2141     "integer": {
  2141     "integer": {
  2142         "type": SIMPLETYPE,
  2142         "type": SIMPLETYPE,
  2143         "basename": "integer", 
  2143         "basename": "integer",
  2144         "extract": GenerateIntegerExtraction(),
  2144         "extract": GenerateIntegerExtraction(),
  2145         "facets": DECIMAL_FACETS,
  2145         "facets": DECIMAL_FACETS,
  2146         "generate": GenerateSimpleTypeXMLText(str),
  2146         "generate": GenerateSimpleTypeXMLText(str),
  2147         "initial": lambda: 0,
  2147         "initial": lambda: 0,
  2148         "check": lambda x: isinstance(x, IntType)
  2148         "check": lambda x: isinstance(x, IntType)
  2149     },
  2149     },
  2150     
  2150 
  2151     "positiveInteger": {
  2151     "positiveInteger": {
  2152         "type": SIMPLETYPE,
  2152         "type": SIMPLETYPE,
  2153         "basename": "positiveInteger", 
  2153         "basename": "positiveInteger",
  2154         "extract": GenerateIntegerExtraction(minExclusive=0),
  2154         "extract": GenerateIntegerExtraction(minExclusive=0),
  2155         "facets": DECIMAL_FACETS,
  2155         "facets": DECIMAL_FACETS,
  2156         "generate": GenerateSimpleTypeXMLText(str),
  2156         "generate": GenerateSimpleTypeXMLText(str),
  2157         "initial": lambda: 1,
  2157         "initial": lambda: 1,
  2158         "check": lambda x: isinstance(x, IntType)
  2158         "check": lambda x: isinstance(x, IntType)
  2159     },
  2159     },
  2160     
  2160 
  2161     "negativeInteger": {
  2161     "negativeInteger": {
  2162         "type": SIMPLETYPE,
  2162         "type": SIMPLETYPE,
  2163         "basename": "negativeInteger",
  2163         "basename": "negativeInteger",
  2164         "extract": GenerateIntegerExtraction(maxExclusive=0),
  2164         "extract": GenerateIntegerExtraction(maxExclusive=0),
  2165         "facets": DECIMAL_FACETS,
  2165         "facets": DECIMAL_FACETS,
  2166         "generate": GenerateSimpleTypeXMLText(str),
  2166         "generate": GenerateSimpleTypeXMLText(str),
  2167         "initial": lambda: -1,
  2167         "initial": lambda: -1,
  2168         "check": lambda x: isinstance(x, IntType)
  2168         "check": lambda x: isinstance(x, IntType)
  2169     },
  2169     },
  2170     
  2170 
  2171     "nonNegativeInteger": {
  2171     "nonNegativeInteger": {
  2172         "type": SIMPLETYPE, 
  2172         "type": SIMPLETYPE,
  2173         "basename": "nonNegativeInteger", 
  2173         "basename": "nonNegativeInteger",
  2174         "extract": GenerateIntegerExtraction(minInclusive=0),
  2174         "extract": GenerateIntegerExtraction(minInclusive=0),
  2175         "facets": DECIMAL_FACETS,
  2175         "facets": DECIMAL_FACETS,
  2176         "generate": GenerateSimpleTypeXMLText(str),
  2176         "generate": GenerateSimpleTypeXMLText(str),
  2177         "initial": lambda: 0,
  2177         "initial": lambda: 0,
  2178         "check": lambda x: isinstance(x, IntType)
  2178         "check": lambda x: isinstance(x, IntType)
  2179     },
  2179     },
  2180     
  2180 
  2181     "nonPositiveInteger": {
  2181     "nonPositiveInteger": {
  2182         "type": SIMPLETYPE,
  2182         "type": SIMPLETYPE,
  2183         "basename": "nonPositiveInteger", 
  2183         "basename": "nonPositiveInteger",
  2184         "extract": GenerateIntegerExtraction(maxInclusive=0),
  2184         "extract": GenerateIntegerExtraction(maxInclusive=0),
  2185         "facets": DECIMAL_FACETS,
  2185         "facets": DECIMAL_FACETS,
  2186         "generate": GenerateSimpleTypeXMLText(str),
  2186         "generate": GenerateSimpleTypeXMLText(str),
  2187         "initial": lambda: 0,
  2187         "initial": lambda: 0,
  2188         "check": lambda x: isinstance(x, IntType)
  2188         "check": lambda x: isinstance(x, IntType)
  2189     },
  2189     },
  2190     
  2190 
  2191     "long": {
  2191     "long": {
  2192         "type": SIMPLETYPE,
  2192         "type": SIMPLETYPE,
  2193         "basename": "long",
  2193         "basename": "long",
  2194         "extract": GenerateIntegerExtraction(minInclusive=-2**63,maxExclusive=2**63),
  2194         "extract": GenerateIntegerExtraction(minInclusive=-2**63,maxExclusive=2**63),
  2195         "facets": DECIMAL_FACETS,
  2195         "facets": DECIMAL_FACETS,
  2196         "generate": GenerateSimpleTypeXMLText(str),
  2196         "generate": GenerateSimpleTypeXMLText(str),
  2197         "initial": lambda: 0,
  2197         "initial": lambda: 0,
  2198         "check": lambda x: isinstance(x, IntType)
  2198         "check": lambda x: isinstance(x, IntType)
  2199     },
  2199     },
  2200     
  2200 
  2201     "unsignedLong": {
  2201     "unsignedLong": {
  2202         "type": SIMPLETYPE,
  2202         "type": SIMPLETYPE,
  2203         "basename": "unsignedLong",
  2203         "basename": "unsignedLong",
  2204         "extract": GenerateIntegerExtraction(minInclusive=0,maxExclusive=2**64),
  2204         "extract": GenerateIntegerExtraction(minInclusive=0,maxExclusive=2**64),
  2205         "facets": DECIMAL_FACETS,
  2205         "facets": DECIMAL_FACETS,
  2238         "check": lambda x: isinstance(x, IntType)
  2238         "check": lambda x: isinstance(x, IntType)
  2239     },
  2239     },
  2240 
  2240 
  2241     "unsignedShort": {
  2241     "unsignedShort": {
  2242         "type": SIMPLETYPE,
  2242         "type": SIMPLETYPE,
  2243         "basename": "unsignedShort", 
  2243         "basename": "unsignedShort",
  2244         "extract": GenerateIntegerExtraction(minInclusive=0,maxExclusive=2**16),
  2244         "extract": GenerateIntegerExtraction(minInclusive=0,maxExclusive=2**16),
  2245         "facets": DECIMAL_FACETS,
  2245         "facets": DECIMAL_FACETS,
  2246         "generate": GenerateSimpleTypeXMLText(str),
  2246         "generate": GenerateSimpleTypeXMLText(str),
  2247         "initial": lambda: 0,
  2247         "initial": lambda: 0,
  2248         "check": lambda x: isinstance(x, IntType)
  2248         "check": lambda x: isinstance(x, IntType)
  2304         "extract": GetBoolean,
  2304         "extract": GetBoolean,
  2305         "facets": GenerateDictFacets(["pattern", "whiteSpace"]),
  2305         "facets": GenerateDictFacets(["pattern", "whiteSpace"]),
  2306         "generate": GenerateSimpleTypeXMLText(lambda x:{True : "true", False : "false"}[x]),
  2306         "generate": GenerateSimpleTypeXMLText(lambda x:{True : "true", False : "false"}[x]),
  2307         "initial": lambda: False,
  2307         "initial": lambda: False,
  2308         "check": lambda x: isinstance(x, BooleanType)
  2308         "check": lambda x: isinstance(x, BooleanType)
  2309     },	
  2309     },
  2310 
  2310 
  2311     "duration": {
  2311     "duration": {
  2312         "type": SIMPLETYPE,
  2312         "type": SIMPLETYPE,
  2313         "basename": "duration",
  2313         "basename": "duration",
  2314         "extract": NotSupportedYet("duration"),
  2314         "extract": NotSupportedYet("duration"),
  2335         "facets": NUMBER_FACETS,
  2335         "facets": NUMBER_FACETS,
  2336         "generate": GenerateSimpleTypeXMLText(datetime.date.isoformat),
  2336         "generate": GenerateSimpleTypeXMLText(datetime.date.isoformat),
  2337         "initial": lambda: datetime.date(1,1,1),
  2337         "initial": lambda: datetime.date(1,1,1),
  2338         "check": lambda x: isinstance(x, datetime.date)
  2338         "check": lambda x: isinstance(x, datetime.date)
  2339     },
  2339     },
  2340     
  2340 
  2341     "time": {
  2341     "time": {
  2342         "type": SIMPLETYPE,
  2342         "type": SIMPLETYPE,
  2343         "basename": "time",
  2343         "basename": "time",
  2344         "extract": GetTime,
  2344         "extract": GetTime,
  2345         "facets": NUMBER_FACETS,
  2345         "facets": NUMBER_FACETS,
  2405         "facets": STRING_FACETS,
  2405         "facets": STRING_FACETS,
  2406         "generate": GenerateSimpleTypeXMLText(lambda x: x),
  2406         "generate": GenerateSimpleTypeXMLText(lambda x: x),
  2407         "initial": lambda: "",
  2407         "initial": lambda: "",
  2408         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2408         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2409     },
  2409     },
  2410     
  2410 
  2411     "QName": {
  2411     "QName": {
  2412         "type": SIMPLETYPE,
  2412         "type": SIMPLETYPE,
  2413         "basename": "QName",
  2413         "basename": "QName",
  2414         "extract": GenerateModelNameExtraction("QName", QName_model),
  2414         "extract": GenerateModelNameExtraction("QName", QName_model),
  2415         "facets": STRING_FACETS,
  2415         "facets": STRING_FACETS,
  2529     },
  2529     },
  2530 
  2530 
  2531     # Complex Types
  2531     # Complex Types
  2532     "anyType": {"type": COMPLEXTYPE, "extract": lambda x:None},
  2532     "anyType": {"type": COMPLEXTYPE, "extract": lambda x:None},
  2533 }
  2533 }
  2534