pyxb.namespace package


pyxb.namespace.archive module

Classes and global objects related to archiving U{XML Namespaces<>}.

pyxb.namespace.archive.DefaultArchivePrefix = '/tmp/pyxbdist.WUiBAra/PyXB-1.2.6'

The default archive prefix, substituted for & in PYXB_ARCHIVE_PATH.


Return the archive path as defined by the PathEnvironmentVariable, or None if that variable is not defined.

class pyxb.namespace.archive.ModuleRecord(namespace, generation_uid, **kw)

Bases: pyxb.utils.utility.PrivateTransient_mixin

_ModuleRecord__PrivateTransient = set(['constructedLocally', 'categoryObjects', 'isIncorporated', 'archive'])
_ModuleRecord__archive = None
_ModuleRecord__categoryObjects = None
_ModuleRecord__constructedLocally = False
_ModuleRecord__dependsOnExternal = None
_ModuleRecord__generationUID = None
_ModuleRecord__isIncorporated = None
_ModuleRecord__isLoadable = None
_ModuleRecord__isPublic = None
_ModuleRecord__modulePath = None
_ModuleRecord__namespace = None
_ModuleRecord__originMap = None
_ModuleRecord__referencedNamespaces = None
_addCategoryObject(category, name, obj)
_setFromOther(other, archive)
class pyxb.namespace.archive.NamespaceArchive(archive_path=None, generation_uid=None, loadable=True, stage=None)

Bases: object

Represent a file from which one or more namespaces can be read, or to which they will be written.

classmethod ForPath(archive_file)

Return the NamespaceArchive instance that can be found at the given path.

classmethod PicklingArchive()

Return a reference to a set specifying the namespace instances that are being archived.

This is needed to determine whether a component must be serialized as aa reference.

classmethod PreLoadArchives(archive_path=None, reset=False)

Scan for available archives, associating them with namespaces.

This only validates potential archive contents; it does not load namespace data from the archives.

Parameters:archive_path – A list of files or directories in which

namespace archives can be found. The entries are separated by os.pathsep, which is a colon on POSIX platforms and a semi-colon on Windows. See PathEnvironmentVariable. Defaults to GetArchivePath(). If not defaulted, reset will be forced to True. For any directory in the path, all files ending with wxs are examined.

Parameters:reset – If False (default), the most recently read set of

archives is returned; if True, the archive path is re-scanned and the namespace associations validated.

classmethod _AnonymousCategory()

The category name to use when storing references to anonymous type definitions. For example, attribute definitions defined within an attribute use in a model group definition.that can be referenced frojm ax different namespace.

_NamespaceArchive__AnonymousCategory = '_anonymousTypeDefinition'
_NamespaceArchive__ArchivePattern_re = <_sre.SRE_Pattern object>
classmethod _NamespaceArchive__GetArchiveInstance(archive_file, stage=None)

Return a NamespaceArchive instance associated with the given file.

To the extent possible, the same file accessed through different paths returns the same NamespaceArchive instance.

_NamespaceArchive__NamespaceArchives = None
_NamespaceArchive__PickleFormat = '200907190858'
_NamespaceArchive__PicklingArchive = None
_NamespaceArchive__archivePath = None
_NamespaceArchive__generationUID = None
_NamespaceArchive__isLoadable = None
_NamespaceArchive__moduleRecords = None
_NamespaceArchive__namespaces = None
_NamespaceArchive__stage = None
_NamespaceArchive__unpickler = None
_STAGE_readComponents = 4
_STAGE_readModules = 2
_STAGE_uid = 1
_STAGE_validateModules = 3

Add the given namespace to the set that is to be stored in this archive.


Path to the file in which this namespace archive is stored.


Remove this archive from the set of available archives.

This is invoked when an archive contains a namespace that the user has specified should not be loaded.


The unique identifier for the generation that produced this archive.


Return True iff it is permissible to load the archive. Archives created for output cannot be loaded.


Return the set of module records stored in this archive.

Each module record represents


Set of namespaces that can be read from this archive.


Read all the components from this archive, integrating them into their respective namespaces.


Add the given namespaces to the set that is to be stored in this archive.


Store the namespaces into the archive.

Parameters:output – An instance substitutable for a writable file, or the

name of a file to write to.

class pyxb.namespace.archive.NamespaceDependencies(**kw)

Bases: object

_NamespaceDependencies__componentGraph = None
_NamespaceDependencies__namespaceGraph = None
_NamespaceDependencies__rootNamespaces = None
_NamespaceDependencies__siblingNamespaces = None
pyxb.namespace.archive.PathEnvironmentVariable = 'PYXB_ARCHIVE_PATH'

Environment variable from which default path to pre-loaded namespaces is read. The value should be a colon-separated list of absolute paths. The character & at the start of a member of the list is replaced by the path to the directory where the %{pyxb} modules are found, including a trailing /. For example, use &pyxb/bundles// to enable search of any archive bundled with PyXB.

Note:If you put a path separator between & and the following path, this

will cause the substitution to be ignored.

class pyxb.namespace.archive._ArchivableObject_mixin(*args, **kw)

Bases: pyxb.cscRoot

Mix-in to any object that can be stored in a namespace within an archive.

_ArchivableObject_mixin__objectOrigin = None
_setObjectOrigin(object_origin, override=False)

Update this instance with additional information provided by the other instance.

This is used, for example, when a built-in type is already registered in the namespace, but we’ve processed the corresponding schema and have obtained more details.

class pyxb.namespace.archive._NamespaceArchivable_mixin(*args, **kw)

Bases: pyxb.cscRoot

Encapsulate the operations and data relevant to archiving namespaces.

This class mixes-in to pyxb.namespace.Namespace

_NamespaceArchivable_mixin__isActive = None
_NamespaceArchivable_mixin__isImportAugmentable = False
_NamespaceArchivable_mixin__loadedFromArchive = None
_NamespaceArchivable_mixin__moduleRecordMap = None
_NamespaceArchivable_mixin__wroteToArchive = None

CSC extension to reset fields of a Namespace.

This one handles category-related data.


Return True iff the component model for this namespace may be extended by import directives.

This is the case if the namespace has been marked with setImportAugmentable, or if there is no archive or built-in that provides a component model for the namespace.


Return True iff the component model for this namespace can be loaded from a namespace archive.


Return the list of archives from which components for this namespace can be loaded.

lookupModuleRecordByUID(generation_uid, create_if_missing=False, *args, **kw)

Prevent loading this namespace from an archive.

This marks all archives in which the namespace appears, whether publically or privately, as not loadable.

class pyxb.namespace.archive._ObjectOrigin(namespace, generation_uid, **kw)

Bases: pyxb.utils.utility.PrivateTransient_mixin, pyxb.cscRoot

Marker class for objects that can serve as an origin for an object in a namespace.

_ObjectOrigin__PrivateTransient = set(['categoryObjectMap', 'originatedObjects'])
_ObjectOrigin__categoryMembers = None
_ObjectOrigin__categoryObjectMap = None
_ObjectOrigin__moduleRecord = None
_ObjectOrigin__originatedObjects = None
_ObjectOrigin__signature = None
addCategoryMember(category, name, obj)
class pyxb.namespace.archive._SchemaOrigin(**kw)

Bases: pyxb.namespace.archive._ObjectOrigin

Holds the data regarding components derived from a single schema.

Coupled to a particular namespace through the _NamespaceComponentAssociation_mixin.

_SchemaOrigin__PrivateTransient = set(['schema'])
_SchemaOrigin__location = None
_SchemaOrigin__schema = None
_SchemaOrigin__version = None

Determine whether this record matches the parameters.

Parameters:schema – a pyxb.xmlschema.structures.Schema instance from

which the other parameters are obtained. :keyword location: a schema location (URI) :keyword signature: a schema signature :return: True iff I{either} location or signature matches.


pyxb.namespace.builtin module

Classes and global objects related to built-in XML Namespaces<>.

pyxb.namespace.builtin.XHTML = <pyxb.namespace.Namespace object>

There really isn’t a schema for this, but it’s used as the default namespace in the XML schema, so define it.

pyxb.namespace.builtin.XML = <pyxb.namespace.builtin._XML object>

Namespace and URI for XML itself (always available as xml)

pyxb.namespace.builtin.XMLNamespaces = <pyxb.namespace.Namespace object>

Namespaces in XML. Not really a namespace, but is always available as xmlns.

pyxb.namespace.builtin.XMLSchema = <pyxb.namespace.builtin._XMLSchema object>

Namespace and URI for the XMLSchema namespace (often xs, or xsd)

pyxb.namespace.builtin.XMLSchema_hfp = <pyxb.namespace.Namespace object>

Elements appearing in appinfo elements to support data types.

pyxb.namespace.builtin.XMLSchema_instance = <pyxb.namespace.builtin._XMLSchema_instance object>

Namespace and URI for the XMLSchema Instance namespace. This is always built-in, and does not (cannot) have an associated schema.


Invoked at the end of the pyxb.xmlschema.structures module to initialize the component models of the built-in namespaces.

Parameters:structures_module – The pyxb.xmlschema.structures module may not

be importable by that name at the time this is invoked (because it is still being processed), so it gets passed in as a parameter.

class pyxb.namespace.builtin._XML(uri, description=None, builtin_namespace=None, builtin_module_path=None, is_undeclared_namespace=False, is_loaded_namespace=False, bound_prefix=None, default_namespace=None, in_scope_namespaces=None)

Bases: pyxb.namespace.Namespace

Extension of Namespace that pre-defines components available in the XML (xml) namespace. Specifically those are the attribute declarations:

  • xml:space
  • xml:lang
  • xml:base
  • xml:id

the encompassing attribute group declaration:

  • xml:specialAttrs

and the anonymous types that support these.


Ensure this namespace is ready for use.

Overrides base class implementation, since there is no schema for this namespace.

class pyxb.namespace.builtin._XMLSchema(uri, description=None, builtin_namespace=None, builtin_module_path=None, is_undeclared_namespace=False, is_loaded_namespace=False, bound_prefix=None, default_namespace=None, in_scope_namespaces=None)

Bases: pyxb.namespace.Namespace

Extension of Namespace that pre-defines components available in the XMLSchema namespace.

The types are defined when pyxb.xmlschema.structures is imported.


Register the built-in types into the XMLSchema namespace.

class pyxb.namespace.builtin._XMLSchema_instance(*args, **kw)

Bases: pyxb.namespace.Namespace

Extension of Namespace that pre-defines components available in the XMLSchema Instance namespace.

PT_lax = 'lax'

xsi:type supersedes the declared type without validation. If no xsi:type is present, or it is present and fails to resolve to a type, the declared element type will be used. If xsi:type is present and resolves to valid type, that type will be used for the binding, even if it is not a subclass of the declared type.

PT_skip = 'skip'

xsi:type attributes are ignored. The declared element type will be used.

PT_strict = 'strict'

xsi:type is validated and supersedes the declared type. If no xsi:type is present, the declared element type will be used. If xsi:type is present, it must resolve to valid type. The resolved type must be a subclass of the declared type (if available), and will be used for the binding.


Specify how PyXB should interpret U{xsi:type <>} attributes when converting a document to a binding instance.

The default value is PT_strict.

xsi:type should only be provided when using an abstract class, or a concrete class that happens to be the same as the xsi:type value, or when accepting a wildcard that has an unrecognized element name. In practice, web services tend to set it on nodes just to inform their lax-processing clients how to interpret the value.

Parameters:value – One of PT_strict, PT_lax, PT_skip, or None (no change)
Returns:The current configuration for processing xsi:type attributes
_InterpretTypeAttribute(type_name, ns_ctx, fallback_namespace, type_class)

Interpret the value of an xsi:type attribute as configured by ProcessTypeAttribute.

Parameters:type_name – The QName value from U{xsi:type

<>}. If this is None, type_class is used as ret_type_class.

Parameters:ns_ctx – The NamespaceContext within which type_name

should be resolved

Parameters:fallback_namespace – The namespace that should be used

if type_name has no prefix

Parameters:type_class – The value to return if type_name is

missing or acceptably invalid (viz., due to PT_skip)

Returns:A tuple (did_replace, ret_type_class) where

did_replace is True iff the ret_type_class is not the same as type_class, and ret_type_class is the class that should be used.

Raises:pyxb.BadDocumentError – if the processing type

configuration is PT_strict and type_name fails to resolve to a type definition that is consistent with any provided type_class.

_XMLSchema_instance__processType = 'strict'

Ensure this namespace is ready for use.

Overrides base class implementation, since there is no schema for this namespace.

nil = None

An expanded name for {}nil.

type = None

An expanded name for {}type.

pyxb.namespace.resolution module

Classes and global objects related to resolving U{XML Namespaces<>}.

class pyxb.namespace.resolution.NamespaceContext(dom_node=None, parent_context=None, including_context=None, recurse=True, default_namespace=None, target_namespace=None, in_scope_namespaces=None, expanded_name=None, finalize_target_namespace=True)

Bases: object

Records information associated with namespaces at a DOM node.

classmethod Current()

Access the currently active namespace context.

If no context is active, None is returned. This probably represents mis-use of the infrastructure (viz., failure to record the context within which a QName must be resolved).

classmethod GetNodeContext(node, **kw)

Get the NamespaceContext instance that was assigned to the node.

If none has been assigned and keyword parameters are present, create one treating this as the root node and the keyword parameters as configuration information (e.g., default_namespace).

Raises:pyxb.LogicError – no context is available and the keywords

required to create one were not provided

classmethod PopContext()

Discard the currently active namespace context, restoring its predecessor.

The discarded context is returned.

classmethod PushContext(ctx)

Make ctx the currently active namespace context.

Prior contexts are retained on a LIFO stack.

classmethod _AddTargetNamespaceAttribute(expanded_name, attribute_name)
classmethod _NamespaceContext__BuildInitialPrefixMap()
_NamespaceContext__ContextStack = []
_NamespaceContext__InitialScopeNamespaces = {'xml': <pyxb.namespace.builtin._XML object>, 'xmlns': <pyxb.namespace.Namespace object>}
_NamespaceContext__InitialScopePrefixes = {<pyxb.namespace.builtin._XML object>: set(['xml']), <pyxb.namespace.Namespace object>: set(['xmlns'])}
_NamespaceContext__TargetNamespaceAttributes = {<pyxb.namespace.ExpandedName object>: <pyxb.namespace.ExpandedName object>}
_NamespaceContext__addPrefixMap(pfx, ns)
_NamespaceContext__defaultNamespace = None
_NamespaceContext__fallbackToTargetNamespace = False
_NamespaceContext__inScopeNamespaces = None
_NamespaceContext__inScopePrefixes = None
_NamespaceContext__initialScopeNamespaces = None
_NamespaceContext__initialScopePrefixes = None
_NamespaceContext__namespacePrefixCounter = None
_NamespaceContext__pendingReferencedNamespaces = None
_NamespaceContext__targetNamespace = None
classmethod _TargetNamespaceAttribute(expanded_name)
declareNamespace(namespace, prefix=None, add_to_map=False)

Record the given namespace as one to be used in this document.

  • namespace (pyxb.namespace.Namespace) – The namespace to be associated with the document.
  • prefix – Optional prefix to be used with this namespace. If

not provided, a unique prefix is generated or a standard prefix is used, depending on the namespace.

Returns:a prefix that may be used with the namespace. If prefix

was None the return value may be a previously-assigned prefix.

Todo:ensure multiple namespaces do not share the same prefix
Todo:provide default prefix in pyxb.namespace.Namespace

The default namespace in effect at this node. E.g., xmlns="URN:default".

finalizeTargetNamespace(tns_uri=None, including_context=None)

Map from prefix strings to Namespace instances associated with those prefixes. The prefix None identifies the default namespace.

interpretQName(name, namespace=None, default_no_namespace=False)

Convert the provided name into an ExpandedName, i.e. a tuple of Namespace and local name.

If the name includes a prefix, that prefix must map to an in-scope namespace in this context. Absence of a prefix maps to defaultNamespace(), which must be provided (or defaults to the target namespace, if that is not absent).

  • name (str or unicode) – A QName.
  • name – Optional namespace to use for unqualified names when

there is no default namespace. Note that a defined default namespace, even if absent, supersedes this value. :keyword default_no_namespace: If False (default), an NCName in a context where namespace is None and no default or fallback namespace can be identified produces an exception. If True, such an NCName is implicitly placed in no namespace. :return: An ExpandedName tuple: ( Namespace, str ) :raise pyxb.QNameResolutionError: The prefix is not in scope :raise pyxb.QNameResolutionError: No prefix is given and the default namespace is absent


Return a prefix associated with the given namespace in this context, or None if the namespace is the default or is not in scope.

processXMLNS(prefix, uri)
queueForResolution(component, depends_on=None)

Forwards to queueForResolution() in targetNamespace().


Reset this instance to the state it was when created, exclusive of XMLNS directives passed in a constructor dom_node parameter.

This preserves parent context and constructor-specified prefix maps, but clears the namespace-prefix mapping of any additions made while processing namespace directives in DOM nodes, or manually added post-construction.

The defaultNamespace is also retained.


Set the default namespace for the generated document.

Even if invoked post construction, the default namespace will affect the entire document, as all namespace declarations are placed in the document root.

Parameters:default_namespace – The namespace to be defined as the default

namespace in the top-level element of the document. May be provided as a real namespace, or just its URI. :type default_namespace: pyxb.namespace.Namespace or str or unicode.


The target namespace in effect at this node. Usually from the targetNamespace attribute. If no namespace is specified for the schema, an absent namespace was assigned upon creation and will be returned.


Resolve all components in the sibling_namespaces.

:param sibling_namespaces : A set of namespaces expected to be closed under dependency.

class pyxb.namespace.resolution._NamespaceResolution_mixin(*args, **kw)

Bases: pyxb.cscRoot

Mix-in that aggregates those aspects of XMLNamespaces relevant to resolving component references.

_NamespaceResolution_mixin__importedNamespaces = None
_NamespaceResolution_mixin__referencedNamespaces = None
_NamespaceResolution_mixin__unresolvedComponents = None
_NamespaceResolution_mixin__unresolvedDependents = None
_replaceComponent_csc(existing_def, replacement_def)

Replace a component definition if present in the list of unresolved components.


CSC extension to reset fields of a Namespace.

This one handles component-resolution–related data.


Returns a reference to the list of unresolved components.


Returns a map from unresolved components to sets of components that must be resolved first.


Return the set of namespaces which some schema imported while processing with this namespace as target.


Return True iff this namespace has not been resolved.

queueForResolution(resolvable, depends_on=None)

Invoked to note that a component may have references that will need to be resolved.

Newly created named components are often unresolved, as are components which, in the course of resolution, are found to depend on another unresolved component.

Parameters:resolvable – An instance of _Resolvable_mixin that is later to

be resolved.

Parameters:depends_onNone, or an instance of _Resolvable_mixin

which resolvable requires to be resolved in order to resolve itself.


Return the set of namespaces which appear in namespace declarations of schema with this namespace as target.


Loop until all references within the associated resolvable objects have been resolved.

This method iterates through all components on the unresolved list, invoking the _resolve method of each. If the component could not be resolved in this pass, it iis placed back on the list for the next iteration. If an iteration completes without resolving any of the unresolved components, a pyxb.NotInNamespaceError exception is raised.

Note:Do not invoke this until all top-level definitions for the

namespace have been provided. The resolution routines are entitled to raise a validation exception if a reference to an unrecognized component is encountered.

class pyxb.namespace.resolution._Resolvable_mixin(*args, **kw)

Bases: pyxb.cscRoot

Mix-in indicating that this object may have references to unseen named components.

This class is mixed-in to those XMLSchema components that have a reference to another component that is identified by a QName. Resolution of that component may need to be delayed if the definition of the component has not yet been read.

_TraceResolution = False
_queueForResolution(why=None, depends_on=None)

Short-hand to requeue an object if the class implements _namespaceContext().


Perform whatever steps are required to resolve this component.

Resolution is performed in the context of the namespace to which the component belongs. Invoking this method may fail to complete the resolution process if the component itself depends on unresolved components. The sole caller of this should be _NamespaceResolution_mixin.resolveDefinitions.

This method is permitted (nay, encouraged) to raise an exception if resolution requires interpreting a QName and the named component cannot be found.

Override this in the child class. In the prefix, if isResolved is true, return right away. If something prevents you from completing resolution, invoke self._queueForResolution() (so it is retried later) and immediately return self. Prior to leaving after successful resolution discard any cached dom node by setting self.__domNode=None.

Returns:self, whether or not resolution succeeds.
Raises:pyxb.SchemaValidationError – if resolution requlres a reference to an unknown component

Determine whether this named component is resolved.

Override this in the child class.

pyxb.namespace.utility module

Utility functions related to XML Namespaces<>.


Return the complete set of Namespace instances known to the system.


Create an absent namespace.

Use this when you need a namespace for declarations in a schema with no target namespace. Absent namespaces are not stored in the infrastructure; it is your responsibility to hold on to the reference you get from this, because you won’t be able to look it up.

pyxb.namespace.utility.NamespaceForURI(uri, create_if_missing=False)

Given a URI, provide the Namespace instance corresponding to it.

This can only be used to lookup or create real namespaces. To create absent namespaces, use CreateAbsentNamespace.

  • uri (A non-empty str or unicode string) – The URI that identifies the namespace
  • create_if_missing – If True, a namespace for the given URI is

created if one has not already been registered. Default is False. :type create_if_missing: bool :return: The Namespace corresponding to uri, if available :rtype: Namespace or None :raise pyxb.LogicError: The uri is not a non-empty string


Get a namespace instance for the given namespace.

This is used when it is unclear whether the namespace is specified by URI or by instance or by any other mechanism we might dream up in the future.

Module contents

Classes and global objects related to XML Namespaces<>.

Since namespaces hold all referenceable objects, this module also defines the infrastructure for resolving named object references, such as schema components.

class pyxb.namespace.ExpandedName(*args, **kw)

Bases: pyxb.cscRoot

Represent an U{expanded name <>}, which pairs a namespace with a local name.

Because a large number of local elements, and most attributes, have no namespace associated with them, this is optimized for representing names with an absent namespace. The hash and equality test methods are set so that a plain string is equivalent to a tuple of None and that string.

Note that absent namespaces can be represented in two ways: with a namespace of None (the name “has no namespace”), and with a namespace that is an absent namespace (the name “has an absent namespace”). Hash code calculations are done so that the two alternatives produce the same hash; however, comparison is done so that the two are distinguished. The latter is the intended behavior; the former should not be counted upon.

This class allows direct lookup of the named object within a category by using the category name as an accessor function. That is, if the namespace of the expanded name en has a category ‘typeDefinition’, then the following two expressions are equivalent:


This class descends from tuple so that its values can be used as dictionary keys without concern for pointer equivalence.

_ExpandedName__expandedName = None
_ExpandedName__localName = None
_ExpandedName__namespace = None
_ExpandedName__namespaceURI = None

Return the input name, except if the input name has no namespace, return a name that uses the namespace from this name with the local name from the input name.

Use this when the XML document has an unqualified name and we’re processing using an absent default namespace.

Warning:Be careful when using a global name to adopt a name from a

local element: if the local element (with no namespace) has the same localName as but is different from the global element (with a namespace), this will improperly provide a namespace when one should not be present. See the comments in pyxb.binding.basis.element.elementForName.


Return a new expanded name in the namespace of this name.

Parameters:local_name – The local name portion of an expanded name.
Returns:An instance of ExpandedName.

Return the value of the attribute identified by this name in the given node.

Returns:An instance of xml.dom.Attr, or None if the node does

not have an attribute with this name.


The local part of the expanded name.


The Namespace part of the expanded name.


Return the URI of the namespace, or None if the namespace is absent.


Return True iff the dom node expanded name matches this expanded name.


Return a tuple consisting of the namespace URI and the local name.

This presents the expanded name as base Python types for persistent storage. Be aware, though, that it will lose the association of the name with an absent namespace, if that matters to you.


Pass model validation through to namespace part.

class pyxb.namespace.NamedObjectMap(category, namespace, *args, **kw)

Bases: dict

An extended dictionary intended to assist with QName resolution.

These dictionaries have an attribute that identifies a category of named objects within a Namespace; the specifications for various documents require that certain groups of objects must be unique, while uniqueness is not required between groups. The dictionary also retains a pointer to the Namespace instance for which it holds objects.

_NamedObjectMap__category = None
_NamedObjectMap__namespace = None

The category of objects (e.g., typeDefinition, elementDeclaration).


The namespace to which the object map belongs.

class pyxb.namespace.Namespace(uri, description=None, builtin_namespace=None, builtin_module_path=None, is_undeclared_namespace=False, is_loaded_namespace=False, bound_prefix=None, default_namespace=None, in_scope_namespaces=None)

Bases: pyxb.namespace._NamespaceCategory_mixin, pyxb.namespace.resolution._NamespaceResolution_mixin, pyxb.namespace._NamespaceComponentAssociation_mixin, pyxb.namespace.archive._NamespaceArchivable_mixin

Represents an XML namespace (a URI).

There is at most one Namespace class instance per namespace (URI). The instance also supports associating arbitrary maps from names to objects, in separate categories. The default categories are configured externally; for example, the Schema component defines a category for each named component in XMLSchema, and the customizing subclass for WSDL definitions adds categories for the service bindings, messages, etc.

Namespaces can be written to and loaded from pickled files. See NamespaceArchive for information.

classmethod AvailableNamespaces()

Return a set of all Namespace instances defined so far.

classmethod CreateAbsentNamespace()

Create an absent namespace.

Use this instead of the standard constructor, in case we need to augment it with a uuid or the like.

classmethod _NamespaceForURI(uri)

If a Namespace instance for the given URI exists, return it; otherwise return None.

Note: Absent namespaces are not stored in the registry. If you use one (e.g., for a schema with no target namespace), don’t lose hold of it.

_Namespace__AbsentNamespaceRegistry = {}
_Namespace__AbsentNamespaces = set([])
_Namespace__Registry = {'': <pyxb.namespace.Namespace object>, '': <pyxb.namespace.Namespace object>, '': <pyxb.namespace.builtin._XMLSchema object>, '': <pyxb.namespace.builtin._XMLSchema_instance object>, '': <pyxb.namespace.Namespace object>, '': <pyxb.namespace.builtin._XML object>}
_Namespace__SerializedVariantAbsent = 'absent'
_Namespace__absentNamespaceID = 0
_Namespace__absentSerializedUUID = None
_Namespace__bindingConfiguration = None
_Namespace__boundPrefix = None
_Namespace__builtinModulePath = None
_Namespace__contextDefaultNamespace = None
_Namespace__contextInScopeNamespaces = None
_Namespace__definedBuiltins = False
_Namespace__description = None
_Namespace__didValidation = False
_Namespace__hasBeenArchived = False

Identify the specified namespace, which should be a built-in.

Normally we can just use a reference to the Namespace module instance, but when creating those instances we sometimes need to refer to ones for which the instance has not yet been created. In that case, we use the name of the instance, and resolve the namespace when we need to create the initial context.

_Namespace__inValidation = False
_Namespace__initialNamespaceContext = None
_Namespace__isBuiltinNamespace = False
_Namespace__isLoadedNamespace = False
_Namespace__isUndeclaredNamespace = False
_Namespace__namespaceArchive = None
_Namespace__prefix = None
_Namespace__uri = None

Attempts to load the named objects held in this namespace.

The base class implementation looks at the set of available archived namespaces, and if one contains this namespace unserializes its named object maps.

Sub-classes may choose to look elsewhere, if this version fails or before attempting it.

There is no guarantee that any particular category of named object has been located when this returns. Caller must check.

_replaceComponent(existing_def, replacement_def)

Replace the existing definition with another.

This is used in a situation where building the component model resulted in a new component instance being created and registered, but for which an existing component is to be preferred. An example is when parsing the schema for XMLSchema itself: the built-in datatype components should be retained instead of the simple type definition components dynamically created from the schema.

By providing the value None as the replacement definition, this can also be used to remove components.

Note:Invoking this requires scans of every item in every category

map in the namespace.


Return the standard prefix to be used for this namespace.

Only a few namespace prefixes are bound to namespaces: xml and xmlns are two. In all other cases, this method should return None. The infrastructure attempts to prevent user creation of Namespace instances that have bound prefixes.


Get, or set, a textual description of the namespace.


When known to be operating in this namespace, provide the Namespace instance to be used when names are associated with no namespace.


Return True iff this namespace has been saved to a namespace archive. See also isLoadedNamespace.


Obtain the namespace context to be used when creating components in this namespace.

Usually applies only to built-in namespaces, but is also used in the autotests when creating a namespace without a xs:schema element. . Note that we must create the instance dynamically, since the information that goes into it has cross-dependencies that can’t be resolved until this module has been completely loaded.


Return True iff this namespace is an absent namespace.

Absent namespaces have no namespace URI; they exist only to hold components created from schemas with no target namespace.


Return True iff this namespace was defined by the infrastructure.

That is the case for all namespaces in the Namespace module.


Return True iff this namespace was loaded from a namespace archive.


Return True iff this namespace is always available regardless of whether there is a declaration for it.

This is the case only for the xml( and xmlns( namespaces.

nodeIsNamed(node, *local_names)

Return the URI for the namespace represented by this instance.

If the URI is None, this is an absent namespace, used to hold declarations not associated with a namespace (e.g., from schema with no target namespace).


Ensure this namespace is ready for use.

If the namespace does not have a map of named objects, the system will attempt to load one.

class pyxb.namespace._ComponentDependency_mixin(*args, **kw)

Bases: pyxb.utils.utility.PrivateTransient_mixin, pyxb.cscRoot

Mix-in for components that can depend on other components.

_ComponentDependency_mixin__PrivateTransient = set(['bindingRequires'])
_ComponentDependency_mixin__bindingRequires = None

Placeholder for subclass method that identifies the necessary components.

Note:Override in subclasses.
Returns:The component instances on which this component depends
Return type:frozenset
Raises:LogicError – A subclass failed to implement this method

CSC extension to reset fields of a component. This one clears dependency-related data, since the clone will have to revise its dependencies. :rtype: None

bindingRequires(reset=False, include_lax=False)

Return a set of components upon whose bindings this component’s bindings depend.

For example, bindings that are extensions or restrictions depend on their base types. Complex type definition bindings require that the types of their attribute declarations be available at the class definition, and the types of their element declarations in the postscript.

Parameters:include_lax – if False (default), only the requirements of

the class itself are returned. If True, all requirements are returned. :rtype: set(L{pyxb.xmlschema.structures._SchemaComponent_mixin)}

class pyxb.namespace._NamespaceCategory_mixin(*args, **kw)

Bases: pyxb.cscRoot

Mix-in that aggregates those aspects of XMLNamespaces that hold references to categories of named objects.

Arbitrary groups of named objects, each requiring unique names within themselves, can be saved. Unless configured otherwise, the Namespace instance is extended with accessors that provide direct access to individual category maps. The name of the method is the category name with a suffix of “s”; e.g., if a category “typeDefinition” exists, it can be accessed from the namespace using the syntax ns.typeDefinitions().

Note that the returned value from the accessor is a live reference to the category map; changes made to the map are reflected in the namespace.

_NamespaceCategory_mixin__categoryMap = None

Define public methods on the Namespace which provide access to individual NamedObjectMaps based on their category.


Add links from pyxb.namespace.archive._ObjectOrigin instances.

For any resolvable item in this namespace from an origin managed by the module_record, ensure that item can be found via a lookup through that origin.

This allows these items to be found when a single namespace comprises items translated from different schema at different times using archives to maintain consistency.


Return the whole map from categories to named objects.


Add the named objects from the given map into the set held by this namespace. It is an error to name something which is already present.

_replaceComponent_csc(existing_def, replacement_def)

Replace a component definition where present in the category maps.

Note:This is a high-cost operation, as every item in every category

map must be examined to see whether its value field matches existing_def.


CSC extension to reset fields of a Namespace.

This one handles category-related data.

addCategoryObject(category, local_name, named_object)

Allow access to the named_object by looking up the local_name in the given category.

Raises pyxb.NamespaceUniquenessError if an object with the same name already exists in the category.


The list of individual categories held in this namespace.


Map from local names to NamedObjectMap instances for the given category.


Ensure there is a map for each of the given categories.

Category configuration activates a namespace.

Existing maps are not affected.


Return True iff schema components have been associated with this namespace.

This only checks whether the corresponding categories have been added, not whether there are any entries in those categories. It is useful for identifying namespaces that were incorporated through a declaration but never actually referenced.

replaceCategoryObject(category, local_name, old_object, new_object)

Replace the referenced object in the category.

The new object will be added only if the old_object matches the current entry for local_name in the category.

class pyxb.namespace._NamespaceComponentAssociation_mixin(*args, **kw)

Bases: pyxb.cscRoot

Mix-in for managing components defined within this namespace.

The component set includes not only top-level named components (such as those accessible through category maps), but internal anonymous components, such as those involved in representing the content model of a complex type definition. We need to be able to get a list of these components, sorted in dependency order, so that generated bindings do not attempt to refer to a binding that has not yet been generated.

_NamespaceComponentAssociation_mixin__components = None
_NamespaceComponentAssociation_mixin__origins = None

Record that the responsibility for the component belongs to this namespace.

_replaceComponent_csc(existing_def, replacement_def)

Replace a component definition in the set of associated components.

Raises:KeyErrorexisting_def is not in the set of components.

CSC extension to reset fields of a Namespace.

This one handles data related to component association with a namespace.


Return a frozenset of all components, named or unnamed, belonging to this namespace.