Patchwork [8,of,8] check-code: more replacement characters

login
register
mail settings
Submitter Simon Heimberg
Date Nov. 2, 2013, 11:36 a.m.
Message ID <a6e2cf456c0f77a30dfa.1383392168@lapsi.heimberg.home>
Download mbox | patch
Permalink /patch/2845/
State Superseded, archived
Headers show

Comments

Simon Heimberg - Nov. 2, 2013, 11:36 a.m.
# HG changeset patch
# User Simon Heimberg <simohe@besonet.ch>
# Date 1383388432 -3600
#      Sat Nov 02 11:33:52 2013 +0100
# Branch stable
# Node ID a6e2cf456c0f77a30dfa8f69f039aef4b80e944c
# Parent  62b32b755aacac71a83eda89229bff551fa8b534
check-code: more replacement characters

for finding '.. note::' (even) more exact by using more characters:
replace '.' with 'p' and ':' with 'q'

Patch

diff -r 62b32b755aac -r a6e2cf456c0f contrib/check-code.py
--- a/contrib/check-code.py	Sat Nov 02 11:33:43 2013 +0100
+++ b/contrib/check-code.py	Sat Nov 02 11:33:52 2013 +0100
@@ -26,8 +26,25 @@ 
     return re.compile(pat)
 
 def repquote(m):
-    t = re.sub(r"\w", "x", m.group('text'))
-    t = re.sub(r"[^\s\nx]", "o", t)
+    fromc = '.:'
+    tochr = 'pq'
+    def encodechr(i):
+        if i > 255:
+            return 'u'
+        c = chr(i)
+        if c in ' \n':
+            return c
+        if c.isalpha():
+            return 'x'
+        if c.isdigit():
+            return 'n'
+        try:
+            return tochr[fromc.find(c)]
+        except (ValueError, IndexError):
+            return 'o'
+    t = m.group('text')
+    tt = ''.join(encodechr(i) for i in xrange(256))
+    t = t.translate(tt)
     return m.group('quote') + t + m.group('quote')
 
 def reppython(m):
@@ -263,7 +280,7 @@ 
   ],
   # warnings
   [
-    (r'(^| )oo +xxxxoo[ \n][^\n]', "add two newlines after '.. note::'"),
+    (r'(^| )pp +xxxxqq[ \n][^\n]', "add two newlines after '.. note::'"),
   ]
 ]