[python-hdf5storage] 23/152: Changed the way marshallers for container objects recursively write their elements.

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:24:30 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to annotated tag 0.1
in repository python-hdf5storage.

commit 649b3d8784f89ce08682eddb2839737682c01678
Author: Freja Nordsiek <fnordsie at gmail.com>
Date:   Sat Jan 25 12:04:38 2014 -0500

    Changed the way marshallers for container objects recursively write their elements.
---
 hdf5storage/Marshallers.py | 16 ++++++++++------
 hdf5storage/lowlevel.py    | 26 ++------------------------
 2 files changed, 12 insertions(+), 30 deletions(-)

diff --git a/hdf5storage/Marshallers.py b/hdf5storage/Marshallers.py
index 58820bf..3a8b1c3 100644
--- a/hdf5storage/Marshallers.py
+++ b/hdf5storage/Marshallers.py
@@ -346,7 +346,6 @@ class NumpyScalarArrayMarshaller(TypeMarshaller):
         # Set matlab_classes to the supported classes (the values).
         self.matlab_classes = list(self.__MATLAB_classes.values())
 
-
     def write(self, f, grp, name, data, type_string, options):
         # Need to make a set of data that will be stored. It will start
         # out as a copy of data and then be steadily manipulated.
@@ -718,11 +717,16 @@ class PythonDictMarshaller(TypeMarshaller):
                                           + ' keys are not supported: '
                                           + repr(fieldname))
 
-        # Return a tuple holding the group to store in, all the elements
-        # of data, and their values to the calling function so that it
-        # can recurse over all the elements.
-
-        return ([grp2], [(n, v) for n, v in data.items()])
+        # Go through all the elements of data and write them. The H5PATH
+        # needs to be set as the path of grp2 on all of them if we are
+        # doing MATLAB compatibility (otherwise, the attribute needs to
+        # be deleted).
+        for k, v in data.items():
+            write_data(f, grp2, k, v, None, Options)
+            if options.MATLAB_compatible:
+                set_attribute_string(grp2[k], 'H5PATH', grp2.name)
+            else:
+                del_attribute(grp2[k], 'H5PATH')
 
     def write_metadata(self, f, grp, name, data, type_string, options):
         # First, call the inherited version to do most of the work.
diff --git a/hdf5storage/lowlevel.py b/hdf5storage/lowlevel.py
index 04cdbd3..bb40046 100644
--- a/hdf5storage/lowlevel.py
+++ b/hdf5storage/lowlevel.py
@@ -53,29 +53,7 @@ def write_data(f, grp, name, data, type_string, options):
     # attribute to be the path to the containing group.
 
     if m is not None:
-        outputs = m.write(f, grp, name, data, type_string, options)
-        if outputs is not None:
-            if len(outputs) > 2:
-                _MATLAB_fields_pairs.extend(outputs[2])
-            for i, v in enumerate(outputs[1]):
-                if len(outputs[0]) == 1:
-                    write_data(f, outputs[0][0], v[0], v[1], None,
-                               options)
-                    if options.MATLAB_compatible:
-                        set_attribute_string(outputs[0][0][v[0]],
-                                             'H5PATH',
-                                             outputs[0][0].name)
-                    else:
-                        del_attribute(outputs[0][0][v[0]], 'H5PATH')
-                else:
-                    write_data(f, outputs[0][i], v[0], v[1], None,
-                               options)
-                    if options.MATLAB_compatible:
-                        set_attribute_string(outputs[0][i][v[0]],
-                                             'H5PATH',
-                                             outputs[0][i].name)
-                    else:
-                        del_attribute(outputs[0][i][v[0]], 'H5PATH')
+        m.write(f, grp, name, data, type_string, options)
     else:
         raise NotImplementedError('Can''t write data type: '+str(tp))
 
@@ -96,7 +74,7 @@ def read_data(f, grp, name, options):
     # use the fallback (NumpyScalarArrayMarshaller for Datasets and
     # PythonDictMarshaller for Groups). If calls to the marshaller
     # collection to get the right marshaller don't return one (return
-    # None, we also go to the default).
+    # None), we also go to the default).
 
     m = None
     mc = options.marshaller_collection

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-hdf5storage.git



More information about the debian-science-commits mailing list