49 except re2.error: |
49 except re2.error: |
50 pass |
50 pass |
51 return re.compile(pat) |
51 return re.compile(pat) |
52 |
52 |
53 def repquote(m): |
53 def repquote(m): |
54 fromc = '.:' |
54 fixedmap = {'.': 'p', ':': 'q'} |
55 tochr = 'pq' |
|
56 def encodechr(i): |
55 def encodechr(i): |
57 if i > 255: |
56 if i > 255: |
58 return 'u' |
57 return 'u' |
59 c = chr(i) |
58 c = chr(i) |
60 if c in ' \n': |
59 if c in ' \n': |
61 return c |
60 return c |
|
61 if c in fixedmap: |
|
62 return fixedmap[c] |
62 if c.isalpha(): |
63 if c.isalpha(): |
63 return 'x' |
64 return 'x' |
64 if c.isdigit(): |
65 if c.isdigit(): |
65 return 'n' |
66 return 'n' |
66 try: |
67 return 'o' |
67 return tochr[fromc.find(c)] |
|
68 except (ValueError, IndexError): |
|
69 return 'o' |
|
70 t = m.group('text') |
68 t = m.group('text') |
71 tt = ''.join(encodechr(i) for i in xrange(256)) |
69 tt = ''.join(encodechr(i) for i in xrange(256)) |
72 t = t.translate(tt) |
70 t = t.translate(tt) |
73 return m.group('quote') + t + m.group('quote') |
71 return m.group('quote') + t + m.group('quote') |
74 |
72 |
246 (r'(\w|\)),\w', "missing whitespace after ,"), |
244 (r'(\w|\)),\w', "missing whitespace after ,"), |
247 (r'(\w|\))[+/*\-<>]\w', "missing whitespace in expression"), |
245 (r'(\w|\))[+/*\-<>]\w', "missing whitespace in expression"), |
248 (r'^\s+(\w|\.)+=\w[^,()\n]*$', "missing whitespace in assignment"), |
246 (r'^\s+(\w|\.)+=\w[^,()\n]*$', "missing whitespace in assignment"), |
249 (r'\w\s=\s\s+\w', "gratuitous whitespace after ="), |
247 (r'\w\s=\s\s+\w', "gratuitous whitespace after ="), |
250 (r'.{81}', "line too long"), |
248 (r'.{81}', "line too long"), |
251 (r' x+[xo][\'"]\n\s+[\'"]x', 'string join across lines with no space'), |
249 (r' x+[xpqo][\'"]\n\s+[\'"]x', 'string join across lines with no space'), |
252 (r'[^\n]\Z', "no trailing newline"), |
250 (r'[^\n]\Z', "no trailing newline"), |
253 (r'(\S[ \t]+|^[ \t]+)\n', "trailing whitespace"), |
251 (r'(\S[ \t]+|^[ \t]+)\n', "trailing whitespace"), |
254 # (r'^\s+[^_ \n][^_. \n]+_[^_\n]+\s*=', |
252 # (r'^\s+[^_ \n][^_. \n]+_[^_\n]+\s*=', |
255 # "don't use underbars in identifiers"), |
253 # "don't use underbars in identifiers"), |
256 (r'^\s+(self\.)?[A-za-z][a-z0-9]+[A-Z]\w* = ', |
254 (r'^\s+(self\.)?[A-za-z][a-z0-9]+[A-Z]\w* = ', |