xmlclass/xsdschema.py
changeset 1739 ec153828ded2
parent 1736 7e61baa047f0
child 1740 b789b695b5c6
equal deleted inserted replaced
1738:d2e979738700 1739:ec153828ded2
   666 
   666 
   667 
   667 
   668 # Attribute elements
   668 # Attribute elements
   669 
   669 
   670 def ReduceAnyAttribute(factory, attributes, elements):
   670 def ReduceAnyAttribute(factory, attributes, elements):
   671     return {"type" : "anyAttribute"}
   671     return {"type": "anyAttribute"}
   672 
   672 
   673 
   673 
   674 def ReduceAttribute(factory, attributes, elements):
   674 def ReduceAttribute(factory, attributes, elements):
   675     annotations, children = factory.ReduceElements(elements)
   675     annotations, children = factory.ReduceElements(elements)
   676 
   676 
  1311                 re.compile("((?:annotation )?(?:simpleContent |complexContent |(?:(?:group |all |choice |sequence )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))))"))
  1311                 re.compile("((?:annotation )?(?:simpleContent |complexContent |(?:(?:group |all |choice |sequence )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))))"))
  1312         },
  1312         },
  1313         "reduce": ReduceComplexType
  1313         "reduce": ReduceComplexType
  1314     },
  1314     },
  1315 
  1315 
  1316     "documentation": {"struct" : """
  1316     "documentation": {"struct": """
  1317         <documentation
  1317         <documentation
  1318           source = anyURI
  1318           source = anyURI
  1319           xml:lang = language
  1319           xml:lang = language
  1320           {any attributes with non-schema namespace . . .}>
  1320           {any attributes with non-schema namespace . . .}>
  1321           Content: ({any})*
  1321           Content: ({any})*
  1502                 re.compile("((?:annotation )?(?:selector (?:field )+))"))
  1502                 re.compile("((?:annotation )?(?:selector (?:field )+))"))
  1503         },
  1503         },
  1504         "reduce": ReduceKeyRef
  1504         "reduce": ReduceKeyRef
  1505     },
  1505     },
  1506 
  1506 
  1507     "length": {"struct" : """
  1507     "length": {"struct": """
  1508         <length
  1508         <length
  1509           fixed = boolean : false
  1509           fixed = boolean : false
  1510           id = ID
  1510           id = ID
  1511           value = nonNegativeInteger
  1511           value = nonNegativeInteger
  1512           {any attributes with non-schema namespace . . .}>
  1512           {any attributes with non-schema namespace . . .}>
  1728                 re.compile("((?:annotation )?(?:element |group |choice |sequence |any )*)"))
  1728                 re.compile("((?:annotation )?(?:element |group |choice |sequence |any )*)"))
  1729         },
  1729         },
  1730         "reduce": ReduceSequence
  1730         "reduce": ReduceSequence
  1731     },
  1731     },
  1732 
  1732 
  1733     "simpleContent": {"struct" : """
  1733     "simpleContent": {"struct": """
  1734         <simpleContent
  1734         <simpleContent
  1735           id = ID
  1735           id = ID
  1736           {any attributes with non-schema namespace . . .}>
  1736           {any attributes with non-schema namespace . . .}>
  1737           Content: (annotation?, (restriction | extension))
  1737           Content: (annotation?, (restriction | extension))
  1738         </simpleContent>""",
  1738         </simpleContent>""",
  1742                 re.compile("((?:annotation )?(?:restriction |extension ))"))
  1742                 re.compile("((?:annotation )?(?:restriction |extension ))"))
  1743         },
  1743         },
  1744         "reduce": ReduceSimpleContent
  1744         "reduce": ReduceSimpleContent
  1745     },
  1745     },
  1746 
  1746 
  1747     "simpleType": {"struct" : """
  1747     "simpleType": {"struct": """
  1748         <simpleType
  1748         <simpleType
  1749           final = (#all | List of (list | union | restriction))
  1749           final = (#all | List of (list | union | restriction))
  1750           id = ID
  1750           id = ID
  1751           name = NCName
  1751           name = NCName
  1752           {any attributes with non-schema namespace . . .}>
  1752           {any attributes with non-schema namespace . . .}>
  1758                 re.compile("((?:annotation )?(?:restriction |list |union ))"))
  1758                 re.compile("((?:annotation )?(?:restriction |list |union ))"))
  1759         },
  1759         },
  1760         "reduce": ReduceSimpleType
  1760         "reduce": ReduceSimpleType
  1761     },
  1761     },
  1762 
  1762 
  1763     "totalDigits": {"struct" : """
  1763     "totalDigits": {"struct": """
  1764         <totalDigits
  1764         <totalDigits
  1765           fixed = boolean : false
  1765           fixed = boolean : false
  1766           id = ID
  1766           id = ID
  1767           value = positiveInteger
  1767           value = positiveInteger
  1768           {any attributes with non-schema namespace . . .}>
  1768           {any attributes with non-schema namespace . . .}>
  1804                 re.compile("((?:annotation )?(?:selector |(?:field )+))"))
  1804                 re.compile("((?:annotation )?(?:selector |(?:field )+))"))
  1805         },
  1805         },
  1806         "reduce": ReduceUnique
  1806         "reduce": ReduceUnique
  1807     },
  1807     },
  1808 
  1808 
  1809     "whiteSpace": {"struct" : """
  1809     "whiteSpace": {"struct": """
  1810         <whiteSpace
  1810         <whiteSpace
  1811           fixed = boolean : false
  1811           fixed = boolean : false
  1812           id = ID
  1812           id = ID
  1813           value = (collapse | preserve | replace)
  1813           value = (collapse | preserve | replace)
  1814           {any attributes with non-schema namespace . . .}>
  1814           {any attributes with non-schema namespace . . .}>
  2110     "string": {
  2110     "string": {
  2111         "type": SIMPLETYPE,
  2111         "type": SIMPLETYPE,
  2112         "basename": "string",
  2112         "basename": "string",
  2113         "extract": GetAttributeValue,
  2113         "extract": GetAttributeValue,
  2114         "facets": STRING_FACETS,
  2114         "facets": STRING_FACETS,
  2115         "generate": GenerateSimpleTypeXMLText(lambda x : x),
  2115         "generate": GenerateSimpleTypeXMLText(lambda x: x),
  2116         "initial": lambda: "",
  2116         "initial": lambda: "",
  2117         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2117         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2118     },
  2118     },
  2119 
  2119 
  2120     "normalizedString": {
  2120     "normalizedString": {
  2121         "type": SIMPLETYPE,
  2121         "type": SIMPLETYPE,
  2122         "basename": "normalizedString",
  2122         "basename": "normalizedString",
  2123         "extract": GetNormalizedString,
  2123         "extract": GetNormalizedString,
  2124         "facets": STRING_FACETS,
  2124         "facets": STRING_FACETS,
  2125         "generate": GenerateSimpleTypeXMLText(lambda x : x),
  2125         "generate": GenerateSimpleTypeXMLText(lambda x: x),
  2126         "initial": lambda: "",
  2126         "initial": lambda: "",
  2127         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2127         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2128     },
  2128     },
  2129 
  2129 
  2130     "token": {
  2130     "token": {
  2131         "type": SIMPLETYPE,
  2131         "type": SIMPLETYPE,
  2132         "basename": "token",
  2132         "basename": "token",
  2133         "extract": GetToken,
  2133         "extract": GetToken,
  2134         "facets": STRING_FACETS,
  2134         "facets": STRING_FACETS,
  2135         "generate": GenerateSimpleTypeXMLText(lambda x : x),
  2135         "generate": GenerateSimpleTypeXMLText(lambda x: x),
  2136         "initial": lambda: "",
  2136         "initial": lambda: "",
  2137         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2137         "check": lambda x: isinstance(x, (StringType, UnicodeType))
  2138     },
  2138     },
  2139 
  2139 
  2140     "base64Binary": {
  2140     "base64Binary": {
  2302         "basename": "float",
  2302         "basename": "float",
  2303         "extract": GenerateFloatExtraction("float", ["INF", "-INF", "NaN"]),
  2303         "extract": GenerateFloatExtraction("float", ["INF", "-INF", "NaN"]),
  2304         "facets": NUMBER_FACETS,
  2304         "facets": NUMBER_FACETS,
  2305         "generate": GenerateFloatXMLText(["INF", "-INF", "NaN"]),
  2305         "generate": GenerateFloatXMLText(["INF", "-INF", "NaN"]),
  2306         "initial": lambda: 0.,
  2306         "initial": lambda: 0.,
  2307         "check": lambda x: {"INF" : True, "-INF" : True, "NaN" : True}.get(x, isinstance(x, (IntType, FloatType)))
  2307         "check": lambda x: {"INF": True, "-INF": True, "NaN": True}.get(x, isinstance(x, (IntType, FloatType)))
  2308     },
  2308     },
  2309 
  2309 
  2310     "double": {
  2310     "double": {
  2311         "type": SIMPLETYPE,
  2311         "type": SIMPLETYPE,
  2312         "basename": "double",
  2312         "basename": "double",
  2313         "extract": GenerateFloatExtraction("double", ["INF", "-INF", "NaN"]),
  2313         "extract": GenerateFloatExtraction("double", ["INF", "-INF", "NaN"]),
  2314         "facets": NUMBER_FACETS,
  2314         "facets": NUMBER_FACETS,
  2315         "generate": GenerateFloatXMLText(["INF", "-INF", "NaN"]),
  2315         "generate": GenerateFloatXMLText(["INF", "-INF", "NaN"]),
  2316         "initial": lambda: 0.,
  2316         "initial": lambda: 0.,
  2317         "check": lambda x: {"INF" : True, "-INF" : True, "NaN" : True}.get(x, isinstance(x, (IntType, FloatType)))
  2317         "check": lambda x: {"INF": True, "-INF": True, "NaN": True}.get(x, isinstance(x, (IntType, FloatType)))
  2318     },
  2318     },
  2319 
  2319 
  2320     "boolean": {
  2320     "boolean": {
  2321         "type": SIMPLETYPE,
  2321         "type": SIMPLETYPE,
  2322         "basename": "boolean",
  2322         "basename": "boolean",
  2323         "extract": GetBoolean,
  2323         "extract": GetBoolean,
  2324         "facets": GenerateDictFacets(["pattern", "whiteSpace"]),
  2324         "facets": GenerateDictFacets(["pattern", "whiteSpace"]),
  2325         "generate": GenerateSimpleTypeXMLText(lambda x:{True : "true", False : "false"}[x]),
  2325         "generate": GenerateSimpleTypeXMLText(lambda x:{True: "true", False: "false"}[x]),
  2326         "initial": lambda: False,
  2326         "initial": lambda: False,
  2327         "check": lambda x: isinstance(x, BooleanType)
  2327         "check": lambda x: isinstance(x, BooleanType)
  2328     },
  2328     },
  2329 
  2329 
  2330     "duration": {
  2330     "duration": {