From 50c631dda4ddd59704f4326248f3817d8314322c 2012-08-27 17:11:51 From: Jörgen Stenarson Date: 2012-08-27 17:11:51 Subject: [PATCH] Convert filename to bytes in getlines. Most files in linecache are stored with the filename as a bytestring (py2.x). When calling getlines with a unicode filename there will be implicit conversions using ascii that fails. This is avoided by an explicit conversion using the filesystem encoding before calling getlines. --- diff --git a/IPython/utils/ulinecache.py b/IPython/utils/ulinecache.py index b87e699..a477850 100644 --- a/IPython/utils/ulinecache.py +++ b/IPython/utils/ulinecache.py @@ -5,6 +5,7 @@ itself. """ import functools import linecache +import sys from IPython.utils import py3compat from IPython.utils import openpy @@ -21,6 +22,7 @@ else: def getlines(filename, module_globals=None): """Get the lines (as unicode) for a file from the cache. Update the cache if it doesn't contain an entry for this file already.""" + filename = py3compat.cast_bytes(filename, sys.getfilesystemencoding()) lines = linecache.getlines(filename, module_globals=module_globals) # The bits we cache ourselves can be unicode.