Mercurial > public > mercurial-scm > hg-stable
comparison contrib/testparseutil.py @ 42409:37f38e1dea44
testparseutil: stop extracting using std* streams as bytes on py3
This is no longer required due to other cleanups in our linting tools.
Differential Revision: https://phab.mercurial-scm.org/D6455
author | Augie Fackler <augie@google.com> |
---|---|
date | Wed, 29 May 2019 09:59:35 -0400 |
parents | 5364ba1f796f |
children | c2deb2512823 |
comparison
equal
deleted
inserted
replaced
42408:055687fe4c47 | 42409:37f38e1dea44 |
---|---|
36 return _rapply(f, xs) | 36 return _rapply(f, xs) |
37 | 37 |
38 if ispy3: | 38 if ispy3: |
39 import builtins | 39 import builtins |
40 | 40 |
41 # TODO: .buffer might not exist if std streams were replaced; we'll need | |
42 # a silly wrapper to make a bytes stream backed by a unicode one. | |
43 stdin = sys.stdin.buffer | |
44 stdout = sys.stdout.buffer | |
45 stderr = sys.stderr.buffer | |
46 | |
47 def bytestr(s): | 41 def bytestr(s): |
48 # tiny version of pycompat.bytestr | 42 # tiny version of pycompat.bytestr |
49 return s.encode('latin1') | 43 return s.encode('latin1') |
50 | 44 |
51 def sysstr(s): | 45 def sysstr(s): |
54 return s.decode(u'latin-1') | 48 return s.decode(u'latin-1') |
55 | 49 |
56 def opentext(f): | 50 def opentext(f): |
57 return open(f, 'r') | 51 return open(f, 'r') |
58 else: | 52 else: |
59 stdin = sys.stdin | |
60 stdout = sys.stdout | |
61 stderr = sys.stderr | |
62 | |
63 bytestr = str | 53 bytestr = str |
64 sysstr = identity | 54 sysstr = identity |
65 | 55 |
66 opentext = open | 56 opentext = open |
67 | 57 |
69 # convert BYTES elements in "x" to SYSSTR recursively | 59 # convert BYTES elements in "x" to SYSSTR recursively |
70 return rapply(sysstr, x) | 60 return rapply(sysstr, x) |
71 | 61 |
72 def writeout(data): | 62 def writeout(data): |
73 # write "data" in BYTES into stdout | 63 # write "data" in BYTES into stdout |
74 stdout.write(data) | 64 sys.stdout.write(data) |
75 | 65 |
76 def writeerr(data): | 66 def writeerr(data): |
77 # write "data" in BYTES into stderr | 67 # write "data" in BYTES into stderr |
78 stderr.write(data) | 68 sys.stderr.write(data) |
79 | 69 |
80 #################### | 70 #################### |
81 | 71 |
82 class embeddedmatcher(object): | 72 class embeddedmatcher(object): |
83 """Base class to detect embedded code fragments in *.t test script | 73 """Base class to detect embedded code fragments in *.t test script |
581 for f in args: | 571 for f in args: |
582 with opentext(f) as fp: | 572 with opentext(f) as fp: |
583 if showembedded(f, fp, embeddedfunc, opts): | 573 if showembedded(f, fp, embeddedfunc, opts): |
584 ret = 1 | 574 ret = 1 |
585 else: | 575 else: |
586 lines = [l for l in stdin.readlines()] | 576 lines = [l for l in sys.stdin.readlines()] |
587 if showembedded('<stdin>', lines, embeddedfunc, opts): | 577 if showembedded('<stdin>', lines, embeddedfunc, opts): |
588 ret = 1 | 578 ret = 1 |
589 return ret | 579 return ret |
590 | 580 |
591 commands = {} | 581 commands = {} |