[python-hdf5storage] 22/152: Added read support for Python scaler types and None.

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 7b8c73477c421189c81d8c99d5061ded196544a4
Author: Freja Nordsiek <fnordsie at gmail.com>
Date:   Tue Jan 21 20:37:13 2014 -0500

    Added read support for Python scaler types and None.
---
 hdf5storage/Marshallers.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/hdf5storage/Marshallers.py b/hdf5storage/Marshallers.py
index a4b809b..58820bf 100644
--- a/hdf5storage/Marshallers.py
+++ b/hdf5storage/Marshallers.py
@@ -606,6 +606,22 @@ class PythonScalarMarshaller(NumpyScalarArrayMarshaller):
                                          self.get_type_string(data,
                                          type_string), options)
 
+    def read(self, f, grp, name, options):
+        # Use the parent class version to read it and do most of the
+        # work.
+        data = NumpyScalarArrayMarshaller.read(self, f, grp, name,
+                                               options)
+
+        # The type string determines how to convert it back to a Python
+        # type (just look up the entry in types). Otherwise, return it
+        # as is.
+        type_string = get_attribute_string(grp[name], 'CPython.Type')
+        if type_string in self.cpython_type_strings:
+            return self.types[self.cpython_type_strings.find( \
+                type_string)](data)
+        else:
+            return data
+
 
 class PythonStringMarshaller(NumpyScalarArrayMarshaller):
     def __init__(self):
@@ -642,6 +658,7 @@ class PythonNoneMarshaller(NumpyScalarArrayMarshaller):
         self.cpython_type_strings = ['builtins.NoneType']
         # None corresponds to no MATLAB class.
         self.matlab_classes = []
+
     def write(self, f, grp, name, data, type_string, options):
         # Just going to use the parent function with an empty double
         # (two dimensional so that MATLAB will import it as a []) as the
@@ -653,6 +670,11 @@ class PythonNoneMarshaller(NumpyScalarArrayMarshaller):
                                          self.get_type_string(data,
                                          type_string), options)
 
+    def read(self, f, grp, name, options):
+        # There is only one value, so return it.
+        return None
+
+
 class PythonDictMarshaller(TypeMarshaller):
     def __init__(self):
         TypeMarshaller.__init__(self)

-- 
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