<!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&nbsp;&nbsp;&nbsp; (revision 53526)<br>+++ src/lxml/tests/test_objectify.py&nbsp;&nbsp;&nbsp; (working copy)<br>@@ -815,7 +815,27 @@<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; el = objectify.DataElement(s)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; val = 5<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.assertRaises(TypeError, el.__mod__, val)<br>+<br>+&nbsp;&nbsp;&nbsp; def test_type_str_as_int(self):<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v = "1"<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; el = objectify.DataElement(v)<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.assertEquals(int(el), 1)<br>&nbsp;<br>+&nbsp;&nbsp;&nbsp; def test_type_str_as_long(self):<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v = "1"<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; el = objectify.DataElement(v)<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.assertEquals(long(el), 1)<br>+<br>+&nbsp;&nbsp;&nbsp; def test_type_str_as_float(self):<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v = "1"<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; el = objectify.DataElement(v)<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.assertEquals(float(el), 1)<br>+<br>+&nbsp;&nbsp;&nbsp; def test_type_str_as_complex(self):<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v = "1"<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; el = objectify.DataElement(v)<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.assertEquals(complex(el), 1)<br>+<br>&nbsp;&nbsp;&nbsp;&nbsp; def test_type_str_mod_data_elements(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s = "%d %f %s %r"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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>&nbsp;&nbsp;&nbsp;&nbsp; def __mod__(self, other):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return _strValueOf(self) % other<br>&nbsp;<br>+&nbsp;&nbsp;&nbsp; def __int__(self):<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return int(textOf(self._c_node))<br>+<br>+&nbsp;&nbsp;&nbsp; def __long__(self):<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return long(textOf(self._c_node))<br>+<br>+&nbsp;&nbsp;&nbsp; def __float__(self):<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return float(textOf(self._c_node))<br>+<br>+&nbsp;&nbsp;&nbsp; def __complex__(self):<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return complex(textOf(self._c_node))<br>+<br>&nbsp;cdef class NoneElement(ObjectifiedDataElement):<br>&nbsp;&nbsp;&nbsp;&nbsp; def __str__(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return "None"<br><br><br>&gt; You mean because of the int/bool duality in Python, but I don't think that's<br>&gt; something we should easily enable without a compelling use case. Remember that<br>&gt; it would mean converting the string value "true" to int(1), I don't think<br>&gt; that's obvious behaviour.<br><br>Yes, I was referring to that:<br><br>&gt;&gt;&gt; int(True)<br>1<br>&gt;&gt;&gt; float(True)<br>1.0<br>&gt;&gt;&gt; long(True)<br>1L<br>&gt;&gt;&gt; complex<br>&lt;type 'complex'&gt;<br>&gt;&gt;&gt; complex(True)<br>(1+0j)<br>&gt;&gt;&gt;<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>&gt;&gt;&gt; root = etree.fromstring("&lt;root&gt;&lt;x&gt;true&lt;/x&gt;&lt;/root&gt;")<br>&gt;&gt;&gt; type(root.x)<br>&lt;type 'lxml.objectify.BoolElement'&gt;<br>&gt;&gt;&gt; root.x.text<br>'true'<br>&gt;&gt;&gt; str(root.x)<br>'True'<br>&gt;&gt;&gt;<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>