genshi.core.Namespace

Package genshi :: Module core :: Class Namespace |

# Class Namespace

    object --+
             |
            Namespace

Utility class creating and testing elements with a namespace.

Internally, namespace URIs are encoded in the QName of any element or attribute, the namespace URI being enclosed in curly braces. This class helps create and test these strings.

A Namespace object is instantiated with the namespace URI.

    >>> html = Namespace('http://www.w3.org/1999/xhtml')
    >>> html
    Namespace('http://www.w3.org/1999/xhtml')
    >>> html.uri
    u'http://www.w3.org/1999/xhtml'

The Namespace object can than be used to generate QName objects with that namespace:

    >>> html.body
    QName('http://www.w3.org/1999/xhtml}body')
    >>> html.body.localname
    u'body'
    >>> html.body.namespace
    u'http://www.w3.org/1999/xhtml'

The same works using item access notation, which is useful for element or attribute names that are not valid Python identifiers:

    >>> html['body']
    QName('http://www.w3.org/1999/xhtml}body')

A Namespace object can also be used to test whether a specific QName belongs to that namespace using the `in` operator:

    >>> qname = html.body
    >>> qname in html
    True
    >>> qname in Namespace('http://www.w3.org/2002/06/xhtml2')
    False

Instance Methods
__getnewargs__(self) |
__getstate__(self) |
__setstate__(self, uri) |
__init__(self, uri) x.__init__(...) initializes x; see x.__class__.__doc__ for signature |
__contains__(self, qname) |
__ne__(self, other) |
__eq__(self, other) |
__getitem__(self, name) |
__getattr__(self, name) |
__hash__(self) hash(x) |
__repr__(self) repr(x) |
__str__(self) str(x) |
__unicode__(self) |
Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__sizeof__`, `__subclasshook__`

Static Methods
a new object with type S, a subtype of T |
__new__(cls, uri) |

Properties
Inherited from `object`: `__class__`

Method Details

### __new__(cls, uri) Static Method |
Returns: a new object with type S, a subtype of T Overrides: object.__new__ (inherited documentation)

### __init__(self, uri) (Constructor) |
x.__init__(...) initializes x; see x.__class__.__doc__ for signature Overrides: object.__init__ (inherited documentation)

### __hash__(self) (Hashing function) |
hash(x) Overrides: object.__hash__ (inherited documentation)

### __repr__(self) (Representation operator) |
repr(x) Overrides: object.__repr__ (inherited documentation)

### __str__(self) (Informal representation operator) |
str(x) Overrides: object.__str__ (inherited documentation)