summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-05-09 23:24:46 (GMT)
committerGuido van Rossum <guido@python.org>2007-05-09 23:24:46 (GMT)
commit33f3124fb1799b2be9fb6907d33c2d1c2a6b3129 (patch)
tree60bfa6af25e9d267398ef31e865defa55ede8522 /Lib
parentcd6ae68943e5bd219d0f32be346d1a730635aaa4 (diff)
downloadcpython-33f3124fb1799b2be9fb6907d33c2d1c2a6b3129.zip
cpython-33f3124fb1799b2be9fb6907d33c2d1c2a6b3129.tar.gz
cpython-33f3124fb1799b2be9fb6907d33c2d1c2a6b3129.tar.bz2
Support PEP-263-style coding declarations.
Default to UTF-8 per PEP-3120.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/linecache.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/linecache.py b/Lib/linecache.py
index 0501a10..9a16acd 100644
--- a/Lib/linecache.py
+++ b/Lib/linecache.py
@@ -7,6 +7,7 @@ that name.
import sys
import os
+import re
__all__ = ["getline", "clearcache", "checkcache"]
@@ -131,6 +132,16 @@ def updatecache(filename, module_globals=None):
except IOError as msg:
## print '*** Cannot open', fullname, ':', msg
return []
+ coding = "utf-8"
+ for line in lines[:2]:
+ m = re.search(r"coding[:=]\s*([-\w.]+)", line)
+ if m:
+ coding = m.group(1)
+ break
+ try:
+ lines = [unicode(line, coding) for line in lines]
+ except UnicodeError:
+ pass # Hope for the best
size, mtime = stat.st_size, stat.st_mtime
cache[filename] = size, mtime, lines, fullname
return lines