[Erp5-report] r38064 cedric.dsm - in /erp5/trunk/utils/xml_marshaller: ./ xml_marshaller/

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Aug 31 05:18:12 CEST 2010


Author: cedric.dsm
Date: Tue Aug 31 05:18:12 2010
New Revision: 38064

URL: http://svn.erp5.org?rev=38064&view=rev
Log:
XML_Marshaller : Instances are now correctly unmarshalled. Also added changelog and cleaned setup.py.

Added:
    erp5/trunk/utils/xml_marshaller/CHANGES.txt
    erp5/trunk/utils/xml_marshaller/README.txt
      - copied, changed from r37472, erp5/trunk/utils/erp5.timmy/README.txt
Modified:
    erp5/trunk/utils/xml_marshaller/setup.py
    erp5/trunk/utils/xml_marshaller/xml_marshaller/xml_marshaller.py

Added: erp5/trunk/utils/xml_marshaller/CHANGES.txt
URL: http://svn.erp5.org/erp5/trunk/utils/xml_marshaller/CHANGES.txt?rev=38064&view=auto
==============================================================================
--- erp5/trunk/utils/xml_marshaller/CHANGES.txt (added)
+++ erp5/trunk/utils/xml_marshaller/CHANGES.txt [utf8] Tue Aug 31 05:18:12 2010
@@ -0,0 +1,5 @@
+0.9.4 (Unreleased)
+----------------
+
+ - [fix] Instances are now correctly unmarshalled.
+    [Cedric de Saint Martin]

Copied: erp5/trunk/utils/xml_marshaller/README.txt (from r37472, erp5/trunk/utils/erp5.timmy/README.txt)
URL: http://svn.erp5.org/erp5/trunk/utils/xml_marshaller/README.txt?p2=erp5/trunk/utils/xml_marshaller/README.txt&p1=erp5/trunk/utils/erp5.timmy/README.txt&r1=37472&r2=38064&rev=38064&view=diff
==============================================================================
--- erp5/trunk/utils/erp5.timmy/README.txt [utf8] (original)
+++ erp5/trunk/utils/xml_marshaller/README.txt [utf8] Tue Aug 31 05:18:12 2010
@@ -1,36 +1,7 @@
-timmy
-=====
-
-TioLive Instance Management System oriented on pull method from remote servers.
-
-This tool allows to manage various instances (Zope, Mysql, Oood) to be defined
-on some remote server and manage them on local server.
-
-It reuses supervisord (http://supervisord.org/) to manage non Zope Instances.
-
-timmy and buildout
-------------------
-
-Timmy is installed and bootstraped by buildout. Then it reuses same buildout
-to manage instances of various kinds.
-
-For now it is assumed that buildout will provide all needed requirements. As
-timmy will become more mature it will be able to fetch requirements by itself.
-
-bootstrapping timmy
--------------------
-
-Run ERP5 Appliance buildout with timmy-base.cfg profile:
-
-  bin/buildout -c timmy-base.cfg
-
-Generate key:
-
-  bin/timmy-keygen -k /path/to/server.key
-
-Keep this file safe.
-
-Invoke timmy:
-
-  bin/timmy -k /path/to/server.key -s url://server/path -b timmy-base.cfg \
-  -o timmy-controller.cfg -d timmy-instances -r bin/buildout -p var/timmy.pid
+Marshals simple Python data types into a custom XML format.
+The Marshaller and Unmarshaller classes can be subclassed in order
+to implement marshalling into a different XML DTD.
+Original Authors are XML-SIG (xml-sig at python.org).
+Fully compatible with PyXML implementation, enable namespace support for
+XML Input/Output.
+Implemented with lxml
\ No newline at end of file

Modified: erp5/trunk/utils/xml_marshaller/setup.py
URL: http://svn.erp5.org/erp5/trunk/utils/xml_marshaller/setup.py?rev=38064&r1=38063&r2=38064&view=diff
==============================================================================
--- erp5/trunk/utils/xml_marshaller/setup.py [utf8] (original)
+++ erp5/trunk/utils/xml_marshaller/setup.py [utf8] Tue Aug 31 05:18:12 2010
@@ -1,21 +1,23 @@
 # -*- coding: utf-8 -*-
 from setuptools import setup, find_packages
-import sys, os
 
-version = '0.9.3'
+name = 'xml_marshaller'
+version = '0.9.4'
 
-setup(name='xml_marshaller',
+def read(name):
+    return open(name).read()
+
+long_description=(
+        read('README.txt')
+        + '\n' +
+        read('CHANGES.txt')
+    )
+
+setup(name=name,
       version=version,
       description="Converting Python objects to XML and back again.",
-      long_description="""
-Marshals simple Python data types into a custom XML format.
-The Marshaller and Unmarshaller classes can be subclassed in order
-to implement marshalling into a different XML DTD.
-Original Authors are XML-SIG (xml-sig at python.org).
-Fully compatible with PyXML implementation, enable namespace support for
-XML Input/Output.
-Implemented with lxml""",
-classifiers=['Development Status :: 4 - Beta',
+      long_description=long_description,
+      classifiers=['Development Status :: 4 - Beta',
              'Intended Audience :: Developers',
              'License :: OSI Approved :: Python License (CNRI Python License)',
              'Operating System :: OS Independent',

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=38064&r1=38063&r2=38064&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] Tue Aug 31 05:18:12 2010
@@ -567,24 +567,15 @@ class Unmarshaller(ElementTreeContentHan
   def um_end_instance(self, name):
     value, module, classname, initargs, kw = self.data_stack[-5:]
     klass = self.find_class(module, classname)
-    instantiated = 0
     if (not initargs and (isinstance(klass, (ClassType, TypeType))) and
       not hasattr(klass, '__getinitargs__')):
       value = klass()
-      instantiated = 1
-
-    if not instantiated:
+    else:
       try:
-        # Uh oh... we need to call the constructor with the initial
-        # arguments, but we also have to preserve the identity of
-        # the object, to keep recursive objects right.
-        v2 = apply(klass, initargs)
+        value = apply(klass, initargs)
       except TypeError, err:
         raise TypeError, 'in constructor for %s: %s' % (
             klass.__name__, str(err)), sys.exc_info()[2]
-      else:
-        for k, v in v2.__dict__.items():
-          setattr(value, k, v)
 
     # Now set the object's attributes from the marshalled dictionary
     for k, v in kw.items():
@@ -634,6 +625,14 @@ class _A:
 class _B(object):
   def __repr__(self):
     return '<B instance>'
+class _C(object):
+  def __init__(self, attr1, attr2=None):
+    self.attr1 = attr1
+    self.attr2 = attr2
+  def __getinitargs__(self):
+    return (self.attr1, )
+  def __repr__(self):
+    return '<C instance>'
 
 def runtests(namespace_uri=None):
   print "Testing XML marshalling..."
@@ -689,6 +688,22 @@ def runtests(namespace_uri=None):
 </marshal:marshal>""")
   assert output == (1.0, 'abc', [])
 
+  c_instance = _C('value1', attr2='value2')
+  c_instance.attr3 = 'value3'
+  nested_instance = _C('somevalue', 'someother')
+  nested_instance.attr3 = "stillanother"
+  c_instance.nested_instance = nested_instance
+  c_marshalled = dumps(c_instance)
+  c_unmarshalled = loads(c_marshalled)
+  assert c_unmarshalled.attr3 == c_instance.attr3
+  assert c_unmarshalled.attr2 == c_instance.attr2
+  assert c_unmarshalled.attr1 == c_instance.attr1
+  assert c_unmarshalled.__class__ == _C
+  assert c_unmarshalled.nested_instance.__class__ == _C
+  assert c_unmarshalled.nested_instance.attr1 == nested_instance.attr1
+  assert c_unmarshalled.nested_instance.attr2 == nested_instance.attr2
+  assert c_unmarshalled.nested_instance.attr3 == nested_instance.attr3
+
 if __name__ == '__main__':
     runtests()
     runtests(namespace_uri='http://www.erp5.org/namespaces/marshaller')




More information about the Erp5-report mailing list