# HG changeset patch # User cmlenz # Date 1197406870 0 # Node ID 9729855cacf49c1b109089df1a220e592598429a # Parent 281ab9fb4b044e640442c1625b004728c3dc191e `QName` can now be constructed from a string with a leading curly brace, and some doc improvements. Closes #164. diff --git a/genshi/core.py b/genshi/core.py --- a/genshi/core.py +++ b/genshi/core.py @@ -646,9 +646,9 @@ """A qualified element or attribute name. The unicode value of instances of this class contains the qualified name of - the element or attribute, in the form ``{namespace}localname``. The namespace - URI can be obtained through the additional `namespace` attribute, while the - local name can be accessed through the `localname` attribute. + the element or attribute, in the form ``{namespace-uri}local-name``. The + namespace URI can be obtained through the additional `namespace` attribute, + while the local name can be accessed through the `localname` attribute. >>> qname = QName('foo') >>> qname @@ -668,10 +668,16 @@ __slots__ = ['namespace', 'localname'] def __new__(cls, qname): + """Create the `QName` instance. + + :param qname: the qualified name as a string of the form + ``{namespace-uri}local-name``, where the leading curly + brace is optional + """ if type(qname) is cls: return qname - parts = qname.split(u'}', 1) + parts = qname.lstrip(u'{').split(u'}', 1) if len(parts) > 1: self = unicode.__new__(cls, u'{%s' % qname) self.namespace, self.localname = map(unicode, parts) diff --git a/genshi/tests/core.py b/genshi/tests/core.py --- a/genshi/tests/core.py +++ b/genshi/tests/core.py @@ -165,6 +165,11 @@ self.assertEqual("QName(u'http://www.example.org/namespace}elem')", repr(QName('http://www.example.org/namespace}elem'))) + def test_leading_curly_brace(self): + qname = QName('{http://www.example.org/namespace}elem') + self.assertEquals('http://www.example.org/namespace', qname.namespace) + self.assertEquals('elem', qname.localname) + def suite(): suite = unittest.TestSuite()