[Erp5-report] r38982 nicolas - /erp5/trunk/utils/xml_marshaller/xml_marshaller/

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Oct 7 18:26:05 CEST 2010


Author: nicolas
Date: Thu Oct  7 18:26:05 2010
New Revision: 38982

URL: http://svn.erp5.org?rev=38982&view=rev
Log:
Support boolean transformation

Modified:
    erp5/trunk/utils/xml_marshaller/xml_marshaller/xml_marshaller.py

Modified: erp5/trunk/utils/xml_marshaller/xml_marshaller/xml_marshaller.py
URL: http://svn.erp5.org/erp5/trunk/utils/xml_marshaller/xml_marshaller/xml_marshaller.py?rev=38982&r1=38981&r2=38982&view=diff
==============================================================================
--- erp5/trunk/utils/xml_marshaller/xml_marshaller/xml_marshaller.py [utf8] (original)
+++ erp5/trunk/utils/xml_marshaller/xml_marshaller/xml_marshaller.py [utf8] Thu Oct  7 18:26:05 2010
@@ -58,6 +58,7 @@ class Marshaller(object):
     self.tag_none = E.none
     self.tag_instance = E.object
     self.tag_set = E.set
+    self.tag_bool = E.bool
 
   # The four basic functions that form the caller's interface
   def dump(self, value, file):
@@ -200,6 +201,9 @@ class Marshaller(object):
       xml_tree.append(self._marshal(elem, kw))
     return xml_tree
 
+  def m_bool(self, value, kw):
+    return self.tag_bool(value and '1' or '0')
+
   # Python 2.2 renames dictionary to dict.
   def m_dict(self, value, kw):
     return self.m_dictionary(value, kw)
@@ -284,6 +288,7 @@ class Unmarshaller(ElementTreeContentHan
       'none': ('um_start_none', 'um_end_none'),
       'object': ('um_start_instance', 'um_end_instance'),
       'set': ('um_start_set', 'um_end_set'),
+      'bool': ('um_start_bool', 'um_end_bool'),
       }
 
   def __init__(self):
@@ -428,6 +433,7 @@ class Unmarshaller(ElementTreeContentHan
   um_start_float = um_start_long = um_start_string = um_start_unicode = um_start_generic
   um_start_complex = um_start_code = um_start_none = um_start_generic
   um_start_int = um_start_generic
+  um_start_bool = um_start_generic
 
   def um_end_string(self, name):
     ds = self.data_stack
@@ -497,6 +503,11 @@ class Unmarshaller(ElementTreeContentHan
       self.kw[id] = S
     self.data_stack.append(S)
 
+  def um_end_bool(self, name):
+    ds = self.data_stack
+    ds[-1] = bool(int(''.join(ds[-1])))
+    self.accumulating_chars = 0
+
   def um_end_list(self, name):
     ds = self.data_stack
     for index in range(len(ds)-1, -1, -1):
@@ -644,6 +655,8 @@ def runtests(namespace_uri=None):
        {'key': 'value', 1: 2},
        'éàù^ç'.decode('utf-8'),
        set(('a', 1,)),
+       True,
+       False
        ]
   if namespace_uri:
     test(load, loads, dump_ns, dumps_ns, L)




More information about the Erp5-report mailing list