Skip to content

Commit 6e33237

Browse files
committed
fix: ensure env values are strings in py2
1 parent 1776ed4 commit 6e33237

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

nipype/utils/filemanip.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
('.BRIK', '.HEAD'),
3939
]
4040

41+
PY3 = sys.version_info[0] >= 3
4142

4243
class FileNotFoundError(Exception):
4344
pass
@@ -877,12 +878,18 @@ def canonicalize_env(env):
877878
if os.name != 'nt':
878879
return env
879880

881+
# convert unicode to string for python 2
882+
if not PY3:
883+
from future.utils import bytes_to_native_str
880884
out_env = {}
881885
for key, val in env.items():
882886
if not isinstance(key, bytes):
883887
key = key.encode('utf-8')
884888
if not isinstance(val, bytes):
885889
val = val.encode('utf-8')
890+
if not PY3:
891+
key = bytes_to_native_str(key)
892+
val = bytes_to_native_str(val)
886893
out_env[key] = val
887894
return out_env
888895

0 commit comments

Comments
 (0)