Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d0bd1e

Browse files
committed
refactor universal line endings detection
1 parent 39b4852 commit 5d0bd1e

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

Tools/freeze/modulefinder.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
import sys
1010
import new
1111

12+
if hasattr(sys.__stdout__, "newlines"):
13+
READ_MODE = "U" # universal line endings
14+
else:
15+
# remain compatible with Python < 2.3
16+
READ_MODE = "r"
17+
1218
IMPORT_NAME = dis.opname.index('IMPORT_NAME')
1319
IMPORT_FROM = dis.opname.index('IMPORT_FROM')
1420
STORE_NAME = dis.opname.index('STORE_NAME')
@@ -95,20 +101,14 @@ def msgout(self, *args):
95101

96102
def run_script(self, pathname):
97103
self.msg(2, "run_script", pathname)
98-
if hasattr(sys.stdout, "newlines"): # detect universal newline support
99-
fp = open(pathname, "U")
100-
else:
101-
fp = open(pathname, "r")
104+
fp = open(pathname, READ_MODE)
102105
stuff = ("", "r", imp.PY_SOURCE)
103106
self.load_module('__main__', fp, pathname, stuff)
104107

105108
def load_file(self, pathname):
106109
dir, name = os.path.split(pathname)
107110
name, ext = os.path.splitext(name)
108-
if hasattr(sys.stdout, "newlines"):
109-
fp = open(pathname, "U")
110-
else:
111-
fp = open(pathname, "r")
111+
fp = open(pathname, READ_MODE)
112112
stuff = (ext, "r", imp.PY_SOURCE)
113113
self.load_module(name, fp, pathname, stuff)
114114

0 commit comments

Comments
 (0)