Details
Details
- Reviewers
- None
- Group Reviewers
hg-reviewers - Commits
- rHGbf953d218a91: py3: encode sys.argv to bytes using .encode()
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
( )
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
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 = open(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].encode('utf8') + b'\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 |
$ cat > writepatterns.py <<EOF | $ cat > writepatterns.py <<EOF | ||||
> import sys | > import sys | ||||
> | > | ||||
> path = sys.argv[1] | > path = sys.argv[1] | ||||
> patterns = sys.argv[2:] | > patterns = sys.argv[2:] | ||||
> | > | ||||
> fp = open(path, 'wb') | > fp = open(path, 'wb') | ||||
> for pattern in patterns: | > for pattern in patterns: | ||||
> count = int(pattern[0:-1]) | > count = int(pattern[0:-1]) | ||||
> char = pattern[-1] + '\n' | > char = pattern[-1].encode('utf8') + b'\n' | ||||
> fp.write(char*count) | > fp.write(char*count) | ||||
> fp.close() | > fp.close() | ||||
> EOF | > EOF | ||||
prepare repo | prepare repo | ||||
$ hg init a | $ hg init a | ||||
$ cd a | $ cd a |