file() is not present in Python 3.
Details
Details
- Reviewers
- None
- Group Reviewers
hg-reviewers - Commits
- rHG4bc983568016: py3: replace file() with open()
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
( )
| hg-reviewers |
file() is not present in Python 3.
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| M | hgext/convert/monotone.py (2 lines) | |||
| M | hgext/rebase.py (2 lines) | |||
| M | hgext/relink.py (4 lines) | |||
| M | tests/test-hgweb.t (2 lines) | |||
| M | tests/test-impexp-branch.t (4 lines) | |||
| M | tests/test-import-context.t (4 lines) | |||
| M | tests/test-notify.t (2 lines) |
| self.automatestdio = False | self.automatestdio = False | ||||
| self.revs = revs | self.revs = revs | ||||
| norepo = common.NoRepo(_("%s does not look like a monotone repository") | norepo = common.NoRepo(_("%s does not look like a monotone repository") | ||||
| % path) | % path) | ||||
| if not os.path.exists(os.path.join(path, '_MTN')): | if not os.path.exists(os.path.join(path, '_MTN')): | ||||
| # Could be a monotone repository (SQLite db file) | # Could be a monotone repository (SQLite db file) | ||||
| try: | try: | ||||
| f = file(path, 'rb') | f = open(path, 'rb') | ||||
| header = f.read(16) | header = f.read(16) | ||||
| f.close() | f.close() | ||||
| except IOError: | except IOError: | ||||
| header = '' | header = '' | ||||
| if header != 'SQLite format 3\x00': | if header != 'SQLite format 3\x00': | ||||
| raise norepo | raise norepo | ||||
| # regular expressions for parsing monotone output | # regular expressions for parsing monotone output | ||||
| repo.ui.debug(" future parents are %d and %d\n" % tuple(newps)) | repo.ui.debug(" future parents are %d and %d\n" % tuple(newps)) | ||||
| return newps[0], newps[1], base | return newps[0], newps[1], base | ||||
| def isagitpatch(repo, patchname): | def isagitpatch(repo, patchname): | ||||
| 'Return true if the given patch is in git format' | 'Return true if the given patch is in git format' | ||||
| mqpatch = os.path.join(repo.mq.path, patchname) | 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'): | if line.startswith('diff --git'): | ||||
| return True | return True | ||||
| return False | return False | ||||
| def updatemq(repo, state, skipped, **opts): | def updatemq(repo, state, skipped, **opts): | ||||
| 'Update rebased mq patches - finalize and then import them' | 'Update rebased mq patches - finalize and then import them' | ||||
| mqrebase = {} | mqrebase = {} | ||||
| mq = repo.mq | mq = repo.mq | ||||
| pos = 0 | pos = 0 | ||||
| total = len(files) | total = len(files) | ||||
| for f, sz in files: | for f, sz in files: | ||||
| pos += 1 | pos += 1 | ||||
| source = os.path.join(src, f) | source = os.path.join(src, f) | ||||
| tgt = os.path.join(dst, f) | tgt = os.path.join(dst, f) | ||||
| # Binary mode, so that read() works correctly, especially on Windows | # Binary mode, so that read() works correctly, especially on Windows | ||||
| sfp = file(source, 'rb') | sfp = open(source, 'rb') | ||||
| dfp = file(tgt, 'rb') | dfp = open(tgt, 'rb') | ||||
| sin = sfp.read(CHUNKLEN) | sin = sfp.read(CHUNKLEN) | ||||
| while sin: | while sin: | ||||
| din = dfp.read(CHUNKLEN) | din = dfp.read(CHUNKLEN) | ||||
| if sin != din: | if sin != din: | ||||
| break | break | ||||
| sin = sfp.read(CHUNKLEN) | sin = sfp.read(CHUNKLEN) | ||||
| sfp.close() | sfp.close() | ||||
| dfp.close() | dfp.close() | ||||
| stop and restart | stop and restart | ||||
| $ killdaemons.py | $ killdaemons.py | ||||
| $ hg serve -p $HGPORT -d --pid-file=hg.pid -A access.log | $ hg serve -p $HGPORT -d --pid-file=hg.pid -A access.log | ||||
| $ cat hg.pid >> $DAEMON_PIDS | $ cat hg.pid >> $DAEMON_PIDS | ||||
| Test the access/error files are opened in append mode | 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 | 14 log lines written | ||||
| static file | static file | ||||
| $ get-with-headers.py --twice localhost:$HGPORT 'static/style-gitweb.css' - date etag server | $ get-with-headers.py --twice localhost:$HGPORT 'static/style-gitweb.css' - date etag server | ||||
| 200 Script output follows | 200 Script output follows | ||||
| content-length: 9126 | content-length: 9126 | ||||
| content-type: text/css | content-type: text/css | ||||
| $ hg import --exact ../r1.patch | $ hg import --exact ../r1.patch | ||||
| applying ../r1.patch | applying ../r1.patch | ||||
| Test --exact and patch header separators (issue3356) | Test --exact and patch header separators (issue3356) | ||||
| $ hg strip --no-backup . | $ hg strip --no-backup . | ||||
| 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | ||||
| >>> import re | >>> import re | ||||
| >>> p = file('../r1.patch', 'rb').read() | >>> p = open('../r1.patch', 'rb').read() | ||||
| >>> p = re.sub(r'Parent\s+', 'Parent ', p) | >>> 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 | $ hg import --exact ../r1-ws.patch | ||||
| applying ../r1-ws.patch | applying ../r1-ws.patch | ||||
| $ cd .. | $ cd .. | ||||
| Test applying context diffs | Test applying context diffs | ||||
| $ cat > writepatterns.py <<EOF | $ cat > writepatterns.py <<EOF | ||||
| > import sys | > import sys | ||||
| > | > | ||||
| > path = sys.argv[1] | > path = sys.argv[1] | ||||
| > lasteol = sys.argv[2] == '1' | > lasteol = sys.argv[2] == '1' | ||||
| > patterns = sys.argv[3:] | > patterns = sys.argv[3:] | ||||
| > | > | ||||
| > fp = file(path, 'wb') | > fp = open(path, 'wb') | ||||
| > for i, pattern in enumerate(patterns): | > for i, pattern in enumerate(patterns): | ||||
| > count = int(pattern[0:-1]) | > count = int(pattern[0:-1]) | ||||
| > char = pattern[-1] + '\n' | > char = pattern[-1] + '\n' | ||||
| > if not lasteol and i == len(patterns) - 1: | > if not lasteol and i == len(patterns) - 1: | ||||
| > fp.write((char*count)[:-1]) | > fp.write((char*count)[:-1]) | ||||
| > else: | > else: | ||||
| > fp.write(char*count) | > fp.write(char*count) | ||||
| > fp.close() | > fp.close() | ||||
| > EOF | > EOF | ||||
| $ cat > cat.py <<EOF | $ cat > cat.py <<EOF | ||||
| > import sys | > 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 | > EOF | ||||
| Initialize the test repository | Initialize the test repository | ||||
| $ hg init repo | $ hg init repo | ||||
| $ cd repo | $ cd repo | ||||
| $ $PYTHON ../writepatterns.py a 0 5A 1B 5C 1D | $ $PYTHON ../writepatterns.py a 0 5A 1B 5C 1D | ||||
| $ $PYTHON ../writepatterns.py b 1 1A 1B | $ $PYTHON ../writepatterns.py b 1 1A 1B | ||||
| long lines | long lines | ||||
| $ cat <<EOF >> $HGRCPATH | $ cat <<EOF >> $HGRCPATH | ||||
| > [notify] | > [notify] | ||||
| > maxsubject = 67 | > maxsubject = 67 | ||||
| > test = False | > test = False | ||||
| > mbox = mbox | > mbox = mbox | ||||
| > EOF | > 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 --cwd a commit -A -m "long line" | ||||
| $ hg --traceback --cwd b pull ../a | $ hg --traceback --cwd b pull ../a | ||||
| pulling from ../a | pulling from ../a | ||||
| searching for changes | searching for changes | ||||
| adding changesets | adding changesets | ||||
| adding manifests | adding manifests | ||||
| adding file changes | adding file changes | ||||
| added 1 changesets with 1 changes to 1 files | added 1 changesets with 1 changes to 1 files | ||||