aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJust van Rossum <just@letterror.com>2002-11-26 09:53:16 +0000
committerJust van Rossum <just@letterror.com>2002-11-26 09:53:16 +0000
commit5d0bd1ebdf4497e705a77dee6f8ca47627105e5d (patch)
treeedf8fa99101149554b427c5e280ba42f7dc02dcc
parentReport Tkinter changes. (diff)
downloadcpython-5d0bd1ebdf4497e705a77dee6f8ca47627105e5d.tar.gz
cpython-5d0bd1ebdf4497e705a77dee6f8ca47627105e5d.tar.bz2
cpython-5d0bd1ebdf4497e705a77dee6f8ca47627105e5d.zip
refactor universal line endings detection
-rw-r--r--Tools/freeze/modulefinder.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/Tools/freeze/modulefinder.py b/Tools/freeze/modulefinder.py
index 7a97a049a41..cd03db4d80c 100644
--- a/Tools/freeze/modulefinder.py
+++ b/Tools/freeze/modulefinder.py
@@ -9,6 +9,12 @@ import os
import sys
import new
+if hasattr(sys.__stdout__, "newlines"):
+ READ_MODE = "U" # universal line endings
+else:
+ # remain compatible with Python < 2.3
+ READ_MODE = "r"
+
IMPORT_NAME = dis.opname.index('IMPORT_NAME')
IMPORT_FROM = dis.opname.index('IMPORT_FROM')
STORE_NAME = dis.opname.index('STORE_NAME')
@@ -95,20 +101,14 @@ class ModuleFinder:
def run_script(self, pathname):
self.msg(2, "run_script", pathname)
- if hasattr(sys.stdout, "newlines"): # detect universal newline support
- fp = open(pathname, "U")
- else:
- fp = open(pathname, "r")
+ fp = open(pathname, READ_MODE)
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)
- if hasattr(sys.stdout, "newlines"):
- fp = open(pathname, "U")
- else:
- fp = open(pathname, "r")
+ fp = open(pathname, READ_MODE)
stuff = (ext, "r", imp.PY_SOURCE)
self.load_module(name, fp, pathname, stuff)