Skip to content

Commit 3cc71e3

Browse files
committed
Python 3 preparation: use open() instead of file().
Tool-assisted patch. Note one case where a simple substitution did not suffice because the change was in a class that defined its own open() method earlier, and thus needed to use builtins.open (respectively __builtin__.open in Python 2).
1 parent bfa8ba1 commit 3cc71e3

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

roundup/cgi/TAL/talgettext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def write(self, s):
285285
if (outfile is None):
286286
outfile = sys.stdout
287287
else:
288-
outfile = file(outfile, update_mode and "a" or "w")
288+
outfile = open(outfile, update_mode and "a" or "w")
289289

290290
catalog = {}
291291
for domain in engine.catalog.keys():

roundup/configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ def save(self, ini_file=None):
14371437
_tmp_file = os.path.splitext(ini_file)[0]
14381438
_bak_file = _tmp_file + ".bak"
14391439
_tmp_file = _tmp_file + ".tmp"
1440-
_fp = file(_tmp_file, "wt")
1440+
_fp = open(_tmp_file, "wt")
14411441
_fp.write("# %s configuration file\n" % self._get_name())
14421442
_fp.write("# Autogenerated at %s\n" % time.asctime())
14431443
need_set = self._get_unset_options()

roundup/instance.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
"""
2929
__docformat__ = 'restructuredtext'
3030

31+
try:
32+
import builtins
33+
except ImportError:
34+
import __builtin__ as builtins
35+
3136
import os
3237
import sys
3338
import warnings
@@ -80,7 +85,7 @@ def __init__(self, tracker_home, optimize=0):
8085
update your config.ini
8186
"""
8287
try:
83-
with file(filename) as backend_file:
88+
with open(filename) as backend_file:
8489
rdbms_backend = backend_file.readline().strip()
8590

8691
with warnings.catch_warnings():
@@ -224,7 +229,7 @@ def nuke(self):
224229

225230
def _compile(self, fname):
226231
fname = os.path.join(self.tracker_home, fname)
227-
return compile(file(fname).read(), fname, 'exec')
232+
return compile(builtins.open(fname).read(), fname, 'exec')
228233

229234
def _exec(self, obj, env):
230235
if self.libdir:

0 commit comments

Comments
 (0)