Skip to content

Commit

Permalink
Fixing issue LightTable#24 -NameError: name 'unicode' is not defined
Browse files Browse the repository at this point in the history
The Python3 way, using unicode strings instead of bytes.
  • Loading branch information
RockyRoad29 committed Jan 15, 2016
1 parent 4d05c76 commit 9be4ce1
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions py-src/ltmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,21 @@ def asUnicode(s):
except:
return str(s)

def ensureUtf(s):
if type(s) == unicode:
return s.encode('utf8', 'ignore')
def ensureUtf(s, encoding='utf8'):
"""Converts input to unicode if necessary.
If `s` is bytes, it will be decoded using the `encoding` parameters.
This function is used for preprocessing /source/ and /filename/ arguments
to the builtin function `compile`.
"""
# In Python2, str == bytes.
# In Python3, bytes remains unchanged, but str means unicode
# while unicode is not defined anymore
if type(s) == bytes:
return s.decode(encoding, 'ignore')
else:
return str(s)
return s

def findLoc(body, line, total):
for i in range(len(body)):
Expand Down

0 comments on commit 9be4ce1

Please sign in to comment.