[python-hdf5storage] 65/84: Fixed bug where dicts could be written with null characters and / in their keys
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:25:05 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to annotated tag 0.1.10
in repository python-hdf5storage.
commit 4324217a7ba3174f985bc57a3b7e70e89c02df0b
Author: Freja Nordsiek <fnordsie at gmail.com>
Date: Sat Aug 22 12:57:13 2015 -0400
Fixed bug where dicts could be written with null characters and / in their keys
---
hdf5storage/Marshallers.py | 14 ++++++++++++--
tests/test_write_readback.py | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/hdf5storage/Marshallers.py b/hdf5storage/Marshallers.py
index ecca431..8e713b3 100644
--- a/hdf5storage/Marshallers.py
+++ b/hdf5storage/Marshallers.py
@@ -1466,8 +1466,10 @@ class PythonDictMarshaller(TypeMarshaller):
def write(self, f, grp, name, data, type_string, options):
# Check for any field names that are not unicode since they
- # cannot be handled. How it is checked (what type it is) and the
- # error message are different for each Python version.
+ # cannot be handled. Also check for null characters and /
+ # characters since they can't be handled either. How it is
+ # checked (what type it is) and the error message are different
+ # for each Python version.
if sys.hexversion >= 0x03000000:
for fieldname in data:
@@ -1476,6 +1478,10 @@ class PythonDictMarshaller(TypeMarshaller):
+ 'str keys are not '
+ 'supported: '
+ repr(fieldname))
+ if '\x00' in fieldname or '/' in fieldname:
+ raise NotImplementedError('Dictionary keys with ' \
+ + "null characters ('\x00') and '/' are not " \
+ + 'supported.')
else:
for fieldname in data:
if not isinstance(fieldname, unicode):
@@ -1483,6 +1489,10 @@ class PythonDictMarshaller(TypeMarshaller):
+ 'unicode keys are not '
+ 'supported: '
+ repr(fieldname))
+ if u'\x00' in fieldname or u'/' in fieldname:
+ raise NotImplementedError('Dictionary keys with ' \
+ + "null characters ('\x00') and '/' are not " \
+ + 'supported.')
# If the group doesn't exist, it needs to be created. If it
# already exists but is not a group, it needs to be deleted
diff --git a/tests/test_write_readback.py b/tests/test_write_readback.py
index 148a23d..e5bc226 100644
--- a/tests/test_write_readback.py
+++ b/tests/test_write_readback.py
@@ -338,6 +338,43 @@ class TestPythonMatlabFormat(object):
self.options)
self.assert_equal(out, data)
+ @raises(NotImplementedError)
+ def test_dict_bytes_key(self):
+ data = random_dict()
+ key = random_bytes(max_dict_key_length)
+ data[key] = random_int()
+ out = self.write_readback(data, random_name(),
+ self.options)
+ self.assert_equal(out, data)
+
+ @raises(NotImplementedError)
+ def test_dict_key_null_character(self):
+ data = random_dict()
+ if sys.hexversion >= 0x03000000:
+ ch = '\x00'
+ else:
+ ch = u'\x00'
+ key = ch.join([random_str_ascii(max_dict_key_length)
+ for i in range(2)])
+ data[key] = random_int()
+ out = self.write_readback(data, random_name(),
+ self.options)
+ self.assert_equal(out, data)
+
+ @raises(NotImplementedError)
+ def test_dict_key_forward_slash(self):
+ data = random_dict()
+ if sys.hexversion >= 0x03000000:
+ ch = '/'
+ else:
+ ch = u'/'
+ key = ch.join([random_str_ascii(max_dict_key_length)
+ for i in range(2)])
+ data[key] = random_int()
+ out = self.write_readback(data, random_name(),
+ self.options)
+ self.assert_equal(out, data)
+
class TestPythonFormat(TestPythonMatlabFormat):
def __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