diff --git a/contrib/check-code.py b/contrib/check-code.py --- a/contrib/check-code.py +++ b/contrib/check-code.py @@ -50,25 +50,26 @@ def compilere(pat, multiline=False): pass return re.compile(pat) +# check "rules depending on implementation of repquote()" in each +# patterns (especially pypats), before changing around repquote() +_repquotefixedmap = {' ': ' ', '\n': '\n', '.': 'p', ':': 'q', + '%': '%', '\\': 'b', '*': 'A', '+': 'P', '-': 'M'} +def _repquoteencodechr(i): + if i > 255: + return 'u' + c = chr(i) + if c in _repquotefixedmap: + return _repquotefixedmap[c] + if c.isalpha(): + return 'x' + if c.isdigit(): + return 'n' + return 'o' +_repquotett = ''.join(_repquoteencodechr(i) for i in xrange(256)) + def repquote(m): - # check "rules depending on implementation of repquote()" in each - # patterns (especially pypats), before changing this function - fixedmap = {' ': ' ', '\n': '\n', '.': 'p', ':': 'q', - '%': '%', '\\': 'b', '*': 'A', '+': 'P', '-': 'M'} - def encodechr(i): - if i > 255: - return 'u' - c = chr(i) - if c in fixedmap: - return fixedmap[c] - if c.isalpha(): - return 'x' - if c.isdigit(): - return 'n' - return 'o' t = m.group('text') - tt = ''.join(encodechr(i) for i in xrange(256)) - t = t.translate(tt) + t = t.translate(_repquotett) return m.group('quote') + t + m.group('quote') def reppython(m): diff --git a/tests/test-contrib-check-code.t b/tests/test-contrib-check-code.t --- a/tests/test-contrib-check-code.t +++ b/tests/test-contrib-check-code.t @@ -276,7 +276,11 @@ web templates > ''' "%-6d \n 123456 .:*+-= foobar") > EOF - $ "$check_code" stringjoin.py +(Checking multiple invalid files at once examines whether caching +translation table for repquote() works as expected or not. All files +should break rules depending on result of repquote(), in this case) + + $ "$check_code" stringjoin.py uigettext.py stringjoin.py:1: > foo = (' foo' string join across lines with no space @@ -301,9 +305,6 @@ web templates stringjoin.py:8: > 'bar foo-' string join across lines with no space - [1] - - $ "$check_code" uigettext.py uigettext.py:1: > ui.status("% 10s %05d % -3.2f %*s %%" missing _() in ui message (use () to hide false-positives)