xmlclass/xsdschema.py
changeset 1784 64beb9e9c749
parent 1782 5b6ad7a7fd9d
child 1826 91796f408540
equal deleted inserted replaced
1729:31e63e25b4cc 1784:64beb9e9c749
    20 #
    20 #
    21 # You should have received a copy of the GNU General Public License
    21 # You should have received a copy of the GNU General Public License
    22 # along with this program; if not, write to the Free Software
    22 # along with this program; if not, write to the Free Software
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 
    24 
    25 import os, re
    25 import os
       
    26 import re
    26 import datetime
    27 import datetime
    27 from xml.dom import minidom
    28 from xml.dom import minidom
    28 from types import *
    29 from types import *
    29 
    30 
    30 from xmlclass import *
    31 from xmlclass import *
    31 
    32 
       
    33 
    32 def GenerateDictFacets(facets):
    34 def GenerateDictFacets(facets):
    33     return dict([(name, (None, False)) for name in facets])
    35     return dict([(name, (None, False)) for name in facets])
       
    36 
    34 
    37 
    35 def GenerateSimpleTypeXMLText(function):
    38 def GenerateSimpleTypeXMLText(function):
    36     def generateXMLTextMethod(value, name=None, indent=0):
    39     def generateXMLTextMethod(value, name=None, indent=0):
    37         text = ""
    40         text = ""
    38         if name is not None:
    41         if name is not None:
    42         if name is not None:
    45         if name is not None:
    43             text += "</%s>\n" % name
    46             text += "</%s>\n" % name
    44         return text
    47         return text
    45     return generateXMLTextMethod
    48     return generateXMLTextMethod
    46 
    49 
       
    50 
    47 def GenerateFloatXMLText(extra_values=[], decimal=None):
    51 def GenerateFloatXMLText(extra_values=[], decimal=None):
    48     float_format = (lambda x: "{:.{width}f}".format(x, width=decimal).rstrip('0')
    52     float_format = (lambda x: "{:.{width}f}".format(x, width=decimal).rstrip('0')
    49                     if decimal is not None else str)
    53                     if decimal is not None else str)
       
    54 
    50     def generateXMLTextMethod(value, name=None, indent=0):
    55     def generateXMLTextMethod(value, name=None, indent=0):
    51         text = ""
    56         text = ""
    52         if name is not None:
    57         if name is not None:
    53             ind1, ind2 = getIndent(indent, name)
    58             ind1, ind2 = getIndent(indent, name)
    54             text += ind1 + "<%s>" % name
    59             text += ind1 + "<%s>" % name
    60             text += "{:.0f}".format(value)
    65             text += "{:.0f}".format(value)
    61         if name is not None:
    66         if name is not None:
    62             text += "</%s>\n" % name
    67             text += "</%s>\n" % name
    63         return text
    68         return text
    64     return generateXMLTextMethod
    69     return generateXMLTextMethod
    65         
    70 
       
    71 
    66 DEFAULT_FACETS = GenerateDictFacets(["pattern", "whiteSpace", "enumeration"])
    72 DEFAULT_FACETS = GenerateDictFacets(["pattern", "whiteSpace", "enumeration"])
    67 NUMBER_FACETS = GenerateDictFacets(DEFAULT_FACETS.keys() + ["maxInclusive", "maxExclusive", "minInclusive", "minExclusive"])
    73 NUMBER_FACETS = GenerateDictFacets(DEFAULT_FACETS.keys() + ["maxInclusive", "maxExclusive", "minInclusive", "minExclusive"])
    68 DECIMAL_FACETS = GenerateDictFacets(NUMBER_FACETS.keys() + ["totalDigits", "fractionDigits"])
    74 DECIMAL_FACETS = GenerateDictFacets(NUMBER_FACETS.keys() + ["totalDigits", "fractionDigits"])
    69 STRING_FACETS = GenerateDictFacets(DEFAULT_FACETS.keys() + ["length", "minLength", "maxLength"])
    75 STRING_FACETS = GenerateDictFacets(DEFAULT_FACETS.keys() + ["length", "minLength", "maxLength"])
    70 
    76 
    71 ALL_FACETS = ["pattern", "whiteSpace", "enumeration", "maxInclusive", 
    77 ALL_FACETS = ["pattern", "whiteSpace", "enumeration", "maxInclusive",
    72     "maxExclusive", "minInclusive", "minExclusive", "totalDigits", 
    78               "maxExclusive", "minInclusive", "minExclusive", "totalDigits",
    73     "fractionDigits", "length", "minLength", "maxLength"]
    79               "fractionDigits", "length", "minLength", "maxLength"]
    74 
    80 
    75 
    81 
    76 #-------------------------------------------------------------------------------
    82 # -------------------------------------------------------------------------------
    77 #                           Structure reducing functions
    83 #                           Structure reducing functions
    78 #-------------------------------------------------------------------------------
    84 # -------------------------------------------------------------------------------
    79 
    85 
    80 
    86 
    81 # Documentation elements
    87 # Documentation elements
    82 
    88 
    83 def ReduceAppInfo(factory, attributes, elements):
    89 def ReduceAppInfo(factory, attributes, elements):
    84     return {"type": "appinfo", "source": attributes.get("source", None), 
    90     return {"type": "appinfo", "source": attributes.get("source", None),
    85             "content": "\n".join(elements)}
    91             "content": "\n".join(elements)}
    86 
    92 
    87 
    93 
    88 def ReduceDocumentation(factory, attributes, elements):
    94 def ReduceDocumentation(factory, attributes, elements):
    89     return {"type": "documentation", "source": attributes.get("source", None), 
    95     return {"type": "documentation", "source": attributes.get("source", None),
    90             "language": attributes.get("lang", "any"), "content": "\n".join(elements)}
    96             "language": attributes.get("lang", "any"), "content": "\n".join(elements)}
    91 
    97 
    92 
    98 
    93 def ReduceAnnotation(factory, attributes, elements):
    99 def ReduceAnnotation(factory, attributes, elements):
    94     annotations, children = factory.ReduceElements(elements)
   100     annotations, children = factory.ReduceElements(elements)
    96     for child in children:
   102     for child in children:
    97         if child["type"] == "appinfo":
   103         if child["type"] == "appinfo":
    98             annotation["appinfo"].append((child["source"], child["content"]))
   104             annotation["appinfo"].append((child["source"], child["content"]))
    99         elif child["type"] == "documentation":
   105         elif child["type"] == "documentation":
   100             if child["source"] is not None:
   106             if child["source"] is not None:
   101                 text = "(source: %(source)s):\n%(content)s\n\n"%child
   107                 text = "(source: %(source)s):\n%(content)s\n\n" % child
   102             else:
   108             else:
   103                 text = child["content"] + "\n\n"
   109                 text = child["content"] + "\n\n"
   104             if not annotation["documentation"].has_key(child["language"]):
   110             if not child["language"] in annotation["documentation"]:
   105                 annotation["documentation"] = text
   111                 annotation["documentation"] = text
   106             else:
   112             else:
   107                 annotation["documentation"] += text
   113                 annotation["documentation"] += text
   108     return annotation
   114     return annotation
   109 
   115 
   110 # Simple type elements
   116 # Simple type elements
   111 
   117 
       
   118 
   112 def GenerateFacetReducing(facetname, canbefixed):
   119 def GenerateFacetReducing(facetname, canbefixed):
   113     def ReduceFacet(factory, attributes, elements):
   120     def ReduceFacet(factory, attributes, elements):
   114         annotations, children = factory.ReduceElements(elements)
   121         annotations, children = factory.ReduceElements(elements)
   115         if attributes.has_key("value"):
   122         if "value" in attributes:
   116             facet = {"type": facetname, "value": attributes["value"], "doc": annotations}
   123             facet = {"type": facetname, "value": attributes["value"], "doc": annotations}
   117             if canbefixed:
   124             if canbefixed:
   118                 facet["fixed"] = attributes.get("fixed", False)
   125                 facet["fixed"] = attributes.get("fixed", False)
   119             return facet
   126             return facet
   120         raise ValueError("A value must be defined for the \"%s\" facet!" % facetname)
   127         raise ValueError("A value must be defined for the \"%s\" facet!" % facetname)
   122 
   129 
   123 
   130 
   124 def ReduceList(factory, attributes, elements):
   131 def ReduceList(factory, attributes, elements):
   125     annotations, children = factory.ReduceElements(elements)
   132     annotations, children = factory.ReduceElements(elements)
   126     list = {"type": "list", "itemType": attributes.get("itemType", None), "doc": annotations}
   133     list = {"type": "list", "itemType": attributes.get("itemType", None), "doc": annotations}
   127     
   134 
   128     if len(children) > 0 and children[0]["type"] == SIMPLETYPE:
   135     if len(children) > 0 and children[0]["type"] == SIMPLETYPE:
   129         if list["itemType"] is None:
   136         if list["itemType"] is None:
   130             list["itemType"] = children[0]
   137             list["itemType"] = children[0]
   131         else:
   138         else:
   132             raise ValueError("Only one base type can be defined for restriction!")
   139             raise ValueError("Only one base type can be defined for restriction!")
   136 
   143 
   137 
   144 
   138 def ReduceUnion(factory, attributes, elements):
   145 def ReduceUnion(factory, attributes, elements):
   139     annotations, children = factory.ReduceElements(elements)
   146     annotations, children = factory.ReduceElements(elements)
   140     union = {"type": "union", "memberTypes": attributes.get("memberTypes", []), "doc": annotations}
   147     union = {"type": "union", "memberTypes": attributes.get("memberTypes", []), "doc": annotations}
   141     
   148 
   142     for child in children:
   149     for child in children:
   143         if child["type"] == SIMPLETYPE:
   150         if child["type"] == SIMPLETYPE:
   144             union["memberTypes"].appendchild
   151             union["memberTypes"].appendchild
   145     if len(union["memberTypes"]) == 0:
   152     if len(union["memberTypes"]) == 0:
   146         raise ValueError("No base type has been defined for union!")
   153         raise ValueError("No base type has been defined for union!")
   149 
   156 
   150 def CreateSimpleType(factory, attributes, typeinfos):
   157 def CreateSimpleType(factory, attributes, typeinfos):
   151     # Initialize type informations
   158     # Initialize type informations
   152     facets = {}
   159     facets = {}
   153     simpleType = {"type": SIMPLETYPE, "final": attributes.get("final", [])}
   160     simpleType = {"type": SIMPLETYPE, "final": attributes.get("final", [])}
   154     if attributes.has_key("name"):
   161     if "name" in attributes:
   155         simpleType["name"] = attributes["name"]
   162         simpleType["name"] = attributes["name"]
   156     
   163 
   157     if typeinfos["type"] in ["restriction", "extension"]:
   164     if typeinfos["type"] in ["restriction", "extension"]:
   158         # Search for base type definition
   165         # Search for base type definition
   159         if isinstance(typeinfos["base"], (StringType, UnicodeType)):
   166         if isinstance(typeinfos["base"], (StringType, UnicodeType)):
   160             basetypeinfos = factory.FindSchemaElement(typeinfos["base"], SIMPLETYPE)
   167             basetypeinfos = factory.FindSchemaElement(typeinfos["base"], SIMPLETYPE)
   161             if basetypeinfos is None:
   168             if basetypeinfos is None:
   162                 raise "\"%s\" isn't defined!" % typeinfos["base"] 
   169                 raise "\"%s\" isn't defined!" % typeinfos["base"]
   163         else:
   170         else:
   164             basetypeinfos = typeinfos["base"]
   171             basetypeinfos = typeinfos["base"]
   165         
   172 
   166         # Check that base type is a simple type
   173         # Check that base type is a simple type
   167         if basetypeinfos["type"] != SIMPLETYPE:
   174         if basetypeinfos["type"] != SIMPLETYPE:
   168             raise ValueError("Base type given isn't a simpleType!")
   175             raise ValueError("Base type given isn't a simpleType!")
   169         
   176 
   170         simpleType["basename"] = basetypeinfos["basename"]
   177         simpleType["basename"] = basetypeinfos["basename"]
   171         
   178 
   172         # Check that derivation is allowed
   179         # Check that derivation is allowed
   173         if basetypeinfos.has_key("final"):
   180         if "final" in basetypeinfos:
   174             if "#all" in basetypeinfos["final"]:
   181             if "#all" in basetypeinfos["final"]:
   175                 raise ValueError("Base type can't be derivated!")
   182                 raise ValueError("Base type can't be derivated!")
   176             if "restriction" in basetypeinfos["final"] and typeinfos["type"] == "restriction":
   183             if "restriction" in basetypeinfos["final"] and typeinfos["type"] == "restriction":
   177                 raise ValueError("Base type can't be derivated by restriction!")
   184                 raise ValueError("Base type can't be derivated by restriction!")
   178         
   185 
   179         # Extract simple type facets
   186         # Extract simple type facets
   180         for facet in typeinfos.get("facets", []):
   187         for facet in typeinfos.get("facets", []):
   181             facettype = facet["type"]
   188             facettype = facet["type"]
   182             if not basetypeinfos["facets"].has_key(facettype):
   189             if facettype not in basetypeinfos["facets"]:
   183                 raise ValueError("\"%s\" facet can't be defined for \"%s\" type!" % (facettype, type))
   190                 raise ValueError("\"%s\" facet can't be defined for \"%s\" type!" % (facettype, type))
   184             elif basetypeinfos["facets"][facettype][1]:
   191             elif basetypeinfos["facets"][facettype][1]:
   185                 raise ValueError("\"%s\" facet is fixed on base type!" % facettype)
   192                 raise ValueError("\"%s\" facet is fixed on base type!" % facettype)
   186             value = facet["value"]
   193             value = facet["value"]
   187             basevalue = basetypeinfos["facets"][facettype][0]
   194             basevalue = basetypeinfos["facets"][facettype][0]
   193                 elif facets.keys() == [facettype]:
   200                 elif facets.keys() == [facettype]:
   194                     facets[facettype][0].append(value)
   201                     facets[facettype][0].append(value)
   195                     continue
   202                     continue
   196                 else:
   203                 else:
   197                     raise ValueError("\"%s\" facet can't be defined with another facet type!" % facettype)
   204                     raise ValueError("\"%s\" facet can't be defined with another facet type!" % facettype)
   198             elif facets.has_key("enumeration"):
   205             elif "enumeration" in facets:
   199                 raise ValueError("\"enumeration\" facet can't be defined with another facet type!")
   206                 raise ValueError("\"enumeration\" facet can't be defined with another facet type!")
   200             elif facets.has_key("pattern"):
   207             elif "pattern" in facets:
   201                 raise ValueError("\"pattern\" facet can't be defined with another facet type!")
   208                 raise ValueError("\"pattern\" facet can't be defined with another facet type!")
   202             elif facets.has_key(facettype):
   209             elif facettype in facets:
   203                 raise ValueError("\"%s\" facet can't be defined two times!" % facettype)
   210                 raise ValueError("\"%s\" facet can't be defined two times!" % facettype)
   204             elif facettype == "length":
   211             elif facettype == "length":
   205                 if facets.has_key("minLength"):
   212                 if "minLength" in facets:
   206                     raise ValueError("\"length\" and \"minLength\" facets can't be defined at the same time!")
   213                     raise ValueError("\"length\" and \"minLength\" facets can't be defined at the same time!")
   207                 if facets.has_key("maxLength"):
   214                 if "maxLength" in facets:
   208                     raise ValueError("\"length\" and \"maxLength\" facets can't be defined at the same time!")
   215                     raise ValueError("\"length\" and \"maxLength\" facets can't be defined at the same time!")
   209                 try:
   216                 try:
   210                     value = int(value)
   217                     value = int(value)
   211                 except:
   218                 except Exception:
   212                     raise ValueError("\"length\" must be an integer!")
   219                     raise ValueError("\"length\" must be an integer!")
   213                 if value < 0:
   220                 if value < 0:
   214                     raise ValueError("\"length\" can't be negative!")
   221                     raise ValueError("\"length\" can't be negative!")
   215                 elif basevalue is not None and basevalue != value:
   222                 elif basevalue is not None and basevalue != value:
   216                     raise ValueError("\"length\" can't be different from \"length\" defined in base type!")
   223                     raise ValueError("\"length\" can't be different from \"length\" defined in base type!")
   217             elif facettype == "minLength":
   224             elif facettype == "minLength":
   218                 if facets.has_key("length"):
   225                 if "length" in facets:
   219                     raise ValueError("\"length\" and \"minLength\" facets can't be defined at the same time!")
   226                     raise ValueError("\"length\" and \"minLength\" facets can't be defined at the same time!")
   220                 try:
   227                 try:
   221                     value = int(value)
   228                     value = int(value)
   222                 except:
   229                 except Exception:
   223                     raise ValueError("\"minLength\" must be an integer!")
   230                     raise ValueError("\"minLength\" must be an integer!")
   224                 if value < 0:
   231                 if value < 0:
   225                     raise ValueError("\"minLength\" can't be negative!")
   232                     raise ValueError("\"minLength\" can't be negative!")
   226                 elif facets.has_key("maxLength") and value > facets["maxLength"]:
   233                 elif "maxLength" in facets and value > facets["maxLength"]:
   227                     raise ValueError("\"minLength\" must be lesser than or equal to \"maxLength\"!")
   234                     raise ValueError("\"minLength\" must be lesser than or equal to \"maxLength\"!")
   228                 elif basevalue is not None and basevalue < value:
   235                 elif basevalue is not None and basevalue < value:
   229                     raise ValueError("\"minLength\" can't be lesser than \"minLength\" defined in base type!")
   236                     raise ValueError("\"minLength\" can't be lesser than \"minLength\" defined in base type!")
   230             elif facettype == "maxLength":
   237             elif facettype == "maxLength":
   231                 if facets.has_key("length"):
   238                 if "length" in facets:
   232                     raise ValueError("\"length\" and \"maxLength\" facets can't be defined at the same time!")
   239                     raise ValueError("\"length\" and \"maxLength\" facets can't be defined at the same time!")
   233                 try:
   240                 try:
   234                     value = int(value)
   241                     value = int(value)
   235                 except:
   242                 except Exception:
   236                     raise ValueError("\"maxLength\" must be an integer!")
   243                     raise ValueError("\"maxLength\" must be an integer!")
   237                 if value < 0:
   244                 if value < 0:
   238                     raise ValueError("\"maxLength\" can't be negative!")
   245                     raise ValueError("\"maxLength\" can't be negative!")
   239                 elif facets.has_key("minLength") and value < facets["minLength"]:
   246                 elif "minLength" in facets and value < facets["minLength"]:
   240                     raise ValueError("\"minLength\" must be lesser than or equal to \"maxLength\"!")
   247                     raise ValueError("\"minLength\" must be lesser than or equal to \"maxLength\"!")
   241                 elif basevalue is not None and basevalue > value:
   248                 elif basevalue is not None and basevalue > value:
   242                     raise ValueError("\"maxLength\" can't be greater than \"maxLength\" defined in base type!")
   249                     raise ValueError("\"maxLength\" can't be greater than \"maxLength\" defined in base type!")
   243             elif facettype == "minInclusive":
   250             elif facettype == "minInclusive":
   244                 if facets.has_key("minExclusive"):
   251                 if "minExclusive" in facets:
   245                     raise ValueError("\"minExclusive\" and \"minInclusive\" facets can't be defined at the same time!")
   252                     raise ValueError("\"minExclusive\" and \"minInclusive\" facets can't be defined at the same time!")
   246                 value = basetypeinfos["extract"](facet["value"], False)
   253                 value = basetypeinfos["extract"](facet["value"], False)
   247                 if facets.has_key("maxInclusive") and value > facets["maxInclusive"][0]:
   254                 if "maxInclusive" in facets and value > facets["maxInclusive"][0]:
   248                     raise ValueError("\"minInclusive\" must be lesser than or equal to \"maxInclusive\"!")
   255                     raise ValueError("\"minInclusive\" must be lesser than or equal to \"maxInclusive\"!")
   249                 elif facets.has_key("maxExclusive") and value >= facets["maxExclusive"][0]:
   256                 elif "maxExclusive" in facets and value >= facets["maxExclusive"][0]:
   250                     raise ValueError("\"minInclusive\" must be lesser than \"maxExclusive\"!")
   257                     raise ValueError("\"minInclusive\" must be lesser than \"maxExclusive\"!")
   251             elif facettype == "minExclusive":
   258             elif facettype == "minExclusive":
   252                 if facets.has_key("minInclusive"):
   259                 if "minInclusive" in facets:
   253                     raise ValueError("\"minExclusive\" and \"minInclusive\" facets can't be defined at the same time!")
   260                     raise ValueError("\"minExclusive\" and \"minInclusive\" facets can't be defined at the same time!")
   254                 value = basetypeinfos["extract"](facet["value"], False)
   261                 value = basetypeinfos["extract"](facet["value"], False)
   255                 if facets.has_key("maxInclusive") and value >= facets["maxInclusive"][0]:
   262                 if "maxInclusive" in facets and value >= facets["maxInclusive"][0]:
   256                     raise ValueError("\"minExclusive\" must be lesser than \"maxInclusive\"!")
   263                     raise ValueError("\"minExclusive\" must be lesser than \"maxInclusive\"!")
   257                 elif facets.has_key("maxExclusive") and value >= facets["maxExclusive"][0]:
   264                 elif "maxExclusive" in facets and value >= facets["maxExclusive"][0]:
   258                     raise ValueError("\"minExclusive\" must be lesser than \"maxExclusive\"!")
   265                     raise ValueError("\"minExclusive\" must be lesser than \"maxExclusive\"!")
   259             elif facettype == "maxInclusive":
   266             elif facettype == "maxInclusive":
   260                 if facets.has_key("maxExclusive"):
   267                 if "maxExclusive" in facets:
   261                     raise ValueError("\"maxExclusive\" and \"maxInclusive\" facets can't be defined at the same time!")
   268                     raise ValueError("\"maxExclusive\" and \"maxInclusive\" facets can't be defined at the same time!")
   262                 value = basetypeinfos["extract"](facet["value"], False)
   269                 value = basetypeinfos["extract"](facet["value"], False)
   263                 if facets.has_key("minInclusive") and value < facets["minInclusive"][0]:
   270                 if "minInclusive" in facets and value < facets["minInclusive"][0]:
   264                     raise ValueError("\"minInclusive\" must be lesser than or equal to \"maxInclusive\"!")
   271                     raise ValueError("\"minInclusive\" must be lesser than or equal to \"maxInclusive\"!")
   265                 elif facets.has_key("minExclusive") and value <= facets["minExclusive"][0]:
   272                 elif "minExclusive" in facets and value <= facets["minExclusive"][0]:
   266                     raise ValueError("\"minExclusive\" must be lesser than \"maxInclusive\"!")
   273                     raise ValueError("\"minExclusive\" must be lesser than \"maxInclusive\"!")
   267             elif facettype == "maxExclusive":
   274             elif facettype == "maxExclusive":
   268                 if facets.has_key("maxInclusive"):
   275                 if "maxInclusive" in facets:
   269                     raise ValueError("\"maxExclusive\" and \"maxInclusive\" facets can't be defined at the same time!")
   276                     raise ValueError("\"maxExclusive\" and \"maxInclusive\" facets can't be defined at the same time!")
   270                 value = basetypeinfos["extract"](facet["value"], False)
   277                 value = basetypeinfos["extract"](facet["value"], False)
   271                 if facets.has_key("minInclusive") and value <= facets["minInclusive"][0]:
   278                 if "minInclusive" in facets and value <= facets["minInclusive"][0]:
   272                     raise ValueError("\"minInclusive\" must be lesser than \"maxExclusive\"!")
   279                     raise ValueError("\"minInclusive\" must be lesser than \"maxExclusive\"!")
   273                 elif facets.has_key("minExclusive") and value <= facets["minExclusive"][0]:
   280                 elif "minExclusive" in facets and value <= facets["minExclusive"][0]:
   274                     raise ValueError("\"minExclusive\" must be lesser than \"maxExclusive\"!")
   281                     raise ValueError("\"minExclusive\" must be lesser than \"maxExclusive\"!")
   275             elif facettype == "whiteSpace":
   282             elif facettype == "whiteSpace":
   276                 if basevalue == "collapse" and value in ["preserve", "replace"] or basevalue == "replace" and value == "preserve":
   283                 if basevalue == "collapse" and value in ["preserve", "replace"] or basevalue == "replace" and value == "preserve":
   277                    raise ValueError("\"whiteSpace\" is incompatible with \"whiteSpace\" defined in base type!")
   284                     raise ValueError("\"whiteSpace\" is incompatible with \"whiteSpace\" defined in base type!")
   278             elif facettype == "totalDigits":
   285             elif facettype == "totalDigits":
   279                 if facets.has_key("fractionDigits") and value <= facets["fractionDigits"][0]:
   286                 if "fractionDigits" in facets and value <= facets["fractionDigits"][0]:
   280                     raise ValueError("\"fractionDigits\" must be lesser than or equal to \"totalDigits\"!")
   287                     raise ValueError("\"fractionDigits\" must be lesser than or equal to \"totalDigits\"!")
   281                 elif basevalue is not None and value > basevalue:
   288                 elif basevalue is not None and value > basevalue:
   282                     raise ValueError("\"totalDigits\" can't be greater than \"totalDigits\" defined in base type!")
   289                     raise ValueError("\"totalDigits\" can't be greater than \"totalDigits\" defined in base type!")
   283             elif facettype == "fractionDigits":
   290             elif facettype == "fractionDigits":
   284                 if facets.has_key("totalDigits") and value <= facets["totalDigits"][0]:
   291                 if "totalDigits" in facets and value <= facets["totalDigits"][0]:
   285                     raise ValueError("\"fractionDigits\" must be lesser than or equal to \"totalDigits\"!")
   292                     raise ValueError("\"fractionDigits\" must be lesser than or equal to \"totalDigits\"!")
   286                 elif basevalue is not None and value > basevalue:
   293                 elif basevalue is not None and value > basevalue:
   287                     raise ValueError("\"totalDigits\" can't be greater than \"totalDigits\" defined in base type!")
   294                     raise ValueError("\"totalDigits\" can't be greater than \"totalDigits\" defined in base type!")
   288             facets[facettype] = (value, facet.get("fixed", False))
   295             facets[facettype] = (value, facet.get("fixed", False))
   289         
   296 
   290         # Report not redefined facet from base type to new created type 
   297         # Report not redefined facet from base type to new created type
   291         for facettype, facetvalue in basetypeinfos["facets"].items():
   298         for facettype, facetvalue in basetypeinfos["facets"].items():
   292             if not facets.has_key(facettype):
   299             if facettype not in facets:
   293                 facets[facettype] = facetvalue
   300                 facets[facettype] = facetvalue
   294         
   301 
   295         # Generate extract value for new created type
   302         # Generate extract value for new created type
   296         def ExtractSimpleTypeValue(attr, extract=True):
   303         def ExtractSimpleTypeValue(attr, extract=True):
   297             value = basetypeinfos["extract"](attr, extract)
   304             value = basetypeinfos["extract"](attr, extract)
   298             for facetname, (facetvalue, facetfixed) in facets.items():
   305             for facetname, (facetvalue, facetfixed) in facets.items():
   299                 if facetvalue is not None:
   306                 if facetvalue is not None:
   309                         raise ValueError("value must be greater than or equal to %s" % str(facetvalue))
   316                         raise ValueError("value must be greater than or equal to %s" % str(facetvalue))
   310                     elif facetname == "minExclusive" and value <= facetvalue:
   317                     elif facetname == "minExclusive" and value <= facetvalue:
   311                         raise ValueError("value must be greater than %s" % str(facetvalue))
   318                         raise ValueError("value must be greater than %s" % str(facetvalue))
   312                     elif facetname == "maxInclusive" and value > facetvalue:
   319                     elif facetname == "maxInclusive" and value > facetvalue:
   313                         raise ValueError("value must be lesser than or equal to %s" % str(facetvalue))
   320                         raise ValueError("value must be lesser than or equal to %s" % str(facetvalue))
   314                     elif facetname == "maxExclusive"  and value >= facetvalue:
   321                     elif facetname == "maxExclusive" and value >= facetvalue:
   315                         raise ValueError("value must be lesser than %s" % str(facetvalue))
   322                         raise ValueError("value must be lesser than %s" % str(facetvalue))
   316                     elif facetname == "pattern":
   323                     elif facetname == "pattern":
   317                         model = re.compile("(?:%s)?$" % "|".join(map(lambda x: "(?:%s)" % x, facetvalue)))
   324                         model = re.compile("(?:%s)?$" % "|".join(map(lambda x: "(?:%s)" % x, facetvalue)))
   318                         result = model.match(value)
   325                         result = model.match(value)
   319                         if result is None:
   326                         if result is None:
   320                             if len(facetvalue) > 1:   
   327                             if len(facetvalue) > 1:
   321                                 raise ValueError("value doesn't follow any of the patterns %s" % ",".join(facetvalue))
   328                                 raise ValueError("value doesn't follow any of the patterns %s" % ",".join(facetvalue))
   322                             else:
   329                             else:
   323                                 raise ValueError("value doesn't follow the pattern %s" % facetvalue[0])
   330                                 raise ValueError("value doesn't follow the pattern %s" % facetvalue[0])
   324                     elif facetname == "whiteSpace":
   331                     elif facetname == "whiteSpace":
   325                         if facetvalue == "replace":
   332                         if facetvalue == "replace":
   326                             value = GetNormalizedString(value, False)
   333                             value = GetNormalizedString(value, False)
   327                         elif facetvalue == "collapse":
   334                         elif facetvalue == "collapse":
   328                             value = GetToken(value, False)
   335                             value = GetToken(value, False)
   329             return value
   336             return value
   330         
   337 
   331         def CheckSimpleTypeValue(value):
   338         def CheckSimpleTypeValue(value):
   332             for facetname, (facetvalue, facetfixed) in facets.items():
   339             for facetname, (facetvalue, facetfixed) in facets.items():
   333                 if facetvalue is not None:
   340                 if facetvalue is not None:
   334                     if facetname == "enumeration" and value not in facetvalue:
   341                     if facetname == "enumeration" and value not in facetvalue:
   335                         return False
   342                         return False
   343                         return False
   350                         return False
   344                     elif facetname == "minExclusive" and value <= facetvalue:
   351                     elif facetname == "minExclusive" and value <= facetvalue:
   345                         return False
   352                         return False
   346                     elif facetname == "maxInclusive" and value > facetvalue:
   353                     elif facetname == "maxInclusive" and value > facetvalue:
   347                         return False
   354                         return False
   348                     elif facetname == "maxExclusive"  and value >= facetvalue:
   355                     elif facetname == "maxExclusive" and value >= facetvalue:
   349                         return False
   356                         return False
   350                     elif facetname == "pattern":
   357                     elif facetname == "pattern":
   351                         model = re.compile("(?:%s)?$" % "|".join(map(lambda x: "(?:%s)" % x, facetvalue)))
   358                         model = re.compile("(?:%s)?$" % "|".join(map(lambda x: "(?:%s)" % x, facetvalue)))
   352                         result = model.match(value)
   359                         result = model.match(value)
   353                         if result is None:
   360                         if result is None:
   354                             if len(facetvalue) > 1:   
   361                             if len(facetvalue) > 1:
   355                                 raise ValueError("value doesn't follow any of the patterns %s" % ",".join(facetvalue))
   362                                 raise ValueError("value doesn't follow any of the patterns %s" % ",".join(facetvalue))
   356                             else:
   363                             else:
   357                                 raise ValueError("value doesn't follow the pattern %s" % facetvalue[0])
   364                                 raise ValueError("value doesn't follow the pattern %s" % facetvalue[0])
   358             return True
   365             return True
   359         
   366 
   360         def SimpleTypeInitialValue():
   367         def SimpleTypeInitialValue():
   361             for facetname, (facetvalue, facetfixed) in facets.items():
   368             for facetname, (facetvalue, facetfixed) in facets.items():
   362                 if facetvalue is not None:
   369                 if facetvalue is not None:
   363                     if facetname == "enumeration":
   370                     if facetname == "enumeration":
   364                         return facetvalue[0]
   371                         return facetvalue[0]
   370                         return facetvalue
   377                         return facetvalue
   371                     elif facetname == "minExclusive" and facetvalue >= 0:
   378                     elif facetname == "minExclusive" and facetvalue >= 0:
   372                         return facetvalue + 1
   379                         return facetvalue + 1
   373                     elif facetname == "maxInclusive" and facetvalue < 0:
   380                     elif facetname == "maxInclusive" and facetvalue < 0:
   374                         return facetvalue
   381                         return facetvalue
   375                     elif facetname == "maxExclusive"  and facetvalue <= 0:
   382                     elif facetname == "maxExclusive" and facetvalue <= 0:
   376                         return facetvalue - 1
   383                         return facetvalue - 1
   377             return basetypeinfos["initial"]()
   384             return basetypeinfos["initial"]()
   378         
   385 
   379         GenerateSimpleType = basetypeinfos["generate"]
   386         GenerateSimpleType = basetypeinfos["generate"]
   380         
   387 
   381     elif typeinfos["type"] == "list":
   388     elif typeinfos["type"] == "list":
   382         # Search for item type definition
   389         # Search for item type definition
   383         if isinstance(typeinfos["itemType"], (StringType, UnicodeType)):
   390         if isinstance(typeinfos["itemType"], (StringType, UnicodeType)):
   384             itemtypeinfos = factory.FindSchemaElement(typeinfos["itemType"], SIMPLETYPE)
   391             itemtypeinfos = factory.FindSchemaElement(typeinfos["itemType"], SIMPLETYPE)
   385             if itemtypeinfos is None:
   392             if itemtypeinfos is None:
   386                 raise "\"%s\" isn't defined!" % typeinfos["itemType"]
   393                 raise "\"%s\" isn't defined!" % typeinfos["itemType"]
   387         else:
   394         else:
   388             itemtypeinfos = typeinfos["itemType"]
   395             itemtypeinfos = typeinfos["itemType"]
   389         
   396 
   390         # Check that item type is a simple type
   397         # Check that item type is a simple type
   391         if itemtypeinfos["type"] != SIMPLETYPE:
   398         if itemtypeinfos["type"] != SIMPLETYPE:
   392             raise ValueError, "Item type given isn't a simpleType!"
   399             raise ValueError("Item type given isn't a simpleType!")
   393         
   400 
   394         simpleType["basename"] = "list"
   401         simpleType["basename"] = "list"
   395         
   402 
   396         # Check that derivation is allowed
   403         # Check that derivation is allowed
   397         if itemtypeinfos.has_key("final"):
   404         if "final" in itemtypeinfos:
   398             if itemtypeinfos["final"].has_key("#all"):
   405             if "#all" in itemtypeinfos["final"]:
   399                 raise ValueError("Item type can't be derivated!")
   406                 raise ValueError("Item type can't be derivated!")
   400             if itemtypeinfos["final"].has_key("list"):
   407             if "list" in itemtypeinfos["final"]:
   401                 raise ValueError("Item type can't be derivated by list!")
   408                 raise ValueError("Item type can't be derivated by list!")
   402         
   409 
   403         # Generate extract value for new created type
   410         # Generate extract value for new created type
   404         def ExtractSimpleTypeValue(attr, extract = True):
   411         def ExtractSimpleTypeValue(attr, extract=True):
   405             values = []
   412             values = []
   406             for value in GetToken(attr, extract).split(" "):
   413             for value in GetToken(attr, extract).split(" "):
   407                 values.append(itemtypeinfos["extract"](value, False))
   414                 values.append(itemtypeinfos["extract"](value, False))
   408             return values
   415             return values
   409         
   416 
   410         def CheckSimpleTypeValue(value):
   417         def CheckSimpleTypeValue(value):
   411             for item in value:
   418             for item in value:
   412                 result = itemtypeinfos["check"](item)
   419                 result = itemtypeinfos["check"](item)
   413                 if not result:
   420                 if not result:
   414                     return result
   421                     return result
   415             return True
   422             return True
   416         
   423 
   417         SimpleTypeInitialValue = lambda: []
   424         def SimpleTypeInitialValue():
   418         
   425             return []
       
   426 
   419         GenerateSimpleType = GenerateSimpleTypeXMLText(lambda x: " ".join(map(itemtypeinfos["generate"], x)))
   427         GenerateSimpleType = GenerateSimpleTypeXMLText(lambda x: " ".join(map(itemtypeinfos["generate"], x)))
   420         
   428 
   421         facets = GenerateDictFacets(["length", "maxLength", "minLength", "enumeration", "pattern"])
   429         facets = GenerateDictFacets(["length", "maxLength", "minLength", "enumeration", "pattern"])
   422         facets["whiteSpace"] = ("collapse", False)
   430         facets["whiteSpace"] = ("collapse", False)
   423     
   431 
   424     elif typeinfos["type"] == "union":
   432     elif typeinfos["type"] == "union":
   425         # Search for member types definition
   433         # Search for member types definition
   426         membertypesinfos = []
   434         membertypesinfos = []
   427         for membertype in typeinfos["memberTypes"]:
   435         for membertype in typeinfos["memberTypes"]:
   428             if isinstance(membertype, (StringType, UnicodeType)):
   436             if isinstance(membertype, (StringType, UnicodeType)):
   429                 infos = factory.FindSchemaElement(membertype, SIMPLETYPE)
   437                 infos = factory.FindSchemaElement(membertype, SIMPLETYPE)
   430                 if infos is None:
   438                 if infos is None:
   431                     raise ValueError("\"%s\" isn't defined!" % membertype)
   439                     raise ValueError("\"%s\" isn't defined!" % membertype)
   432             else:
   440             else:
   433                 infos = membertype
   441                 infos = membertype
   434             
   442 
   435             # Check that member type is a simple type
   443             # Check that member type is a simple type
   436             if infos["type"] != SIMPLETYPE:
   444             if infos["type"] != SIMPLETYPE:
   437                 raise ValueError("Member type given isn't a simpleType!")
   445                 raise ValueError("Member type given isn't a simpleType!")
   438             
   446 
   439             # Check that derivation is allowed
   447             # Check that derivation is allowed
   440             if infos.has_key("final"):
   448             if "final" in infos:
   441                 if infos["final"].has_key("#all"):
   449                 if "#all" in infos["final"]:
   442                     raise ValueError("Item type can't be derivated!")
   450                     raise ValueError("Item type can't be derivated!")
   443                 if infos["final"].has_key("union"):
   451                 if "union" in infos["final"]:
   444                     raise ValueError("Member type can't be derivated by union!")
   452                     raise ValueError("Member type can't be derivated by union!")
   445             
   453 
   446             membertypesinfos.append(infos)
   454             membertypesinfos.append(infos)
   447         
   455 
   448         simpleType["basename"] = "union"
   456         simpleType["basename"] = "union"
   449         
   457 
   450         # Generate extract value for new created type
   458         # Generate extract value for new created type
   451         def ExtractSimpleTypeValue(attr, extract = True):
   459         def ExtractSimpleTypeValue(attr, extract=True):
   452             if extract:
   460             if extract:
   453                 value = GetAttributeValue(attr)
   461                 value = GetAttributeValue(attr)
   454             else:
   462             else:
   455                 value = attr
   463                 value = attr
   456             for infos in membertypesinfos:
   464             for infos in membertypesinfos:
   457                 try:
   465                 try:
   458                     return infos["extract"](attr, False)
   466                     return infos["extract"](attr, False)
   459                 except:
   467                 except Exception:
   460                     pass
   468                     pass
   461             raise ValueError("\"%s\" isn't valid for type defined for union!")
   469             raise ValueError("\"%s\" isn't valid for type defined for union!")
   462         
   470 
   463         def CheckSimpleTypeValue(value):
   471         def CheckSimpleTypeValue(value):
   464             for infos in membertypesinfos:
   472             for infos in membertypesinfos:
   465                 result = infos["check"](value)
   473                 result = infos["check"](value)
   466                 if result:
   474                 if result:
   467                     return result
   475                     return result
   468             return False
   476             return False
   469         
   477 
   470         SimpleTypeInitialValue = membertypesinfos[0]["initial"]
   478         SimpleTypeInitialValue = membertypesinfos[0]["initial"]
   471         
   479 
   472         def GenerateSimpleTypeFunction(value):
   480         def GenerateSimpleTypeFunction(value):
   473             if isinstance(value, BooleanType):
   481             if isinstance(value, BooleanType):
   474                 return {True: "true", False: "false"}[value]
   482                 return {True: "true", False: "false"}[value]
   475             else:
   483             else:
   476                 return str(value)
   484                 return str(value)
   477         GenerateSimpleType = GenerateSimpleTypeXMLText(GenerateSimpleTypeFunction)
   485         GenerateSimpleType = GenerateSimpleTypeXMLText(GenerateSimpleTypeFunction)
   478         
   486 
   479         facets = GenerateDictFacets(["pattern", "enumeration"])
   487         facets = GenerateDictFacets(["pattern", "enumeration"])
   480     
   488 
   481     simpleType["facets"] = facets
   489     simpleType["facets"] = facets
   482     simpleType["extract"] = ExtractSimpleTypeValue
   490     simpleType["extract"] = ExtractSimpleTypeValue
   483     simpleType["initial"] = SimpleTypeInitialValue
   491     simpleType["initial"] = SimpleTypeInitialValue
   484     simpleType["check"] = CheckSimpleTypeValue
   492     simpleType["check"] = CheckSimpleTypeValue
   485     simpleType["generate"] = GenerateSimpleType
   493     simpleType["generate"] = GenerateSimpleType
   486     return simpleType
   494     return simpleType
   487 
   495 
       
   496 
   488 def ReduceSimpleType(factory, attributes, elements):
   497 def ReduceSimpleType(factory, attributes, elements):
   489     # Reduce all the simple type children
   498     # Reduce all the simple type children
   490     annotations, children = factory.ReduceElements(elements)
   499     annotations, children = factory.ReduceElements(elements)
   491     
   500 
   492     simpleType = CreateSimpleType(factory, attributes, children[0])
   501     simpleType = CreateSimpleType(factory, attributes, children[0])
   493     simpleType["doc"] = annotations
   502     simpleType["doc"] = annotations
   494     
   503 
   495     return simpleType
   504     return simpleType
   496 
   505 
   497 # Complex type
   506 # Complex type
       
   507 
   498 
   508 
   499 def ExtractAttributes(factory, elements, base=None):
   509 def ExtractAttributes(factory, elements, base=None):
   500     attrs = []
   510     attrs = []
   501     attrnames = {}
   511     attrnames = {}
   502     if base is not None:
   512     if base is not None:
   503         basetypeinfos = factory.FindSchemaElement(base)
   513         basetypeinfos = factory.FindSchemaElement(base)
   504         if not isinstance(basetypeinfos, (UnicodeType, StringType)) and basetypeinfos["type"] == COMPLEXTYPE:
   514         if not isinstance(basetypeinfos, (UnicodeType, StringType)) and basetypeinfos["type"] == COMPLEXTYPE:
   505             attrnames = dict(map(lambda x:(x["name"], True), basetypeinfos["attributes"]))
   515             attrnames = dict(map(lambda x: (x["name"], True), basetypeinfos["attributes"]))
   506         
   516 
   507     for element in elements:
   517     for element in elements:
   508         if element["type"] == ATTRIBUTE:
   518         if element["type"] == ATTRIBUTE:
   509             if attrnames.get(element["name"], False):
   519             if attrnames.get(element["name"], False):
   510                 raise ValueError("\"%s\" attribute has been defined two times!" % element["name"])
   520                 raise ValueError("\"%s\" attribute has been defined two times!" % element["name"])
   511             else:
   521             else:
   532             restriction["base"] = children.pop(0)
   542             restriction["base"] = children.pop(0)
   533         else:
   543         else:
   534             raise ValueError("Only one base type can be defined for restriction!")
   544             raise ValueError("Only one base type can be defined for restriction!")
   535     if restriction["base"] is None:
   545     if restriction["base"] is None:
   536         raise ValueError("No base type has been defined for restriction!")
   546         raise ValueError("No base type has been defined for restriction!")
   537     
   547 
   538     while len(children) > 0 and children[0]["type"] in ALL_FACETS:
   548     while len(children) > 0 and children[0]["type"] in ALL_FACETS:
   539         restriction["facets"].append(children.pop(0))
   549         restriction["facets"].append(children.pop(0))
   540     restriction["attributes"] = ExtractAttributes(factory, children, restriction["base"])
   550     restriction["attributes"] = ExtractAttributes(factory, children, restriction["base"])
   541     return restriction
   551     return restriction
   542 
   552 
   543 
   553 
   544 def ReduceExtension(factory, attributes, elements):
   554 def ReduceExtension(factory, attributes, elements):
   545     annotations, children = factory.ReduceElements(elements)
   555     annotations, children = factory.ReduceElements(elements)
   546     if not attributes.has_key("base"):
   556     if "base" not in attributes:
   547         raise ValueError("No base type has been defined for extension!")
   557         raise ValueError("No base type has been defined for extension!")
   548     extension = {"type": "extension", "attributes": [], "elements": [], "base": attributes["base"], "doc": annotations}
   558     extension = {"type": "extension", "attributes": [], "elements": [], "base": attributes["base"], "doc": annotations}
   549     if len(children) > 0:
   559     if len(children) > 0:
   550         if children[0]["type"] in ["group", "all", CHOICE, "sequence"]:
   560         if children[0]["type"] in ["group", "all", CHOICE, "sequence"]:
   551             group = children.pop(0)
   561             group = children.pop(0)
   556                 content = group.copy()
   566                 content = group.copy()
   557                 content["name"] = "content"
   567                 content["name"] = "content"
   558                 extension["elements"].append(content)
   568                 extension["elements"].append(content)
   559             elif group["type"] == "group":
   569             elif group["type"] == "group":
   560                 elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP)
   570                 elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP)
   561                 if elmtgroup.has_key("elements"):
   571                 if "elements" in elmtgroup:
   562                     extension["elements"] = elmtgroup["elements"]
   572                     extension["elements"] = elmtgroup["elements"]
   563                     extension["order"] = elmtgroup["order"]
   573                     extension["order"] = elmtgroup["order"]
   564                 else:
   574                 else:
   565                     content = elmtgroup.copy()
   575                     content = elmtgroup.copy()
   566                     content["name"] = "content"
   576                     content["name"] = "content"
   569     return extension
   579     return extension
   570 
   580 
   571 
   581 
   572 def ReduceSimpleContent(factory, attributes, elements):
   582 def ReduceSimpleContent(factory, attributes, elements):
   573     annotations, children = factory.ReduceElements(elements)
   583     annotations, children = factory.ReduceElements(elements)
   574     
   584 
   575     simpleContent = children[0].copy()
   585     simpleContent = children[0].copy()
   576     
   586 
   577     basetypeinfos = factory.FindSchemaElement(simpleContent["base"])
   587     basetypeinfos = factory.FindSchemaElement(simpleContent["base"])
   578     if basetypeinfos["type"] == SIMPLETYPE:
   588     if basetypeinfos["type"] == SIMPLETYPE:
   579         contenttypeinfos = simpleContent.copy()
   589         contenttypeinfos = simpleContent.copy()
   580         simpleContent.pop("base")
   590         simpleContent.pop("base")
   581     elif basetypeinfos["type"] == COMPLEXTYPE and \
   591     elif (basetypeinfos["type"] == COMPLEXTYPE and
   582          len(basetypeinfos["elements"]) == 1 and \
   592           len(basetypeinfos["elements"]) == 1 and
   583          basetypeinfos["elements"][0]["name"] == "content" and \
   593           basetypeinfos["elements"][0]["name"] == "content" and
   584          basetypeinfos["elements"][0].has_key("elmt_type") and \
   594           "elmt_type" in basetypeinfos["elements"][0] and
   585          basetypeinfos["elements"][0]["elmt_type"]["type"] == SIMPLETYPE:
   595           basetypeinfos["elements"][0]["elmt_type"]["type"] == SIMPLETYPE):
   586         contenttypeinfos = simpleContent.copy()
   596         contenttypeinfos = simpleContent.copy()
   587         contenttypeinfos["base"] = basetypeinfos["elements"][0]["elmt_type"]
   597         contenttypeinfos["base"] = basetypeinfos["elements"][0]["elmt_type"]
   588     else:
   598     else:
   589         raise ValueError("No compatible base type defined for simpleContent!")
   599         raise ValueError("No compatible base type defined for simpleContent!")
   590     contenttypeinfos = CreateSimpleType(factory, attributes, contenttypeinfos)
   600     contenttypeinfos = CreateSimpleType(factory, attributes, contenttypeinfos)
   591     
   601 
   592     simpleContent["elements"] = [{"name": "content", "type": ELEMENT,
   602     simpleContent["elements"] = [{"name": "content", "type": ELEMENT,
   593                                   "elmt_type": contenttypeinfos, "doc": annotations,
   603                                   "elmt_type": contenttypeinfos, "doc": annotations,
   594                                   "minOccurs": 1, "maxOccurs": 1}]
   604                                   "minOccurs": 1, "maxOccurs": 1}]
   595     simpleContent["type"] = "simpleContent"
   605     simpleContent["type"] = "simpleContent"
   596     return simpleContent
   606     return simpleContent
   603     return complexContent
   613     return complexContent
   604 
   614 
   605 
   615 
   606 def ReduceComplexType(factory, attributes, elements):
   616 def ReduceComplexType(factory, attributes, elements):
   607     annotations, children = factory.ReduceElements(elements)
   617     annotations, children = factory.ReduceElements(elements)
   608     
   618 
   609     if len(children) > 0:
   619     if len(children) > 0:
   610         if children[0]["type"] in ["simpleContent", "complexContent"]:
   620         if children[0]["type"] in ["simpleContent", "complexContent"]:
   611             complexType = children[0].copy()
   621             complexType = children[0].copy()
   612             complexType.update(attributes)
   622             complexType.update(attributes)
   613             complexType["type"] = COMPLEXTYPE
   623             complexType["type"] = COMPLEXTYPE
   639                 content = group.copy()
   649                 content = group.copy()
   640                 content["name"] = "content"
   650                 content["name"] = "content"
   641                 complexType["elements"].append(content)
   651                 complexType["elements"].append(content)
   642             elif group["type"] == "group":
   652             elif group["type"] == "group":
   643                 elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP)
   653                 elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP)
   644                 if elmtgroup.has_key("elements"):
   654                 if "elements" in elmtgroup:
   645                     complexType["elements"] = elmtgroup["elements"]
   655                     complexType["elements"] = elmtgroup["elements"]
   646                     complexType["order"] = elmtgroup["order"]
   656                     complexType["order"] = elmtgroup["order"]
   647                 else:
   657                 else:
   648                     content = elmtgroup.copy()
   658                     content = elmtgroup.copy()
   649                     content["name"] = "content"
   659                     content["name"] = "content"
   659 
   669 
   660 
   670 
   661 # Attribute elements
   671 # Attribute elements
   662 
   672 
   663 def ReduceAnyAttribute(factory, attributes, elements):
   673 def ReduceAnyAttribute(factory, attributes, elements):
   664     return {"type" : "anyAttribute"}
   674     return {"type": "anyAttribute"}
   665 
   675 
   666 
   676 
   667 def ReduceAttribute(factory, attributes, elements):
   677 def ReduceAttribute(factory, attributes, elements):
   668     annotations, children = factory.ReduceElements(elements)
   678     annotations, children = factory.ReduceElements(elements)
   669     
   679 
   670     if attributes.has_key("default"):
   680     if "default" in attributes:
   671         if attributes.has_key("fixed"):
   681         if "fixed" in attributes:
   672             raise ValueError("\"default\" and \"fixed\" can't be defined at the same time!")
   682             raise ValueError("\"default\" and \"fixed\" can't be defined at the same time!")
   673         elif attributes.get("use", "optional") != "optional":
   683         elif attributes.get("use", "optional") != "optional":
   674             raise ValueError("if \"default\" present, \"use\" can only have the value \"optional\"!")
   684             raise ValueError("if \"default\" present, \"use\" can only have the value \"optional\"!")
   675     
   685 
   676     attribute = {"type": ATTRIBUTE, "attr_type": attributes.get("type", None), "doc": annotations}
   686     attribute = {"type": ATTRIBUTE, "attr_type": attributes.get("type", None), "doc": annotations}
   677     if len(children) > 0:
   687     if len(children) > 0:
   678         if attribute["attr_type"] is None:
   688         if attribute["attr_type"] is None:
   679             attribute["attr_type"] = children[0]
   689             attribute["attr_type"] = children[0]
   680         else:
   690         else:
   681             raise ValueError("Only one type can be defined for attribute!")
   691             raise ValueError("Only one type can be defined for attribute!")
   682     
   692 
   683     if attributes.has_key("ref"):
   693     if "ref" in attributes:
   684         if attributes.has_key("name"):
   694         if "name" in attributes:
   685             raise ValueError("\"ref\" and \"name\" can't be defined at the same time!")
   695             raise ValueError("\"ref\" and \"name\" can't be defined at the same time!")
   686         elif attributes.has_key("form"):
   696         elif "form" in attributes:
   687             raise ValueError("\"ref\" and \"form\" can't be defined at the same time!")
   697             raise ValueError("\"ref\" and \"form\" can't be defined at the same time!")
   688         elif attribute["attr_type"] is not None:
   698         elif attribute["attr_type"] is not None:
   689             raise ValueError("if \"ref\" is present, no type can be defined!")
   699             raise ValueError("if \"ref\" is present, no type can be defined!")
   690     elif attribute["attr_type"] is None:
   700     elif attribute["attr_type"] is None:
   691         raise ValueError("No type has been defined for attribute \"%s\"!" % attributes["name"])
   701         raise ValueError("No type has been defined for attribute \"%s\"!" % attributes["name"])
   692     
   702 
   693     if attributes.has_key("type"):
   703     if "type" in attributes:
   694         tmp_attrs = attributes.copy()
   704         tmp_attrs = attributes.copy()
   695         tmp_attrs.pop("type")
   705         tmp_attrs.pop("type")
   696         attribute.update(tmp_attrs)
   706         attribute.update(tmp_attrs)
   697     else:
   707     else:
   698         attribute.update(attributes)
   708         attribute.update(attributes)
   699     return attribute
   709     return attribute
   700 
   710 
   701 
   711 
   702 def ReduceAttributeGroup(factory, attributes, elements):
   712 def ReduceAttributeGroup(factory, attributes, elements):
   703     annotations, children = factory.ReduceElements(elements)
   713     annotations, children = factory.ReduceElements(elements)
   704     if attributes.has_key("ref"):
   714     if "ref" in attributes:
   705         return {"type": "attributeGroup", "ref": attributes["ref"], "doc": annotations}
   715         return {"type": "attributeGroup", "ref": attributes["ref"], "doc": annotations}
   706     else:
   716     else:
   707         return {"type": ATTRIBUTESGROUP, "attributes": ExtractAttributes(factory, children), "doc": annotations}
   717         return {"type": ATTRIBUTESGROUP, "attributes": ExtractAttributes(factory, children), "doc": annotations}
   708 
   718 
   709 
   719 
   710 # Elements groups
   720 # Elements groups
   711 
   721 
   712 def ReduceAny(factory, attributes, elements):
   722 def ReduceAny(factory, attributes, elements):
   713     annotations, children = factory.ReduceElements(elements)
   723     annotations, children = factory.ReduceElements(elements)
   714     
   724 
   715     any = {"type": ANY, "doc": annotations}
   725     any = {"type": ANY, "doc": annotations}
   716     any.update(attributes)
   726     any.update(attributes)
   717     return any
   727     return any
   718 
   728 
       
   729 
   719 def ReduceElement(factory, attributes, elements):
   730 def ReduceElement(factory, attributes, elements):
   720     annotations, children = factory.ReduceElements(elements)
   731     annotations, children = factory.ReduceElements(elements)
   721     
   732 
   722     types = []
   733     types = []
   723     constraints = []
   734     constraints = []
   724     for child in children:
   735     for child in children:
   725         if child["type"] == CONSTRAINT:
   736         if child["type"] == CONSTRAINT:
   726             constraints.append(child)
   737             constraints.append(child)
   727         else:
   738         else:
   728             types.append(child)
   739             types.append(child)
   729     
   740 
   730     if attributes.has_key("default") and attributes.has_key("fixed"):
   741     if "default" in attributes and "fixed" in attributes:
   731         raise ValueError("\"default\" and \"fixed\" can't be defined at the same time!")
   742         raise ValueError("\"default\" and \"fixed\" can't be defined at the same time!")
   732     
   743 
   733     if attributes.has_key("ref"):
   744     if "ref" in attributes:
   734         for attr in ["name", "default", "fixed", "form", "block", "type"]:
   745         for attr in ["name", "default", "fixed", "form", "block", "type"]:
   735             if attributes.has_key(attr):
   746             if attr in attributes:
   736                 raise ValueError("\"ref\" and \"%s\" can't be defined at the same time!" % attr)
   747                 raise ValueError("\"ref\" and \"%s\" can't be defined at the same time!" % attr)
   737         if attributes.has_key("nillable"):
   748         if "nillable" in attributes:
   738             raise ValueError("\"ref\" and \"nillable\" can't be defined at the same time!")
   749             raise ValueError("\"ref\" and \"nillable\" can't be defined at the same time!")
   739         if len(types) > 0:
   750         if len(types) > 0:
   740             raise ValueError("No type and no constraints can be defined where \"ref\" is defined!")
   751             raise ValueError("No type and no constraints can be defined where \"ref\" is defined!")
   741     
   752 
   742         infos = factory.FindSchemaElement(attributes["ref"], ELEMENT)
   753         infos = factory.FindSchemaElement(attributes["ref"], ELEMENT)
   743         if infos is not None:
   754         if infos is not None:
   744             element = infos.copy()
   755             element = infos.copy()
   745             element["constraints"] = constraints
   756             element["constraints"] = constraints
   746             element["minOccurs"] = attributes["minOccurs"]
   757             element["minOccurs"] = attributes["minOccurs"]
   747             element["maxOccurs"] = attributes["maxOccurs"]
   758             element["maxOccurs"] = attributes["maxOccurs"]
   748             return element
   759             return element
   749         else:
   760         else:
   750             raise ValueError("\"%s\" base type isn't defined or circular referenced!" % name)
   761             raise ValueError("\"%s\" base type isn't defined or circular referenced!" % name)
   751     
   762 
   752     elif attributes.has_key("name"):
   763     elif "name" in attributes:
   753         element = {"type": ELEMENT, "elmt_type": attributes.get("type", None), "constraints": constraints, "doc": annotations}
   764         element = {"type": ELEMENT, "elmt_type": attributes.get("type", None), "constraints": constraints, "doc": annotations}
   754         if len(types) > 0:
   765         if len(types) > 0:
   755             if element["elmt_type"] is None:
   766             if element["elmt_type"] is None:
   756                 element["elmt_type"] = types[0]
   767                 element["elmt_type"] = types[0]
   757             else:
   768             else:
   758                 raise ValueError("Only one type can be defined for attribute!")
   769                 raise ValueError("Only one type can be defined for attribute!")
   759         elif element["elmt_type"] is None:
   770         elif element["elmt_type"] is None:
   760             element["elmt_type"] = "tag"
   771             element["elmt_type"] = "tag"
   761             element["type"] = TAG
   772             element["type"] = TAG
   762         
   773 
   763         if attributes.has_key("type"):
   774         if "type" in attributes:
   764             tmp_attrs = attributes.copy()
   775             tmp_attrs = attributes.copy()
   765             tmp_attrs.pop("type")
   776             tmp_attrs.pop("type")
   766             element.update(tmp_attrs)
   777             element.update(tmp_attrs)
   767         else:
   778         else:
   768             element.update(attributes)
   779             element.update(attributes)
   769         return element
   780         return element
   770     else:
   781     else:
   771         raise ValueError("\"Element\" must have at least a \"ref\" or a \"name\" defined!")
   782         raise ValueError("\"Element\" must have at least a \"ref\" or a \"name\" defined!")
   772 
   783 
       
   784 
   773 def ReduceAll(factory, attributes, elements):
   785 def ReduceAll(factory, attributes, elements):
   774     annotations, children = factory.ReduceElements(elements)
   786     annotations, children = factory.ReduceElements(elements)
   775     
   787 
   776     for child in children:
   788     for child in children:
   777         if children["maxOccurs"] == "unbounded" or children["maxOccurs"] > 1:
   789         if children["maxOccurs"] == "unbounded" or children["maxOccurs"] > 1:
   778             raise ValueError("\"all\" item can't have \"maxOccurs\" attribute greater than 1!")
   790             raise ValueError("\"all\" item can't have \"maxOccurs\" attribute greater than 1!")
   779     
   791 
   780     return {"type": "all", "elements": children, "minOccurs": attributes["minOccurs"],
   792     return {"type": "all", "elements": children, "minOccurs": attributes["minOccurs"],
   781             "maxOccurs": attributes["maxOccurs"], "order": False, "doc": annotations}
   793             "maxOccurs": attributes["maxOccurs"], "order": False, "doc": annotations}
   782 
   794 
   783 
   795 
   784 def ReduceChoice(factory, attributes, elements):
   796 def ReduceChoice(factory, attributes, elements):
   785     annotations, children = factory.ReduceElements(elements)
   797     annotations, children = factory.ReduceElements(elements)
   786     
   798 
   787     choices = []
   799     choices = []
   788     for child in children:
   800     for child in children:
   789         if child["type"] in [ELEMENT, ANY, TAG]:
   801         if child["type"] in [ELEMENT, ANY, TAG]:
   790             choices.append(child)
   802             choices.append(child)
   791         elif child["type"] == "sequence":
   803         elif child["type"] == "sequence":
   792             child["minOccurs"] = child["maxOccurs"] = 1
   804             child["minOccurs"] = child["maxOccurs"] = 1
   793             choices.append(child)
   805             choices.append(child)
   794             #raise ValueError("\"sequence\" in \"choice\" is not supported. Create instead a new complex type!")
   806             # raise ValueError("\"sequence\" in \"choice\" is not supported. Create instead a new complex type!")
   795         elif child["type"] == CHOICE:
   807         elif child["type"] == CHOICE:
   796             choices.extend(child["choices"])
   808             choices.extend(child["choices"])
   797         elif child["type"] == "group":
   809         elif child["type"] == "group":
   798             elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP) 
   810             elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP)
   799             if not elmtgroup.has_key("choices"):
   811             if "choices" not in elmtgroup:
   800                 raise ValueError("Only group composed of \"choice\" can be referenced in \"choice\" element!")
   812                 raise ValueError("Only group composed of \"choice\" can be referenced in \"choice\" element!")
   801             choices_tmp = []
   813             choices_tmp = []
   802             for choice in elmtgroup["choices"]:
   814             for choice in elmtgroup["choices"]:
   803                 if not isinstance(choice["elmt_type"], (UnicodeType, StringType)) and choice["elmt_type"]["type"] == COMPLEXTYPE:
   815                 if not isinstance(choice["elmt_type"], (UnicodeType, StringType)) and choice["elmt_type"]["type"] == COMPLEXTYPE:
   804                     elmt_type = "%s_%s" % (elmtgroup["name"], choice["name"])
   816                     elmt_type = "%s_%s" % (elmtgroup["name"], choice["name"])
   808                     new_choice["elmt_type"] = elmt_type
   820                     new_choice["elmt_type"] = elmt_type
   809                     choices_tmp.append(new_choice)
   821                     choices_tmp.append(new_choice)
   810                 else:
   822                 else:
   811                     choices_tmp.append(choice)
   823                     choices_tmp.append(choice)
   812             choices.extend(choices_tmp)
   824             choices.extend(choices_tmp)
   813     
   825 
   814     for choice in choices:
   826     for choice in choices:
   815         attributes["minOccurs"] = min(attributes["minOccurs"], choice["minOccurs"])
   827         attributes["minOccurs"] = min(attributes["minOccurs"], choice["minOccurs"])
   816         choice["minOccurs"] = 1
   828         choice["minOccurs"] = 1
   817     
   829 
   818     return {"type": CHOICE, "choices": choices, "minOccurs": attributes["minOccurs"],
   830     return {"type": CHOICE, "choices": choices, "minOccurs": attributes["minOccurs"],
   819             "maxOccurs": attributes["maxOccurs"], "doc": annotations}
   831             "maxOccurs": attributes["maxOccurs"], "doc": annotations}
   820 
   832 
   821 
   833 
   822 def ReduceSequence(factory, attributes, elements):
   834 def ReduceSequence(factory, attributes, elements):
   823     annotations, children = factory.ReduceElements(elements)
   835     annotations, children = factory.ReduceElements(elements)
   824     
   836 
   825     sequence = []
   837     sequence = []
   826     for child in children:
   838     for child in children:
   827         if child["type"] in [ELEMENT, ANY, TAG, CHOICE]:
   839         if child["type"] in [ELEMENT, ANY, TAG, CHOICE]:
   828             sequence.append(child)
   840             sequence.append(child)
   829         elif child["type"] == "sequence":
   841         elif child["type"] == "sequence":
   830             sequence.extend(child["elements"])
   842             sequence.extend(child["elements"])
   831         elif child["type"] == "group":
   843         elif child["type"] == "group":
   832             elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP)
   844             elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP)
   833             if not elmtgroup.has_key("elements") or not elmtgroup["order"]:
   845             if "elements" not in elmtgroup or not elmtgroup["order"]:
   834                 raise ValueError("Only group composed of \"sequence\" can be referenced in \"sequence\" element!")
   846                 raise ValueError("Only group composed of \"sequence\" can be referenced in \"sequence\" element!")
   835             elements_tmp = []
   847             elements_tmp = []
   836             for element in elmtgroup["elements"]:
   848             for element in elmtgroup["elements"]:
   837                 if not isinstance(element["elmt_type"], (UnicodeType, StringType)) and element["elmt_type"]["type"] == COMPLEXTYPE:
   849                 if not isinstance(element["elmt_type"], (UnicodeType, StringType)) and element["elmt_type"]["type"] == COMPLEXTYPE:
   838                     elmt_type = "%s_%s"%(elmtgroup["name"], element["name"])
   850                     elmt_type = "%s_%s" % (elmtgroup["name"], element["name"])
   839                     if factory.TargetNamespace is not None:
   851                     if factory.TargetNamespace is not None:
   840                         elmt_type = "%s:%s" % (factory.TargetNamespace, elmt_type)
   852                         elmt_type = "%s:%s" % (factory.TargetNamespace, elmt_type)
   841                     new_element = element.copy()
   853                     new_element = element.copy()
   842                     new_element["elmt_type"] = elmt_type
   854                     new_element["elmt_type"] = elmt_type
   843                     elements_tmp.append(new_element)
   855                     elements_tmp.append(new_element)
   844                 else:
   856                 else:
   845                     elements_tmp.append(element)
   857                     elements_tmp.append(element)
   846             sequence.extend(elements_tmp)
   858             sequence.extend(elements_tmp)
   847             
   859 
   848     return {"type": "sequence", "elements": sequence, "minOccurs": attributes["minOccurs"],
   860     return {"type": "sequence", "elements": sequence, "minOccurs": attributes["minOccurs"],
   849             "maxOccurs": attributes["maxOccurs"], "order": True, "doc": annotations}
   861             "maxOccurs": attributes["maxOccurs"], "order": True, "doc": annotations}
   850     
   862 
   851     
   863 
   852 def ReduceGroup(factory, attributes, elements):
   864 def ReduceGroup(factory, attributes, elements):
   853     annotations, children = factory.ReduceElements(elements)
   865     annotations, children = factory.ReduceElements(elements)
   854     
   866 
   855     if attributes.has_key("ref"):
   867     if "ref" in attributes:
   856         return {"type": "group", "ref": attributes["ref"], "doc": annotations}
   868         return {"type": "group", "ref": attributes["ref"], "doc": annotations}
   857     else:
   869     else:
   858         element = children[0]
   870         element = children[0]
   859         group = {"type": ELEMENTSGROUP, "doc": annotations}
   871         group = {"type": ELEMENTSGROUP, "doc": annotations}
   860         if element["type"] == CHOICE:
   872         if element["type"] == CHOICE:
   864         group.update(attributes)
   876         group.update(attributes)
   865         return group
   877         return group
   866 
   878 
   867 # Constraint elements
   879 # Constraint elements
   868 
   880 
       
   881 
   869 def ReduceUnique(factory, attributes, elements):
   882 def ReduceUnique(factory, attributes, elements):
   870     annotations, children = factory.ReduceElements(elements)
   883     annotations, children = factory.ReduceElements(elements)
   871     
   884 
   872     unique = {"type": CONSTRAINT, "const_type": "unique", "selector": children[0], "fields": children[1:]}
   885     unique = {"type": CONSTRAINT, "const_type": "unique", "selector": children[0], "fields": children[1:]}
   873     unique.update(attributes)
   886     unique.update(attributes)
   874     return unique
   887     return unique
   875     
   888 
       
   889 
   876 def ReduceKey(factory, attributes, elements):
   890 def ReduceKey(factory, attributes, elements):
   877     annotations, children = factory.ReduceElements(elements)
   891     annotations, children = factory.ReduceElements(elements)
   878     
   892 
   879     key = {"type": CONSTRAINT, "const_type": "key", "selector": children[0], "fields": children[1:]}
   893     key = {"type": CONSTRAINT, "const_type": "key", "selector": children[0], "fields": children[1:]}
   880     key.update(attributes)
   894     key.update(attributes)
   881     return key
   895     return key
   882 
   896 
       
   897 
   883 def ReduceKeyRef(factory, attributes, elements):
   898 def ReduceKeyRef(factory, attributes, elements):
   884     annotations, children = factory.ReduceElements(elements)
   899     annotations, children = factory.ReduceElements(elements)
   885     
   900 
   886     keyref = {"type": CONSTRAINT, "const_type": "keyref", "selector": children[0], "fields": children[1:]}
   901     keyref = {"type": CONSTRAINT, "const_type": "keyref", "selector": children[0], "fields": children[1:]}
   887     keyref.update(attributes)
   902     keyref.update(attributes)
   888     return keyref
   903     return keyref
   889     
   904 
       
   905 
   890 def ReduceSelector(factory, attributes, elements):
   906 def ReduceSelector(factory, attributes, elements):
   891     annotations, children = factory.ReduceElements(elements)
   907     annotations, children = factory.ReduceElements(elements)
   892     
   908 
   893     selector = {"type": CONSTRAINT, "const_type": "selector"}
   909     selector = {"type": CONSTRAINT, "const_type": "selector"}
   894     selector.update(attributes)
   910     selector.update(attributes)
   895     return selector
   911     return selector
   896 
   912 
       
   913 
   897 def ReduceField(factory, attributes, elements):
   914 def ReduceField(factory, attributes, elements):
   898     annotations, children = factory.ReduceElements(elements)
   915     annotations, children = factory.ReduceElements(elements)
   899     
   916 
   900     field = {"type": CONSTRAINT, "const_type": "field"}
   917     field = {"type": CONSTRAINT, "const_type": "field"}
   901     field.update(attributes)
   918     field.update(attributes)
   902     return field
   919     return field
   903     
   920 
   904 
   921 
   905 # Inclusion elements
   922 # Inclusion elements
   906 
   923 
   907 def ReduceImport(factory, attributes, elements):
   924 def ReduceImport(factory, attributes, elements):
   908     annotations, children = factory.ReduceElements(elements)
   925     annotations, children = factory.ReduceElements(elements)
   909     raise ValueError("\"import\" element isn't supported yet!")
   926     raise ValueError("\"import\" element isn't supported yet!")
   910 
   927 
       
   928 
   911 def ReduceInclude(factory, attributes, elements):
   929 def ReduceInclude(factory, attributes, elements):
   912     annotations, children = factory.ReduceElements(elements)
   930     annotations, children = factory.ReduceElements(elements)
   913     
   931 
   914     if factory.FileName is None:
   932     if factory.FileName is None:
   915         raise ValueError("Include in XSD string not yet supported")
   933         raise ValueError("Include in XSD string not yet supported")
   916     filepath = attributes["schemaLocation"]
   934     filepath = attributes["schemaLocation"]
   917     if filepath is not None and not os.path.exists(filepath):
   935     if filepath is not None and not os.path.exists(filepath):
   918         filepath = os.path.join(factory.BaseFolder, filepath)
   936         filepath = os.path.join(factory.BaseFolder, filepath)
   920             raise ValueError("No file '%s' found for include" % attributes["schemaLocation"])
   938             raise ValueError("No file '%s' found for include" % attributes["schemaLocation"])
   921     xsdfile = open(filepath, 'r')
   939     xsdfile = open(filepath, 'r')
   922     include_factory = XSDClassFactory(minidom.parse(xsdfile), filepath)
   940     include_factory = XSDClassFactory(minidom.parse(xsdfile), filepath)
   923     xsdfile.close()
   941     xsdfile.close()
   924     include_factory.CreateClasses()
   942     include_factory.CreateClasses()
   925     
   943 
   926     if factory.TargetNamespace == include_factory.TargetNamespace:
   944     if factory.TargetNamespace == include_factory.TargetNamespace:
   927         factory.Namespaces[factory.TargetNamespace].update(include_factory.Namespaces[include_factory.TargetNamespace])
   945         factory.Namespaces[factory.TargetNamespace].update(include_factory.Namespaces[include_factory.TargetNamespace])
   928     else:
   946     else:
   929         factory.Namespaces[include_factory.TargetNamespace] = include_factory.Namespaces[include_factory.TargetNamespace]
   947         factory.Namespaces[include_factory.TargetNamespace] = include_factory.Namespaces[include_factory.TargetNamespace]
   930     factory.ComputedClasses.update(include_factory.ComputedClasses)
   948     factory.ComputedClasses.update(include_factory.ComputedClasses)
   931     factory.ComputedClassesLookUp.update(include_factory.ComputedClassesLookUp)
   949     factory.ComputedClassesLookUp.update(include_factory.ComputedClassesLookUp)
   932     factory.EquivalentClassesParent.update(include_factory.EquivalentClassesParent)
   950     factory.EquivalentClassesParent.update(include_factory.EquivalentClassesParent)
   933     return None
   951     return None
   934     
   952 
       
   953 
   935 def ReduceRedefine(factory, attributes, elements):
   954 def ReduceRedefine(factory, attributes, elements):
   936     annotations, children = factory.ReduceElements(elements)
   955     annotations, children = factory.ReduceElements(elements)
   937     raise ValueError("\"redefine\" element isn't supported yet!")
   956     raise ValueError("\"redefine\" element isn't supported yet!")
   938 
   957 
   939 
   958 
   942 def ReduceSchema(factory, attributes, elements):
   961 def ReduceSchema(factory, attributes, elements):
   943     factory.AttributeFormDefault = attributes["attributeFormDefault"]
   962     factory.AttributeFormDefault = attributes["attributeFormDefault"]
   944     factory.ElementFormDefault = attributes["elementFormDefault"]
   963     factory.ElementFormDefault = attributes["elementFormDefault"]
   945     factory.BlockDefault = attributes["blockDefault"]
   964     factory.BlockDefault = attributes["blockDefault"]
   946     factory.FinalDefault = attributes["finalDefault"]
   965     factory.FinalDefault = attributes["finalDefault"]
   947     
   966 
   948     targetNamespace = attributes.get("targetNamespace", None)
   967     targetNamespace = attributes.get("targetNamespace", None)
   949     factory.TargetNamespace = factory.DefinedNamespaces.get(targetNamespace, None)
   968     factory.TargetNamespace = factory.DefinedNamespaces.get(targetNamespace, None)
   950     if factory.TargetNamespace is not None:
   969     if factory.TargetNamespace is not None:
   951         factory.etreeNamespaceFormat = "{%s}%%s" % targetNamespace
   970         factory.etreeNamespaceFormat = "{%s}%%s" % targetNamespace
   952     factory.Namespaces[factory.TargetNamespace] = {}
   971     factory.Namespaces[factory.TargetNamespace] = {}
   953     
   972 
   954     annotations, children = factory.ReduceElements(elements, True)
   973     annotations, children = factory.ReduceElements(elements, True)
   955     
   974 
   956     for child in children:
   975     for child in children:
   957         if child.has_key("name"):
   976         if "name" in child:
   958             infos = factory.GetQualifiedNameInfos(child["name"], factory.TargetNamespace, True)
   977             infos = factory.GetQualifiedNameInfos(child["name"], factory.TargetNamespace, True)
   959             if infos is None:
   978             if infos is None:
   960                 factory.Namespaces[factory.TargetNamespace][child["name"]] = child
   979                 factory.Namespaces[factory.TargetNamespace][child["name"]] = child
   961             elif not CompareSchema(infos, child):
   980             elif not CompareSchema(infos, child):
   962                 raise ValueError("\"%s\" is defined twice in targetNamespace!" % child["name"])
   981                 raise ValueError("\"%s\" is defined twice in targetNamespace!" % child["name"])
       
   982 
   963 
   983 
   964 def CompareSchema(schema, reference):
   984 def CompareSchema(schema, reference):
   965     if isinstance(schema, ListType):
   985     if isinstance(schema, ListType):
   966         if not isinstance(reference, ListType) or len(schema) != len(reference):
   986         if not isinstance(reference, ListType) or len(schema) != len(reference):
   967             return False
   987             return False
   973     elif isinstance(schema, DictType):
   993     elif isinstance(schema, DictType):
   974         if not isinstance(reference, DictType) or len(schema) != len(reference):
   994         if not isinstance(reference, DictType) or len(schema) != len(reference):
   975             return False
   995             return False
   976         for name, value in schema.items():
   996         for name, value in schema.items():
   977             ref_value = reference.get(name, None)
   997             ref_value = reference.get(name, None)
   978             if ref_value is None and value != None:
   998             if ref_value is None and value is not None:
   979                 return False
   999                 return False
   980             result = CompareSchema(value, ref_value)
  1000             result = CompareSchema(value, ref_value)
   981             if not result:
  1001             if not result:
   982                 return result
  1002                 return result
   983         return True
  1003         return True
   985         if not isinstance(reference, FunctionType) or schema.__name__ != reference.__name__:
  1005         if not isinstance(reference, FunctionType) or schema.__name__ != reference.__name__:
   986             return False
  1006             return False
   987         else:
  1007         else:
   988             return True
  1008             return True
   989     return schema == reference
  1009     return schema == reference
   990     
  1010 
   991 #-------------------------------------------------------------------------------
  1011 
       
  1012 # -------------------------------------------------------------------------------
   992 #                       Base class for XSD schema extraction
  1013 #                       Base class for XSD schema extraction
   993 #-------------------------------------------------------------------------------
  1014 # -------------------------------------------------------------------------------
   994 
  1015 
   995 
  1016 
   996 class XSDClassFactory(ClassFactory):
  1017 class XSDClassFactory(ClassFactory):
   997 
  1018 
   998     def __init__(self, document, filepath=None, debug=False):
  1019     def __init__(self, document, filepath=None, debug=False):
   999         ClassFactory.__init__(self, document, filepath, debug)
  1020         ClassFactory.__init__(self, document, filepath, debug)
  1000         self.Namespaces["xml"] = {
  1021         self.Namespaces["xml"] = {
  1001             "lang": {
  1022             "lang": {
  1002                 "type": SYNTAXATTRIBUTE, 
  1023                 "type": SYNTAXATTRIBUTE,
  1003                 "extract": {
  1024                 "extract": {
  1004                     "default": GenerateModelNameExtraction("lang", LANGUAGE_model)
  1025                     "default": GenerateModelNameExtraction("lang", LANGUAGE_model)
  1005                 }
  1026                 }
  1006             }
  1027             }
  1007         }
  1028         }
  1008         self.Namespaces["xsi"] = {
  1029         self.Namespaces["xsi"] = {
  1009             "noNamespaceSchemaLocation": {
  1030             "noNamespaceSchemaLocation": {
  1010                 "type": SYNTAXATTRIBUTE, 
  1031                 "type": SYNTAXATTRIBUTE,
  1011                 "extract": {
  1032                 "extract": {
  1012                     "default": NotSupportedYet("noNamespaceSchemaLocation")
  1033                     "default": NotSupportedYet("noNamespaceSchemaLocation")
  1013                 }
  1034                 }
  1014             },
  1035             },
  1015             "nil": {
  1036             "nil": {
  1016                 "type": SYNTAXATTRIBUTE, 
  1037                 "type": SYNTAXATTRIBUTE,
  1017                 "extract": {
  1038                 "extract": {
  1018                     "default": NotSupportedYet("nil")
  1039                     "default": NotSupportedYet("nil")
  1019                 }
  1040                 }
  1020             },
  1041             },
  1021             "schemaLocation": {
  1042             "schemaLocation": {
  1022                 "type": SYNTAXATTRIBUTE, 
  1043                 "type": SYNTAXATTRIBUTE,
  1023                 "extract": {
  1044                 "extract": {
  1024                     "default": NotSupportedYet("schemaLocation")
  1045                     "default": NotSupportedYet("schemaLocation")
  1025                 }
  1046                 }
  1026             },
  1047             },
  1027             "type": {
  1048             "type": {
  1028                 "type": SYNTAXATTRIBUTE, 
  1049                 "type": SYNTAXATTRIBUTE,
  1029                 "extract": {
  1050                 "extract": {
  1030                     "default": NotSupportedYet("type")
  1051                     "default": NotSupportedYet("type")
  1031                 }
  1052                 }
  1032             }
  1053             }
  1033         }
  1054         }
  1034         
  1055 
  1035     def ParseSchema(self):
  1056     def ParseSchema(self):
  1036         for child in self.Document.childNodes:
  1057         for child in self.Document.childNodes:
  1037             if child.nodeType == self.Document.ELEMENT_NODE:
  1058             if child.nodeType == self.Document.ELEMENT_NODE:
  1038                 schema = child
  1059                 schema = child
  1039                 break
  1060                 break
  1065             else:
  1086             else:
  1066                 raise ValueError("\"%s\" isn't defined!" % element_name)
  1087                 raise ValueError("\"%s\" isn't defined!" % element_name)
  1067         if element_type is not None and element["type"] != element_type:
  1088         if element_type is not None and element["type"] != element_type:
  1068             raise ValueError("\"%s\" isn't of the expected type!" % element_name)
  1089             raise ValueError("\"%s\" isn't of the expected type!" % element_name)
  1069         return element
  1090         return element
  1070     
  1091 
  1071     def CreateSchemaElement(self, element_name, element_type):
  1092     def CreateSchemaElement(self, element_name, element_type):
  1072         for type, attributes, elements in self.Schema[2]:
  1093         for type, attributes, elements in self.Schema[2]:
  1073             namespace, name = DecomposeQualifiedName(type)
  1094             namespace, name = DecomposeQualifiedName(type)
  1074             if attributes.get("name", None) == element_name:
  1095             if attributes.get("name", None) == element_name:
  1075                 element_infos = None
  1096                 element_infos = None
  1088                 if element_infos is not None:
  1109                 if element_infos is not None:
  1089                     self.Namespaces[self.TargetNamespace][element_name] = element_infos
  1110                     self.Namespaces[self.TargetNamespace][element_name] = element_infos
  1090                     return element_infos
  1111                     return element_infos
  1091         return None
  1112         return None
  1092 
  1113 
  1093 """
  1114 
  1094 This function opens the xsd file and generate a xml parser with class lookup from 
       
  1095 the xml tree
       
  1096 """
       
  1097 def GenerateParserFromXSD(filepath):
  1115 def GenerateParserFromXSD(filepath):
       
  1116     """
       
  1117     This function opens the xsd file and generate a xml parser with class lookup from
       
  1118     the xml tree
       
  1119     """
  1098     xsdfile = open(filepath, 'r')
  1120     xsdfile = open(filepath, 'r')
  1099     xsdstring = xsdfile.read()
  1121     xsdstring = xsdfile.read()
  1100     xsdfile.close()
  1122     xsdfile.close()
  1101     cwd = os.getcwd()
  1123     cwd = os.getcwd()
  1102     os.chdir(os.path.dirname(filepath))
  1124     os.chdir(os.path.dirname(filepath))
  1103     parser = GenerateParser(XSDClassFactory(minidom.parseString(xsdstring), filepath), xsdstring)
  1125     parser = GenerateParser(XSDClassFactory(minidom.parseString(xsdstring), filepath), xsdstring)
  1104     os.chdir(cwd)
  1126     os.chdir(cwd)
  1105     return parser
  1127     return parser
  1106 
  1128 
  1107 """
  1129 
  1108 This function generate a xml from the xsd given as a string
       
  1109 """
       
  1110 def GenerateParserFromXSDstring(xsdstring):
  1130 def GenerateParserFromXSDstring(xsdstring):
       
  1131     """
       
  1132     This function generate a xml from the xsd given as a string
       
  1133     """
  1111     return GenerateParser(XSDClassFactory(minidom.parseString(xsdstring)), xsdstring)
  1134     return GenerateParser(XSDClassFactory(minidom.parseString(xsdstring)), xsdstring)
  1112 
  1135 
  1113 
  1136 
  1114 #-------------------------------------------------------------------------------
  1137 # -------------------------------------------------------------------------------
  1115 #                           XSD schema syntax elements
  1138 #                           XSD schema syntax elements
  1116 #-------------------------------------------------------------------------------
  1139 # -------------------------------------------------------------------------------
       
  1140 
  1117 
  1141 
  1118 XSD_NAMESPACE = {
  1142 XSD_NAMESPACE = {
  1119 
  1143 
  1120 #-------------------------------------------------------------------------------
  1144     # -------------------------------------------------------------------------------
  1121 #                           Syntax elements definition
  1145     #                           Syntax elements definition
  1122 #-------------------------------------------------------------------------------
  1146     # -------------------------------------------------------------------------------
  1123 
  1147 
  1124     "all": {"struct": """
  1148     "all": {
       
  1149         "struct": """
  1125         <all
  1150         <all
  1126           id = ID
  1151           id = ID
  1127           maxOccurs = 1 : 1
  1152           maxOccurs = 1 : 1
  1128           minOccurs = (0 | 1) : 1
  1153           minOccurs = (0 | 1) : 1
  1129           {any attributes with non-schema namespace . . .}>
  1154           {any attributes with non-schema namespace . . .}>
  1130           Content: (annotation?, element*)
  1155           Content: (annotation?, element*)
  1131         </all>""",
  1156         </all>""",
  1132         "type": SYNTAXELEMENT, 
  1157         "type": SYNTAXELEMENT,
  1133         "extract": {
  1158         "extract": {
  1134             "default": GenerateElement("all", ["id", "maxOccurs", "minOccurs"], 
  1159             "default": GenerateElement(
       
  1160                 "all", ["id", "maxOccurs", "minOccurs"],
  1135                 re.compile("((?:annotation )?(?:element )*)"))
  1161                 re.compile("((?:annotation )?(?:element )*)"))
  1136         },
  1162         },
  1137         "reduce": ReduceAll
  1163         "reduce": ReduceAll
  1138     },
  1164     },
  1139 
  1165 
  1140     "annotation": {"struct": """
  1166     "annotation": {
       
  1167         "struct": """
  1141         <annotation
  1168         <annotation
  1142           id = ID
  1169           id = ID
  1143           {any attributes with non-schema namespace . . .}>
  1170           {any attributes with non-schema namespace . . .}>
  1144           Content: (appinfo | documentation)*
  1171           Content: (appinfo | documentation)*
  1145         </annotation>""",
  1172         </annotation>""",
  1146         "type": SYNTAXELEMENT, 
  1173         "type": SYNTAXELEMENT,
  1147         "extract": {
  1174         "extract": {
  1148             "default": GenerateElement("annotation", ["id"], 
  1175             "default": GenerateElement(
       
  1176                 "annotation", ["id"],
  1149                 re.compile("((?:app_info |documentation )*)"))
  1177                 re.compile("((?:app_info |documentation )*)"))
  1150         },
  1178         },
  1151         "reduce": ReduceAnnotation
  1179         "reduce": ReduceAnnotation
  1152     },
  1180     },
  1153 
  1181 
  1154     "any": {"struct": """
  1182     "any": {
       
  1183         "struct": """
  1155         <any
  1184         <any
  1156           id = ID
  1185           id = ID
  1157           maxOccurs = (nonNegativeInteger | unbounded)  : 1
  1186           maxOccurs = (nonNegativeInteger | unbounded)  : 1
  1158           minOccurs = nonNegativeInteger : 1
  1187           minOccurs = nonNegativeInteger : 1
  1159           namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) )  : ##any
  1188           namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) )  : ##any
  1160           processContents = (lax | skip | strict) : strict
  1189           processContents = (lax | skip | strict) : strict
  1161           {any attributes with non-schema namespace . . .}>
  1190           {any attributes with non-schema namespace . . .}>
  1162           Content: (annotation?)
  1191           Content: (annotation?)
  1163         </any>""",
  1192         </any>""",
  1164         "type": SYNTAXELEMENT, 
  1193         "type": SYNTAXELEMENT,
  1165         "extract": {
  1194         "extract": {
  1166             "default": GenerateElement("any", 
  1195             "default": GenerateElement(
  1167                 ["id", "maxOccurs", "minOccurs", "namespace", "processContents"], 
  1196                 "any",
       
  1197                 ["id", "maxOccurs", "minOccurs", "namespace", "processContents"],
  1168                 re.compile("((?:annotation )?(?:simpleType )*)"))
  1198                 re.compile("((?:annotation )?(?:simpleType )*)"))
  1169         },
  1199         },
  1170         "reduce": ReduceAny
  1200         "reduce": ReduceAny
  1171     },
  1201     },
  1172 
  1202 
  1173     "anyAttribute": {"struct": """
  1203     "anyAttribute": {
       
  1204         "struct": """
  1174         <anyAttribute
  1205         <anyAttribute
  1175           id = ID
  1206           id = ID
  1176           namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) )  : ##any
  1207           namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) )  : ##any
  1177           processContents = (lax | skip | strict) : strict
  1208           processContents = (lax | skip | strict) : strict
  1178           {any attributes with non-schema namespace . . .}>
  1209           {any attributes with non-schema namespace . . .}>
  1179           Content: (annotation?)
  1210           Content: (annotation?)
  1180         </anyAttribute>""",
  1211         </anyAttribute>""",
  1181         "type": SYNTAXELEMENT, 
  1212         "type": SYNTAXELEMENT,
  1182         "extract": {
  1213         "extract": {
  1183             "default": GenerateElement("anyAttribute",
  1214             "default": GenerateElement(
  1184                 ["id", "namespace", "processContents"], ONLY_ANNOTATION)
  1215                 "anyAttribute", ["id", "namespace", "processContents"], ONLY_ANNOTATION)
  1185         },
  1216         },
  1186         "reduce": ReduceAnyAttribute
  1217         "reduce": ReduceAnyAttribute
  1187     },
  1218     },
  1188 
  1219 
  1189     "appinfo": {"struct": """
  1220     "appinfo": {
       
  1221         "struct": """
  1190         <appinfo
  1222         <appinfo
  1191           source = anyURI
  1223           source = anyURI
  1192           {any attributes with non-schema namespace . . .}>
  1224           {any attributes with non-schema namespace . . .}>
  1193           Content: ({any})*
  1225           Content: ({any})*
  1194         </appinfo>""",
  1226         </appinfo>""",
  1195         "type": SYNTAXELEMENT, 
  1227         "type": SYNTAXELEMENT,
  1196         "extract": {
  1228         "extract": {
  1197             "default": GenerateElement("appinfo", ["source"], re.compile("(.*)"), True)
  1229             "default": GenerateElement("appinfo", ["source"], re.compile("(.*)"), True)
  1198         },
  1230         },
  1199         "reduce": ReduceAppInfo
  1231         "reduce": ReduceAppInfo
  1200     },
  1232     },
  1201 
  1233 
  1202     "attribute": {"struct": """
  1234     "attribute": {
       
  1235         "struct": """
  1203         <attribute
  1236         <attribute
  1204           default = string
  1237           default = string
  1205           fixed = string
  1238           fixed = string
  1206           form = (qualified | unqualified)
  1239           form = (qualified | unqualified)
  1207           id = ID
  1240           id = ID
  1210           type = QName
  1243           type = QName
  1211           use = (optional | prohibited | required) : optional
  1244           use = (optional | prohibited | required) : optional
  1212           {any attributes with non-schema namespace . . .}>
  1245           {any attributes with non-schema namespace . . .}>
  1213           Content: (annotation?, simpleType?)
  1246           Content: (annotation?, simpleType?)
  1214         </attribute>""",
  1247         </attribute>""",
  1215         "type": SYNTAXELEMENT, 
  1248         "type": SYNTAXELEMENT,
  1216         "extract": {
  1249         "extract": {
  1217             "default": GenerateElement("attribute", 
  1250             "default": GenerateElement(
  1218                 ["default", "fixed", "form", "id", "name", "ref", "type", "use"], 
  1251                 "attribute",
       
  1252                 ["default", "fixed", "form", "id", "name", "ref", "type", "use"],
  1219                 re.compile("((?:annotation )?(?:simpleType )?)")),
  1253                 re.compile("((?:annotation )?(?:simpleType )?)")),
  1220             "schema": GenerateElement("attribute", 
  1254             "schema": GenerateElement(
  1221                 ["default", "fixed", "form", "id", "name", "type"], 
  1255                 "attribute",
       
  1256                 ["default", "fixed", "form", "id", "name", "type"],
  1222                 re.compile("((?:annotation )?(?:simpleType )?)"))
  1257                 re.compile("((?:annotation )?(?:simpleType )?)"))
  1223         },
  1258         },
  1224         "reduce": ReduceAttribute
  1259         "reduce": ReduceAttribute
  1225     },
  1260     },
  1226 
  1261 
  1227     "attributeGroup": {"struct": """
  1262     "attributeGroup": {
       
  1263         "struct": """
  1228         <attributeGroup
  1264         <attributeGroup
  1229           id = ID
  1265           id = ID
  1230           name = NCName
  1266           name = NCName
  1231           ref = QName
  1267           ref = QName
  1232           {any attributes with non-schema namespace . . .}>
  1268           {any attributes with non-schema namespace . . .}>
  1233           Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
  1269           Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
  1234         </attributeGroup>""",
  1270         </attributeGroup>""",
  1235         "type": SYNTAXELEMENT, 
  1271         "type": SYNTAXELEMENT,
  1236         "extract": {
  1272         "extract": {
  1237             "default": GenerateElement("attributeGroup", 
  1273             "default": GenerateElement(
       
  1274                 "attributeGroup",
  1238                 ["id", "ref"], ONLY_ANNOTATION),
  1275                 ["id", "ref"], ONLY_ANNOTATION),
  1239             "schema": GenerateElement("attributeGroup",
  1276             "schema": GenerateElement(
  1240                 ["id", "name"], 
  1277                 "attributeGroup",
       
  1278                 ["id", "name"],
  1241                 re.compile("((?:annotation )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))"))
  1279                 re.compile("((?:annotation )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))"))
  1242         },
  1280         },
  1243         "reduce": ReduceAttributeGroup
  1281         "reduce": ReduceAttributeGroup
  1244     },
  1282     },
  1245 
  1283 
  1246     "choice": {"struct": """
  1284     "choice": {
       
  1285         "struct": """
  1247         <choice
  1286         <choice
  1248           id = ID
  1287           id = ID
  1249           maxOccurs = (nonNegativeInteger | unbounded)  : 1
  1288           maxOccurs = (nonNegativeInteger | unbounded)  : 1
  1250           minOccurs = nonNegativeInteger : 1
  1289           minOccurs = nonNegativeInteger : 1
  1251           {any attributes with non-schema namespace . . .}>
  1290           {any attributes with non-schema namespace . . .}>
  1252           Content: (annotation?, (element | group | choice | sequence | any)*)
  1291           Content: (annotation?, (element | group | choice | sequence | any)*)
  1253         </choice>""",
  1292         </choice>""",
  1254         "type": SYNTAXELEMENT, 
  1293         "type": SYNTAXELEMENT,
  1255         "extract": {
  1294         "extract": {
  1256             "default": GenerateElement("choice", ["id", "maxOccurs", "minOccurs"], 
  1295             "default": GenerateElement(
       
  1296                 "choice",
       
  1297                 ["id", "maxOccurs", "minOccurs"],
  1257                 re.compile("((?:annotation )?(?:element |group |choice |sequence |any )*)"))
  1298                 re.compile("((?:annotation )?(?:element |group |choice |sequence |any )*)"))
  1258         },
  1299         },
  1259         "reduce": ReduceChoice
  1300         "reduce": ReduceChoice
  1260     },
  1301     },
  1261 
  1302 
  1262     "complexContent": {"struct": """
  1303     "complexContent": {
       
  1304         "struct": """
  1263         <complexContent
  1305         <complexContent
  1264           id = ID
  1306           id = ID
  1265           mixed = boolean
  1307           mixed = boolean
  1266           {any attributes with non-schema namespace . . .}>
  1308           {any attributes with non-schema namespace . . .}>
  1267           Content: (annotation?, (restriction | extension))
  1309           Content: (annotation?, (restriction | extension))
  1268         </complexContent>""",
  1310         </complexContent>""",
  1269         "type": SYNTAXELEMENT, 
  1311         "type": SYNTAXELEMENT,
  1270         "extract": {
  1312         "extract": {
  1271             "default": GenerateElement("complexContent", ["id", "mixed"], 
  1313             "default": GenerateElement(
       
  1314                 "complexContent",
       
  1315                 ["id", "mixed"],
  1272                 re.compile("((?:annotation )?(?:restriction |extension ))"))
  1316                 re.compile("((?:annotation )?(?:restriction |extension ))"))
  1273         },
  1317         },
  1274         "reduce": ReduceComplexContent
  1318         "reduce": ReduceComplexContent
  1275     },
  1319     },
  1276 
  1320 
  1277     "complexType": {"struct": """
  1321     "complexType": {
       
  1322         "struct": """
  1278         <complexType
  1323         <complexType
  1279           abstract = boolean : false
  1324           abstract = boolean : false
  1280           block = (#all | List of (extension | restriction))
  1325           block = (#all | List of (extension | restriction))
  1281           final = (#all | List of (extension | restriction))
  1326           final = (#all | List of (extension | restriction))
  1282           id = ID
  1327           id = ID
  1283           mixed = boolean : false
  1328           mixed = boolean : false
  1284           name = NCName
  1329           name = NCName
  1285           {any attributes with non-schema namespace . . .}>
  1330           {any attributes with non-schema namespace . . .}>
  1286           Content: (annotation?, (simpleContent | complexContent | ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))))
  1331           Content: (annotation?, (simpleContent | complexContent | ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))))
  1287         </complexType>""",
  1332         </complexType>""",
  1288         "type": SYNTAXELEMENT, 
  1333         "type": SYNTAXELEMENT,
  1289         "extract": {
  1334         "extract": {
  1290             "default": GenerateElement("complexType", 
  1335             "default": GenerateElement(
  1291                 ["abstract", "block", "final", "id", "mixed", "name"], 
  1336                 "complexType",
       
  1337                 ["abstract", "block", "final", "id", "mixed", "name"],
  1292                 re.compile("((?:annotation )?(?:simpleContent |complexContent |(?:(?:group |all |choice |sequence )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))))"))
  1338                 re.compile("((?:annotation )?(?:simpleContent |complexContent |(?:(?:group |all |choice |sequence )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))))"))
  1293         },
  1339         },
  1294         "reduce": ReduceComplexType
  1340         "reduce": ReduceComplexType
  1295     },
  1341     },
  1296 
  1342 
  1297     "documentation": {"struct" : """
  1343     "documentation": {
       
  1344         "struct": """
  1298         <documentation
  1345         <documentation
  1299           source = anyURI
  1346           source = anyURI
  1300           xml:lang = language
  1347           xml:lang = language
  1301           {any attributes with non-schema namespace . . .}>
  1348           {any attributes with non-schema namespace . . .}>
  1302           Content: ({any})*
  1349           Content: ({any})*
  1303         </documentation>""",
  1350         </documentation>""",
  1304         "type": SYNTAXELEMENT, 
  1351         "type": SYNTAXELEMENT,
  1305         "extract": {
  1352         "extract": {
  1306             "default": GenerateElement("documentation", 
  1353             "default": GenerateElement(
  1307                 ["source", "lang"], re.compile("(.*)"), True)
  1354                 "documentation",
       
  1355                 ["source", "lang"],
       
  1356                 re.compile("(.*)"), True)
  1308         },
  1357         },
  1309         "reduce": ReduceDocumentation
  1358         "reduce": ReduceDocumentation
  1310     },
  1359     },
  1311 
  1360 
  1312     "element": {"struct": """
  1361     "element": {
       
  1362         "struct": """
  1313         <element
  1363         <element
  1314           abstract = boolean : false
  1364           abstract = boolean : false
  1315           block = (#all | List of (extension | restriction | substitution))
  1365           block = (#all | List of (extension | restriction | substitution))
  1316           default = string
  1366           default = string
  1317           final = (#all | List of (extension | restriction))
  1367           final = (#all | List of (extension | restriction))
  1326           substitutionGroup = QName
  1376           substitutionGroup = QName
  1327           type = QName
  1377           type = QName
  1328           {any attributes with non-schema namespace . . .}>
  1378           {any attributes with non-schema namespace . . .}>
  1329           Content: (annotation?, ((simpleType | complexType)?, (unique | key | keyref)*))
  1379           Content: (annotation?, ((simpleType | complexType)?, (unique | key | keyref)*))
  1330         </element>""",
  1380         </element>""",
  1331         "type": SYNTAXELEMENT, 
  1381         "type": SYNTAXELEMENT,
  1332         "extract": {
  1382         "extract": {
  1333             "default": GenerateElement("element", 
  1383             "default": GenerateElement(
  1334                 ["abstract", "block", "default", "final", "fixed", "form", "id", "maxOccurs", "minOccurs", "name", "nillable", "ref", "substitutionGroup", "type"], 
  1384                 "element",
       
  1385                 ["abstract", "block", "default", "final", "fixed", "form", "id", "maxOccurs", "minOccurs", "name", "nillable", "ref", "substitutionGroup", "type"],
  1335                 re.compile("((?:annotation )?(?:simpleType |complexType )?(?:unique |key |keyref )*)")),
  1386                 re.compile("((?:annotation )?(?:simpleType |complexType )?(?:unique |key |keyref )*)")),
  1336             "schema": GenerateElement("element", 
  1387             "schema": GenerateElement(
  1337                 ["abstract", "block", "default", "final", "fixed", "form", "id", "name", "nillable", "substitutionGroup", "type"], 
  1388                 "element",
       
  1389                 ["abstract", "block", "default", "final", "fixed", "form", "id", "name", "nillable", "substitutionGroup", "type"],
  1338                 re.compile("((?:annotation )?(?:simpleType |complexType )?(?:unique |key |keyref )*)"))
  1390                 re.compile("((?:annotation )?(?:simpleType |complexType )?(?:unique |key |keyref )*)"))
  1339         },
  1391         },
  1340         "reduce": ReduceElement
  1392         "reduce": ReduceElement
  1341     },
  1393     },
  1342 
  1394 
  1343     "enumeration": {"struct": """
  1395     "enumeration": {
       
  1396         "struct": """
  1344         <enumeration
  1397         <enumeration
  1345           id = ID
  1398           id = ID
  1346           value = anySimpleType
  1399           value = anySimpleType
  1347           {any attributes with non-schema namespace . . .}>
  1400           {any attributes with non-schema namespace . . .}>
  1348           Content: (annotation?)
  1401           Content: (annotation?)
  1349         </enumeration>""",
  1402         </enumeration>""",
  1350         "type": SYNTAXELEMENT, 
  1403         "type": SYNTAXELEMENT,
  1351         "extract": {
  1404         "extract": {
  1352             "default": GenerateElement("enumeration", ["id", "value"], ONLY_ANNOTATION)
  1405             "default": GenerateElement("enumeration", ["id", "value"], ONLY_ANNOTATION)
  1353         },
  1406         },
  1354         "reduce": GenerateFacetReducing("enumeration", False)
  1407         "reduce": GenerateFacetReducing("enumeration", False)
  1355     },
  1408     },
  1356 
  1409 
  1357     "extension": {"struct": """
  1410     "extension": {
       
  1411         "struct": """
  1358         <extension
  1412         <extension
  1359           base = QName
  1413           base = QName
  1360           id = ID
  1414           id = ID
  1361           {any attributes with non-schema namespace . . .}>
  1415           {any attributes with non-schema namespace . . .}>
  1362           Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
  1416           Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
  1363         </extension>""",
  1417         </extension>""",
  1364         "type": SYNTAXELEMENT, 
  1418         "type": SYNTAXELEMENT,
  1365         "extract": {
  1419         "extract": {
  1366             "default": GenerateElement("extension", ["base", "id"], 
  1420             "default": GenerateElement(
       
  1421                 "extension",
       
  1422                 ["base", "id"],
  1367                 re.compile("((?:annotation )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))")),
  1423                 re.compile("((?:annotation )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))")),
  1368             "complexContent": GenerateElement("extension", ["base", "id"], 
  1424             "complexContent": GenerateElement(
       
  1425                 "extension",
       
  1426                 ["base", "id"],
  1369                 re.compile("((?:annotation )?(?:group |all |choice |sequence )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))"))
  1427                 re.compile("((?:annotation )?(?:group |all |choice |sequence )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))"))
  1370         },
  1428         },
  1371         "reduce": ReduceExtension
  1429         "reduce": ReduceExtension
  1372     },
  1430     },
  1373 
  1431 
  1374     "field": {"struct": """
  1432     "field": {
       
  1433         "struct": """
  1375         <field
  1434         <field
  1376           id = ID
  1435           id = ID
  1377           xpath = a subset of XPath expression, see below
  1436           xpath = a subset of XPath expression, see below
  1378           {any attributes with non-schema namespace . . .}>
  1437           {any attributes with non-schema namespace . . .}>
  1379           Content: (annotation?)
  1438           Content: (annotation?)
  1380         </field>""",
  1439         </field>""",
  1381         "type": SYNTAXELEMENT, 
  1440         "type": SYNTAXELEMENT,
  1382         "extract": {
  1441         "extract": {
  1383             "default": GenerateElement("field", ["id", "xpath"], ONLY_ANNOTATION)
  1442             "default": GenerateElement("field", ["id", "xpath"], ONLY_ANNOTATION)
  1384         },
  1443         },
  1385         "reduce": ReduceField
  1444         "reduce": ReduceField
  1386     },
  1445     },
  1387 
  1446 
  1388     "fractionDigits": {"struct": """
  1447     "fractionDigits": {
       
  1448         "struct": """
  1389         <fractionDigits
  1449         <fractionDigits
  1390           fixed = boolean : false
  1450           fixed = boolean : false
  1391           id = ID
  1451           id = ID
  1392           value = nonNegativeInteger
  1452           value = nonNegativeInteger
  1393           {any attributes with non-schema namespace . . .}>
  1453           {any attributes with non-schema namespace . . .}>
  1394           Content: (annotation?)
  1454           Content: (annotation?)
  1395         </fractionDigits>""",
  1455         </fractionDigits>""",
  1396         "type": SYNTAXELEMENT, 
  1456         "type": SYNTAXELEMENT,
  1397         "extract": {
  1457         "extract": {
  1398             "default": GenerateElement("fractionDigits", 
  1458             "default": GenerateElement(
  1399                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1459                 "fractionDigits",
       
  1460                 ["fixed", "id", "value"],
       
  1461                 ONLY_ANNOTATION)
  1400         },
  1462         },
  1401         "reduce": GenerateFacetReducing("fractionDigits", True)
  1463         "reduce": GenerateFacetReducing("fractionDigits", True)
  1402     },
  1464     },
  1403 
  1465 
  1404     "group": {"struct": """
  1466     "group": {
       
  1467         "struct": """
  1405         <group
  1468         <group
  1406           id = ID
  1469           id = ID
  1407           maxOccurs = (nonNegativeInteger | unbounded)  : 1
  1470           maxOccurs = (nonNegativeInteger | unbounded)  : 1
  1408           minOccurs = nonNegativeInteger : 1
  1471           minOccurs = nonNegativeInteger : 1
  1409           name = NCName
  1472           name = NCName
  1410           ref = QName
  1473           ref = QName
  1411           {any attributes with non-schema namespace . . .}>
  1474           {any attributes with non-schema namespace . . .}>
  1412           Content: (annotation?, (all | choice | sequence)?)
  1475           Content: (annotation?, (all | choice | sequence)?)
  1413         </group>""",
  1476         </group>""",
  1414         "type": SYNTAXELEMENT, 
  1477         "type": SYNTAXELEMENT,
  1415         "extract": {
  1478         "extract": {
  1416             "default": GenerateElement("group",
  1479             "default": GenerateElement(
  1417                 ["id", "maxOccurs", "minOccurs", "ref"], 
  1480                 "group",
       
  1481                 ["id", "maxOccurs", "minOccurs", "ref"],
  1418                 re.compile("((?:annotation )?(?:all |choice |sequence )?)")),
  1482                 re.compile("((?:annotation )?(?:all |choice |sequence )?)")),
  1419             "schema": GenerateElement("group",
  1483             "schema": GenerateElement(
  1420                 ["id", "name"], 
  1484                 "group",
       
  1485                 ["id", "name"],
  1421                 re.compile("((?:annotation )?(?:all |choice |sequence )?)"))
  1486                 re.compile("((?:annotation )?(?:all |choice |sequence )?)"))
  1422         },
  1487         },
  1423         "reduce": ReduceGroup
  1488         "reduce": ReduceGroup
  1424     },
  1489     },
  1425 
  1490 
  1426     "import": {"struct": """
  1491     "import": {
       
  1492         "struct": """
  1427         <import
  1493         <import
  1428           id = ID
  1494           id = ID
  1429           namespace = anyURI
  1495           namespace = anyURI
  1430           schemaLocation = anyURI
  1496           schemaLocation = anyURI
  1431           {any attributes with non-schema namespace . . .}>
  1497           {any attributes with non-schema namespace . . .}>
  1432           Content: (annotation?)
  1498           Content: (annotation?)
  1433         </import>""",
  1499         </import>""",
  1434         "type": SYNTAXELEMENT, 
  1500         "type": SYNTAXELEMENT,
  1435         "extract": {
  1501         "extract": {
  1436             "default": GenerateElement("import",
  1502             "default": GenerateElement(
  1437                 ["id", "namespace", "schemaLocation"], ONLY_ANNOTATION)
  1503                 "import",
       
  1504                 ["id", "namespace", "schemaLocation"],
       
  1505                 ONLY_ANNOTATION)
  1438         },
  1506         },
  1439         "reduce": ReduceImport
  1507         "reduce": ReduceImport
  1440     },
  1508     },
  1441 
  1509 
  1442     "include": {"struct": """
  1510     "include": {
       
  1511         "struct": """
  1443         <include
  1512         <include
  1444           id = ID
  1513           id = ID
  1445           schemaLocation = anyURI
  1514           schemaLocation = anyURI
  1446           {any attributes with non-schema namespace . . .}>
  1515           {any attributes with non-schema namespace . . .}>
  1447           Content: (annotation?)
  1516           Content: (annotation?)
  1448         </include>""",
  1517         </include>""",
  1449         "type": SYNTAXELEMENT, 
  1518         "type": SYNTAXELEMENT,
  1450         "extract": {
  1519         "extract": {
  1451             "default": GenerateElement("include",
  1520             "default": GenerateElement(
  1452                 ["id", "schemaLocation"], ONLY_ANNOTATION)
  1521                 "include",
       
  1522                 ["id", "schemaLocation"],
       
  1523                 ONLY_ANNOTATION)
  1453         },
  1524         },
  1454         "reduce": ReduceInclude
  1525         "reduce": ReduceInclude
  1455     },
  1526     },
  1456 
  1527 
  1457     "key": {"struct": """
  1528     "key": {
       
  1529         "struct": """
  1458         <key
  1530         <key
  1459           id = ID
  1531           id = ID
  1460           name = NCName
  1532           name = NCName
  1461           {any attributes with non-schema namespace . . .}>
  1533           {any attributes with non-schema namespace . . .}>
  1462           Content: (annotation?, (selector, field+))
  1534           Content: (annotation?, (selector, field+))
  1463         </key>""",
  1535         </key>""",
  1464         "type": SYNTAXELEMENT, 
  1536         "type": SYNTAXELEMENT,
  1465         "extract": {
  1537         "extract": {
  1466             "default": GenerateElement("key", ["id", "name"], 
  1538             "default": GenerateElement(
       
  1539                 "key", ["id", "name"],
  1467                 re.compile("((?:annotation )?(?:selector (?:field )+))"))
  1540                 re.compile("((?:annotation )?(?:selector (?:field )+))"))
  1468         },
  1541         },
  1469         "reduce": ReduceKey
  1542         "reduce": ReduceKey
  1470     },
  1543     },
  1471 
  1544 
  1472     "keyref": {"struct": """
  1545     "keyref": {
       
  1546         "struct": """
  1473         <keyref
  1547         <keyref
  1474           id = ID
  1548           id = ID
  1475           name = NCName
  1549           name = NCName
  1476           refer = QName
  1550           refer = QName
  1477           {any attributes with non-schema namespace . . .}>
  1551           {any attributes with non-schema namespace . . .}>
  1478           Content: (annotation?, (selector, field+))
  1552           Content: (annotation?, (selector, field+))
  1479         </keyref>""",
  1553         </keyref>""",
  1480         "type": SYNTAXELEMENT, 
  1554         "type": SYNTAXELEMENT,
  1481         "extract": {
  1555         "extract": {
  1482             "default": GenerateElement("keyref", ["id", "name", "refer"], 
  1556             "default": GenerateElement(
       
  1557                 "keyref", ["id", "name", "refer"],
  1483                 re.compile("((?:annotation )?(?:selector (?:field )+))"))
  1558                 re.compile("((?:annotation )?(?:selector (?:field )+))"))
  1484         },
  1559         },
  1485         "reduce": ReduceKeyRef
  1560         "reduce": ReduceKeyRef
  1486     },
  1561     },
  1487 
  1562 
  1488     "length": {"struct" : """
  1563     "length": {
       
  1564         "struct": """
  1489         <length
  1565         <length
  1490           fixed = boolean : false
  1566           fixed = boolean : false
  1491           id = ID
  1567           id = ID
  1492           value = nonNegativeInteger
  1568           value = nonNegativeInteger
  1493           {any attributes with non-schema namespace . . .}>
  1569           {any attributes with non-schema namespace . . .}>
  1494           Content: (annotation?)
  1570           Content: (annotation?)
  1495         </length>""",
  1571         </length>""",
  1496         "type": SYNTAXELEMENT, 
  1572         "type": SYNTAXELEMENT,
  1497         "extract": {
  1573         "extract": {
  1498             "default": GenerateElement("length", 
  1574             "default": GenerateElement(
  1499                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1575                 "length", ["fixed", "id", "value"], ONLY_ANNOTATION)
  1500         },
  1576         },
  1501         "reduce": GenerateFacetReducing("length", True)
  1577         "reduce": GenerateFacetReducing("length", True)
  1502     },
  1578     },
  1503 
  1579 
  1504     "list": {"struct": """
  1580     "list": {
       
  1581         "struct": """
  1505         <list
  1582         <list
  1506           id = ID
  1583           id = ID
  1507           itemType = QName
  1584           itemType = QName
  1508           {any attributes with non-schema namespace . . .}>
  1585           {any attributes with non-schema namespace . . .}>
  1509           Content: (annotation?, simpleType?)
  1586           Content: (annotation?, simpleType?)
  1510         </list>""",
  1587         </list>""",
  1511         "type": SYNTAXELEMENT, 
  1588         "type": SYNTAXELEMENT,
  1512         "extract": {
  1589         "extract": {
  1513             "default": GenerateElement("list", ["id", "itemType"], 
  1590             "default": GenerateElement(
       
  1591                 "list", ["id", "itemType"],
  1514                 re.compile("((?:annotation )?(?:simpleType )?)$"))
  1592                 re.compile("((?:annotation )?(?:simpleType )?)$"))
  1515         },
  1593         },
  1516         "reduce": ReduceList
  1594         "reduce": ReduceList
  1517     },
  1595     },
  1518 
  1596 
  1519     "maxExclusive": {"struct": """
  1597     "maxExclusive": {
       
  1598         "struct": """
  1520         <maxInclusive
  1599         <maxInclusive
  1521           fixed = boolean : false
  1600           fixed = boolean : false
  1522           id = ID
  1601           id = ID
  1523           value = anySimpleType
  1602           value = anySimpleType
  1524           {any attributes with non-schema namespace . . .}>
  1603           {any attributes with non-schema namespace . . .}>
  1525           Content: (annotation?)
  1604           Content: (annotation?)
  1526         </maxInclusive>""",
  1605         </maxInclusive>""",
  1527         "type": SYNTAXELEMENT, 
  1606         "type": SYNTAXELEMENT,
  1528         "extract": {
  1607         "extract": {
  1529             "default": GenerateElement("maxExclusive",
  1608             "default": GenerateElement(
  1530                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1609                 "maxExclusive", ["fixed", "id", "value"], ONLY_ANNOTATION)
  1531         },
  1610         },
  1532         "reduce": GenerateFacetReducing("maxExclusive", True)
  1611         "reduce": GenerateFacetReducing("maxExclusive", True)
  1533     },
  1612     },
  1534 
  1613 
  1535     "maxInclusive": {"struct": """
  1614     "maxInclusive": {
       
  1615         "struct": """
  1536         <maxExclusive
  1616         <maxExclusive
  1537           fixed = boolean : false
  1617           fixed = boolean : false
  1538           id = ID
  1618           id = ID
  1539           value = anySimpleType
  1619           value = anySimpleType
  1540           {any attributes with non-schema namespace . . .}>
  1620           {any attributes with non-schema namespace . . .}>
  1541           Content: (annotation?)
  1621           Content: (annotation?)
  1542         </maxExclusive>""",
  1622         </maxExclusive>""",
  1543         "type": SYNTAXELEMENT, 
  1623         "type": SYNTAXELEMENT,
  1544         "extract": {
  1624         "extract": {
  1545             "default": GenerateElement("maxInclusive", 
  1625             "default": GenerateElement(
  1546                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1626                 "maxInclusive", ["fixed", "id", "value"], ONLY_ANNOTATION)
  1547         },
  1627         },
  1548         "reduce": GenerateFacetReducing("maxInclusive", True)
  1628         "reduce": GenerateFacetReducing("maxInclusive", True)
  1549     },
  1629     },
  1550 
  1630 
  1551     "maxLength": {"struct": """
  1631     "maxLength": {
       
  1632         "struct": """
  1552         <maxLength
  1633         <maxLength
  1553           fixed = boolean : false
  1634           fixed = boolean : false
  1554           id = ID
  1635           id = ID
  1555           value = nonNegativeInteger
  1636           value = nonNegativeInteger
  1556           {any attributes with non-schema namespace . . .}>
  1637           {any attributes with non-schema namespace . . .}>
  1557           Content: (annotation?)
  1638           Content: (annotation?)
  1558         </maxLength>""",
  1639         </maxLength>""",
  1559         "type": SYNTAXELEMENT, 
  1640         "type": SYNTAXELEMENT,
  1560         "extract": {
  1641         "extract": {
  1561             "default": GenerateElement("maxLength", 
  1642             "default": GenerateElement(
  1562                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1643                 "maxLength", ["fixed", "id", "value"], ONLY_ANNOTATION)
  1563         },
  1644         },
  1564         "reduce": GenerateFacetReducing("maxLength", True)
  1645         "reduce": GenerateFacetReducing("maxLength", True)
  1565     },
  1646     },
  1566 
  1647 
  1567     "minExclusive": {"struct": """
  1648     "minExclusive": {
       
  1649         "struct": """
  1568         <minExclusive
  1650         <minExclusive
  1569           fixed = boolean : false
  1651           fixed = boolean : false
  1570           id = ID
  1652           id = ID
  1571           value = anySimpleType
  1653           value = anySimpleType
  1572           {any attributes with non-schema namespace . . .}>
  1654           {any attributes with non-schema namespace . . .}>
  1573           Content: (annotation?)
  1655           Content: (annotation?)
  1574         </minExclusive>""",
  1656         </minExclusive>""",
  1575         "type": SYNTAXELEMENT, 
  1657         "type": SYNTAXELEMENT,
  1576         "extract": {
  1658         "extract": {
  1577             "default": GenerateElement("minExclusive", 
  1659             "default": GenerateElement(
  1578                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1660                 "minExclusive", ["fixed", "id", "value"], ONLY_ANNOTATION)
  1579         },
  1661         },
  1580         "reduce": GenerateFacetReducing("minExclusive", True)
  1662         "reduce": GenerateFacetReducing("minExclusive", True)
  1581     },
  1663     },
  1582 
  1664 
  1583     "minInclusive": {"struct": """
  1665     "minInclusive": {
       
  1666         "struct": """
  1584         <minInclusive
  1667         <minInclusive
  1585           fixed = boolean : false
  1668           fixed = boolean : false
  1586           id = ID
  1669           id = ID
  1587           value = anySimpleType
  1670           value = anySimpleType
  1588           {any attributes with non-schema namespace . . .}>
  1671           {any attributes with non-schema namespace . . .}>
  1589           Content: (annotation?)
  1672           Content: (annotation?)
  1590         </minInclusive>""",
  1673         </minInclusive>""",
  1591         "type": SYNTAXELEMENT, 
  1674         "type": SYNTAXELEMENT,
  1592         "extract": {
  1675         "extract": {
  1593             "default": GenerateElement("minInclusive", 
  1676             "default": GenerateElement(
  1594                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1677                 "minInclusive", ["fixed", "id", "value"], ONLY_ANNOTATION)
  1595         },
  1678         },
  1596         "reduce": GenerateFacetReducing("minInclusive", True)
  1679         "reduce": GenerateFacetReducing("minInclusive", True)
  1597     },
  1680     },
  1598 
  1681 
  1599     "minLength": {"struct": """
  1682     "minLength": {
       
  1683         "struct": """
  1600         <minLength
  1684         <minLength
  1601           fixed = boolean : false
  1685           fixed = boolean : false
  1602           id = ID
  1686           id = ID
  1603           value = nonNegativeInteger
  1687           value = nonNegativeInteger
  1604           {any attributes with non-schema namespace . . .}>
  1688           {any attributes with non-schema namespace . . .}>
  1605           Content: (annotation?)
  1689           Content: (annotation?)
  1606         </minLength>""",
  1690         </minLength>""",
  1607         "type": SYNTAXELEMENT, 
  1691         "type": SYNTAXELEMENT,
  1608         "extract": {
  1692         "extract": {
  1609             "default": GenerateElement("minLength",
  1693             "default": GenerateElement(
  1610                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1694                 "minLength", ["fixed", "id", "value"], ONLY_ANNOTATION)
  1611         },
  1695         },
  1612         "reduce": GenerateFacetReducing("minLength", True)
  1696         "reduce": GenerateFacetReducing("minLength", True)
  1613     },
  1697     },
  1614 
  1698 
  1615     "pattern": {"struct": """
  1699     "pattern": {
       
  1700         "struct": """
  1616         <pattern
  1701         <pattern
  1617           id = ID
  1702           id = ID
  1618           value = string
  1703           value = string
  1619           {any attributes with non-schema namespace . . .}>
  1704           {any attributes with non-schema namespace . . .}>
  1620           Content: (annotation?)
  1705           Content: (annotation?)
  1621         </pattern>""",
  1706         </pattern>""",
  1622         "type": SYNTAXELEMENT, 
  1707         "type": SYNTAXELEMENT,
  1623         "extract": {
  1708         "extract": {
  1624             "default": GenerateElement("pattern", ["id", "value"], ONLY_ANNOTATION)
  1709             "default": GenerateElement("pattern", ["id", "value"], ONLY_ANNOTATION)
  1625         },
  1710         },
  1626         "reduce": GenerateFacetReducing("pattern", False)
  1711         "reduce": GenerateFacetReducing("pattern", False)
  1627     },
  1712     },
  1628 
  1713 
  1629     "redefine": {"struct": """
  1714     "redefine": {
       
  1715         "struct": """
  1630         <redefine
  1716         <redefine
  1631           id = ID
  1717           id = ID
  1632           schemaLocation = anyURI
  1718           schemaLocation = anyURI
  1633           {any attributes with non-schema namespace . . .}>
  1719           {any attributes with non-schema namespace . . .}>
  1634           Content: (annotation | (simpleType | complexType | group | attributeGroup))*
  1720           Content: (annotation | (simpleType | complexType | group | attributeGroup))*
  1635         </redefine>""",
  1721         </redefine>""",
  1636         "type": SYNTAXELEMENT, 
  1722         "type": SYNTAXELEMENT,
  1637         "extract": {
  1723         "extract": {
  1638             "default": GenerateElement("refine", ["id", "schemaLocation"], 
  1724             "default": GenerateElement(
       
  1725                 "refine", ["id", "schemaLocation"],
  1639                 re.compile("((?:annotation |(?:simpleType |complexType |group |attributeGroup ))*)"))
  1726                 re.compile("((?:annotation |(?:simpleType |complexType |group |attributeGroup ))*)"))
  1640         },
  1727         },
  1641         "reduce": ReduceRedefine
  1728         "reduce": ReduceRedefine
  1642     },
  1729     },
  1643 
  1730 
  1644     "restriction": {"struct": """
  1731     "restriction": {
       
  1732         "struct": """
  1645         <restriction
  1733         <restriction
  1646           base = QName
  1734           base = QName
  1647           id = ID
  1735           id = ID
  1648           {any attributes with non-schema namespace . . .}>
  1736           {any attributes with non-schema namespace . . .}>
  1649           Content: (annotation?, (group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))
  1737           Content: (annotation?, (group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))
  1650         </restriction>""",
  1738         </restriction>""",
  1651         "type": SYNTAXELEMENT, 
  1739         "type": SYNTAXELEMENT,
  1652         "extract": {
  1740         "extract": {
  1653             "default": GenerateElement("restriction", ["base", "id"], 
  1741             "default": GenerateElement(
       
  1742                 "restriction",
       
  1743                 ["base", "id"],
  1654                 re.compile("((?:annotation )?(?:(?:simpleType )?(?:(?:minExclusive |minInclusive |maxExclusive |maxInclusive |totalDigits |fractionDigits |length |minLength |maxLength |enumeration |whiteSpace |pattern )*)))")),
  1744                 re.compile("((?:annotation )?(?:(?:simpleType )?(?:(?:minExclusive |minInclusive |maxExclusive |maxInclusive |totalDigits |fractionDigits |length |minLength |maxLength |enumeration |whiteSpace |pattern )*)))")),
  1655             "simpleContent": GenerateElement("restriction", ["base", "id"], 
  1745             "simpleContent": GenerateElement(
       
  1746                 "restriction",
       
  1747                 ["base", "id"],
  1656                 re.compile("((?:annotation )?(?:(?:simpleType )?(?:(?:minExclusive |minInclusive |maxExclusive |maxInclusive |totalDigits |fractionDigits |length |minLength |maxLength |enumeration |whiteSpace |pattern )*)?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?)))")),
  1748                 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"], 
  1749             "complexContent": GenerateElement(
       
  1750                 "restriction",
       
  1751                 ["base", "id"],
  1658                 re.compile("((?:annotation )?(?:(?:simpleType )?(?:group |all |choice |sequence )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?)))")),
  1752                 re.compile("((?:annotation )?(?:(?:simpleType )?(?:group |all |choice |sequence )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?)))")),
  1659         },
  1753         },
  1660         "reduce": ReduceRestriction
  1754         "reduce": ReduceRestriction
  1661     },
  1755     },
  1662 
  1756 
  1663     "schema": {"struct": """
  1757     "schema": {
       
  1758         "struct": """
  1664         <schema
  1759         <schema
  1665           attributeFormDefault = (qualified | unqualified) : unqualified
  1760           attributeFormDefault = (qualified | unqualified) : unqualified
  1666           blockDefault = (#all | List of (extension | restriction | substitution))  : ''
  1761           blockDefault = (#all | List of (extension | restriction | substitution))  : ''
  1667           elementFormDefault = (qualified | unqualified) : unqualified
  1762           elementFormDefault = (qualified | unqualified) : unqualified
  1668           finalDefault = (#all | List of (extension | restriction | list | union))  : ''
  1763           finalDefault = (#all | List of (extension | restriction | list | union))  : ''
  1671           version = token
  1766           version = token
  1672           xml:lang = language
  1767           xml:lang = language
  1673           {any attributes with non-schema namespace . . .}>
  1768           {any attributes with non-schema namespace . . .}>
  1674           Content: ((include | import | redefine | annotation)*, (((simpleType | complexType | group | attributeGroup) | element | attribute | notation), annotation*)*)
  1769           Content: ((include | import | redefine | annotation)*, (((simpleType | complexType | group | attributeGroup) | element | attribute | notation), annotation*)*)
  1675         </schema>""",
  1770         </schema>""",
  1676         "type": SYNTAXELEMENT, 
  1771         "type": SYNTAXELEMENT,
  1677         "extract": {
  1772         "extract": {
  1678             "default": GenerateElement("schema",
  1773             "default": GenerateElement(
  1679                 ["attributeFormDefault", "blockDefault", "elementFormDefault", "finalDefault", "id", "targetNamespace", "version", "lang"], 
  1774                 "schema",
       
  1775                 ["attributeFormDefault",
       
  1776                  "blockDefault",
       
  1777                  "elementFormDefault",
       
  1778                  "finalDefault",
       
  1779                  "id",
       
  1780                  "targetNamespace",
       
  1781                  "version",
       
  1782                  "lang"],
  1680                 re.compile("((?:include |import |redefine |annotation )*(?:(?:(?:simpleType |complexType |group |attributeGroup )|element |attribute |annotation )(?:annotation )*)*)"))
  1783                 re.compile("((?:include |import |redefine |annotation )*(?:(?:(?:simpleType |complexType |group |attributeGroup )|element |attribute |annotation )(?:annotation )*)*)"))
  1681         }
  1784         }
  1682     },
  1785     },
  1683 
  1786 
  1684     "selector": {"struct": """
  1787     "selector": {
       
  1788         "struct": """
  1685         <selector
  1789         <selector
  1686           id = ID
  1790           id = ID
  1687           xpath = a subset of XPath expression, see below
  1791           xpath = a subset of XPath expression, see below
  1688           {any attributes with non-schema namespace . . .}>
  1792           {any attributes with non-schema namespace . . .}>
  1689           Content: (annotation?)
  1793           Content: (annotation?)
  1690         </selector>""",
  1794         </selector>""",
  1691         "type": SYNTAXELEMENT, 
  1795         "type": SYNTAXELEMENT,
  1692         "extract": {
  1796         "extract": {
  1693             "default": GenerateElement("selector", ["id", "xpath"], ONLY_ANNOTATION)
  1797             "default": GenerateElement("selector", ["id", "xpath"], ONLY_ANNOTATION)
  1694         },
  1798         },
  1695         "reduce": ReduceSelector
  1799         "reduce": ReduceSelector
  1696     },
  1800     },
  1697 
  1801 
  1698     "sequence": {"struct": """
  1802     "sequence": {
       
  1803         "struct": """
  1699         <sequence
  1804         <sequence
  1700           id = ID
  1805           id = ID
  1701           maxOccurs = (nonNegativeInteger | unbounded)  : 1
  1806           maxOccurs = (nonNegativeInteger | unbounded)  : 1
  1702           minOccurs = nonNegativeInteger : 1
  1807           minOccurs = nonNegativeInteger : 1
  1703           {any attributes with non-schema namespace . . .}>
  1808           {any attributes with non-schema namespace . . .}>
  1704           Content: (annotation?, (element | group | choice | sequence | any)*)
  1809           Content: (annotation?, (element | group | choice | sequence | any)*)
  1705         </sequence>""",
  1810         </sequence>""",
  1706         "type": SYNTAXELEMENT, 
  1811         "type": SYNTAXELEMENT,
  1707         "extract": {
  1812         "extract": {
  1708             "default": GenerateElement("sequence", ["id", "maxOccurs", "minOccurs"], 
  1813             "default": GenerateElement(
       
  1814                 "sequence", ["id", "maxOccurs", "minOccurs"],
  1709                 re.compile("((?:annotation )?(?:element |group |choice |sequence |any )*)"))
  1815                 re.compile("((?:annotation )?(?:element |group |choice |sequence |any )*)"))
  1710         },
  1816         },
  1711         "reduce": ReduceSequence
  1817         "reduce": ReduceSequence
  1712     },
  1818     },
  1713 
  1819 
  1714     "simpleContent": {"struct" : """
  1820     "simpleContent": {
       
  1821         "struct": """
  1715         <simpleContent
  1822         <simpleContent
  1716           id = ID
  1823           id = ID
  1717           {any attributes with non-schema namespace . . .}>
  1824           {any attributes with non-schema namespace . . .}>
  1718           Content: (annotation?, (restriction | extension))
  1825           Content: (annotation?, (restriction | extension))
  1719         </simpleContent>""",
  1826         </simpleContent>""",
  1720         "type": SYNTAXELEMENT, 
  1827         "type": SYNTAXELEMENT,
  1721         "extract": {
  1828         "extract": {
  1722             "default": GenerateElement("simpleContent", ["id"], 
  1829             "default": GenerateElement(
       
  1830                 "simpleContent", ["id"],
  1723                 re.compile("((?:annotation )?(?:restriction |extension ))"))
  1831                 re.compile("((?:annotation )?(?:restriction |extension ))"))
  1724         },
  1832         },
  1725         "reduce": ReduceSimpleContent
  1833         "reduce": ReduceSimpleContent
  1726     },
  1834     },
  1727 
  1835 
  1728     "simpleType": {"struct" : """
  1836     "simpleType": {
       
  1837         "struct": """
  1729         <simpleType
  1838         <simpleType
  1730           final = (#all | List of (list | union | restriction))
  1839           final = (#all | List of (list | union | restriction))
  1731           id = ID
  1840           id = ID
  1732           name = NCName
  1841           name = NCName
  1733           {any attributes with non-schema namespace . . .}>
  1842           {any attributes with non-schema namespace . . .}>
  1734           Content: (annotation?, (restriction | list | union))
  1843           Content: (annotation?, (restriction | list | union))
  1735         </simpleType>""",
  1844         </simpleType>""",
  1736         "type": SYNTAXELEMENT, 
  1845         "type": SYNTAXELEMENT,
  1737         "extract": {
  1846         "extract": {
  1738             "default": GenerateElement("simpleType", ["final", "id", "name"], 
  1847             "default": GenerateElement(
       
  1848                 "simpleType", ["final", "id", "name"],
  1739                 re.compile("((?:annotation )?(?:restriction |list |union ))"))
  1849                 re.compile("((?:annotation )?(?:restriction |list |union ))"))
  1740         },
  1850         },
  1741         "reduce": ReduceSimpleType
  1851         "reduce": ReduceSimpleType
  1742     },
  1852     },
  1743 
  1853 
  1744     "totalDigits": {"struct" : """
  1854     "totalDigits": {
       
  1855         "struct": """
  1745         <totalDigits
  1856         <totalDigits
  1746           fixed = boolean : false
  1857           fixed = boolean : false
  1747           id = ID
  1858           id = ID
  1748           value = positiveInteger
  1859           value = positiveInteger
  1749           {any attributes with non-schema namespace . . .}>
  1860           {any attributes with non-schema namespace . . .}>
  1750           Content: (annotation?)
  1861           Content: (annotation?)
  1751         </totalDigits>""",
  1862         </totalDigits>""",
  1752         "type": SYNTAXELEMENT, 
  1863         "type": SYNTAXELEMENT,
  1753         "extract": {
  1864         "extract": {
  1754             "default": GenerateElement("totalDigits", 
  1865             "default": GenerateElement(
  1755                 ["fixed", "id", "value"], ONLY_ANNOTATION),
  1866                 "totalDigits", ["fixed", "id", "value"], ONLY_ANNOTATION),
  1756         },
  1867         },
  1757         "reduce": GenerateFacetReducing("totalDigits", True)
  1868         "reduce": GenerateFacetReducing("totalDigits", True)
  1758     },
  1869     },
  1759 
  1870 
  1760     "union": {"struct": """
  1871     "union": {
       
  1872         "struct": """
  1761         <union
  1873         <union
  1762           id = ID
  1874           id = ID
  1763           memberTypes = List of QName
  1875           memberTypes = List of QName
  1764           {any attributes with non-schema namespace . . .}>
  1876           {any attributes with non-schema namespace . . .}>
  1765           Content: (annotation?, simpleType*)
  1877           Content: (annotation?, simpleType*)
  1766         </union>""",
  1878         </union>""",
  1767         "type": SYNTAXELEMENT, 
  1879         "type": SYNTAXELEMENT,
  1768         "extract": {
  1880         "extract": {
  1769             "default": GenerateElement("union", ["id", "memberTypes"], 
  1881             "default": GenerateElement(
       
  1882                 "union", ["id", "memberTypes"],
  1770                 re.compile("((?:annotation )?(?:simpleType )*)"))
  1883                 re.compile("((?:annotation )?(?:simpleType )*)"))
  1771         },
  1884         },
  1772         "reduce": ReduceUnion
  1885         "reduce": ReduceUnion
  1773     },
  1886     },
  1774 
  1887 
  1775     "unique": {"struct": """
  1888     "unique": {
       
  1889         "struct": """
  1776         <unique
  1890         <unique
  1777           id = ID
  1891           id = ID
  1778           name = NCName
  1892           name = NCName
  1779           {any attributes with non-schema namespace . . .}>
  1893           {any attributes with non-schema namespace . . .}>
  1780           Content: (annotation?, (selector, field+))
  1894           Content: (annotation?, (selector, field+))
  1781         </unique>""",
  1895         </unique>""",
  1782         "type": SYNTAXELEMENT, 
  1896         "type": SYNTAXELEMENT,
  1783         "extract": {
  1897         "extract": {
  1784             "default": GenerateElement("unique", ["id", "name"], 
  1898             "default": GenerateElement(
       
  1899                 "unique", ["id", "name"],
  1785                 re.compile("((?:annotation )?(?:selector |(?:field )+))"))
  1900                 re.compile("((?:annotation )?(?:selector |(?:field )+))"))
  1786         },
  1901         },
  1787         "reduce": ReduceUnique
  1902         "reduce": ReduceUnique
  1788     },
  1903     },
  1789     
  1904 
  1790     "whiteSpace": {"struct" : """
  1905     "whiteSpace": {
       
  1906         "struct": """
  1791         <whiteSpace
  1907         <whiteSpace
  1792           fixed = boolean : false
  1908           fixed = boolean : false
  1793           id = ID
  1909           id = ID
  1794           value = (collapse | preserve | replace)
  1910           value = (collapse | preserve | replace)
  1795           {any attributes with non-schema namespace . . .}>
  1911           {any attributes with non-schema namespace . . .}>
  1796           Content: (annotation?)
  1912           Content: (annotation?)
  1797         </whiteSpace>""",
  1913         </whiteSpace>""",
  1798         "type": SYNTAXELEMENT, 
  1914         "type": SYNTAXELEMENT,
  1799         "extract": {
  1915         "extract": {
  1800             "default": GenerateElement("whiteSpace", 
  1916             "default": GenerateElement(
  1801                 ["fixed", "id", "value"], ONLY_ANNOTATION)
  1917                 "whiteSpace", ["fixed", "id", "value"], ONLY_ANNOTATION)
  1802         },
  1918         },
  1803         "reduce": GenerateFacetReducing("whiteSpace", True)
  1919         "reduce": GenerateFacetReducing("whiteSpace", True)
  1804     },
  1920     },
  1805 
  1921 
  1806 #-------------------------------------------------------------------------------
  1922     # -------------------------------------------------------------------------------
  1807 #                       Syntax attributes definition
  1923     #                       Syntax attributes definition
  1808 #-------------------------------------------------------------------------------
  1924     # -------------------------------------------------------------------------------
  1809 
  1925 
  1810     "abstract": {
  1926     "abstract": {
  1811         "type": SYNTAXATTRIBUTE, 
  1927         "type": SYNTAXATTRIBUTE,
  1812         "extract": {
  1928         "extract": {
  1813             "default": GetBoolean
  1929             "default": GetBoolean
  1814         },
  1930         },
  1815         "default": {
  1931         "default": {
  1816             "default": False
  1932             "default": False
  1817         }
  1933         }
  1818     },
  1934     },
  1819 
  1935 
  1820     "attributeFormDefault": {
  1936     "attributeFormDefault": {
  1821         "type": SYNTAXATTRIBUTE, 
  1937         "type": SYNTAXATTRIBUTE,
  1822         "extract": {
  1938         "extract": {
  1823             "default": GenerateEnumeratedExtraction("member attributeFormDefault", ["qualified", "unqualified"])
  1939             "default": GenerateEnumeratedExtraction(
       
  1940                 "member attributeFormDefault", ["qualified", "unqualified"])
  1824         },
  1941         },
  1825         "default": {
  1942         "default": {
  1826             "default": "unqualified"
  1943             "default": "unqualified"
  1827         }
  1944         }
  1828     },
  1945     },
  1829     
  1946 
  1830     "base": {
  1947     "base": {
  1831         "type": SYNTAXATTRIBUTE, 
  1948         "type": SYNTAXATTRIBUTE,
  1832         "extract": {
  1949         "extract": {
  1833             "default": GenerateModelNameExtraction("member base", QName_model)
  1950             "default": GenerateModelNameExtraction("member base", QName_model)
  1834         }
  1951         }
  1835     },
  1952     },
  1836     
  1953 
  1837     "block": {
  1954     "block": {
  1838         "type": SYNTAXATTRIBUTE, 
  1955         "type": SYNTAXATTRIBUTE,
  1839         "extract": {
  1956         "extract": {
  1840             "default": GenerateGetList("block", ["restriction", "extension", "substitution"])
  1957             "default": GenerateGetList("block", ["restriction", "extension", "substitution"])
  1841         }
  1958         }
  1842     },
  1959     },
  1843     
  1960 
  1844     "blockDefault": {
  1961     "blockDefault": {
  1845         "type": SYNTAXATTRIBUTE, 
  1962         "type": SYNTAXATTRIBUTE,
  1846         "extract": {
  1963         "extract": {
  1847             "default": GenerateGetList("block", ["restriction", "extension", "substitution"])
  1964             "default": GenerateGetList("block", ["restriction", "extension", "substitution"])
  1848         },
  1965         },
  1849         "default": {
  1966         "default": {
  1850             "default": ""
  1967             "default": ""
  1851         }
  1968         }
  1852     },
  1969     },
  1853     
  1970 
  1854     "default": {
  1971     "default": {
  1855         "type": SYNTAXATTRIBUTE, 
  1972         "type": SYNTAXATTRIBUTE,
  1856         "extract": {
  1973         "extract": {
  1857             "default": GetAttributeValue
  1974             "default": GetAttributeValue
  1858         }
  1975         }
  1859     },
  1976     },
  1860 
  1977 
  1861     "elementFormDefault": {
  1978     "elementFormDefault": {
  1862         "type": SYNTAXATTRIBUTE, 
  1979         "type": SYNTAXATTRIBUTE,
  1863         "extract": {
  1980         "extract": {
  1864             "default": GenerateEnumeratedExtraction("member elementFormDefault", ["qualified", "unqualified"])
  1981             "default": GenerateEnumeratedExtraction("member elementFormDefault", ["qualified", "unqualified"])
  1865         },
  1982         },
  1866         "default": {
  1983         "default": {
  1867             "default": "unqualified"
  1984             "default": "unqualified"
  1868         }
  1985         }
  1869     },
  1986     },
  1870     
  1987 
  1871     "final": {
  1988     "final": {
  1872         "type": SYNTAXATTRIBUTE, 
  1989         "type": SYNTAXATTRIBUTE,
  1873         "extract": {
  1990         "extract": {
  1874             "default": GenerateGetList("final", ["restriction", "extension", "substitution"]),
  1991             "default": GenerateGetList("final", ["restriction", "extension", "substitution"]),
  1875             "simpleType": GenerateGetList("final", ["list", "union", "restriction"])
  1992             "simpleType": GenerateGetList("final", ["list", "union", "restriction"])
  1876         }
  1993         }
  1877     },
  1994     },
  1878 
  1995 
  1879     "finalDefault": {
  1996     "finalDefault": {
  1880         "type": SYNTAXATTRIBUTE, 
  1997         "type": SYNTAXATTRIBUTE,
  1881         "extract": {
  1998         "extract": {
  1882             "default": GenerateGetList("finalDefault", ["restriction", "extension", "list", "union"])
  1999             "default": GenerateGetList("finalDefault", ["restriction", "extension", "list", "union"])
  1883         },
  2000         },
  1884         "default": {
  2001         "default": {
  1885             "default": ""
  2002             "default": ""
  1886         }
  2003         }
  1887     },
  2004     },
  1888     
  2005 
  1889     "fixed": {
  2006     "fixed": {
  1890         "type": SYNTAXATTRIBUTE, 
  2007         "type": SYNTAXATTRIBUTE,
  1891         "extract": {
  2008         "extract": {
  1892             "default": GetBoolean,
  2009             "default": GetBoolean,
  1893             "attribute": GetAttributeValue,
  2010             "attribute": GetAttributeValue,
  1894             "element": GetAttributeValue
  2011             "element": GetAttributeValue
  1895         },
  2012         },
  1899             "element": None
  2016             "element": None
  1900         }
  2017         }
  1901     },
  2018     },
  1902 
  2019 
  1903     "form": {
  2020     "form": {
  1904         "type": SYNTAXATTRIBUTE, 
  2021         "type": SYNTAXATTRIBUTE,
  1905         "extract": {
  2022         "extract": {
  1906             "default": GenerateEnumeratedExtraction("member form", ["qualified", "unqualified"])
  2023             "default": GenerateEnumeratedExtraction("member form", ["qualified", "unqualified"])
  1907         }
  2024         }
  1908     },
  2025     },
  1909 
  2026 
  1910     "id": {
  2027     "id": {
  1911         "type": SYNTAXATTRIBUTE, 
  2028         "type": SYNTAXATTRIBUTE,
  1912         "extract": {
  2029         "extract": {
  1913             "default": GenerateModelNameExtraction("member id", NCName_model)
  2030             "default": GenerateModelNameExtraction("member id", NCName_model)
  1914         }
  2031         }
  1915     },
  2032     },
  1916     
  2033 
  1917     "itemType": {
  2034     "itemType": {
  1918         "type": SYNTAXATTRIBUTE, 
  2035         "type": SYNTAXATTRIBUTE,
  1919         "extract": {
  2036         "extract": {
  1920             "default": GenerateModelNameExtraction("member itemType", QName_model)
  2037             "default": GenerateModelNameExtraction("member itemType", QName_model)
  1921         }
  2038         }
  1922     },
  2039     },
  1923 
  2040 
  1924     "memberTypes": {
  2041     "memberTypes": {
  1925         "type": SYNTAXATTRIBUTE, 
  2042         "type": SYNTAXATTRIBUTE,
  1926         "extract": {
  2043         "extract": {
  1927             "default": GenerateModelNameListExtraction("member memberTypes", QNames_model)
  2044             "default": GenerateModelNameListExtraction("member memberTypes", QNames_model)
  1928         },
  2045         },
  1929     },
  2046     },
  1930     
  2047 
  1931     "maxOccurs": {
  2048     "maxOccurs": {
  1932         "type": SYNTAXATTRIBUTE, 
  2049         "type": SYNTAXATTRIBUTE,
  1933         "extract": {
  2050         "extract": {
  1934             "default": GenerateLimitExtraction(),
  2051             "default": GenerateLimitExtraction(),
  1935             "all": GenerateLimitExtraction(1, 1, False)
  2052             "all": GenerateLimitExtraction(1, 1, False)
  1936         },
  2053         },
  1937         "default": {
  2054         "default": {
  1938             "default": 1
  2055             "default": 1
  1939         }
  2056         }
  1940     },
  2057     },
  1941 
  2058 
  1942     "minOccurs": {
  2059     "minOccurs": {
  1943         "type": SYNTAXATTRIBUTE, 
  2060         "type": SYNTAXATTRIBUTE,
  1944         "extract": {
  2061         "extract": {
  1945             "default": GenerateLimitExtraction(unbounded = False),
  2062             "default": GenerateLimitExtraction(unbounded=False),
  1946             "all": GenerateLimitExtraction(0, 1, False)
  2063             "all": GenerateLimitExtraction(0, 1, False)
  1947         },
  2064         },
  1948         "default": {
  2065         "default": {
  1949             "default": 1
  2066             "default": 1
  1950         }
  2067         }
  1951     },
  2068     },
  1952 
  2069 
  1953     "mixed": {
  2070     "mixed": {
  1954         "type": SYNTAXATTRIBUTE, 
  2071         "type": SYNTAXATTRIBUTE,
  1955         "extract": {
  2072         "extract": {
  1956             "default": GetBoolean
  2073             "default": GetBoolean
  1957         },
  2074         },
  1958         "default": {
  2075         "default": {
  1959             "default": None,
  2076             "default": None,
  1960             "complexType": False
  2077             "complexType": False
  1961         }
  2078         }
  1962     },
  2079     },
  1963     
  2080 
  1964     "name": {
  2081     "name": {
  1965         "type": SYNTAXATTRIBUTE, 
  2082         "type": SYNTAXATTRIBUTE,
  1966         "extract": {
  2083         "extract": {
  1967             "default": GenerateModelNameExtraction("member name", NCName_model)
  2084             "default": GenerateModelNameExtraction("member name", NCName_model)
  1968         }
  2085         }
  1969     },
  2086     },
  1970     
  2087 
  1971     "namespace": {
  2088     "namespace": {
  1972         "type": SYNTAXATTRIBUTE, 
  2089         "type": SYNTAXATTRIBUTE,
  1973         "extract": {
  2090         "extract": {
  1974             "default": GenerateModelNameExtraction("member namespace", URI_model),
  2091             "default": GenerateModelNameExtraction("member namespace", URI_model),
  1975             "any": GetNamespaces
  2092             "any": GetNamespaces
  1976         },
  2093         },
  1977         "default": {
  2094         "default": {
  1979             "any": "##any"
  2096             "any": "##any"
  1980         }
  2097         }
  1981     },
  2098     },
  1982 
  2099 
  1983     "nillable": {
  2100     "nillable": {
  1984         "type": SYNTAXATTRIBUTE, 
  2101         "type": SYNTAXATTRIBUTE,
  1985         "extract": {
  2102         "extract": {
  1986             "default": GetBoolean
  2103             "default": GetBoolean
  1987         },
  2104         },
  1988     },
  2105     },
  1989     
  2106 
  1990     "processContents": {
  2107     "processContents": {
  1991         "type": SYNTAXATTRIBUTE, 
  2108         "type": SYNTAXATTRIBUTE,
  1992         "extract": {
  2109         "extract": {
  1993             "default": GenerateEnumeratedExtraction("member processContents", ["lax", "skip", "strict"])
  2110             "default": GenerateEnumeratedExtraction("member processContents", ["lax", "skip", "strict"])
  1994         },
  2111         },
  1995         "default": {
  2112         "default": {
  1996             "default": "strict"
  2113             "default": "strict"
  1997         }
  2114         }
  1998     },
  2115     },
  1999     
  2116 
  2000     "ref": {
  2117     "ref": {
  2001         "type": SYNTAXATTRIBUTE, 
  2118         "type": SYNTAXATTRIBUTE,
  2002         "extract": {
  2119         "extract": {
  2003             "default": GenerateModelNameExtraction("member ref", QName_model)
  2120             "default": GenerateModelNameExtraction("member ref", QName_model)
  2004         }
  2121         }
  2005     },
  2122     },
  2006 
  2123 
  2008         "type": SYNTAXATTRIBUTE,
  2125         "type": SYNTAXATTRIBUTE,
  2009         "extract": {
  2126         "extract": {
  2010             "default": GenerateModelNameExtraction("member refer", QName_model)
  2127             "default": GenerateModelNameExtraction("member refer", QName_model)
  2011         }
  2128         }
  2012     },
  2129     },
  2013     
  2130 
  2014     "schemaLocation": {
  2131     "schemaLocation": {
  2015         "type": SYNTAXATTRIBUTE, 
  2132         "type": SYNTAXATTRIBUTE,
  2016         "extract": {
  2133         "extract": {
  2017             "default": GenerateModelNameExtraction("member schemaLocation", URI_model)
  2134             "default": GenerateModelNameExtraction("member schemaLocation", URI_model)
  2018         }
  2135         }
  2019     },
  2136     },
  2020     
  2137 
  2021     "source": {
  2138     "source": {
  2022         "type": SYNTAXATTRIBUTE,
  2139         "type": SYNTAXATTRIBUTE,
  2023         "extract": {
  2140         "extract": {
  2024             "default": GenerateModelNameExtraction("member source", URI_model)
  2141             "default": GenerateModelNameExtraction("member source", URI_model)
  2025         }
  2142         }
  2026     },
  2143     },
  2027     
  2144 
  2028     "substitutionGroup": {
  2145     "substitutionGroup": {
  2029         "type": SYNTAXATTRIBUTE, 
  2146         "type": SYNTAXATTRIBUTE,
  2030         "extract": {
  2147         "extract": {
  2031             "default": GenerateModelNameExtraction("member substitutionGroup", QName_model)
  2148             "default": GenerateModelNameExtraction("member substitutionGroup", QName_model)
  2032         }
  2149         }
  2033     },
  2150     },
  2034 
  2151 
  2035     "targetNamespace": {
  2152     "targetNamespace": {
  2036         "type": SYNTAXATTRIBUTE, 
  2153         "type": SYNTAXATTRIBUTE,
  2037         "extract": {
  2154         "extract": {
  2038             "default": GenerateModelNameExtraction("member targetNamespace", URI_model)
  2155             "default": GenerateModelNameExtraction("member targetNamespace", URI_model)
  2039         }
  2156         }
  2040     },
  2157     },
  2041     
  2158 
  2042     "type": {
  2159     "type": {
  2043         "type": SYNTAXATTRIBUTE, 
  2160         "type": SYNTAXATTRIBUTE,
  2044         "extract": {
  2161         "extract": {
  2045             "default": GenerateModelNameExtraction("member type", QName_model)
  2162             "default": GenerateModelNameExtraction("member type", QName_model)
  2046         }
  2163         }
  2047     },
  2164     },
  2048 
  2165 
  2049     "use": {
  2166     "use": {
  2050         "type": SYNTAXATTRIBUTE, 
  2167         "type": SYNTAXATTRIBUTE,
  2051         "extract": {
  2168         "extract": {
  2052             "default": GenerateEnumeratedExtraction("member usage", ["required", "optional", "prohibited"])
  2169             "default": GenerateEnumeratedExtraction("member usage", ["required", "optional", "prohibited"])
  2053         },
  2170         },
  2054         "default": {
  2171         "default": {
  2055             "default": "optional"
  2172             "default": "optional"
  2056         }
  2173         }
  2057     },
  2174     },
  2058 
  2175 
  2059     "value": {
  2176     "value": {
  2060         "type": SYNTAXATTRIBUTE, 
  2177         "type": SYNTAXATTRIBUTE,
  2061         "extract": {
  2178         "extract": {
  2062             "default": GetAttributeValue,
  2179             "default": GetAttributeValue,
  2063             "fractionDigits": GenerateIntegerExtraction(minInclusive=0),
  2180             "fractionDigits": GenerateIntegerExtraction(minInclusive=0),
  2064             "length": GenerateIntegerExtraction(minInclusive=0),
  2181             "length": GenerateIntegerExtraction(minInclusive=0),
  2065             "maxLength": GenerateIntegerExtraction(minInclusive=0),
  2182             "maxLength": GenerateIntegerExtraction(minInclusive=0),
  2075             "default": GetToken
  2192             "default": GetToken
  2076         }
  2193         }
  2077     },
  2194     },
  2078 
  2195 
  2079     "xpath": {
  2196     "xpath": {
  2080         "type": SYNTAXATTRIBUTE, 
  2197         "type": SYNTAXATTRIBUTE,
  2081         "extract": {
  2198         "extract": {
  2082 #            "default": NotSupportedYet("xpath")
  2199             # "default": NotSupportedYet("xpath")
  2083             "default": GetAttributeValue
  2200             "default": GetAttributeValue
  2084         }
  2201         }
  2085     },
  2202     },
  2086     
  2203 
  2087 #-------------------------------------------------------------------------------
  2204     # -------------------------------------------------------------------------------
  2088 #                           Simple types definition
  2205     #                           Simple types definition
  2089 #-------------------------------------------------------------------------------
  2206     # -------------------------------------------------------------------------------
  2090 
  2207 
  2091     "string": {
  2208     "string": {
  2092         "type": SIMPLETYPE,
  2209         "type": SIMPLETYPE,
  2093         "basename": "string",
  2210         "basename": "string",
  2094         "extract": GetAttributeValue,
  2211         "extract": GetAttributeValue,
  2095         "facets": STRING_FACETS,
  2212         "facets": STRING_FACETS,
  2096         "generate": GenerateSimpleTypeXMLText(lambda x : x),
  2213         "generate": GenerateSimpleTypeXMLText(lambda x: x),
  2097         "initial": lambda: "",
  2214         "initial": lambda: "",
  2098         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2215         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2099     },
  2216     },
  2100 
  2217 
  2101     "normalizedString": {
  2218     "normalizedString": {
  2102         "type": SIMPLETYPE,
  2219         "type": SIMPLETYPE,
  2103         "basename": "normalizedString",
  2220         "basename": "normalizedString",
  2104         "extract": GetNormalizedString,
  2221         "extract": GetNormalizedString,
  2105         "facets": STRING_FACETS,
  2222         "facets": STRING_FACETS,
  2106         "generate": GenerateSimpleTypeXMLText(lambda x : x),
  2223         "generate": GenerateSimpleTypeXMLText(lambda x: x),
  2107         "initial": lambda: "",
  2224         "initial": lambda: "",
  2108         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2225         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2109     },
  2226     },
  2110 
  2227 
  2111     "token": {
  2228     "token": {
  2112         "type": SIMPLETYPE,
  2229         "type": SIMPLETYPE,
  2113         "basename": "token",  
  2230         "basename": "token",
  2114         "extract": GetToken,
  2231         "extract": GetToken,
  2115         "facets": STRING_FACETS,
  2232         "facets": STRING_FACETS,
  2116         "generate": GenerateSimpleTypeXMLText(lambda x : x),
  2233         "generate": GenerateSimpleTypeXMLText(lambda x: x),
  2117         "initial": lambda: "",
  2234         "initial": lambda: "",
  2118         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2235         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2119     },
  2236     },
  2120     
  2237 
  2121     "base64Binary": {
  2238     "base64Binary": {
  2122         "type": SIMPLETYPE, 
  2239         "type": SIMPLETYPE,
  2123         "basename": "base64Binary", 
  2240         "basename": "base64Binary",
  2124         "extract": NotSupportedYet("base64Binary"),
  2241         "extract": NotSupportedYet("base64Binary"),
  2125         "facets": STRING_FACETS,
  2242         "facets": STRING_FACETS,
  2126         "generate": GenerateSimpleTypeXMLText(str),
  2243         "generate": GenerateSimpleTypeXMLText(str),
  2127         "initial": lambda: 0,
  2244         "initial": lambda: 0,
  2128         "check": lambda x: isinstance(x, (IntType, LongType))
  2245         "check": lambda x: isinstance(x, (IntType, LongType))
  2129     },
  2246     },
  2130     
  2247 
  2131     "hexBinary": {
  2248     "hexBinary": {
  2132         "type": SIMPLETYPE,
  2249         "type": SIMPLETYPE,
  2133         "basename": "hexBinary", 
  2250         "basename": "hexBinary",
  2134         "extract": GetHexInteger,
  2251         "extract": GetHexInteger,
  2135         "facets": STRING_FACETS,
  2252         "facets": STRING_FACETS,
  2136         "generate": GenerateSimpleTypeXMLText(lambda x: ("%."+str(int(round(len("%X"%x)/2.)*2))+"X")%x),
  2253         "generate": GenerateSimpleTypeXMLText(lambda x: ("%."+str(int(round(len("%X" % x)/2.)*2))+"X") % x),
  2137         "initial": lambda: 0,
  2254         "initial": lambda: 0,
  2138         "check": lambda x: isinstance(x, (IntType, LongType))
  2255         "check": lambda x: isinstance(x, (IntType, LongType))
  2139     },
  2256     },
  2140 
  2257 
  2141     "integer": {
  2258     "integer": {
  2142         "type": SIMPLETYPE,
  2259         "type": SIMPLETYPE,
  2143         "basename": "integer", 
  2260         "basename": "integer",
  2144         "extract": GenerateIntegerExtraction(),
  2261         "extract": GenerateIntegerExtraction(),
  2145         "facets": DECIMAL_FACETS,
  2262         "facets": DECIMAL_FACETS,
  2146         "generate": GenerateSimpleTypeXMLText(str),
  2263         "generate": GenerateSimpleTypeXMLText(str),
  2147         "initial": lambda: 0,
  2264         "initial": lambda: 0,
  2148         "check": lambda x: isinstance(x, IntType)
  2265         "check": lambda x: isinstance(x, IntType)
  2149     },
  2266     },
  2150     
  2267 
  2151     "positiveInteger": {
  2268     "positiveInteger": {
  2152         "type": SIMPLETYPE,
  2269         "type": SIMPLETYPE,
  2153         "basename": "positiveInteger", 
  2270         "basename": "positiveInteger",
  2154         "extract": GenerateIntegerExtraction(minExclusive=0),
  2271         "extract": GenerateIntegerExtraction(minExclusive=0),
  2155         "facets": DECIMAL_FACETS,
  2272         "facets": DECIMAL_FACETS,
  2156         "generate": GenerateSimpleTypeXMLText(str),
  2273         "generate": GenerateSimpleTypeXMLText(str),
  2157         "initial": lambda: 1,
  2274         "initial": lambda: 1,
  2158         "check": lambda x: isinstance(x, IntType)
  2275         "check": lambda x: isinstance(x, IntType)
  2159     },
  2276     },
  2160     
  2277 
  2161     "negativeInteger": {
  2278     "negativeInteger": {
  2162         "type": SIMPLETYPE,
  2279         "type": SIMPLETYPE,
  2163         "basename": "negativeInteger",
  2280         "basename": "negativeInteger",
  2164         "extract": GenerateIntegerExtraction(maxExclusive=0),
  2281         "extract": GenerateIntegerExtraction(maxExclusive=0),
  2165         "facets": DECIMAL_FACETS,
  2282         "facets": DECIMAL_FACETS,
  2166         "generate": GenerateSimpleTypeXMLText(str),
  2283         "generate": GenerateSimpleTypeXMLText(str),
  2167         "initial": lambda: -1,
  2284         "initial": lambda: -1,
  2168         "check": lambda x: isinstance(x, IntType)
  2285         "check": lambda x: isinstance(x, IntType)
  2169     },
  2286     },
  2170     
  2287 
  2171     "nonNegativeInteger": {
  2288     "nonNegativeInteger": {
  2172         "type": SIMPLETYPE, 
  2289         "type": SIMPLETYPE,
  2173         "basename": "nonNegativeInteger", 
  2290         "basename": "nonNegativeInteger",
  2174         "extract": GenerateIntegerExtraction(minInclusive=0),
  2291         "extract": GenerateIntegerExtraction(minInclusive=0),
  2175         "facets": DECIMAL_FACETS,
  2292         "facets": DECIMAL_FACETS,
  2176         "generate": GenerateSimpleTypeXMLText(str),
  2293         "generate": GenerateSimpleTypeXMLText(str),
  2177         "initial": lambda: 0,
  2294         "initial": lambda: 0,
  2178         "check": lambda x: isinstance(x, IntType)
  2295         "check": lambda x: isinstance(x, IntType)
  2179     },
  2296     },
  2180     
  2297 
  2181     "nonPositiveInteger": {
  2298     "nonPositiveInteger": {
  2182         "type": SIMPLETYPE,
  2299         "type": SIMPLETYPE,
  2183         "basename": "nonPositiveInteger", 
  2300         "basename": "nonPositiveInteger",
  2184         "extract": GenerateIntegerExtraction(maxInclusive=0),
  2301         "extract": GenerateIntegerExtraction(maxInclusive=0),
  2185         "facets": DECIMAL_FACETS,
  2302         "facets": DECIMAL_FACETS,
  2186         "generate": GenerateSimpleTypeXMLText(str),
  2303         "generate": GenerateSimpleTypeXMLText(str),
  2187         "initial": lambda: 0,
  2304         "initial": lambda: 0,
  2188         "check": lambda x: isinstance(x, IntType)
  2305         "check": lambda x: isinstance(x, IntType)
  2189     },
  2306     },
  2190     
  2307 
  2191     "long": {
  2308     "long": {
  2192         "type": SIMPLETYPE,
  2309         "type": SIMPLETYPE,
  2193         "basename": "long",
  2310         "basename": "long",
  2194         "extract": GenerateIntegerExtraction(minInclusive=-2**63,maxExclusive=2**63),
  2311         "extract": GenerateIntegerExtraction(minInclusive=-2**63, maxExclusive=2**63),
  2195         "facets": DECIMAL_FACETS,
  2312         "facets": DECIMAL_FACETS,
  2196         "generate": GenerateSimpleTypeXMLText(str),
  2313         "generate": GenerateSimpleTypeXMLText(str),
  2197         "initial": lambda: 0,
  2314         "initial": lambda: 0,
  2198         "check": lambda x: isinstance(x, IntType)
  2315         "check": lambda x: isinstance(x, IntType)
  2199     },
  2316     },
  2200     
  2317 
  2201     "unsignedLong": {
  2318     "unsignedLong": {
  2202         "type": SIMPLETYPE,
  2319         "type": SIMPLETYPE,
  2203         "basename": "unsignedLong",
  2320         "basename": "unsignedLong",
  2204         "extract": GenerateIntegerExtraction(minInclusive=0,maxExclusive=2**64),
  2321         "extract": GenerateIntegerExtraction(minInclusive=0, maxExclusive=2**64),
  2205         "facets": DECIMAL_FACETS,
  2322         "facets": DECIMAL_FACETS,
  2206         "generate": GenerateSimpleTypeXMLText(str),
  2323         "generate": GenerateSimpleTypeXMLText(str),
  2207         "initial": lambda: 0,
  2324         "initial": lambda: 0,
  2208         "check": lambda x: isinstance(x, IntType)
  2325         "check": lambda x: isinstance(x, IntType)
  2209     },
  2326     },
  2210 
  2327 
  2211     "int": {
  2328     "int": {
  2212         "type": SIMPLETYPE,
  2329         "type": SIMPLETYPE,
  2213         "basename": "int",
  2330         "basename": "int",
  2214         "extract": GenerateIntegerExtraction(minInclusive=-2**31,maxExclusive=2**31),
  2331         "extract": GenerateIntegerExtraction(minInclusive=-2**31, maxExclusive=2**31),
  2215         "facets": DECIMAL_FACETS,
  2332         "facets": DECIMAL_FACETS,
  2216         "generate": GenerateSimpleTypeXMLText(str),
  2333         "generate": GenerateSimpleTypeXMLText(str),
  2217         "initial": lambda: 0,
  2334         "initial": lambda: 0,
  2218         "check": lambda x: isinstance(x, IntType)
  2335         "check": lambda x: isinstance(x, IntType)
  2219     },
  2336     },
  2220 
  2337 
  2221     "unsignedInt": {
  2338     "unsignedInt": {
  2222         "type": SIMPLETYPE,
  2339         "type": SIMPLETYPE,
  2223         "basename": "unsignedInt",
  2340         "basename": "unsignedInt",
  2224         "extract": GenerateIntegerExtraction(minInclusive=0,maxExclusive=2**32),
  2341         "extract": GenerateIntegerExtraction(minInclusive=0, maxExclusive=2**32),
  2225         "facets": DECIMAL_FACETS,
  2342         "facets": DECIMAL_FACETS,
  2226         "generate": GenerateSimpleTypeXMLText(str),
  2343         "generate": GenerateSimpleTypeXMLText(str),
  2227         "initial": lambda: 0,
  2344         "initial": lambda: 0,
  2228         "check": lambda x: isinstance(x, IntType)
  2345         "check": lambda x: isinstance(x, IntType)
  2229     },
  2346     },
  2230 
  2347 
  2231     "short": {
  2348     "short": {
  2232         "type": SIMPLETYPE,
  2349         "type": SIMPLETYPE,
  2233         "basename": "short",
  2350         "basename": "short",
  2234         "extract": GenerateIntegerExtraction(minInclusive=-2**15,maxExclusive=2**15),
  2351         "extract": GenerateIntegerExtraction(minInclusive=-2**15, maxExclusive=2**15),
  2235         "facets": DECIMAL_FACETS,
  2352         "facets": DECIMAL_FACETS,
  2236         "generate": GenerateSimpleTypeXMLText(str),
  2353         "generate": GenerateSimpleTypeXMLText(str),
  2237         "initial": lambda: 0,
  2354         "initial": lambda: 0,
  2238         "check": lambda x: isinstance(x, IntType)
  2355         "check": lambda x: isinstance(x, IntType)
  2239     },
  2356     },
  2240 
  2357 
  2241     "unsignedShort": {
  2358     "unsignedShort": {
  2242         "type": SIMPLETYPE,
  2359         "type": SIMPLETYPE,
  2243         "basename": "unsignedShort", 
  2360         "basename": "unsignedShort",
  2244         "extract": GenerateIntegerExtraction(minInclusive=0,maxExclusive=2**16),
  2361         "extract": GenerateIntegerExtraction(minInclusive=0, maxExclusive=2**16),
  2245         "facets": DECIMAL_FACETS,
  2362         "facets": DECIMAL_FACETS,
  2246         "generate": GenerateSimpleTypeXMLText(str),
  2363         "generate": GenerateSimpleTypeXMLText(str),
  2247         "initial": lambda: 0,
  2364         "initial": lambda: 0,
  2248         "check": lambda x: isinstance(x, IntType)
  2365         "check": lambda x: isinstance(x, IntType)
  2249     },
  2366     },
  2250 
  2367 
  2251     "byte": {
  2368     "byte": {
  2252         "type": SIMPLETYPE,
  2369         "type": SIMPLETYPE,
  2253         "basename": "byte",
  2370         "basename": "byte",
  2254         "extract": GenerateIntegerExtraction(minInclusive=-2**7,maxExclusive=2**7),
  2371         "extract": GenerateIntegerExtraction(minInclusive=-2**7, maxExclusive=2**7),
  2255         "facets": DECIMAL_FACETS,
  2372         "facets": DECIMAL_FACETS,
  2256         "generate": GenerateSimpleTypeXMLText(str),
  2373         "generate": GenerateSimpleTypeXMLText(str),
  2257         "initial": lambda: 0,
  2374         "initial": lambda: 0,
  2258         "check": lambda x: isinstance(x, IntType)
  2375         "check": lambda x: isinstance(x, IntType)
  2259     },
  2376     },
  2260 
  2377 
  2261     "unsignedByte": {
  2378     "unsignedByte": {
  2262         "type": SIMPLETYPE,
  2379         "type": SIMPLETYPE,
  2263         "basename": "unsignedByte",
  2380         "basename": "unsignedByte",
  2264         "extract": GenerateIntegerExtraction(minInclusive=0,maxExclusive=2**8),
  2381         "extract": GenerateIntegerExtraction(minInclusive=0, maxExclusive=2**8),
  2265         "facets": DECIMAL_FACETS,
  2382         "facets": DECIMAL_FACETS,
  2266         "generate": GenerateSimpleTypeXMLText(str),
  2383         "generate": GenerateSimpleTypeXMLText(str),
  2267         "initial": lambda: 0,
  2384         "initial": lambda: 0,
  2268         "check": lambda x: isinstance(x, IntType)
  2385         "check": lambda x: isinstance(x, IntType)
  2269     },
  2386     },
  2283         "basename": "float",
  2400         "basename": "float",
  2284         "extract": GenerateFloatExtraction("float", ["INF", "-INF", "NaN"]),
  2401         "extract": GenerateFloatExtraction("float", ["INF", "-INF", "NaN"]),
  2285         "facets": NUMBER_FACETS,
  2402         "facets": NUMBER_FACETS,
  2286         "generate": GenerateFloatXMLText(["INF", "-INF", "NaN"]),
  2403         "generate": GenerateFloatXMLText(["INF", "-INF", "NaN"]),
  2287         "initial": lambda: 0.,
  2404         "initial": lambda: 0.,
  2288         "check": lambda x: {"INF" : True, "-INF" : True, "NaN" : True}.get(x, isinstance(x, (IntType, FloatType)))
  2405         "check": lambda x: {"INF": True, "-INF": True, "NaN": True}.get(x, isinstance(x, (IntType, FloatType)))
  2289     },
  2406     },
  2290 
  2407 
  2291     "double": {
  2408     "double": {
  2292         "type": SIMPLETYPE,
  2409         "type": SIMPLETYPE,
  2293         "basename": "double",
  2410         "basename": "double",
  2294         "extract": GenerateFloatExtraction("double", ["INF", "-INF", "NaN"]),
  2411         "extract": GenerateFloatExtraction("double", ["INF", "-INF", "NaN"]),
  2295         "facets": NUMBER_FACETS,
  2412         "facets": NUMBER_FACETS,
  2296         "generate": GenerateFloatXMLText(["INF", "-INF", "NaN"]),
  2413         "generate": GenerateFloatXMLText(["INF", "-INF", "NaN"]),
  2297         "initial": lambda: 0.,
  2414         "initial": lambda: 0.,
  2298         "check": lambda x: {"INF" : True, "-INF" : True, "NaN" : True}.get(x, isinstance(x, (IntType, FloatType)))
  2415         "check": lambda x: {"INF": True, "-INF": True, "NaN": True}.get(x, isinstance(x, (IntType, FloatType)))
  2299     },
  2416     },
  2300 
  2417 
  2301     "boolean": {
  2418     "boolean": {
  2302         "type": SIMPLETYPE,
  2419         "type": SIMPLETYPE,
  2303         "basename": "boolean",
  2420         "basename": "boolean",
  2304         "extract": GetBoolean,
  2421         "extract": GetBoolean,
  2305         "facets": GenerateDictFacets(["pattern", "whiteSpace"]),
  2422         "facets": GenerateDictFacets(["pattern", "whiteSpace"]),
  2306         "generate": GenerateSimpleTypeXMLText(lambda x:{True : "true", False : "false"}[x]),
  2423         "generate": GenerateSimpleTypeXMLText(lambda x: {True: "true", False: "false"}[x]),
  2307         "initial": lambda: False,
  2424         "initial": lambda: False,
  2308         "check": lambda x: isinstance(x, BooleanType)
  2425         "check": lambda x: isinstance(x, BooleanType)
  2309     },	
  2426     },
  2310 
  2427 
  2311     "duration": {
  2428     "duration": {
  2312         "type": SIMPLETYPE,
  2429         "type": SIMPLETYPE,
  2313         "basename": "duration",
  2430         "basename": "duration",
  2314         "extract": NotSupportedYet("duration"),
  2431         "extract": NotSupportedYet("duration"),
  2322         "type": SIMPLETYPE,
  2439         "type": SIMPLETYPE,
  2323         "basename": "dateTime",
  2440         "basename": "dateTime",
  2324         "extract": GetDateTime,
  2441         "extract": GetDateTime,
  2325         "facets": NUMBER_FACETS,
  2442         "facets": NUMBER_FACETS,
  2326         "generate": GenerateSimpleTypeXMLText(datetime.datetime.isoformat),
  2443         "generate": GenerateSimpleTypeXMLText(datetime.datetime.isoformat),
  2327         "initial": lambda: datetime.datetime(1,1,1,0,0,0,0),
  2444         "initial": lambda: datetime.datetime(1, 1, 1, 0, 0, 0, 0),
  2328         "check": lambda x: isinstance(x, datetime.datetime)
  2445         "check": lambda x: isinstance(x, datetime.datetime)
  2329     },
  2446     },
  2330 
  2447 
  2331     "date": {
  2448     "date": {
  2332         "type": SIMPLETYPE,
  2449         "type": SIMPLETYPE,
  2333         "basename": "date",
  2450         "basename": "date",
  2334         "extract": GetDate,
  2451         "extract": GetDate,
  2335         "facets": NUMBER_FACETS,
  2452         "facets": NUMBER_FACETS,
  2336         "generate": GenerateSimpleTypeXMLText(datetime.date.isoformat),
  2453         "generate": GenerateSimpleTypeXMLText(datetime.date.isoformat),
  2337         "initial": lambda: datetime.date(1,1,1),
  2454         "initial": lambda: datetime.date(1, 1, 1),
  2338         "check": lambda x: isinstance(x, datetime.date)
  2455         "check": lambda x: isinstance(x, datetime.date)
  2339     },
  2456     },
  2340     
  2457 
  2341     "time": {
  2458     "time": {
  2342         "type": SIMPLETYPE,
  2459         "type": SIMPLETYPE,
  2343         "basename": "time",
  2460         "basename": "time",
  2344         "extract": GetTime,
  2461         "extract": GetTime,
  2345         "facets": NUMBER_FACETS,
  2462         "facets": NUMBER_FACETS,
  2346         "generate": GenerateSimpleTypeXMLText(datetime.time.isoformat),
  2463         "generate": GenerateSimpleTypeXMLText(datetime.time.isoformat),
  2347         "initial": lambda: datetime.time(0,0,0,0),
  2464         "initial": lambda: datetime.time(0, 0, 0, 0),
  2348         "check": lambda x: isinstance(x, datetime.time)
  2465         "check": lambda x: isinstance(x, datetime.time)
  2349     },
  2466     },
  2350 
  2467 
  2351     "gYear": {
  2468     "gYear": {
  2352         "type": SIMPLETYPE,
  2469         "type": SIMPLETYPE,
  2405         "facets": STRING_FACETS,
  2522         "facets": STRING_FACETS,
  2406         "generate": GenerateSimpleTypeXMLText(lambda x: x),
  2523         "generate": GenerateSimpleTypeXMLText(lambda x: x),
  2407         "initial": lambda: "",
  2524         "initial": lambda: "",
  2408         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2525         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2409     },
  2526     },
  2410     
  2527 
  2411     "QName": {
  2528     "QName": {
  2412         "type": SIMPLETYPE,
  2529         "type": SIMPLETYPE,
  2413         "basename": "QName",
  2530         "basename": "QName",
  2414         "extract": GenerateModelNameExtraction("QName", QName_model),
  2531         "extract": GenerateModelNameExtraction("QName", QName_model),
  2415         "facets": STRING_FACETS,
  2532         "facets": STRING_FACETS,
  2527         "initial": lambda: "",
  2644         "initial": lambda: "",
  2528         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2645         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2529     },
  2646     },
  2530 
  2647 
  2531     # Complex Types
  2648     # Complex Types
  2532     "anyType": {"type": COMPLEXTYPE, "extract": lambda x:None},
  2649     "anyType": {"type": COMPLEXTYPE, "extract": lambda x: None},
  2533 }
  2650 }
  2534