Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.

Commit 9be4ce1

Browse files
committed
Fixing issue #24 -NameError: name 'unicode' is not defined
The Python3 way, using unicode strings instead of bytes.
1 parent 4d05c76 commit 9be4ce1

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

py-src/ltmain.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,21 @@ def asUnicode(s):
4646
except:
4747
return str(s)
4848

49-
def ensureUtf(s):
50-
if type(s) == unicode:
51-
return s.encode('utf8', 'ignore')
49+
def ensureUtf(s, encoding='utf8'):
50+
"""Converts input to unicode if necessary.
51+
52+
If `s` is bytes, it will be decoded using the `encoding` parameters.
53+
54+
This function is used for preprocessing /source/ and /filename/ arguments
55+
to the builtin function `compile`.
56+
"""
57+
# In Python2, str == bytes.
58+
# In Python3, bytes remains unchanged, but str means unicode
59+
# while unicode is not defined anymore
60+
if type(s) == bytes:
61+
return s.decode(encoding, 'ignore')
5262
else:
53-
return str(s)
63+
return s
5464

5565
def findLoc(body, line, total):
5666
for i in range(len(body)):

0 commit comments

Comments
 (0)