Mercurial > public > mercurial-scm > hg
comparison contrib/testparseutil.py @ 49874:cd3b8fd1d3eb
contrib: drop py2 support from testparseutil.py
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Tue, 03 Jan 2023 23:53:44 -0500 |
parents | 642e31cb55f0 |
children | 5cc8deb96b48 |
comparison
equal
deleted
inserted
replaced
49873:e9d06ed64161 | 49874:cd3b8fd1d3eb |
---|---|
5 # This software may be used and distributed according to the terms of the | 5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 | 7 |
8 | 8 |
9 import abc | 9 import abc |
10 import builtins | |
10 import re | 11 import re |
11 import sys | |
12 | 12 |
13 #################### | 13 #################### |
14 # for Python3 compatibility (almost comes from mercurial/pycompat.py) | 14 # for Python3 compatibility (almost comes from mercurial/pycompat.py) |
15 | |
16 ispy3 = sys.version_info[0] >= 3 | |
17 | 15 |
18 | 16 |
19 def identity(a): | 17 def identity(a): |
20 return a | 18 return a |
21 | 19 |
36 # fast path mainly for py2 | 34 # fast path mainly for py2 |
37 return xs | 35 return xs |
38 return _rapply(f, xs) | 36 return _rapply(f, xs) |
39 | 37 |
40 | 38 |
41 if ispy3: | 39 def bytestr(s): |
42 import builtins | 40 # tiny version of pycompat.bytestr |
43 | 41 return s.encode('latin1') |
44 def bytestr(s): | 42 |
45 # tiny version of pycompat.bytestr | 43 |
46 return s.encode('latin1') | 44 def sysstr(s): |
47 | 45 if isinstance(s, builtins.str): |
48 def sysstr(s): | 46 return s |
49 if isinstance(s, builtins.str): | 47 return s.decode('latin-1') |
50 return s | 48 |
51 return s.decode('latin-1') | 49 |
52 | 50 def opentext(f): |
53 def opentext(f): | 51 return open(f, 'r') |
54 return open(f, 'r') | |
55 | |
56 | |
57 else: | |
58 bytestr = str | |
59 sysstr = identity | |
60 | |
61 opentext = open | |
62 | 52 |
63 | 53 |
64 def b2s(x): | 54 def b2s(x): |
65 # convert BYTES elements in "x" to SYSSTR recursively | 55 # convert BYTES elements in "x" to SYSSTR recursively |
66 return rapply(sysstr, x) | 56 return rapply(sysstr, x) |