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

Class ExpandedName

source code

object --+
         |
        ExpandedName

Represent an 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:

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

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

Instance Methods [hide private]
 
namespace(self)
The Namespace part of the expanded name.
source code
 
namespaceURI(self)
Return the URI of the namespace, or None if the namespace is absent.
source code
 
localName(self)
The local part of the expanded name.
source code
 
validateComponentModel(self)
Pass model validation through to namespace part.
source code
 
uriTuple(self)
Return a tuple consisting of the namespace URI and the local name.
source code
 
__getattr__(self, name) source code
 
createName(self, local_name)
Return a new expanded name in the namespace of this name.
source code
 
adoptName(self, 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.
source code
 
__init__(self, *args, **kw)
Create an expanded name.
source code
 
__str__(self)
str(x)
source code
 
__hash__(self)
hash(x)
source code
 
__cmp__(self, other) source code
 
getAttribute(self, dom_node)
Return the value of the attribute identified by this name in the given node.
source code
 
nodeMatches(self, dom_node)
Return True iff the dom node expanded name matches this expanded name.
source code

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

Class Variables [hide private]
  __namespace = None
hash(x)
  __namespaceURI = None
hash(x)
  __localName = None
hash(x)
  __expandedName = None
hash(x)
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

uriTuple(self)

source code 

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.

createName(self, local_name)

source code 

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.

adoptName(self, name)

source code 

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.

__init__(self, *args, **kw)
(Constructor)

source code 

Create an expanded name.

Expected argument patterns are:

  • ( str ) : the local name in an absent namespace
  • ( ExpandedName ) : a copy of the given expanded name
  • ( xml.dom.Node ) : The name extracted from node.namespaceURI and node.localName
  • ( str, str ) : the namespace URI and the local name
  • ( Namespace, str ) : the namespace and the local name
  • ( ExpandedName, str) : the namespace from the expanded name, and the local name

Wherever str occurs unicode is also permitted.

Parameters:
  • fallback_namespace - Optional Namespace instance to use if the namespace would otherwise be None. This is only used if it is an absent namespace.
Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

__hash__(self)
(Hashing function)

source code 

hash(x)

Overrides: object.__hash__
(inherited documentation)

getAttribute(self, dom_node)

source code 

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.