summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Heller <theller@ctypes.org>2002-11-25 20:21:59 +0000
committerThomas Heller <theller@ctypes.org>2002-11-25 20:21:59 +0000
commit919000e9ec36c513f08253091b71a3aead2aff08 (patch)
treeb5d6ce01dd00685186dfbbc133a6d8b04ed76fc6
parent057ab14e7d1ed35013613b44b423f44ba4bb315e (diff)
downloadcpython-git-919000e9ec36c513f08253091b71a3aead2aff08.tar.gz
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.
-rw-r--r--Tools/freeze/modulefinder.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/Tools/freeze/modulefinder.py b/Tools/freeze/modulefinder.py
index 5886e7be21..48f2eca1e5 100644
--- a/Tools/freeze/modulefinder.py
+++ b/Tools/freeze/modulefinder.py
@@ -1,5 +1,7 @@
"""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 imp
import marshal
@@ -127,14 +129,20 @@ class ModuleFinder:
def run_script(self, pathname):
self.msg(2, "run_script", pathname)
- fp = open(pathname, "U")
+ if hasattr(sys.stdout, "newlines"): # detect universal newline support
+ fp = open(pathname, "U")
+ else:
+ fp = open(pathname, "r")
stuff = ("", "r", imp.PY_SOURCE)
self.load_module('__main__', fp, pathname, stuff)
def load_file(self, pathname):
dir, name = os.path.split(pathname)
name, ext = os.path.splitext(name)
- fp = open(pathname, "U")
+ if hasattr(sys.stdout, "newlines"):
+ fp = open(pathname, "U")
+ else:
+ fp = open(pathname, "r")
stuff = (ext, "r", imp.PY_SOURCE)
self.load_module(name, fp, pathname, stuff)