2016-10-14 13:48:19 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2019-01-20 16:53:23 +01:00
|
|
|
# Copyright (c), 2016-2019, SISSA (International School for Advanced Studies).
|
2016-10-14 13:48:19 +02:00
|
|
|
# All rights reserved.
|
|
|
|
# This file is distributed under the terms of the MIT License.
|
|
|
|
# See the file 'LICENSE' in the root directory of the present
|
|
|
|
# distribution, or http://opensource.org/licenses/MIT.
|
|
|
|
#
|
|
|
|
# @author Davide Brunato <brunato@sissa.it>
|
|
|
|
#
|
|
|
|
"""
|
2016-12-23 16:55:50 +01:00
|
|
|
This module contains definitions and functions for XSD builtin datatypes.
|
2018-10-30 18:15:23 +01:00
|
|
|
|
|
|
|
Only atomic builtins are created, the list builtins types ('NMTOKENS', 'ENTITIES', 'IDREFS')
|
|
|
|
are created using the XSD 1.0 meta-schema or with and additional base schema for XSD 1.1.
|
2016-10-14 13:48:19 +02:00
|
|
|
"""
|
2018-09-15 22:18:16 +02:00
|
|
|
from __future__ import unicode_literals
|
2018-10-10 07:17:48 +02:00
|
|
|
|
2019-01-20 22:59:23 +01:00
|
|
|
import re
|
2018-06-04 15:02:26 +02:00
|
|
|
import base64
|
2016-10-14 13:48:19 +02:00
|
|
|
from decimal import Decimal
|
2019-05-04 23:52:54 +02:00
|
|
|
from math import isinf, isnan
|
2016-12-21 12:34:55 +01:00
|
|
|
|
2019-01-01 15:53:13 +01:00
|
|
|
from elementpath import datatypes
|
|
|
|
|
|
|
|
from ..compat import PY3, long_type, unicode_type
|
2017-12-14 13:38:23 +01:00
|
|
|
from ..exceptions import XMLSchemaValueError
|
2019-10-07 15:31:18 +02:00
|
|
|
from ..qnames import XSD_LENGTH, XSD_MIN_LENGTH, XSD_MAX_LENGTH, XSD_ENUMERATION, \
|
|
|
|
XSD_PATTERN, XSD_WHITE_SPACE, XSD_MIN_INCLUSIVE, XSD_MIN_EXCLUSIVE, XSD_MAX_INCLUSIVE, \
|
|
|
|
XSD_MAX_EXCLUSIVE, XSD_TOTAL_DIGITS, XSD_FRACTION_DIGITS, XSD_EXPLICIT_TIMEZONE, \
|
|
|
|
XSD_STRING, XSD_NORMALIZED_STRING, XSD_NAME, XSD_NCNAME, XSD_QNAME, XSD_TOKEN, \
|
|
|
|
XSD_NMTOKEN, XSD_ID, XSD_IDREF, XSD_LANGUAGE, XSD_DECIMAL, XSD_DOUBLE, XSD_FLOAT, \
|
|
|
|
XSD_INTEGER, XSD_BYTE, XSD_SHORT, XSD_INT, XSD_LONG, XSD_UNSIGNED_BYTE, \
|
|
|
|
XSD_UNSIGNED_SHORT, XSD_UNSIGNED_INT, XSD_UNSIGNED_LONG, XSD_POSITIVE_INTEGER, \
|
|
|
|
XSD_NEGATIVE_INTEGER, XSD_NON_NEGATIVE_INTEGER, XSD_NON_POSITIVE_INTEGER, \
|
|
|
|
XSD_GDAY, XSD_GMONTH, XSD_GMONTH_DAY, XSD_GYEAR, XSD_GYEAR_MONTH, XSD_TIME, XSD_DATE, \
|
|
|
|
XSD_DATETIME, XSD_DATE_TIME_STAMP, XSD_ENTITY, XSD_ANY_URI, XSD_BOOLEAN, \
|
|
|
|
XSD_DURATION, XSD_DAY_TIME_DURATION, XSD_YEAR_MONTH_DURATION, XSD_BASE64_BINARY, \
|
|
|
|
XSD_HEX_BINARY, XSD_NOTATION_TYPE, XSD_ERROR, XSD_ASSERTION, XSD_SIMPLE_TYPE, \
|
|
|
|
XSD_COMPLEX_TYPE, XSD_ANY_TYPE, XSD_ANY_ATOMIC_TYPE, XSD_ANY_SIMPLE_TYPE
|
|
|
|
from ..etree import etree_element
|
|
|
|
from ..helpers import is_etree_element
|
2017-12-14 13:38:23 +01:00
|
|
|
from .exceptions import XMLSchemaValidationError
|
2019-02-11 17:15:17 +01:00
|
|
|
from .facets import XSD_10_FACETS_BUILDERS, XSD_11_FACETS_BUILDERS
|
2018-08-08 19:11:01 +02:00
|
|
|
from .simple_types import XsdSimpleType, XsdAtomicBuiltin
|
2016-10-14 13:48:19 +02:00
|
|
|
|
2019-01-20 22:59:23 +01:00
|
|
|
HEX_BINARY_PATTERN = re.compile(r'^[0-9a-fA-F]+$')
|
|
|
|
NOT_BASE64_BINARY_PATTERN = re.compile(r'[^0-9a-zA-z+/= \t\n]')
|
|
|
|
|
2019-02-11 17:15:17 +01:00
|
|
|
#
|
|
|
|
# Admitted facets sets for XSD atomic types
|
|
|
|
STRING_FACETS = (
|
|
|
|
XSD_LENGTH, XSD_MIN_LENGTH, XSD_MAX_LENGTH, XSD_PATTERN,
|
|
|
|
XSD_ENUMERATION, XSD_WHITE_SPACE, XSD_ASSERTION
|
|
|
|
)
|
|
|
|
|
|
|
|
BOOLEAN_FACETS = (XSD_PATTERN, XSD_WHITE_SPACE, XSD_ASSERTION)
|
|
|
|
|
|
|
|
FLOAT_FACETS = (
|
|
|
|
XSD_PATTERN, XSD_ENUMERATION, XSD_WHITE_SPACE, XSD_MAX_INCLUSIVE,
|
|
|
|
XSD_MAX_EXCLUSIVE, XSD_MIN_INCLUSIVE, XSD_MIN_EXCLUSIVE, XSD_ASSERTION
|
|
|
|
)
|
|
|
|
|
|
|
|
DECIMAL_FACETS = (
|
|
|
|
XSD_TOTAL_DIGITS, XSD_FRACTION_DIGITS, XSD_PATTERN, XSD_ENUMERATION,
|
|
|
|
XSD_WHITE_SPACE, XSD_MAX_INCLUSIVE, XSD_MAX_EXCLUSIVE, XSD_MIN_INCLUSIVE,
|
|
|
|
XSD_MIN_EXCLUSIVE, XSD_ASSERTION
|
|
|
|
)
|
|
|
|
|
|
|
|
DATETIME_FACETS = (
|
|
|
|
XSD_PATTERN, XSD_ENUMERATION, XSD_WHITE_SPACE,
|
|
|
|
XSD_MAX_INCLUSIVE, XSD_MAX_EXCLUSIVE, XSD_MIN_INCLUSIVE,
|
|
|
|
XSD_MIN_EXCLUSIVE, XSD_ASSERTION, XSD_EXPLICIT_TIMEZONE
|
|
|
|
)
|
|
|
|
|
2017-07-04 16:14:26 +02:00
|
|
|
|
2016-12-21 12:34:55 +01:00
|
|
|
#
|
2019-03-28 07:26:36 +01:00
|
|
|
# XSD built-in types validator functions
|
2019-05-04 23:52:54 +02:00
|
|
|
def finite_number_validator(x):
|
|
|
|
try:
|
|
|
|
if isinf(x) or isnan(x):
|
|
|
|
yield XMLSchemaValidationError(finite_number_validator, x, "value {!r} is not an xs:decimal".format(x))
|
|
|
|
except TypeError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2019-03-28 07:26:36 +01:00
|
|
|
def qname_validator(x):
|
|
|
|
if datatypes.QNAME_PATTERN.match(x) is None:
|
|
|
|
yield XMLSchemaValidationError(qname_validator, x, "value {!r} is not an xs:QName".format(x))
|
|
|
|
|
|
|
|
|
2016-12-21 12:34:55 +01:00
|
|
|
def byte_validator(x):
|
|
|
|
if not (-2**7 <= x < 2**7):
|
2017-02-01 06:59:50 +01:00
|
|
|
yield XMLSchemaValidationError(int_validator, x, "value must be -128 <= x < 128.")
|
2016-12-21 12:34:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
def short_validator(x):
|
2018-11-15 10:54:11 +01:00
|
|
|
if not (-2**15 <= x < 2**15):
|
2017-02-01 06:59:50 +01:00
|
|
|
yield XMLSchemaValidationError(short_validator, x, "value must be -2^16 <= x < 2^16.")
|
2016-12-21 12:34:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
def int_validator(x):
|
|
|
|
if not (-2**63 <= x < 2**63):
|
2017-02-01 06:59:50 +01:00
|
|
|
yield XMLSchemaValidationError(int_validator, x, "value must be -2^63 <= x < 2^63.")
|
2016-12-21 12:34:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
def long_validator(x):
|
|
|
|
if not (-2**127 <= x < 2**127):
|
2017-02-01 06:59:50 +01:00
|
|
|
yield XMLSchemaValidationError(long_validator, x, "value must be -2^127 <= x < 2^127.")
|
2016-12-21 12:34:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
def unsigned_byte_validator(x):
|
|
|
|
if not (0 <= x < 2**8):
|
2017-02-01 06:59:50 +01:00
|
|
|
yield XMLSchemaValidationError(unsigned_byte_validator, x, "value must be 0 <= x < 256.")
|
2016-12-21 12:34:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
def unsigned_short_validator(x):
|
2018-11-15 10:54:11 +01:00
|
|
|
if not (0 <= x < 2**16):
|
2017-02-01 06:59:50 +01:00
|
|
|
yield XMLSchemaValidationError(unsigned_short_validator, x, "value must be 0 <= x < 2^32.")
|
2016-12-21 12:34:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
def unsigned_int_validator(x):
|
|
|
|
if not (0 <= x < 2**64):
|
2017-02-01 06:59:50 +01:00
|
|
|
yield XMLSchemaValidationError(unsigned_int_validator, x, "value must be 0 <= x < 2^64.")
|
2016-12-21 12:34:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
def unsigned_long_validator(x):
|
|
|
|
if not (0 <= x < 2**128):
|
2017-02-01 06:59:50 +01:00
|
|
|
yield XMLSchemaValidationError(unsigned_long_validator, x, "value must be 0 <= x < 2^128.")
|
2016-12-21 12:34:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
def negative_int_validator(x):
|
|
|
|
if x >= 0:
|
2017-02-01 06:59:50 +01:00
|
|
|
yield XMLSchemaValidationError(negative_int_validator, x, reason="value must be negative.")
|
2016-12-21 12:34:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
def positive_int_validator(x):
|
|
|
|
if x <= 0:
|
2017-02-01 06:59:50 +01:00
|
|
|
yield XMLSchemaValidationError(positive_int_validator, x, "value must be positive.")
|
2016-12-21 12:34:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
def non_positive_int_validator(x):
|
|
|
|
if x > 0:
|
2017-02-01 06:59:50 +01:00
|
|
|
yield XMLSchemaValidationError(non_positive_int_validator, x, "value must be non positive.")
|
2016-12-21 12:34:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
def non_negative_int_validator(x):
|
|
|
|
if x < 0:
|
2017-02-01 06:59:50 +01:00
|
|
|
yield XMLSchemaValidationError(non_negative_int_validator, x, "value must be non negative.")
|
2016-12-21 12:34:55 +01:00
|
|
|
|
|
|
|
|
2018-06-04 15:02:26 +02:00
|
|
|
def hex_binary_validator(x):
|
2019-03-11 11:42:51 +01:00
|
|
|
if x and (len(x) % 2 or HEX_BINARY_PATTERN.match(x) is None):
|
2018-06-04 15:02:26 +02:00
|
|
|
yield XMLSchemaValidationError(hex_binary_validator, x, "not an hexadecimal number.")
|
|
|
|
|
|
|
|
|
|
|
|
def base64_binary_validator(x):
|
2019-03-11 11:42:51 +01:00
|
|
|
if not x:
|
|
|
|
return
|
2018-10-08 23:47:18 +02:00
|
|
|
match = NOT_BASE64_BINARY_PATTERN.search(x)
|
2018-06-04 15:02:26 +02:00
|
|
|
if match is not None:
|
|
|
|
reason = "not a base64 encoding: illegal character %r at position %d." % (match.group(0), match.span()[0])
|
|
|
|
yield XMLSchemaValidationError(base64_binary_validator, x, reason)
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
base64.standard_b64decode(x)
|
|
|
|
except (ValueError, TypeError) as err:
|
|
|
|
yield XMLSchemaValidationError(base64_binary_validator, x, "not a base64 encoding: %s." % err)
|
|
|
|
|
2018-06-04 13:12:01 +02:00
|
|
|
|
2019-08-01 17:16:12 +02:00
|
|
|
def error_type_validator(x):
|
|
|
|
yield XMLSchemaValidationError(error_type_validator, x, "not value is allowed for xs:error type.")
|
|
|
|
|
|
|
|
|
2017-01-23 10:02:11 +01:00
|
|
|
#
|
|
|
|
# XSD builtin decoding functions
|
|
|
|
def boolean_to_python(s):
|
|
|
|
if s in ('true', '1'):
|
|
|
|
return True
|
|
|
|
elif s in ('false', '0'):
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
raise XMLSchemaValueError('not a boolean value: %r' % s)
|
|
|
|
|
2017-05-15 08:06:32 +02:00
|
|
|
|
|
|
|
def python_to_boolean(obj):
|
|
|
|
return unicode_type(obj).lower()
|
|
|
|
|
|
|
|
|
2016-10-14 13:48:19 +02:00
|
|
|
#
|
2016-12-29 10:06:00 +01:00
|
|
|
# Element facets instances for builtin types.
|
2019-03-28 07:26:36 +01:00
|
|
|
PRESERVE_WHITE_SPACE_ELEMENT = etree_element(XSD_WHITE_SPACE, value='preserve')
|
|
|
|
COLLAPSE_WHITE_SPACE_ELEMENT = etree_element(XSD_WHITE_SPACE, value='collapse')
|
|
|
|
REPLACE_WHITE_SPACE_ELEMENT = etree_element(XSD_WHITE_SPACE, value='replace')
|
2016-12-29 10:06:00 +01:00
|
|
|
|
|
|
|
|
2019-01-20 18:08:07 +01:00
|
|
|
XSD_COMMON_BUILTIN_TYPES = (
|
2018-08-08 15:47:24 +02:00
|
|
|
# ***********************
|
|
|
|
# *** Primitive types ***
|
|
|
|
# ***********************
|
|
|
|
|
2016-10-14 13:48:19 +02:00
|
|
|
# --- String Types ---
|
2016-12-29 10:06:00 +01:00
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_STRING,
|
2018-05-18 11:28:03 +02:00
|
|
|
'python_type': (unicode_type, str),
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': STRING_FACETS,
|
|
|
|
'facets': [PRESERVE_WHITE_SPACE_ELEMENT],
|
2016-12-29 10:06:00 +01:00
|
|
|
}, # character string
|
2016-10-14 13:48:19 +02:00
|
|
|
|
|
|
|
# --- Numerical Types ---
|
2016-12-29 10:06:00 +01:00
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_DECIMAL,
|
2018-05-18 11:28:03 +02:00
|
|
|
'python_type': (Decimal, str, unicode_type, int, float),
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': DECIMAL_FACETS,
|
2019-05-04 23:52:54 +02:00
|
|
|
'facets': [finite_number_validator, COLLAPSE_WHITE_SPACE_ELEMENT],
|
2016-12-29 10:06:00 +01:00
|
|
|
}, # decimal number
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_DOUBLE,
|
2016-12-29 10:06:00 +01:00
|
|
|
'python_type': float,
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': FLOAT_FACETS,
|
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT],
|
2016-12-29 10:06:00 +01:00
|
|
|
}, # 64 bit floating point
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_FLOAT,
|
2016-12-29 10:06:00 +01:00
|
|
|
'python_type': float,
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': FLOAT_FACETS,
|
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT],
|
2016-12-29 10:06:00 +01:00
|
|
|
}, # 32 bit floating point
|
2016-10-14 13:48:19 +02:00
|
|
|
|
2019-01-20 18:08:07 +01:00
|
|
|
# --- Dates and Times (not year related) ---
|
2016-12-29 10:06:00 +01:00
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_GDAY,
|
2019-01-01 15:53:13 +01:00
|
|
|
'python_type': (unicode_type, str, datatypes.GregorianDay),
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': DATETIME_FACETS,
|
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT],
|
2019-01-03 09:28:32 +01:00
|
|
|
'to_python': datatypes.GregorianDay.fromstring,
|
2016-12-29 10:06:00 +01:00
|
|
|
}, # DD
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_GMONTH,
|
2019-01-01 15:53:13 +01:00
|
|
|
'python_type': (unicode_type, str, datatypes.GregorianMonth),
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': DATETIME_FACETS,
|
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT],
|
2019-01-03 09:28:32 +01:00
|
|
|
'to_python': datatypes.GregorianMonth.fromstring,
|
2016-12-29 10:06:00 +01:00
|
|
|
}, # MM
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_GMONTH_DAY,
|
2019-01-01 15:53:13 +01:00
|
|
|
'python_type': (unicode_type, str, datatypes.GregorianMonthDay),
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': DATETIME_FACETS,
|
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT],
|
2019-01-03 09:28:32 +01:00
|
|
|
'to_python': datatypes.GregorianMonthDay.fromstring,
|
2016-12-29 10:06:00 +01:00
|
|
|
}, # MM-DD
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_TIME,
|
2019-01-01 15:53:13 +01:00
|
|
|
'python_type': (unicode_type, str, datatypes.Time),
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': DATETIME_FACETS,
|
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT],
|
2019-01-03 09:28:32 +01:00
|
|
|
'to_python': datatypes.Time.fromstring,
|
2016-12-29 10:06:00 +01:00
|
|
|
}, # hh:mm:ss
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_DURATION,
|
2019-01-01 15:53:13 +01:00
|
|
|
'python_type': (unicode_type, str, datatypes.Duration),
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': FLOAT_FACETS,
|
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT],
|
2019-01-03 09:28:32 +01:00
|
|
|
'to_python': datatypes.Duration.fromstring,
|
2016-12-29 10:06:00 +01:00
|
|
|
}, # PnYnMnDTnHnMnS
|
2016-12-23 16:55:50 +01:00
|
|
|
|
|
|
|
# Other primitive types
|
2016-12-29 10:06:00 +01:00
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_QNAME,
|
2018-05-18 11:28:03 +02:00
|
|
|
'python_type': (unicode_type, str),
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': STRING_FACETS,
|
2019-03-28 07:26:36 +01:00
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT, qname_validator],
|
|
|
|
}, # prf:name (the prefix needs to be qualified with an in-scope namespace)
|
2017-05-29 15:19:03 +02:00
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_NOTATION_TYPE,
|
2018-05-18 11:28:03 +02:00
|
|
|
'python_type': (unicode_type, str),
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': STRING_FACETS,
|
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT],
|
2017-05-29 15:19:03 +02:00
|
|
|
}, # type for NOTATION attributes: QNames of xs:notation declarations as value space.
|
2016-12-29 10:06:00 +01:00
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_ANY_URI,
|
2018-05-18 11:28:03 +02:00
|
|
|
'python_type': (unicode_type, str),
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': STRING_FACETS,
|
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT],
|
2016-12-29 10:06:00 +01:00
|
|
|
}, # absolute or relative uri (RFC 2396)
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_BOOLEAN,
|
2016-12-29 10:06:00 +01:00
|
|
|
'python_type': bool,
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': BOOLEAN_FACETS,
|
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT],
|
2017-01-23 10:02:11 +01:00
|
|
|
'to_python': boolean_to_python,
|
2017-05-15 08:06:32 +02:00
|
|
|
'from_python': python_to_boolean,
|
2016-12-29 10:06:00 +01:00
|
|
|
}, # true/false or 1/0
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_BASE64_BINARY,
|
2018-05-18 11:28:03 +02:00
|
|
|
'python_type': (unicode_type, str),
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': STRING_FACETS,
|
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT, base64_binary_validator],
|
2016-12-29 10:06:00 +01:00
|
|
|
}, # base64 encoded binary value
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_HEX_BINARY,
|
2018-05-18 11:28:03 +02:00
|
|
|
'python_type': (unicode_type, str),
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': STRING_FACETS,
|
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT, hex_binary_validator],
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # hexadecimal encoded binary value
|
2016-12-29 10:06:00 +01:00
|
|
|
|
2018-08-08 15:47:24 +02:00
|
|
|
# *********************
|
|
|
|
# *** Derived types ***
|
|
|
|
# *********************
|
2016-12-29 10:06:00 +01:00
|
|
|
|
2016-12-23 16:55:50 +01:00
|
|
|
# --- String Types ---
|
2018-08-08 15:47:24 +02:00
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_NORMALIZED_STRING,
|
2018-08-08 15:47:24 +02:00
|
|
|
'python_type': (unicode_type, str),
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_STRING,
|
2019-01-01 15:53:13 +01:00
|
|
|
'facets': [REPLACE_WHITE_SPACE_ELEMENT],
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # line breaks are normalized
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_TOKEN,
|
2018-08-08 15:47:24 +02:00
|
|
|
'python_type': (unicode_type, str),
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_NORMALIZED_STRING,
|
2019-01-01 15:53:13 +01:00
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT],
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # whitespaces are normalized
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_LANGUAGE,
|
2018-08-08 15:47:24 +02:00
|
|
|
'python_type': (unicode_type, str),
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_TOKEN,
|
2018-08-08 15:47:24 +02:00
|
|
|
'facets': [
|
2019-08-17 09:36:24 +02:00
|
|
|
etree_element(XSD_PATTERN, value=r"[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*")
|
2016-12-29 10:06:00 +01:00
|
|
|
]
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # language codes
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_NAME,
|
2018-08-08 15:47:24 +02:00
|
|
|
'python_type': (unicode_type, str),
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_TOKEN,
|
2019-03-28 07:26:36 +01:00
|
|
|
'facets': [etree_element(XSD_PATTERN, value=r"\i\c*")]
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # not starting with a digit
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_NCNAME,
|
2018-08-08 15:47:24 +02:00
|
|
|
'python_type': (unicode_type, str),
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_NAME,
|
2019-03-28 07:26:36 +01:00
|
|
|
'facets': [etree_element(XSD_PATTERN, value=r"[\i-[:]][\c-[:]]*")]
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # cannot contain colons
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_ID,
|
2018-08-08 15:47:24 +02:00
|
|
|
'python_type': (unicode_type, str),
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_NCNAME
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # unique identification in document (attribute only)
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_IDREF,
|
2018-08-08 15:47:24 +02:00
|
|
|
'python_type': (unicode_type, str),
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_NCNAME
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # reference to ID field in document (attribute only)
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_ENTITY,
|
2018-08-08 15:47:24 +02:00
|
|
|
'python_type': (unicode_type, str),
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_NCNAME
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # reference to entity (attribute only)
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_NMTOKEN,
|
2018-08-08 15:47:24 +02:00
|
|
|
'python_type': (unicode_type, str),
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_TOKEN,
|
2019-03-28 07:26:36 +01:00
|
|
|
'facets': [etree_element(XSD_PATTERN, value=r"\c+")]
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # should not contain whitespace (attribute only)
|
2016-12-23 16:55:50 +01:00
|
|
|
|
2018-08-08 15:47:24 +02:00
|
|
|
# --- Numerical derived types ---
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_INTEGER,
|
2019-01-01 15:53:13 +01:00
|
|
|
'python_type': int if PY3 else (long_type, int),
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_DECIMAL
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # any integer value
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_LONG,
|
2019-01-01 15:53:13 +01:00
|
|
|
'python_type': int if PY3 else (long_type, int),
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_INTEGER,
|
2019-03-28 07:26:36 +01:00
|
|
|
'facets': [long_validator,
|
|
|
|
etree_element(XSD_MIN_INCLUSIVE, value='-9223372036854775808'),
|
|
|
|
etree_element(XSD_MAX_INCLUSIVE, value='9223372036854775807')]
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # signed 128 bit value
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_INT,
|
2018-08-08 15:47:24 +02:00
|
|
|
'python_type': int,
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_LONG,
|
2019-03-28 07:26:36 +01:00
|
|
|
'facets': [int_validator,
|
|
|
|
etree_element(XSD_MIN_INCLUSIVE, value='-2147483648'),
|
|
|
|
etree_element(XSD_MAX_INCLUSIVE, value='2147483647')]
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # signed 64 bit value
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_SHORT,
|
2018-08-08 15:47:24 +02:00
|
|
|
'python_type': int,
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_INT,
|
2019-03-28 07:26:36 +01:00
|
|
|
'facets': [short_validator,
|
|
|
|
etree_element(XSD_MIN_INCLUSIVE, value='-32768'),
|
|
|
|
etree_element(XSD_MAX_INCLUSIVE, value='32767')]
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # signed 32 bit value
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_BYTE,
|
2018-08-08 15:47:24 +02:00
|
|
|
'python_type': int,
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_SHORT,
|
2019-03-28 07:26:36 +01:00
|
|
|
'facets': [byte_validator,
|
|
|
|
etree_element(XSD_MIN_INCLUSIVE, value='-128'),
|
|
|
|
etree_element(XSD_MAX_INCLUSIVE, value='127')]
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # signed 8 bit value
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_NON_NEGATIVE_INTEGER,
|
2019-01-01 15:53:13 +01:00
|
|
|
'python_type': int if PY3 else (long_type, int),
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_INTEGER,
|
2019-03-28 07:26:36 +01:00
|
|
|
'facets': [non_negative_int_validator, etree_element(XSD_MIN_INCLUSIVE, value='0')]
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # only zero and more value allowed [>= 0]
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_POSITIVE_INTEGER,
|
2019-01-01 15:53:13 +01:00
|
|
|
'python_type': int if PY3 else (long_type, int),
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_NON_NEGATIVE_INTEGER,
|
2019-03-28 07:26:36 +01:00
|
|
|
'facets': [positive_int_validator, etree_element(XSD_MIN_INCLUSIVE, value='1')]
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # only positive value allowed [> 0]
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_UNSIGNED_LONG,
|
2019-01-01 15:53:13 +01:00
|
|
|
'python_type': int if PY3 else (long_type, int),
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_NON_NEGATIVE_INTEGER,
|
2019-03-28 07:26:36 +01:00
|
|
|
'facets': [unsigned_long_validator, etree_element(XSD_MAX_INCLUSIVE, value='18446744073709551615')]
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # unsigned 128 bit value
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_UNSIGNED_INT,
|
2018-08-08 15:47:24 +02:00
|
|
|
'python_type': int,
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_UNSIGNED_LONG,
|
2019-03-28 07:26:36 +01:00
|
|
|
'facets': [unsigned_int_validator, etree_element(XSD_MAX_INCLUSIVE, value='4294967295')]
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # unsigned 64 bit value
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_UNSIGNED_SHORT,
|
2018-08-08 15:47:24 +02:00
|
|
|
'python_type': int,
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_UNSIGNED_INT,
|
2019-03-28 07:26:36 +01:00
|
|
|
'facets': [unsigned_short_validator, etree_element(XSD_MAX_INCLUSIVE, value='65535')]
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # unsigned 32 bit value
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_UNSIGNED_BYTE,
|
2018-08-08 15:47:24 +02:00
|
|
|
'python_type': int,
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_UNSIGNED_SHORT,
|
2019-03-28 07:26:36 +01:00
|
|
|
'facets': [unsigned_byte_validator, etree_element(XSD_MAX_INCLUSIVE, value='255')]
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # unsigned 8 bit value
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_NON_POSITIVE_INTEGER,
|
2018-08-08 15:47:24 +02:00
|
|
|
'python_type': (long_type, int),
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_INTEGER,
|
2019-03-28 07:26:36 +01:00
|
|
|
'facets': [non_positive_int_validator, etree_element(XSD_MAX_INCLUSIVE, value='0')]
|
2018-08-08 15:47:24 +02:00
|
|
|
}, # only zero and smaller value allowed [<= 0]
|
|
|
|
{
|
2018-10-08 15:32:50 +02:00
|
|
|
'name': XSD_NEGATIVE_INTEGER,
|
2018-08-08 15:47:24 +02:00
|
|
|
'python_type': (long_type, int),
|
2018-10-08 15:32:50 +02:00
|
|
|
'base_type': XSD_NON_POSITIVE_INTEGER,
|
2019-03-28 07:26:36 +01:00
|
|
|
'facets': [negative_int_validator, etree_element(XSD_MAX_INCLUSIVE, value='-1')]
|
2018-10-10 07:17:48 +02:00
|
|
|
}, # only negative value allowed [< 0]
|
2019-01-20 18:08:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
XSD_10_BUILTIN_TYPES = XSD_COMMON_BUILTIN_TYPES + (
|
|
|
|
# --- Year related primitive types (year 0 not allowed) ---
|
|
|
|
{
|
|
|
|
'name': XSD_DATETIME,
|
2019-05-02 17:10:13 +02:00
|
|
|
'python_type': (unicode_type, str, datatypes.DateTime10),
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': DATETIME_FACETS,
|
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT],
|
2019-01-20 18:08:07 +01:00
|
|
|
'to_python': datatypes.DateTime10.fromstring,
|
2019-01-21 22:12:04 +01:00
|
|
|
}, # [-][Y*]YYYY-MM-DD[Thh:mm:ss]
|
2019-01-20 18:08:07 +01:00
|
|
|
{
|
|
|
|
'name': XSD_DATE,
|
2019-05-02 17:10:13 +02:00
|
|
|
'python_type': (unicode_type, str, datatypes.Date10),
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': DATETIME_FACETS,
|
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT],
|
2019-01-20 18:08:07 +01:00
|
|
|
'to_python': datatypes.Date10.fromstring,
|
|
|
|
}, # [-][Y*]YYYY-MM-DD
|
|
|
|
{
|
|
|
|
'name': XSD_GYEAR,
|
2019-05-02 17:10:13 +02:00
|
|
|
'python_type': (unicode_type, str, datatypes.GregorianYear10),
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': DATETIME_FACETS,
|
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT],
|
2019-01-20 18:08:07 +01:00
|
|
|
'to_python': datatypes.GregorianYear10.fromstring,
|
|
|
|
}, # [-][Y*]YYYY
|
|
|
|
{
|
|
|
|
'name': XSD_GYEAR_MONTH,
|
2019-05-02 17:10:13 +02:00
|
|
|
'python_type': (unicode_type, str, datatypes.GregorianYearMonth10),
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': DATETIME_FACETS,
|
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT],
|
2019-01-20 18:08:07 +01:00
|
|
|
'to_python': datatypes.GregorianYearMonth10.fromstring,
|
|
|
|
}, # [-][Y*]YYYY-MM
|
|
|
|
)
|
2018-10-10 07:17:48 +02:00
|
|
|
|
2019-01-20 18:08:07 +01:00
|
|
|
XSD_11_BUILTIN_TYPES = XSD_COMMON_BUILTIN_TYPES + (
|
|
|
|
# --- Year related primitive types (year 0 allowed and mapped to 1 BCE) ---
|
|
|
|
{
|
|
|
|
'name': XSD_DATETIME,
|
|
|
|
'python_type': (unicode_type, str, datatypes.DateTime),
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': DATETIME_FACETS,
|
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT],
|
2019-01-20 18:08:07 +01:00
|
|
|
'to_python': datatypes.DateTime.fromstring,
|
2019-01-21 22:12:04 +01:00
|
|
|
}, # [-][Y*]YYYY-MM-DD[Thh:mm:ss]
|
2019-01-20 18:08:07 +01:00
|
|
|
{
|
|
|
|
'name': XSD_DATE,
|
|
|
|
'python_type': (unicode_type, str, datatypes.Date),
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': DATETIME_FACETS,
|
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT],
|
2019-01-20 18:08:07 +01:00
|
|
|
'to_python': datatypes.Date.fromstring,
|
|
|
|
}, # [-][Y*]YYYY-MM-DD
|
|
|
|
{
|
|
|
|
'name': XSD_GYEAR,
|
|
|
|
'python_type': (unicode_type, str, datatypes.GregorianYear),
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': DATETIME_FACETS,
|
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT],
|
2019-02-22 22:50:05 +01:00
|
|
|
'to_python': datatypes.GregorianYear.fromstring,
|
2019-01-20 18:08:07 +01:00
|
|
|
}, # [-][Y*]YYYY
|
|
|
|
{
|
|
|
|
'name': XSD_GYEAR_MONTH,
|
|
|
|
'python_type': (unicode_type, str, datatypes.GregorianYearMonth),
|
2019-02-11 17:15:17 +01:00
|
|
|
'admitted_facets': DATETIME_FACETS,
|
|
|
|
'facets': [COLLAPSE_WHITE_SPACE_ELEMENT],
|
2019-02-22 22:50:05 +01:00
|
|
|
'to_python': datatypes.GregorianYearMonth.fromstring,
|
2019-01-20 18:08:07 +01:00
|
|
|
}, # [-][Y*]YYYY-MM
|
2018-10-20 12:12:22 +02:00
|
|
|
# --- Datetime derived types (XSD 1.1) ---
|
2018-10-10 07:17:48 +02:00
|
|
|
{
|
|
|
|
'name': XSD_DATE_TIME_STAMP,
|
|
|
|
'python_type': (unicode_type, str),
|
|
|
|
'base_type': XSD_DATETIME,
|
2019-01-21 22:12:04 +01:00
|
|
|
'to_python': datatypes.DateTime.fromstring,
|
2019-03-28 07:26:36 +01:00
|
|
|
'facets': [etree_element(XSD_EXPLICIT_TIMEZONE, value='required')],
|
2019-01-21 22:12:04 +01:00
|
|
|
}, # [-][Y*]YYYY-MM-DD[Thh:mm:ss] with required timezone
|
2018-10-10 07:17:48 +02:00
|
|
|
{
|
|
|
|
'name': XSD_DAY_TIME_DURATION,
|
|
|
|
'python_type': (unicode_type, str),
|
|
|
|
'base_type': XSD_DURATION,
|
2019-01-20 22:59:23 +01:00
|
|
|
'to_python': datatypes.DayTimeDuration.fromstring,
|
2018-10-20 12:12:22 +02:00
|
|
|
}, # PnYnMnDTnHnMnS with month an year equal to 0
|
2018-10-10 07:17:48 +02:00
|
|
|
{
|
|
|
|
'name': XSD_YEAR_MONTH_DURATION,
|
|
|
|
'python_type': (unicode_type, str),
|
|
|
|
'base_type': XSD_DURATION,
|
2019-01-20 22:59:23 +01:00
|
|
|
'to_python': datatypes.YearMonthDuration.fromstring,
|
2018-10-20 12:12:22 +02:00
|
|
|
}, # PnYnMnDTnHnMnS with day and time equals to 0
|
2019-08-01 17:16:12 +02:00
|
|
|
# --- xs:error primitive type (XSD 1.1) ---
|
|
|
|
{
|
|
|
|
'name': XSD_ERROR,
|
|
|
|
'python_type': type(None),
|
|
|
|
'admitted_facets': (),
|
|
|
|
'facets': [error_type_validator],
|
|
|
|
}, # xs:error has no value space and no lexical space
|
2018-08-08 19:11:01 +02:00
|
|
|
)
|
2016-12-29 10:06:00 +01:00
|
|
|
|
2016-10-14 13:48:19 +02:00
|
|
|
|
2019-02-11 17:15:17 +01:00
|
|
|
def xsd_builtin_types_factory(meta_schema, xsd_types, atomic_builtin_class=None):
|
2017-07-03 15:29:33 +02:00
|
|
|
"""
|
|
|
|
Builds the dictionary for XML Schema built-in types mapping.
|
|
|
|
"""
|
2019-02-11 17:15:17 +01:00
|
|
|
atomic_builtin_class = atomic_builtin_class or XsdAtomicBuiltin
|
|
|
|
if meta_schema.XSD_VERSION == '1.1':
|
|
|
|
builtin_types = XSD_11_BUILTIN_TYPES
|
|
|
|
facets_map = XSD_11_FACETS_BUILDERS
|
|
|
|
else:
|
|
|
|
builtin_types = XSD_10_BUILTIN_TYPES
|
|
|
|
facets_map = XSD_10_FACETS_BUILDERS
|
|
|
|
|
2017-07-03 15:29:33 +02:00
|
|
|
#
|
|
|
|
# Special builtin types.
|
|
|
|
#
|
|
|
|
# xs:anyType
|
2017-07-05 15:23:16 +02:00
|
|
|
# Ref: https://www.w3.org/TR/xmlschema11-1/#builtin-ctd
|
2018-08-08 19:11:01 +02:00
|
|
|
any_type = meta_schema.BUILDERS.complex_type_class(
|
2019-03-28 07:26:36 +01:00
|
|
|
elem=etree_element(XSD_COMPLEX_TYPE, name=XSD_ANY_TYPE),
|
2017-07-07 12:48:19 +02:00
|
|
|
schema=meta_schema,
|
2018-08-08 15:47:24 +02:00
|
|
|
parent=None,
|
|
|
|
mixed=True
|
2017-07-03 15:29:33 +02:00
|
|
|
)
|
2018-08-08 19:11:01 +02:00
|
|
|
any_type.content_type = meta_schema.create_any_content_group(any_type)
|
|
|
|
any_type.attributes = meta_schema.create_any_attribute_group(any_type)
|
2018-08-08 15:47:24 +02:00
|
|
|
xsd_types[XSD_ANY_TYPE] = any_type
|
|
|
|
|
2017-07-05 15:23:16 +02:00
|
|
|
# xs:anySimpleType
|
|
|
|
# Ref: https://www.w3.org/TR/xmlschema11-2/#builtin-stds
|
2017-07-03 15:29:33 +02:00
|
|
|
xsd_types[XSD_ANY_SIMPLE_TYPE] = XsdSimpleType(
|
2019-03-28 07:26:36 +01:00
|
|
|
elem=etree_element(XSD_SIMPLE_TYPE, name=XSD_ANY_SIMPLE_TYPE),
|
2017-07-07 12:48:19 +02:00
|
|
|
schema=meta_schema,
|
2018-08-08 15:47:24 +02:00
|
|
|
parent=None,
|
2019-02-11 17:15:17 +01:00
|
|
|
name=XSD_ANY_SIMPLE_TYPE
|
2017-07-03 15:29:33 +02:00
|
|
|
)
|
2018-08-08 15:47:24 +02:00
|
|
|
|
2017-07-05 15:23:16 +02:00
|
|
|
# xs:anyAtomicType
|
|
|
|
# Ref: https://www.w3.org/TR/xmlschema11-2/#builtin-stds
|
2018-08-08 19:11:01 +02:00
|
|
|
xsd_types[XSD_ANY_ATOMIC_TYPE] = meta_schema.BUILDERS.restriction_class(
|
2019-03-28 07:26:36 +01:00
|
|
|
elem=etree_element(XSD_SIMPLE_TYPE, name=XSD_ANY_ATOMIC_TYPE),
|
2017-07-07 12:48:19 +02:00
|
|
|
schema=meta_schema,
|
2018-08-08 15:47:24 +02:00
|
|
|
parent=None,
|
2017-07-07 12:48:19 +02:00
|
|
|
name=XSD_ANY_ATOMIC_TYPE,
|
2018-08-08 15:47:24 +02:00
|
|
|
base_type=xsd_types[XSD_ANY_SIMPLE_TYPE]
|
2017-07-03 15:29:33 +02:00
|
|
|
)
|
|
|
|
|
2019-01-20 18:08:07 +01:00
|
|
|
for item in builtin_types:
|
2018-08-08 15:47:24 +02:00
|
|
|
item = item.copy()
|
2018-08-09 07:10:39 +02:00
|
|
|
name = item['name']
|
|
|
|
try:
|
|
|
|
elem, schema = xsd_types[name]
|
|
|
|
except KeyError:
|
|
|
|
# If builtin type element is missing create a dummy element. Necessary for the
|
|
|
|
# meta-schema XMLSchema.xsd of XSD 1.1, that not includes builtins declarations.
|
2019-03-28 07:26:36 +01:00
|
|
|
elem = etree_element(XSD_SIMPLE_TYPE, name=name, id=name)
|
2018-08-09 07:10:39 +02:00
|
|
|
else:
|
|
|
|
if schema is not meta_schema:
|
|
|
|
raise XMLSchemaValueError("loaded entry schema doesn't match meta_schema!")
|
2018-08-08 15:47:24 +02:00
|
|
|
|
2019-02-11 17:15:17 +01:00
|
|
|
if 'base_type' in item:
|
2019-03-28 07:26:36 +01:00
|
|
|
base_type = item['base_type'] = xsd_types[item['base_type']]
|
2017-07-03 15:29:33 +02:00
|
|
|
else:
|
2018-08-08 15:47:24 +02:00
|
|
|
base_type = None
|
|
|
|
|
2019-02-11 17:15:17 +01:00
|
|
|
facets = item.pop('facets', None)
|
|
|
|
builtin_type = atomic_builtin_class(elem, meta_schema, **item)
|
|
|
|
if isinstance(facets, (list, tuple)):
|
|
|
|
built_facets = builtin_type.facets
|
|
|
|
for e in facets:
|
|
|
|
if is_etree_element(e):
|
|
|
|
cls = facets_map[e.tag]
|
|
|
|
built_facets[e.tag] = cls(e, meta_schema, builtin_type, base_type)
|
|
|
|
elif callable(e):
|
|
|
|
if None in facets:
|
|
|
|
raise XMLSchemaValueError("Almost one callable for facet group!!")
|
|
|
|
built_facets[None] = e
|
|
|
|
else:
|
|
|
|
raise XMLSchemaValueError("Wrong type for item %r" % e)
|
|
|
|
builtin_type.facets = built_facets
|
|
|
|
|
|
|
|
xsd_types[name] = builtin_type
|