Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/h5py/_hl/compat.py: 32%

19 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-10-05 06:32 +0000

1""" 

2Compatibility module for high-level h5py 

3""" 

4import sys 

5from os import fspath, fsencode, fsdecode 

6from ..version import hdf5_built_version_tuple 

7 

8WINDOWS_ENCODING = "utf-8" if hdf5_built_version_tuple >= (1, 10, 6) else "mbcs" 

9 

10 

11def filename_encode(filename): 

12 """ 

13 Encode filename for use in the HDF5 library. 

14 

15 Due to how HDF5 handles filenames on different systems, this should be 

16 called on any filenames passed to the HDF5 library. See the documentation on 

17 filenames in h5py for more information. 

18 """ 

19 filename = fspath(filename) 

20 if sys.platform == "win32": 

21 if isinstance(filename, str): 

22 return filename.encode(WINDOWS_ENCODING, "strict") 

23 return filename 

24 return fsencode(filename) 

25 

26 

27def filename_decode(filename): 

28 """ 

29 Decode filename used by HDF5 library. 

30 

31 Due to how HDF5 handles filenames on different systems, this should be 

32 called on any filenames passed from the HDF5 library. See the documentation 

33 on filenames in h5py for more information. 

34 """ 

35 if sys.platform == "win32": 

36 if isinstance(filename, bytes): 

37 return filename.decode(WINDOWS_ENCODING, "strict") 

38 elif isinstance(filename, str): 

39 return filename 

40 else: 

41 raise TypeError("expect bytes or str, not %s" % type(filename).__name__) 

42 return fsdecode(filename)