[Lxml-checkins] r53527 - in lxml/trunk/src/lxml: . tests
jholg at codespeak.net
jholg at codespeak.net
Mon Apr 7 15:29:27 CEST 2008
Author: jholg
Date: Mon Apr 7 15:29:27 2008
New Revision: 53527
Modified:
lxml/trunk/src/lxml/lxml.objectify.pyx
lxml/trunk/src/lxml/tests/test_objectify.py
Log:
Added __int__, __long__, __float__, __complex__ methods to StringElement,
plus tests.
Modified: lxml/trunk/src/lxml/lxml.objectify.pyx
==============================================================================
--- lxml/trunk/src/lxml/lxml.objectify.pyx (original)
+++ lxml/trunk/src/lxml/lxml.objectify.pyx Mon Apr 7 15:29:27 2008
@@ -773,6 +773,18 @@
def __mod__(self, other):
return _strValueOf(self) % other
+ def __int__(self):
+ return int(textOf(self._c_node))
+
+ def __long__(self):
+ return long(textOf(self._c_node))
+
+ def __float__(self):
+ return float(textOf(self._c_node))
+
+ def __complex__(self):
+ return complex(textOf(self._c_node))
+
cdef class NoneElement(ObjectifiedDataElement):
def __str__(self):
return "None"
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 Mon Apr 7 15:29:27 2008
@@ -815,6 +815,26 @@
el = objectify.DataElement(s)
val = 5
self.assertRaises(TypeError, el.__mod__, val)
+
+ def test_type_str_as_int(self):
+ v = "1"
+ el = objectify.DataElement(v)
+ self.assertEquals(int(el), 1)
+
+ def test_type_str_as_long(self):
+ v = "1"
+ el = objectify.DataElement(v)
+ self.assertEquals(long(el), 1)
+
+ def test_type_str_as_float(self):
+ v = "1"
+ el = objectify.DataElement(v)
+ self.assertEquals(float(el), 1)
+
+ def test_type_str_as_complex(self):
+ v = "1"
+ el = objectify.DataElement(v)
+ self.assertEquals(complex(el), 1)
def test_type_str_mod_data_elements(self):
s = "%d %f %s %r"
More information about the lxml-checkins
mailing list