Package pyxb :: Package namespace :: Class Namespace
[hide private]
[frames] | no frames]

Class Namespace

source code

                       object --+        
                                |        
                          cscRoot --+    
                                    |    
             _NamespaceCategory_mixin --+
                                        |
                       object --+       |
                                |       |
                          cscRoot --+   |
                                    |   |
resolution._NamespaceResolution_mixin --+
                                        |
                       object --+       |
                                |       |
                          cscRoot --+   |
                                    |   |
 _NamespaceComponentAssociation_mixin --+
                                        |
                       object --+       |
                                |       |
                          cscRoot --+   |
                                    |   |
   archive._NamespaceArchivable_mixin --+
                                        |
                                       Namespace
Known Subclasses:

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.

Instance Methods [hide private]
 
__getnewargs__(self)
Pickling support.
source code
 
__init__(self, 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)
Create a new Namespace.
source code
 
_reset(self)
CSC extension to reset fields of a Namespace.
source code
 
uri(self)
Return the URI for the namespace represented by this instance.
source code
 
setPrefix(self, prefix) source code
 
prefix(self) source code
 
isAbsentNamespace(self)
Return True iff this namespace is an absent namespace.
source code
 
fallbackNamespace(self)
When known to be operating in this namespace, provide the Namespace instance to be used when names are associated with no namespace.
source code
 
_overrideAbsentNamespace(self, uri) source code
 
boundPrefix(self)
Return the standard prefix to be used for this namespace.
source code
 
isBuiltinNamespace(self)
Return True iff this namespace was defined by the infrastructure.
source code
 
builtinNamespaceRepresentation(self) source code
 
builtinModulePath(self) source code
 
isUndeclaredNamespace(self)
Return True iff this namespace is always available regardless of whether there is a declaration for it.
source code
 
isLoadedNamespace(self)
Return True iff this namespace was loaded from a namespace archive.
source code
 
hasBeenArchived(self)
Return True iff this namespace has been saved to a namespace archive.
source code
 
description(self, description=None)
Get, or set, a textual description of the namespace.
source code
 
nodeIsNamed(self, node, *local_names) source code
 
createExpandedName(self, local_name) source code
 
__getstate__(self)
Support pickling.
source code
 
_defineBuiltins_ox(self, structures_module) source code
 
_defineBuiltins(self, structures_module) source code
 
_loadComponentsFromArchives(self, structures_module)
Attempts to load the named objects held in this namespace.
source code
 
validateComponentModel(self, structures_module=None)
Ensure this namespace is ready for use.
source code
 
_replaceComponent(self, existing_def, replacement_def)
Replace the existing definition with another.
source code
 
initialNamespaceContext(self)
Obtain the namespace context to be used when creating components in this namespace.
source code
 
__identifyNamespace(self, nsval)
Identify the specified namespace, which should be a built-in.
source code
 
__str__(self)
str(x)
source code

Inherited from _NamespaceCategory_mixin: addCategoryObject, categories, categoryMap, configureCategories, hasSchemaComponents, replaceCategoryObject

Inherited from resolution._NamespaceResolution_mixin: importNamespace, importedNamespaces, needsResolution, queueForResolution, referencedNamespaces, resolveDefinitions

Inherited from _NamespaceComponentAssociation_mixin: addSchema, components, lookupSchemaByLocation, schemas

Inherited from archive._NamespaceArchivable_mixin: addModuleRecord, isActive, isLoadable, loadableFrom, lookupModuleRecordByUID, markNotLoadable, moduleRecords

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Class Methods [hide private]
 
_NamespaceForURI(cls, uri)
If a Namespace instance for the given URI exists, return it; otherwise return None.
source code
 
AvailableNamespaces(cls)
Return a set of all Namespace instances defined so far.
source code
 
CreateAbsentNamespace(cls)
Create an absent namespace.
source code
Static Methods [hide private]
a new object with type S, a subtype of T
__new__(cls, *args, **kw)
Pickling and singleton support.
source code
Class Variables [hide private]
  __uri = None
hash(x)
  __absentNamespaceID = 0
  __boundPrefix = None
hash(x)
  __prefix = None
hash(x)
  __Registry = {}
  __AbsentNamespaces = set([])
  __description = None
hash(x)
  __isBuiltinNamespace = False
  __isUndeclaredNamespace = False
  __isLoadedNamespace = False
  __namespaceArchive = None
hash(x)
  __hasBeenArchived = False
  __builtinModulePath = None
hash(x)
  __bindingConfiguration = None
hash(x)
  __initialNamespaceContext = None
hash(x)
  __contextDefaultNamespace = None
hash(x)
  __contextInScopeNamespaces = None
hash(x)
  __definedBuiltins = False
  __didValidation = False
  __inValidation = False
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

_NamespaceForURI(cls, uri)
Class Method

source code 

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.

__getnewargs__(self)

source code 

Pickling support.

To ensure that unpickled Namespace instances are unique per URI, we ensure that the routine that creates unpickled instances knows what it's supposed to return.

__new__(cls, *args, **kw)
Static Method

source code 

Pickling and singleton support.

This ensures that no more than one Namespace instance exists for any given URI. We could do this up in __init__, but that doesn't normally get called when unpickling instances; this does. See also __getnewargs__().

Returns: a new object with type S, a subtype of T
Overrides: object.__new__

__init__(self, 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)
(Constructor)

source code 

Create a new Namespace.

The URI must be non-None, and must not already be assigned to a Namespace instance. See _NamespaceForURI().

User-created Namespace instances may also provide a description.

Users should never provide a builtin_namespace parameter.

Overrides: object.__init__

_reset(self)

source code 

CSC extension to reset fields of a Namespace.

This one handles category-related data.

Overrides: archive._NamespaceArchivable_mixin._reset
(inherited documentation)

uri(self)

source code 

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

isAbsentNamespace(self)

source code 

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.

CreateAbsentNamespace(cls)
Class Method

source code 

Create an absent namespace.

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

boundPrefix(self)

source code 

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.

isBuiltinNamespace(self)

source code 

Return True iff this namespace was defined by the infrastructure.

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

isUndeclaredNamespace(self)

source code 

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.

hasBeenArchived(self)

source code 

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

__getstate__(self)

source code 

Support pickling.

Well, no, not really. Because namespace instances must be unique, we represent them as their URI, and that's done by __getnewargs__ above. All the interesting information is in the ModuleRecords.

_loadComponentsFromArchives(self, structures_module)

source code 

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.

validateComponentModel(self, structures_module=None)

source code 

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.

_replaceComponent(self, existing_def, replacement_def)

source code 

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.

Returns:
replacement_def

Note: Invoking this requires scans of every item in every category map in the namespace.

initialNamespaceContext(self)

source code 

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.

__identifyNamespace(self, nsval)

source code 

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.

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)