pyxsd.relaxng.datatypes¶
RELAX NG datatype protocols and the built-in/XSD 1.0 libraries.
RELAX NG delegates lexical acceptance and value equality to datatype
libraries. A factory compiles a type name, its parameters, and the
schema-side context into a reusable Datatype. Every operation
receives the context of the string it interprets, so a value pattern can
compare a schema-side QName against an instance-side QName in different
prefix scopes.
The empty library URI is the RELAX NG built-in library. It has exactly the
two datatypes of RELAX NG 1.0 §6.2.9: string accepts every string and
compares by identity, and token accepts every string and compares after
XML-whitespace normalization. Parameters are not allowed.
XSD_LIBRARY adapts pyxsd’s existing XSD built-in classes. The
adapter follows XSD 1.0 semantics, not the XSD compiler’s default 1.1
profile:
the XSD 1.1-only types
anyAtomicType,dateTimeStamp,dayTimeDuration,yearMonthDuration(andprecisionDecimal) are rejected explicitly rather than accepted as strings;lexical year
0000is rejected fordate,dateTime,gYearandgYearMonth; lexical-0001is 1 BCE, so 1 BCE is a leap year and-0001-02-29is valid while-0004-02-29(4 BCE) is not;temporal value equality, bounds, and decoding use the XSD 1.0 astronomical mapping for negative years (lexical
y < 0is astronomicaly + 1), not the shared classes’ XSD 1.1 numbering;duration equality uses the six-dimensional XSD 1.0 value space, so
P1YandP12Mare distinct values;duration bound facets use the XSD 1.0 §3.2.6.2 four-reference-date partial order, and an indeterminate comparison is false for every bound facet, as §3.2.6.3 requires;
anyURIuses the XSD 1.0 lexical space: the XLink 5.4 escaping procedure is applied, and the result must be an RFC 2396 URI reference as amended by RFC 2732. XSD 1.1’s “any XML character sequence” rule is not used. Equality remains identity of the lexical URI-reference representation; XSD 1.0 defines no anyURI normalization.
Scheme-specific URI syntax is not checked, matching XSD 1.0’s conformance note; the generic URI-reference grammar is.
The XSD adapter rejects the whiteSpace and enumeration parameters as
the RELAX NG datatype guidelines require. Repeated pattern parameters
are intersected; every other parameter may appear at most once. Facets are
validated when the datatype is compiled, and an inapplicable facet is a
parameter error.
allows, equal, decode and encode are independent operations.
decode and encode are optional pyxsd capabilities, not RELAX NG
conformance: a custom datatype may implement only validation, in which case
the inherited methods raise UnsupportedDatatypeOperation. A datatype
that genuinely provides decoding must declare supports_decode = True;
overriding Datatype.decode() is not by itself a capability declaration,
because an implementation may override it only to report the operation as
unsupported. Value equality deliberately ignores facet parameters because
RELAX NG’s datatypeEqual service has no parameters.
A compiled datatype is frozen, hashable, and value-comparable. Its repr
is deterministic because the canonical choice order of the pattern IR sorts
leaves by repr. The schema-side DatatypeContext is retained for
later value matching; for context-insensitive types it does not
participate in datatype equality, while QName and NOTATION datatypes compare
by their schema-side namespace bindings.
Attributes¶
Exceptions¶
Base class for datatype capability and parameter failures. |
|
A datatype library or type is outside the adapter's capabilities. |
|
A datatype parameter is unknown, inapplicable, or inconsistent. |
|
A datatype-library registration is invalid or would replace an identity. |
|
The datatype has no decoder or encoder for the requested operation. |
Classes¶
The schema- or instance-side context a lexical value is read in. |
|
One RELAX NG datatype parameter: an XSD facet name and its lexical value. |
|
The compiled behavior of one RELAX NG datatype. |
|
A datatype library: compile a type name and parameters into a datatype. |
|
A frozen scalar datatype backed by one pyxsd XSD built-in class. |
|
RELAX NG's built-in datatype library: |
|
The RELAX NG XSD datatype library with XSD 1.0 semantics. |
|
A custom datatype library factory and its stable configuration identity. |
|
The available datatype libraries with fixed built-in/XSD identities. |
Functions¶
|
Return whether datatype explicitly declares decoder support. |
|
Return whether datatype explicitly declares encoder support. |
|
Resolve a selector to |
Module Contents¶
- pyxsd.relaxng.datatypes.BUILTIN_LIBRARY = ''¶
- pyxsd.relaxng.datatypes.XSD_LIBRARY = 'http://www.w3.org/2001/XMLSchema-datatypes'¶
- pyxsd.relaxng.datatypes.BUILTIN_FINGERPRINT = 'pyxsd.relaxng.builtin/1'¶
- pyxsd.relaxng.datatypes.XSD_FINGERPRINT = 'pyxsd.relaxng.xsd-1.0/3'¶
- pyxsd.relaxng.datatypes.DatatypeSelector¶
- exception pyxsd.relaxng.datatypes.DatatypeError¶
Base class for datatype capability and parameter failures.
- exception pyxsd.relaxng.datatypes.UnsupportedDatatypeError¶
A datatype library or type is outside the adapter’s capabilities.
- exception pyxsd.relaxng.datatypes.DatatypeParameterError¶
A datatype parameter is unknown, inapplicable, or inconsistent.
- exception pyxsd.relaxng.datatypes.DatatypeRegistrationError¶
A datatype-library registration is invalid or would replace an identity.
- exception pyxsd.relaxng.datatypes.UnsupportedDatatypeOperation¶
The datatype has no decoder or encoder for the requested operation.
- class pyxsd.relaxng.datatypes.DatatypeContext¶
The schema- or instance-side context a lexical value is read in.
base_uriis retained for datatypes that resolve relative references.namespacesmaps in-scope prefixes to namespace URIs; the empty prefix is the default namespace. The mapping is copied into an immutable, hashable form at construction.- namespaces: collections.abc.Mapping[str, str]¶
- class pyxsd.relaxng.datatypes.DatatypeParameter¶
One RELAX NG datatype parameter: an XSD facet name and its lexical value.
- class pyxsd.relaxng.datatypes.Datatype¶
The compiled behavior of one RELAX NG datatype.
supports_decodeis an explicit, schema-static capability declaration fordecode();supports_encodeis the matching declaration forencode(). The base class does not infer capability from method overrides: a subclass may overridedecodeorencodeonly to raiseUnsupportedDatatypeOperation, and such a datatype remains nondecodable/nonencodable for shape selection until it declares support. The flags are implementation behavior, not datatype semantic identity; they do not participate in equality, hashing, or pattern identity.Implementations that serve as pattern payloads must also be immutable, hashable, value-comparable, and deterministically
repr-able, because the pattern IR interns and canonically orders them.- abstractmethod allows(lexical, context)¶
Return whether lexical is a legal value in context.
- Parameters:
lexical (str)
context (DatatypeContext)
- Return type:
- abstractmethod equal(left, left_context, right, right_context)¶
Return whether two lexical values denote the same datatype value.
- Parameters:
left (str)
left_context (DatatypeContext)
right (str)
right_context (DatatypeContext)
- Return type:
- decode(lexical, context)¶
Decode lexical into a Python value when support is declared.
- Parameters:
lexical (str)
context (DatatypeContext)
- Return type:
Any
- encode(value, context)¶
Encode a Python value as a lexical form, when the datatype supports it.
- Parameters:
value (Any)
context (DatatypeContext)
- Return type:
- pyxsd.relaxng.datatypes.datatype_supports_decode(datatype)¶
Return whether datatype explicitly declares decoder support.
This reads the class-level
Datatype.supports_decodedeclaration. It is not an inference from adecodeoverride and does not calldecode. Instance state cannot turn capability on or off.
- pyxsd.relaxng.datatypes.datatype_supports_encode(datatype)¶
Return whether datatype explicitly declares encoder support.
This reads the class-level
Datatype.supports_encodedeclaration. It never infers support from anencodeoverride and never callsencode. Instance state cannot turn capability on or off.
- class pyxsd.relaxng.datatypes.DatatypeFactory¶
A datatype library: compile a type name and parameters into a datatype.
- abstractmethod create(type_name, parameters, context)¶
Compile one datatype or report why it is unavailable.
- Parameters:
type_name (str)
parameters (tuple[DatatypeParameter, ...])
context (DatatypeContext)
- Return type:
- class pyxsd.relaxng.datatypes.ScalarDatatype¶
A frozen scalar datatype backed by one pyxsd XSD built-in class.
contextis the schema-side context retained for latervaluematching. It is excluded from equality for context-insensitive types;semantic_contextcarries the namespace bindings that actually affect QName/NOTATION identity.- parameters: tuple[DatatypeParameter, ...]¶
- context: DatatypeContext¶
- constraints: pyxsd.facets.FacetConstraints¶
- allows(lexical, context)¶
Return whether lexical is a legal value in context.
- Parameters:
lexical (str)
context (DatatypeContext)
- Return type:
- equal(left, left_context, right, right_context)¶
Compare two values in this datatype’s value space.
Facet parameters do not participate: RELAX NG’s
datatypeEqualservice has no parameters. A lexical form outside the base datatype has no value and therefore compares unequal to everything.- Parameters:
left (str)
left_context (DatatypeContext)
right (str)
right_context (DatatypeContext)
- Return type:
- decode(lexical, context)¶
Decode a validated lexical form into its Python value.
hexBinaryandbase64Binaryreturnbytes;booleanreturns a Pythonbool; QName and NOTATION return a context-resolvedQName; the four year-bearing temporal types return a validated lexicalstrsubclass with alexical()method; every other type returns its XSD value object (anint,Decimal,float, orstrsubclass). Facets are enforced, so an out-of-range or pattern-violating lexical form raisesTypeErrororValueErrorinstead of producing a value outside the datatype.- Parameters:
lexical (str)
context (DatatypeContext)
- Return type:
Any
- encode(value, context)¶
Encode a Python value as a canonical lexical form.
Expected inputs are
bytes-like for binary types,boolorintfor boolean,intfor the integer family,Decimalorintfor decimal,intorfloatfor float/double,strfor string and temporal types, andQNameorstrfor QName and NOTATION. The produced lexical form is validated against the datatype’s facets. A QName prefix must be bound in context; a resolved QName must denote the same namespace there, so no unresolved prefix is invented.- Parameters:
value (Any)
context (DatatypeContext)
- Return type:
- class pyxsd.relaxng.datatypes.BuiltinDatatypeFactory¶
RELAX NG’s built-in datatype library:
stringandtoken.- create(type_name, parameters, context)¶
Compile one datatype or report why it is unavailable.
- Parameters:
type_name (str)
parameters (tuple[DatatypeParameter, ...])
context (DatatypeContext)
- Return type:
- class pyxsd.relaxng.datatypes.XsdDatatypeFactory¶
The RELAX NG XSD datatype library with XSD 1.0 semantics.
- create(type_name, parameters, context)¶
Compile one datatype or report why it is unavailable.
- Parameters:
type_name (str)
parameters (tuple[DatatypeParameter, ...])
context (DatatypeContext)
- Return type:
- pyxsd.relaxng.datatypes.resolve_datatype_selector(selector)¶
Resolve a selector to
(library_uri, type_name).A bare string names a type in the built-in library. The documented
xsd:shorthand names a type in the XSD library; it is a fixed alias, never a prefix lookup against the datatype context. A tuple is an explicit(library_uri, type_name)selector.- Parameters:
selector (DatatypeSelector)
- Return type:
- class pyxsd.relaxng.datatypes.DatatypeLibraryRegistration¶
A custom datatype library factory and its stable configuration identity.
- factory: DatatypeFactory¶
- class pyxsd.relaxng.datatypes.DatatypeLibraryRegistry¶
The available datatype libraries with fixed built-in/XSD identities.
- registration(uri)¶
Return the registration for uri or raise an unsupported failure.
- Parameters:
uri (str)
- Return type:
- register(uri, registration)¶
Register a custom datatype library under uri.
The built-in and XSD identities are fixed and cannot be replaced. Every custom fingerprint must be stable and process-independent, so a blank string or a captured object address is rejected.
- Parameters:
uri (str)
registration (DatatypeLibraryRegistration)
- Return type:
None
- resolve(selector)¶
Resolve a selector without constructing a datatype.
- Parameters:
selector (DatatypeSelector)
- Return type:
- create(selector, parameters, context)¶
Compile the selected datatype.
- Parameters:
selector (DatatypeSelector)
parameters (tuple[DatatypeParameter, ...])
context (DatatypeContext)
- Return type: