[Lxml-checkins] r46056 - in lxml/trunk: doc src/lxml

scoder at codespeak.net scoder at codespeak.net
Mon Aug 27 20:05:35 CEST 2007


Author: scoder
Date: Mon Aug 27 20:05:35 2007
New Revision: 46056

Modified:
   lxml/trunk/doc/objectify.txt
   lxml/trunk/src/lxml/objectify.pyx
Log:
always py-annotate when setting objectify values from Python types (not sure about bool strings yet)

Modified: lxml/trunk/doc/objectify.txt
==============================================================================
--- lxml/trunk/doc/objectify.txt	(original)
+++ lxml/trunk/doc/objectify.txt	Mon Aug 27 20:05:35 2007
@@ -643,25 +643,33 @@
     >>> print objectify.dump(root)
     root = None [ObjectifiedElement]
         a = 'nice string!' [StringElement]
+          * py:pytype = 'str'
 
     >>> root.a = True
     >>> print objectify.dump(root)
     root = None [ObjectifiedElement]
         a = True [BoolElement]
+          * py:pytype = 'bool'
 
     >>> root.a = [1, 2, 3]
     >>> print objectify.dump(root)
     root = None [ObjectifiedElement]
         a = 1 [IntElement]
+          * py:pytype = 'int'
         a = 2 [IntElement]
+          * py:pytype = 'int'
         a = 3 [IntElement]
+          * py:pytype = 'int'
 
     >>> root.a = (1, 2, 3)
     >>> print objectify.dump(root)
     root = None [ObjectifiedElement]
         a = 1 [IntElement]
+          * py:pytype = 'int'
         a = 2 [IntElement]
+          * py:pytype = 'int'
         a = 3 [IntElement]
+          * py:pytype = 'int'
 
 
 Recursive string representation of elements
@@ -887,34 +895,6 @@
           * py:pytype = 'str'
           * myattr = 'someval'
 
-    >>> root.x = objectify.DataElement(5, _xsi="integer")
-    >>> print objectify.dump(root)
-    root = None [ObjectifiedElement]
-        x = 5L [LongElement]
-          * py:pytype = 'long'
-          * xsi:type = 'xsd:integer'
-
-There is a side effect of the type lookup.  If you assign a string value using
-attribute assignment and that string value turns out to be valid for any of
-the type checks, you will end up with the resolved type instead of a
-StringElement::
-
-    >>> root = objectify.Element("root")
-    >>> root.s = "5"
-    >>> print objectify.dump(root)
-    root = None [ObjectifiedElement]
-        s = 5 [IntElement]
-
-You can use the ``DataElement()`` factory to avoid this behaviour and thus
-provide the type of a data element by hand::
-
-    >>> root = objectify.Element("root")
-    >>> root.s = objectify.DataElement(5, _pytype="str")
-    >>> print objectify.dump(root)
-    root = None [ObjectifiedElement]
-        s = '5' [StringElement]
-          * py:pytype = 'str'
-
 Likewise, the data type can be provided as an XML Schema type using the _xsi
 argument of ``DataElement()``::
 

Modified: lxml/trunk/src/lxml/objectify.pyx
==============================================================================
--- lxml/trunk/src/lxml/objectify.pyx	(original)
+++ lxml/trunk/src/lxml/objectify.pyx	Mon Aug 27 20:05:35 2007
@@ -507,11 +507,15 @@
     else:
         cetree.delAttributeFromNsName(
             element._c_node, _XML_SCHEMA_INSTANCE_NS, "nil")
-        if not python._isString(value):
+        if python._isString(value):
+            pytype_name = "str"
+        else:
+            pytype_name = _typename(value)
             if isinstance(value, bool):
                 value = _lower_bool(value)
             else:
                 value = str(value)
+        cetree.setAttributeValue(element, PYTYPE_ATTRIBUTE, pytype_name)
     cetree.setNodeText(element._c_node, value)
 
 ################################################################################


More information about the lxml-checkins mailing list