# pyxb.namespace package

## Submodules

## pyxb.namespace.archive module

Classes and global objects related to archiving U{XML Namespaces<http://www.w3.org/TR/2006/REC-xml-names-20060816/index.html>}.

`pyxb.namespace.archive.``DefaultArchivePrefix` = '/build/pyxb-vpYZZW/pyxb-1.2.6+dfsg'

  The default archive prefix, substituted for C{&} in C{PYXB_ARCHIVE_PATH}.

`pyxb.namespace.archive.``GetArchivePath`()

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

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

  Bases: `pyxb.utils.utility.PrivateTransient_mixin`

  `_ModuleRecord__PrivateTransient` = {'isIncorporated', 'constructedLocally', 'archive', 'categoryObjects'}
  `_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)
  `_loadCategoryObjects`(category_objects)
  `_setArchive`(archive)
  `_setFromOther`(other, archive)
  `_setIsLoadable`(is_loadable)
  `_setIsPublic`(is_public)
  `_setOrigins`(origins)
  `_setReferencedNamespaces`(referenced_namespaces)
  `addOrigin`(origin)
  `archive`()
  `categoryObjects`()
  `completeGenerationAssociations`()
  `dependsOnExternal`()
  `generationUID`()
  `hasMatchingOrigin`(**kw)
  `isIncorporated`()
  `isLoadable`()
  `isPublic`()
  `lookupOriginBySignature`(signature)
  `markIncorporated`()
  `modulePath`()
  `namespace`()
  `origins`()
  `prepareForArchive`(archive)
  `referenceNamespace`(namespace)
  `referencedNamespaces`()
  `resetCategoryObjects`()
  `setModulePath`(module_path)

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 L{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.

    @keyword 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 L{PathEnvironmentVariable}. Defaults to L{GetArchivePath()}. If not defaulted, C{reset} will be forced to C{True}. For any directory in the path, all files ending with C{.wxs} are examined.

    @keyword reset: If C{False} (default), the most recently read set of archives is returned; if C{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` = re.compile('\\.wxs$')
  classmethod `_NamespaceArchive__GetArchiveInstance`(archive_file, stage=None)

    Return a L{NamespaceArchive} instance associated with the given file.

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

  `_NamespaceArchive__NamespaceArchives` = None
  `_NamespaceArchive__PickleFormat` = '200907190858'
  `_NamespaceArchive__PicklingArchive` = None
  `_NamespaceArchive__archivePath` = None
  `_NamespaceArchive__createPickler`(output)
  `_NamespaceArchive__createUnpickler`()
  `_NamespaceArchive__generationUID` = None
  `_NamespaceArchive__isLoadable` = None
  `_NamespaceArchive__locateModuleRecords`()
  `_NamespaceArchive__moduleRecords` = None
  `_NamespaceArchive__namespaces` = None
  `_NamespaceArchive__readComponentSet`(unpickler)
  `_NamespaceArchive__readModules`(unpickler)
  `_NamespaceArchive__stage` = None
  `_NamespaceArchive__unpickler` = None
  `_NamespaceArchive__validateModules`()
  `_NamespaceArchive__validatePrerequisites`(stage)
  `_STAGE_COMPLETE` = 4
  `_STAGE_UNOPENED` = 0
  `_STAGE_readComponents` = 4
  `_STAGE_readModules` = 2
  `_STAGE_uid` = 1
  `_STAGE_validateModules` = 3
  `__NamespaceArchives` = None

    A mapping from generation UID to NamespaceArchive instances.

  `_readToStage`(stage)
  `_stage`()
  `_unsatisfiedModulePrerequisites`()
  `add`(namespace)

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

  `archivePath`()

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

  `discard`()

    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.

  `generationUID`()

    The unique identifier for the generation that produced this archive.

  `isLoadable`()

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

  `moduleRecords`()

    Return the set of L{module records <ModuleRecord>} stored in this archive.

    Each module record represents

  `namespaces`()

    Set of namespaces that can be read from this archive.

  `readNamespaces`()

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

  `update`(namespace_set)

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

  `writeNamespaces`(output)

    Store the namespaces into the archive.

    @param 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
  `componentGraph`(reset=False)
  `componentOrder`(reset=False)
  `dependentNamespaces`(reset=False)
  `namespaceGraph`(reset=False)
  `namespaceOrder`(reset=False)
  `rootNamespaces`()
  `setSiblingNamespaces`(sibling_namespaces)
  `siblingNamespaces`()
  `siblingsFromGraph`(reset=False)

`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 C{&} 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 C{/}. For example, use C{&pyxb/bundles//} to enable search of any archive bundled with PyXB.

  @note: If you put a path separator between C{&} 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
  `_allowUpdateFromOther`(other)
  `_objectOrigin`()
  `_prepareForArchive`(archive)
  `_setObjectOrigin`(object_origin, override=False)
  `_updateFromOther`(other)

    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.

  `_updateFromOther_csc`(other)

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 L{pyxb.namespace.Namespace}

  `_NamespaceArchivable_mixin__isActive` = None
  `_NamespaceArchivable_mixin__isImportAugmentable` = False
  `_NamespaceArchivable_mixin__loadedFromArchive` = None
  `_NamespaceArchivable_mixin__moduleRecordMap` = None
  `_NamespaceArchivable_mixin__wroteToArchive` = None
  `_activate`()
  `_loadedFromArchive`()
  `_removeArchive`(archive)
  `_reset`()

    CSC extension to reset fields of a Namespace.

    This one handles category-related data.

  `_setLoadedFromArchive`(archive)
  `_setState_csc`(kw)
  `_setWroteToArchive`(archive)
  `addModuleRecord`(module_record)
  `isActive`(empty_inactive=False)
  `isImportAugmentable`()

    Return C{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 L{setImportAugmentable}, or if there is no archive or built-in that provides a component model for the namespace.

  `isLoadable`()

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

  `loadableFrom`()

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

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

    Prevent loading this namespace from an archive.

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

  `moduleRecords`()
  `setImportAugmentable`(value=True)

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` = {'categoryObjectMap', 'originatedObjects'}
  `_ObjectOrigin__categoryMembers` = None
  `_ObjectOrigin__categoryObjectMap` = None
  `_ObjectOrigin__moduleRecord` = None
  `_ObjectOrigin__originatedObjects` = None
  `_ObjectOrigin__signature` = None
  `addCategoryMember`(category, name, obj)
  `categoryMembers`()
  `generationUID`()
  `moduleRecord`()
  `namespace`()
  `originatedObjects`()
  `resetCategoryMembers`()
  `signature`()

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 L{_NamespaceComponentAssociation_mixin}.

  `_SchemaOrigin__PrivateTransient` = {'schema'}
  `_SchemaOrigin__location` = None
  `_SchemaOrigin__schema` = None
  `_SchemaOrigin__setDefaultKW`(kw)
  `_SchemaOrigin__version` = None
  `location`()
  `match`(**kw)

    Determine whether this record matches the parameters.

    @keyword schema: a L{pyxb.xmlschema.structures.Schema} instance from which the other parameters are obtained. @keyword location: a schema location (URI) @keyword signature: a schema signature @return: C{True} iff I{either} C{location} or C{signature} matches.

  `schema`()
  `version`()

## pyxb.namespace.builtin module

Classes and global objects related to built-in U{XML Namespaces<http://www.w3.org/TR/2006/REC-xml-names-20060816/index.html>}.

`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 C{xml})

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

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

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

  Namespace and URI for the XMLSchema namespace (often C{xs}, or C{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.

`pyxb.namespace.builtin.``_InitializeBuiltinNamespaces`(structures_module)

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

  @param structures_module: The L{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 L{Namespace} that pre-defines components available in the XML (xml) namespace. Specifically those are the attribute declarations:

  > - C{xml:space}
  > - C{xml:lang}
  > - C{xml:base}
  > - C{xml:id}

  the encompassing attribute group declaration:

  > - C{xml:specialAttrs}

  and the anonymous types that support these.

  `_defineBuiltins_ox`(structures_module)

    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 L{Namespace} that pre-defines components available in the XMLSchema namespace.

  The types are defined when L{pyxb.xmlschema.structures} is imported.

  `_defineBuiltins_ox`(structures_module)

    Register the built-in types into the XMLSchema namespace.

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

  Bases: `pyxb.namespace.Namespace`

  Extension of L{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.

  `ProcessTypeAttribute`(value=None)

    Specify how PyXB should interpret U{xsi:type <http://www.w3.org/TR/xmlschema-1/#xsi_type>} attributes when converting a document to a binding instance.

    The default value is L{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.

    @param value: One of L{PT_strict}, L{PT_lax}, L{PT_skip}, or C{None} (no change) @return: 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 L{ProcessTypeAttribute}.

    @param type_name: The QName value from U{xsi:type <http://www.w3.org/TR/xmlschema-1/#xsi_type>}. If this is C{None}, C{type_class} is used as C{ret_type_class}.

    @param ns_ctx: The NamespaceContext within which C{type_name} should be resolved

    @param fallback_namespace: The namespace that should be used if C{type_name} has no prefix

    @param type_class: The value to return if C{type_name} is missing or acceptably invalid (viz., due to L{PT_skip})

    @return: A tuple C{(did_replace, ret_type_class)} where C{did_replace} is C{True} iff the C{ret_type_class} is not the same as C{type_class}, and C{ret_type_class} is the class that should be used.

    @raises pyxb.BadDocumentError: if the processing type configuration is L{PT_strict} and C{type_name} fails to resolve to a type definition that is consistent with any provided C{type_class}.

  `_XMLSchema_instance__processType` = 'strict'
  `_defineBuiltins_ox`(structures_module)

    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 {http://www.w3.org/2001/XMLSchema-instance}nil.

  `type` = None

    An expanded name for {http://www.w3.org/2001/XMLSchema-instance}type.

## pyxb.namespace.resolution module

Classes and global objects related to resolving U{XML Namespaces<http://www.w3.org/TR/2006/REC-xml-names-20060816/index.html>}.

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, C{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 L{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).

    @raise 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 C{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 at 0x7f0430dbd588>, 'xmlns': <pyxb.namespace.Namespace object at 0x7f0430dbd898>}
  `_NamespaceContext__InitialScopePrefixes` = {<pyxb.namespace.Namespace object>: {'xmlns'}, <pyxb.namespace.builtin._XML object>: {'xml'}}
  `_NamespaceContext__TargetNamespaceAttributes` = {<pyxb.namespace.ExpandedName object at 0x7f0430dbdc88>: <pyxb.namespace.ExpandedName object at 0x7f0430dbdcc0>}
  `_NamespaceContext__addPrefixMap`(pfx, ns)
  `_NamespaceContext__clonePrefixMap`()
  `_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__removePrefixMap`(pfx)
  `_NamespaceContext__targetNamespace` = None
  classmethod `_TargetNamespaceAttribute`(expanded_name)
  `__inScopeNamespaces` = None

    Map from L{Namespace} instances to sets of prefix strings associated with the namespace. The default namespace is not represented.

  `declareNamespace`(namespace, prefix=None, add_to_map=False)

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

    @param namespace: The namespace to be associated with the document. @type namespace: L{pyxb.namespace.Namespace}

    @keyword 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.

    @return: a prefix that may be used with the namespace. If C{prefix} was C{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 L{pyxb.namespace.Namespace}

  `defaultNamespace`()

    The default namespace in effect at this node. E.g., C{xmlns=”URN:default”}.

  `finalizeTargetNamespace`(tns_uri=None, including_context=None)
  `inScopeNamespaces`()

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

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

    Convert the provided name into an L{ExpandedName}, i.e. a tuple of L{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 L{defaultNamespace()}, which must be provided (or defaults to the target namespace, if that is not absent).

    @param name: A QName. @type name: C{str} or C{unicode} @param 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 C{False} (default), an NCName in a context where C{namespace} is C{None} and no default or fallback namespace can be identified produces an exception. If C{True}, such an NCName is implicitly placed in no namespace. @return: An L{ExpandedName} tuple: ( L{Namespace}, C{str} ) @raise pyxb.QNameResolutionError: The prefix is not in scope @raise pyxb.QNameResolutionError: No prefix is given and the default namespace is absent

  `prefixForNamespace`(namespace)

    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 L{queueForResolution()<Namespace.queueForResolution>} in L{targetNamespace()}.

  `reset`()

    Reset this instance to the state it was when created, exclusive of XMLNS directives passed in a constructor C{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.

  `setDefaultNamespace`(default_namespace)

    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.

    @param 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: L{pyxb.namespace.Namespace} or C{str} or C{unicode}.

  `setNodeContext`(node)
  `targetNamespace`()

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

`pyxb.namespace.resolution.``ResolveSiblingNamespaces`(sibling_namespaces)

  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
  `_getState_csc`(kw)
  `_referenceNamespace`(namespace)
  `_replaceComponent_csc`(existing_def, replacement_def)

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

  `_reset`()

    CSC extension to reset fields of a Namespace.

    This one handles component-resolution–related data.

  `_setState_csc`(kw)
  `_transferReferencedNamespaces`(module_record)
  `_unresolvedComponents`()

    Returns a reference to the list of unresolved components.

  `_unresolvedDependents`()

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

  `importNamespace`(namespace)
  `importedNamespaces`()

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

  `needsResolution`()

    Return C{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.

    @param resolvable: An instance of L{_Resolvable_mixin} that is later to be resolved.

    @keyword depends_on: C{None}, or an instance of L{_Resolvable_mixin} which C{resolvable} requires to be resolved in order to resolve itself.

    @return: C{resolvable}

  `referencedNamespaces`()

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

  `resolveDefinitions`(allow_unresolved=False)

    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().

  `_resolve`()

    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 L{_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 L{isResolved} is true, return right away. If something prevents you from completing resolution, invoke L{self._queueForResolution()} (so it is retried later) and immediately return self. Prior to leaving after successful resolution discard any cached dom node by setting C{self.__domNode=None}.

    @return: C{self}, whether or not resolution succeeds. @raise pyxb.SchemaValidationError: if resolution requlres a reference to an unknown component

  `isResolved`()

    Determine whether this named component is resolved.

    Override this in the child class.

## pyxb.namespace.utility module

Utility functions related to U{XML Namespaces<http://www.w3.org/TR/2006/REC-xml-names-20060816/index.html>}.

`pyxb.namespace.utility.``AvailableNamespaces`()

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

`pyxb.namespace.utility.``CreateAbsentNamespace`()

  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 L{Namespace} instance corresponding to it.

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

  @param uri: The URI that identifies the namespace @type uri: A non-empty C{str} or C{unicode} string @keyword create_if_missing: If C{True}, a namespace for the given URI is created if one has not already been registered. Default is C{False}. @type create_if_missing: C{bool} @return: The Namespace corresponding to C{uri}, if available @rtype: L{Namespace} or C{None} @raise pyxb.LogicError: The uri is not a non-empty string

`pyxb.namespace.utility.``NamespaceInstance`(namespace)

  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 U{XML Namespaces<http://www.w3.org/TR/2006/REC-xml-names-20060816/index.html>}.

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 <http://www.w3.org/TR/REC-xml-names/#dt-expname>}, 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 C{None} and that string.

  Note that absent namespaces can be represented in two ways: with a namespace of C{None} (the name “has no namespace”), and with a namespace that is an L{absent namespace <Namespace.CreateAbsentNamespace>} (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 C{en} has a category ‘typeDefinition’, then the following two expressions are equivalent:

      en.typeDefinition()
      en.namespace().categoryMap('typeDefinition').get(en.localName())

  This class descends from C{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
  `_ExpandedName__otherForCompare`(other)
  `adoptName`(name)

    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 L{pyxb.binding.basis.element.elementForName}.

  `createName`(local_name)

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

    @param local_name: The local name portion of an expanded name. @return: An instance of L{ExpandedName}.

  `getAttribute`(dom_node)

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

    @return: An instance of C{xml.dom.Attr}, or C{None} if the node does not have an attribute with this name.

  `localName`()

    The local part of the expanded name.

  `namespace`()

    The L{Namespace} part of the expanded name.

  `namespaceURI`()

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

  `nodeMatches`(dom_node)

    Return C{True} iff the dom node expanded name matches this expanded name.

  `uriTuple`()

    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.

  `validateComponentModel`()

    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
  `category`()

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

  `namespace`()

    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 L{Namespace} class instance per namespace (URI). The instance also supports associating arbitrary L{maps<NamedObjectMap>} from names to objects, in separate categories. The default categories are configured externally; for example, the L{Schema<pyxb.xmlschema.structures.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 L{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` = {'http://www.w3.org/1999/xhtml': <pyxb.namespace.Namespace object at 0x7f0430dbd940>, 'http://www.w3.org/2000/xmlns/': <pyxb.namespace.Namespace object at 0x7f0430dbd898>, 'http://www.w3.org/2001/XMLSchema': <pyxb.namespace.builtin._XMLSchema object at 0x7f0430dbd828>, 'http://www.w3.org/2001/XMLSchema-hasFacetAndProperty': <pyxb.namespace.Namespace object at 0x7f0430dbd5c0>, 'http://www.w3.org/2001/XMLSchema-instance': <pyxb.namespace.builtin._XMLSchema_instance object at 0x7f0430dbd7b8>, 'http://www.w3.org/XML/1998/namespace': <pyxb.namespace.builtin._XML object at 0x7f0430dbd588>}
  `_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
  `_Namespace__identifyNamespace`(nsval)

    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
  `_defineBuiltins`(structures_module)
  `_defineBuiltins_ox`(structures_module)
  `_loadComponentsFromArchives`(structures_module)

    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.

  `_overrideAbsentNamespace`(uri)
  `_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 C{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: C{replacement_def}

  `_reset`()
  `boundPrefix`()

    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.

  `builtinModulePath`()
  `builtinNamespaceRepresentation`()
  `createExpandedName`(local_name)
  `description`(description=None)

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

  `fallbackNamespace`()

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

  `hasBeenArchived`()

    Return C{True} iff this namespace has been saved to a namespace archive. See also L{isLoadedNamespace}.

  `initialNamespaceContext`()

    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.

  `isAbsentNamespace`()

    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.

  `isBuiltinNamespace`()

    Return True iff this namespace was defined by the infrastructure.

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

  `isLoadedNamespace`()

    Return C{True} iff this namespace was loaded from a namespace archive.

  `isUndeclaredNamespace`()

    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(http://www.w3.org/XML/1998/namespace) and xmlns(http://www.w3.org/2000/xmlns/) namespaces.

  `nodeIsNamed`(node, *local_names)
  `prefix`()
  `setPrefix`(prefix)
  `uri`()

    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).

  `validateComponentModel`(structures_module=None)

    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` = {'bindingRequires'}
  `_ComponentDependency_mixin__bindingRequires` = None
  `_bindingRequires_vx`(include_lax)

    Placeholder for subclass method that identifies the necessary components.

    @note: Override in subclasses.

    @return: The component instances on which this component depends @rtype: C{frozenset} @raise LogicError: A subclass failed to implement this method

  `_resetClone_csc`(**kw)

    CSC extension to reset fields of a component. This one clears dependency-related data, since the clone will have to revise its dependencies. @rtype: C{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.

    @keyword include_lax: if C{False} (default), only the requirements of the class itself are returned. If C{True}, all requirements are returned. @rtype: C{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 C{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
  `_NamespaceCategory_mixin__checkCategoriesEmpty`()
  `_NamespaceCategory_mixin__defineCategoryAccessors`()

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

  `_associateOrigins`(module_record)

    Add links from L{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.

  `_categoryMap`()

    Return the whole map from categories to named objects.

  `_loadNamedObjects`(category_map)

    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.

  `_namedObjects`()
  `_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 C{existing_def}.

  `_reset`()

    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.

  `categories`()

    The list of individual categories held in this namespace.

  `categoryMap`(category)

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

  `configureCategories`(categories)

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

    Category configuration L{activates<archive._NamespaceArchivable_mixin.isActive>} a namespace.

    Existing maps are not affected.

  `hasSchemaComponents`()

    Return C{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
  `_associateComponent`(component)

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

  `_releaseNamespaceContexts`()
  `_replaceComponent_csc`(existing_def, replacement_def)

    Replace a component definition in the set of associated components.

    @raise KeyError: C{existing_def} is not in the set of components.

  `_reset`()

    CSC extension to reset fields of a Namespace.

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

  `addSchema`(schema)
  `components`()

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

  `lookupSchemaByLocation`(schema_location)
  `schemas`()