Commit df7b2061 authored by Thomas Heller's avatar Thomas Heller

Add a note that this file should be kept compatible with Python 1.5.2,

per PEP 291 (although there are currently string methods used).

This patch makes it compatible with 2.2, at least, by detecting
universal newline support.
parent 136aa56e
"""Find modules used by a script, using introspection.""" """Find modules used by a script, using introspection."""
# This module should be kept compatible with Python 1.5.2, see PEP 291.
import dis import dis
import imp import imp
import marshal import marshal
...@@ -127,14 +129,20 @@ class ModuleFinder: ...@@ -127,14 +129,20 @@ class ModuleFinder:
def run_script(self, pathname): def run_script(self, pathname):
self.msg(2, "run_script", pathname) self.msg(2, "run_script", pathname)
if hasattr(sys.stdout, "newlines"): # detect universal newline support
fp = open(pathname, "U") fp = open(pathname, "U")
else:
fp = open(pathname, "r")
stuff = ("", "r", imp.PY_SOURCE) stuff = ("", "r", imp.PY_SOURCE)
self.load_module('__main__', fp, pathname, stuff) self.load_module('__main__', fp, pathname, stuff)
def load_file(self, pathname): def load_file(self, pathname):
dir, name = os.path.split(pathname) dir, name = os.path.split(pathname)
name, ext = os.path.splitext(name) name, ext = os.path.splitext(name)
if hasattr(sys.stdout, "newlines"):
fp = open(pathname, "U") fp = open(pathname, "U")
else:
fp = open(pathname, "r")
stuff = (ext, "r", imp.PY_SOURCE) stuff = (ext, "r", imp.PY_SOURCE)
self.load_module(name, fp, pathname, stuff) self.load_module(name, fp, pathname, stuff)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment