Skip to content

Commit

Permalink
FIX: Use system encoding for errors, not utf-8
Browse files Browse the repository at this point in the history
  • Loading branch information
aragilar committed Apr 18, 2018
1 parent 3d1edda commit 32b59af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion h5py/_errors.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

# Python-style minor error classes. If the minor error code matches an entry
# in this dict, the generated exception will be used.

from ._hl.compat import filename_encode, filename_decode

_minor_table = {
H5E_SEEKERROR: IOError, # Seek failed
H5E_READERROR: IOError, # Read failed
Expand Down Expand Up @@ -120,7 +123,10 @@ cdef int set_exception() except -1:
if desc_bottom is NULL:
raise RuntimeError("Failed to extract bottom-level error description")

msg = ("%s (%s)" % (desc.decode('utf-8').capitalize(), desc_bottom.decode('utf-8'))).encode('utf-8')
msg = filename_encode(u"{} ({})".format(
filename_decode(desc).capitalize(),
filename_decode(desc_bottom)
))

# Finally, set the exception. We do this with the Python C function
# so that the traceback doesn't point here.
Expand Down
10 changes: 10 additions & 0 deletions h5py/tests/old/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,16 @@ def test_unicode_hdf5_python_consistent(self):
with File(fname, 'w') as f:
self.assertTrue(os.path.exists(fname))

def test_nonexistent_file_unicode(self):
"""
Modes 'r' and 'r+' do not create files even when given unicode names
"""
fname = self.mktemp(prefix = six.unichr(0x201a))
with self.assertRaises(IOError):
File(fname, 'r')
with self.assertRaises(IOError):
File(fname, 'r+')


class TestFileProperty(TestCase):

Expand Down

0 comments on commit 32b59af

Please sign in to comment.