Mercurial > hg-stable
changeset 36424:4bc983568016
py3: replace file() with open()
file() is not present in Python 3.
Differential Revision: https://phab.mercurial-scm.org/D2417
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Sat, 24 Feb 2018 16:07:45 +0530 |
parents | 54f4328a07c2 |
children | fb7897e53d49 |
files | hgext/convert/monotone.py hgext/rebase.py hgext/relink.py tests/test-hgweb.t tests/test-impexp-branch.t tests/test-import-context.t tests/test-notify.t |
diffstat | 7 files changed, 10 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/convert/monotone.py Sat Feb 24 16:06:21 2018 +0530 +++ b/hgext/convert/monotone.py Sat Feb 24 16:07:45 2018 +0530 @@ -37,7 +37,7 @@ if not os.path.exists(os.path.join(path, '_MTN')): # Could be a monotone repository (SQLite db file) try: - f = file(path, 'rb') + f = open(path, 'rb') header = f.read(16) f.close() except IOError:
--- a/hgext/rebase.py Sat Feb 24 16:06:21 2018 +0530 +++ b/hgext/rebase.py Sat Feb 24 16:07:45 2018 +0530 @@ -1440,7 +1440,7 @@ def isagitpatch(repo, patchname): 'Return true if the given patch is in git format' mqpatch = os.path.join(repo.mq.path, patchname) - for line in patch.linereader(file(mqpatch, 'rb')): + for line in patch.linereader(open(mqpatch, 'rb')): if line.startswith('diff --git'): return True return False
--- a/hgext/relink.py Sat Feb 24 16:06:21 2018 +0530 +++ b/hgext/relink.py Sat Feb 24 16:07:45 2018 +0530 @@ -168,8 +168,8 @@ source = os.path.join(src, f) tgt = os.path.join(dst, f) # Binary mode, so that read() works correctly, especially on Windows - sfp = file(source, 'rb') - dfp = file(tgt, 'rb') + sfp = open(source, 'rb') + dfp = open(tgt, 'rb') sin = sfp.read(CHUNKLEN) while sin: din = dfp.read(CHUNKLEN)
--- a/tests/test-hgweb.t Sat Feb 24 16:06:21 2018 +0530 +++ b/tests/test-hgweb.t Sat Feb 24 16:07:45 2018 +0530 @@ -333,7 +333,7 @@ Test the access/error files are opened in append mode - $ $PYTHON -c "print len(file('access.log').readlines()), 'log lines written'" + $ $PYTHON -c "print len(open('access.log', 'rb').readlines()), 'log lines written'" 14 log lines written static file
--- a/tests/test-impexp-branch.t Sat Feb 24 16:06:21 2018 +0530 +++ b/tests/test-impexp-branch.t Sat Feb 24 16:07:45 2018 +0530 @@ -74,9 +74,9 @@ $ hg strip --no-backup . 1 files updated, 0 files merged, 0 files removed, 0 files unresolved >>> import re - >>> p = file('../r1.patch', 'rb').read() + >>> p = open('../r1.patch', 'rb').read() >>> p = re.sub(r'Parent\s+', 'Parent ', p) - >>> file('../r1-ws.patch', 'wb').write(p) + >>> open('../r1-ws.patch', 'wb').write(p) $ hg import --exact ../r1-ws.patch applying ../r1-ws.patch
--- a/tests/test-import-context.t Sat Feb 24 16:06:21 2018 +0530 +++ b/tests/test-import-context.t Sat Feb 24 16:07:45 2018 +0530 @@ -7,7 +7,7 @@ > lasteol = sys.argv[2] == '1' > patterns = sys.argv[3:] > - > fp = file(path, 'wb') + > fp = open(path, 'wb') > for i, pattern in enumerate(patterns): > count = int(pattern[0:-1]) > char = pattern[-1] + '\n' @@ -19,7 +19,7 @@ > EOF $ cat > cat.py <<EOF > import sys - > sys.stdout.write(repr(file(sys.argv[1], 'rb').read()) + '\n') + > sys.stdout.write(repr(open(sys.argv[1], 'rb').read()) + '\n') > EOF Initialize the test repository
--- a/tests/test-notify.t Sat Feb 24 16:06:21 2018 +0530 +++ b/tests/test-notify.t Sat Feb 24 16:07:45 2018 +0530 @@ -421,7 +421,7 @@ > test = False > mbox = mbox > EOF - $ $PYTHON -c 'file("a/a", "ab").write("no" * 500 + "\xd1\x84" + "\n")' + $ $PYTHON -c 'open("a/a", "ab").write("no" * 500 + "\xd1\x84" + "\n")' $ hg --cwd a commit -A -m "long line" $ hg --traceback --cwd b pull ../a pulling from ../a