##// END OF EJS Templates
py3: byteify docchecker...
Matt Harbison -
r41042:9bfbb9fc default
parent child Browse files
Show More
@@ -9,18 +9,28 b''
9
9
10 from __future__ import absolute_import, print_function
10 from __future__ import absolute_import, print_function
11
11
12 import os
12 import re
13 import re
13 import sys
14 import sys
14
15
15 leadingline = re.compile(r'(^\s*)(\S.*)$')
16 try:
17 import msvcrt
18 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
19 msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
20 except ImportError:
21 pass
22
23 stdout = getattr(sys.stdout, 'buffer', sys.stdout)
24
25 leadingline = re.compile(br'(^\s*)(\S.*)$')
16
26
17 checks = [
27 checks = [
18 (r""":hg:`[^`]*'[^`]*`""",
28 (br""":hg:`[^`]*'[^`]*`""",
19 """warning: please avoid nesting ' in :hg:`...`"""),
29 b"""warning: please avoid nesting ' in :hg:`...`"""),
20 (r'\w:hg:`',
30 (br'\w:hg:`',
21 'warning: please have a space before :hg:'),
31 b'warning: please have a space before :hg:'),
22 (r"""(?:[^a-z][^'.])hg ([^,;"`]*'(?!hg)){2}""",
32 (br"""(?:[^a-z][^'.])hg ([^,;"`]*'(?!hg)){2}""",
23 '''warning: please use " instead of ' for hg ... "..."'''),
33 b'''warning: please use " instead of ' for hg ... "..."'''),
24 ]
34 ]
25
35
26 def check(line):
36 def check(line):
@@ -29,25 +39,25 b' def check(line):'
29 if re.search(match, line):
39 if re.search(match, line):
30 messages.append(msg)
40 messages.append(msg)
31 if messages:
41 if messages:
32 print(line)
42 stdout.write(b'%s\n' % line)
33 for msg in messages:
43 for msg in messages:
34 print(msg)
44 stdout.write(b'%s\n' % msg)
35
45
36 def work(file):
46 def work(file):
37 (llead, lline) = ('', '')
47 (llead, lline) = (b'', b'')
38
48
39 for line in file:
49 for line in file:
40 # this section unwraps lines
50 # this section unwraps lines
41 match = leadingline.match(line)
51 match = leadingline.match(line)
42 if not match:
52 if not match:
43 check(lline)
53 check(lline)
44 (llead, lline) = ('', '')
54 (llead, lline) = (b'', b'')
45 continue
55 continue
46
56
47 lead, line = match.group(1), match.group(2)
57 lead, line = match.group(1), match.group(2)
48 if (lead == llead):
58 if (lead == llead):
49 if (lline != ''):
59 if (lline != b''):
50 lline += ' ' + line
60 lline += b' ' + line
51 else:
61 else:
52 lline = line
62 lline = line
53 else:
63 else:
@@ -58,9 +68,9 b' def work(file):'
58 def main():
68 def main():
59 for f in sys.argv[1:]:
69 for f in sys.argv[1:]:
60 try:
70 try:
61 with open(f) as file:
71 with open(f, 'rb') as file:
62 work(file)
72 work(file)
63 except BaseException as e:
73 except BaseException as e:
64 print("failed to process %s: %s" % (f, e))
74 sys.stdout.write(r"failed to process %s: %s\n" % (f, e))
65
75
66 main()
76 main()
General Comments 0
You need to be logged in to leave comments. Login now