[Lxml-checkins] r32600 - in lxml/trunk/src/lxml: . tests
scoder at codespeak.net
scoder at codespeak.net
Sat Sep 23 07:59:31 CEST 2006
Author: scoder
Date: Sat Sep 23 07:59:28 2006
New Revision: 32600
Modified:
lxml/trunk/src/lxml/objectify.pyx
lxml/trunk/src/lxml/tests/test_objectify.py
Log:
'x * StringElement' operation
Modified: lxml/trunk/src/lxml/objectify.pyx
==============================================================================
--- lxml/trunk/src/lxml/objectify.pyx (original)
+++ lxml/trunk/src/lxml/objectify.pyx Sat Sep 23 07:59:28 2006
@@ -635,6 +635,8 @@
def __mul__(self, other):
if isinstance(self, StringElement):
return textOf((<StringElement>self)._c_node) * _numericValueOf(other)
+ elif isinstance(other, StringElement):
+ return _numericValueOf(self) * textOf((<StringElement>other)._c_node)
else:
raise TypeError, "invalid types for * operator"
Modified: lxml/trunk/src/lxml/tests/test_objectify.py
==============================================================================
--- lxml/trunk/src/lxml/tests/test_objectify.py (original)
+++ lxml/trunk/src/lxml/tests/test_objectify.py Sat Sep 23 07:59:28 2006
@@ -273,6 +273,28 @@
root.none = "test"
self.assert_(isinstance(root.none, objectify.StringElement))
+ def test_type_str_mul(self):
+ Element = self.Element
+ SubElement = self.etree.SubElement
+ root = Element("{objectified}root")
+ root.none = "test"
+
+ self.assertEquals("test" * 5, root.none * 5)
+ self.assertEquals(5 * "test", 5 * root.none)
+
+ self.assertRaises(TypeError, operator.mul, root.none, "honk")
+ self.assertRaises(TypeError, operator.mul, "honk", root.none)
+
+ def test_type_str_add(self):
+ Element = self.Element
+ SubElement = self.etree.SubElement
+ root = Element("{objectified}root")
+ root.none = "test"
+
+ s = "toast"
+ self.assertEquals("test" + s, root.none + s)
+ self.assertEquals(s + "test", s + root.none)
+
def test_data_element_str(self):
value = objectify.DataElement("test")
self.assert_(isinstance(value, objectify.StringElement))
More information about the lxml-checkins
mailing list