[Lxml-checkins] r50159 - in lxml/trunk: . src/lxml src/lxml/tests

scoder at codespeak.net scoder at codespeak.net
Fri Dec 28 13:25:27 CET 2007


Author: scoder
Date: Fri Dec 28 13:25:27 2007
New Revision: 50159

Modified:
   lxml/trunk/   (props changed)
   lxml/trunk/CHANGES.txt
   lxml/trunk/src/lxml/lxml.etree.pyx
   lxml/trunk/src/lxml/tests/test_etree.py
Log:
 r3187 at delle:  sbehnel | 2007-12-28 13:23:37 +0100
 make 'entity.text' return the textual representation, such as é


Modified: lxml/trunk/CHANGES.txt
==============================================================================
--- lxml/trunk/CHANGES.txt	(original)
+++ lxml/trunk/CHANGES.txt	Fri Dec 28 13:25:27 2007
@@ -8,6 +8,9 @@
 Features added
 --------------
 
+* ``entity.text`` now returns the textual representation of the
+  entity, e.g. ``&``.
+
 Bugs fixed
 ----------
 

Modified: lxml/trunk/src/lxml/lxml.etree.pyx
==============================================================================
--- lxml/trunk/src/lxml/lxml.etree.pyx	(original)
+++ lxml/trunk/src/lxml/lxml.etree.pyx	Fri Dec 28 13:25:27 2007
@@ -1352,9 +1352,17 @@
 
         def __set__(self, value):
             value = _utf8(value)
+            assert '&' not in value and ';' not in value, \
+                "Invalid entity name '%s'" % value
             c_text = _cstr(value)
             tree.xmlNodeSetName(self._c_node, c_text)
 
+    property text:
+        # FIXME: should this be None or '&[VALUE];' or the resolved
+        # entity value ?
+        def __get__(self):
+            return '&%s;' % funicode(self._c_node.name)
+
     def __repr__(self):
         return "&%s;" % self.name
 
@@ -1940,10 +1948,10 @@
     first pre-order).  Note that this also includes comments, entities and
     processing instructions.  To filter them out, check if the ``tag``
     property of the returned element is a string (i.e. not None and not a
-    factory function).
+    factory function), or pass the ``Element`` factory for the ``tag`` keyword.
 
-    If the optional 'tag' argument is not None, the iterator returns only the
-    elements that match the respective name and namespace.
+    If the optional ``tag`` argument is not None, the iterator returns only
+    the elements that match the respective name and namespace.
 
     The optional boolean argument 'inclusive' defaults to True and can be set
     to False to exclude the start element itself.

Modified: lxml/trunk/src/lxml/tests/test_etree.py
==============================================================================
--- lxml/trunk/src/lxml/tests/test_etree.py	(original)
+++ lxml/trunk/src/lxml/tests/test_etree.py	Fri Dec 28 13:25:27 2007
@@ -582,7 +582,7 @@
             tree = parse(StringIO(xml), parser)
             root = tree.getroot()
             self.assertEquals(root[0].tag, Entity)
-            self.assertFalse(root[0].text)
+            self.assertEquals(root[0].text, "&myentity;")
             self.assertEquals(root[0].tail, None)
             self.assertEquals(root[0].name, "myentity")
 
@@ -598,7 +598,7 @@
         root.append( Entity("test") )
 
         self.assertEquals(root[0].tag, Entity)
-        self.assertFalse(root[0].text)
+        self.assertEquals(root[0].text, "&test;")
         self.assertEquals(root[0].tail, None)
         self.assertEquals(root[0].name, "test")
 


More information about the lxml-checkins mailing list