equal
deleted
inserted
replaced
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) |