# HG changeset patch # User Alejandro Santos # Date 2009-07-05 09:01:30 # Node ID 3b76321aa0de3fc5b65f649f3cce3fb1938486b7 # Parent 3f56055ff1d7b6fd2cb041c40d2576146378adfb compat: use open() instead of file() everywhere diff --git a/hgext/convert/cvs.py b/hgext/convert/cvs.py --- a/hgext/convert/cvs.py +++ b/hgext/convert/cvs.py @@ -38,8 +38,8 @@ class convert_cvs(converter_source): self.lastbranch = {} self.parent = {} self.socket = None - self.cvsroot = file(os.path.join(cvs, "Root")).read()[:-1] - self.cvsrepo = file(os.path.join(cvs, "Repository")).read()[:-1] + self.cvsroot = open(os.path.join(cvs, "Root")).read()[:-1] + self.cvsrepo = open(os.path.join(cvs, "Repository")).read()[:-1] self.encoding = locale.getpreferredencoding() self._connect() diff --git a/hgext/convert/cvsps.py b/hgext/convert/cvsps.py --- a/hgext/convert/cvsps.py +++ b/hgext/convert/cvsps.py @@ -130,7 +130,7 @@ def createlog(ui, directory=None, root=" # Get the real directory in the repository try: - prefix = file(os.path.join('CVS','Repository')).read().strip() + prefix = open(os.path.join('CVS','Repository')).read().strip() if prefix == ".": prefix = "" directory = prefix @@ -142,7 +142,7 @@ def createlog(ui, directory=None, root=" # Use the Root file in the sandbox, if it exists try: - root = file(os.path.join('CVS','Root')).read().strip() + root = open(os.path.join('CVS','Root')).read().strip() except IOError: pass @@ -175,7 +175,7 @@ def createlog(ui, directory=None, root=" if cache == 'update': try: ui.note(_('reading cvs log cache %s\n') % cachefile) - oldlog = pickle.load(file(cachefile)) + oldlog = pickle.load(open(cachefile)) ui.note(_('cache has %d log entries\n') % len(oldlog)) except Exception, e: ui.note(_('error reading cache: %r\n') % e) @@ -445,7 +445,7 @@ def createlog(ui, directory=None, root=" # write the new cachefile ui.note(_('writing cvs log cache %s\n') % cachefile) - pickle.dump(log, file(cachefile, 'w')) + pickle.dump(log, open(cachefile, 'w')) else: log = oldlog diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -750,7 +750,7 @@ def debugcomplete(ui, cmd='', **opts): ui.write("%s\n" % "\n".join(sorted(cmdlist))) def debugfsinfo(ui, path = "."): - file('.debugfsinfo', 'w').write('') + open('.debugfsinfo', 'w').write('') ui.write('exec: %s\n' % (util.checkexec(path) and 'yes' or 'no')) ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no')) ui.write('case-sensitive: %s\n' % (util.checkcase('.debugfsinfo') @@ -983,7 +983,7 @@ def debuginstall(ui): if list(files) != [os.path.basename(fa)]: ui.write(_(" unexpected patch output!\n")) patchproblems += 1 - a = file(fa).read() + a = open(fa).read() if a != b: ui.write(_(" patch test failed!\n")) patchproblems += 1 diff --git a/mercurial/hgweb/common.py b/mercurial/hgweb/common.py --- a/mercurial/hgweb/common.py +++ b/mercurial/hgweb/common.py @@ -69,7 +69,7 @@ def staticfile(directory, fname, req): os.stat(path) ct = mimetypes.guess_type(path)[0] or "text/plain" req.respond(HTTP_OK, ct, length = os.path.getsize(path)) - return file(path, 'rb').read() + return open(path, 'rb').read() except TypeError: raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal filename') except OSError, err: diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -1139,7 +1139,7 @@ def internalpatch(patchobj, ui, strip, c raise util.Abort(_('Unsupported line endings type: %s') % eolmode) try: - fp = file(patchobj, 'rb') + fp = open(patchobj, 'rb') except TypeError: fp = patchobj if cwd: diff --git a/mercurial/posix.py b/mercurial/posix.py --- a/mercurial/posix.py +++ b/mercurial/posix.py @@ -9,7 +9,7 @@ from i18n import _ import osutil import os, sys, errno, stat, getpass, pwd, grp -posixfile = file +posixfile = open nulldev = '/dev/null' normpath = os.path.normpath samestat = os.path.samestat @@ -70,20 +70,20 @@ def set_flags(f, l, x): if l: if not stat.S_ISLNK(s): # switch file to link - data = file(f).read() + data = open(f).read() os.unlink(f) try: os.symlink(data, f) except: # failed to make a link, rewrite file - file(f, "w").write(data) + open(f, "w").write(data) # no chmod needed at this point return if stat.S_ISLNK(s): # switch link to file data = os.readlink(f) os.unlink(f) - file(f, "w").write(data) + open(f, "w").write(data) s = 0666 & ~umask # avoid restatting for chmod sx = s & 0100 diff --git a/mercurial/pure/osutil.py b/mercurial/pure/osutil.py --- a/mercurial/pure/osutil.py +++ b/mercurial/pure/osutil.py @@ -8,7 +8,7 @@ import os import stat as _stat -posixfile = file +posixfile = open def _mode_to_kind(mode): if _stat.S_ISREG(mode): return _stat.S_IFREG diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -143,7 +143,7 @@ elif os.path.exists('.hg_archival.txt'): break if version: - f = file("mercurial/__version__.py", "w") + f = open("mercurial/__version__.py", "w") f.write('# this file is autogenerated by setup.py\n') f.write('version = "%s"\n' % version) f.close() diff --git a/tests/killdaemons.py b/tests/killdaemons.py --- a/tests/killdaemons.py +++ b/tests/killdaemons.py @@ -4,7 +4,7 @@ import os, sys, time, errno, signal # Kill off any leftover daemon processes try: - fp = file(os.environ['DAEMON_PIDS']) + fp = open(os.environ['DAEMON_PIDS']) for line in fp: try: pid = int(line) diff --git a/tests/run-tests.py b/tests/run-tests.py --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -419,7 +419,7 @@ def runone(options, test, skips, fails): vlog("# Test", test) # create a fresh hgrc - hgrc = file(HGRCPATH, 'w+') + hgrc = open(HGRCPATH, 'w+') hgrc.write('[ui]\n') hgrc.write('slash = True\n') hgrc.write('[defaults]\n') @@ -525,7 +525,7 @@ def runone(options, test, skips, fails): # Kill off any leftover daemon processes try: - fp = file(DAEMON_PIDS) + fp = open(DAEMON_PIDS) for line in fp: try: pid = int(line) diff --git a/tests/test-context.py b/tests/test-context.py --- a/tests/test-context.py +++ b/tests/test-context.py @@ -7,7 +7,7 @@ repo = hg.repository(u, 'test1', create= os.chdir('test1') # create 'foo' with fixed time stamp -f = file('foo', 'w') +f = open('foo', 'w') f.write('foo\n') f.close() os.utime('foo', (1000, 1000)) diff --git a/tests/test-dispatch.py b/tests/test-dispatch.py --- a/tests/test-dispatch.py +++ b/tests/test-dispatch.py @@ -15,14 +15,14 @@ testdispatch("init test1") os.chdir('test1') # create file 'foo', add and commit -f = file('foo', 'wb') +f = open('foo', 'wb') f.write('foo\n') f.close() testdispatch("add foo") testdispatch("commit -m commit1 -d 2000-01-01 foo") # append to file 'foo' and commit -f = file('foo', 'ab') +f = open('foo', 'ab') f.write('bar\n') f.close() testdispatch("commit -m commit2 -d 2000-01-02 foo") diff --git a/tests/test-revlog-ancestry.py b/tests/test-revlog-ancestry.py --- a/tests/test-revlog-ancestry.py +++ b/tests/test-revlog-ancestry.py @@ -10,7 +10,7 @@ def commit(text, time): repo.commit(text=text, date="%d 0" % time) def addcommit(name, time): - f = file(name, 'w') + f = open(name, 'w') f.write('%s\n' % name) f.close() repo.add([name])