<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><style>p {margin:0px;padding:0px;} blockquote { border: 0px; margin-top: 0px; margin-bottom: 0px; }</style></head><body style="">
<p><font color="#000000" face="Verdana" size="2">Hi,<br><br>Checked in as revision 53527:<br><br>$ svn diff -r 53526<br>Index: src/lxml/tests/test_objectify.py<br>===================================================================<br>--- src/lxml/tests/test_objectify.py (revision 53526)<br>+++ src/lxml/tests/test_objectify.py (working copy)<br>@@ -815,7 +815,27 @@<br> el = objectify.DataElement(s)<br> val = 5<br> self.assertRaises(TypeError, el.__mod__, val)<br>+<br>+ def test_type_str_as_int(self):<br>+ v = "1"<br>+ el = objectify.DataElement(v)<br>+ self.assertEquals(int(el), 1)<br> <br>+ def test_type_str_as_long(self):<br>+ v = "1"<br>+ el = objectify.DataElement(v)<br>+ self.assertEquals(long(el), 1)<br>+<br>+ def test_type_str_as_float(self):<br>+ v = "1"<br>+ el = objectify.DataElement(v)<br>+ self.assertEquals(float(el), 1)<br>+<br>+ def test_type_str_as_complex(self):<br>+ v = "1"<br>+ el = objectify.DataElement(v)<br>+ self.assertEquals(complex(el), 1)<br>+<br> def test_type_str_mod_data_elements(self):<br> s = "%d %f %s %r"<br> el = objectify.DataElement(s)<br>Index: src/lxml/lxml.objectify.pyx<br>===================================================================<br>--- src/lxml/lxml.objectify.pyx (revision 53526)<br>+++ src/lxml/lxml.objectify.pyx (working copy)<br>@@ -773,6 +773,18 @@<br> def __mod__(self, other):<br> return _strValueOf(self) % other<br> <br>+ def __int__(self):<br>+ return int(textOf(self._c_node))<br>+<br>+ def __long__(self):<br>+ return long(textOf(self._c_node))<br>+<br>+ def __float__(self):<br>+ return float(textOf(self._c_node))<br>+<br>+ def __complex__(self):<br>+ return complex(textOf(self._c_node))<br>+<br> cdef class NoneElement(ObjectifiedDataElement):<br> def __str__(self):<br> return "None"<br><br><br>> You mean because of the int/bool duality in Python, but I don't think that's<br>> something we should easily enable without a compelling use case. Remember that<br>> it would mean converting the string value "true" to int(1), I don't think<br>> that's obvious behaviour.<br><br>Yes, I was referring to that:<br><br>>>> int(True)<br>1<br>>>> float(True)<br>1.0<br>>>> long(True)<br>1L<br>>>> complex<br><type 'complex'><br>>>> complex(True)<br>(1+0j)<br>>>><br><br>I actually wasn't aware of that behaviour of Python booleans.<br>And this is definitely no priority for me. Then again, one could argue<br>that BoolElement should behave as much as a native bool in Python,<br>only that its XML representation is the string value "true".</font></p><p><font color="#000000" face="Verdana" size="2">And there are already subtleties for BoolElement:<br><br>>>> root = etree.fromstring("<root><x>true</x></root>")<br>>>> type(root.x)<br><type 'lxml.objectify.BoolElement'><br>>>> root.x.text<br>'true'<br>>>> str(root.x)<br>'True'<br>>>><br><br><br>Cheers,<br><br>Holger</font></p><div class="signature"><br /><br /><br />-- <br />Psssst! Schon vom neuen GMX MultiMessenger gehört?<br />Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger</div></body></html>