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

login
register
mail settings
Submitter Simon Heimberg
Date Nov. 5, 2013, 8:06 a.m.
Message ID <2e096bfe9691bc594c92.1383638799@lapsi.heimberg.home>
Download mbox | patch
Permalink /patch/2857/
State Accepted
Commit 169cb9e47f8e86079ee9fd79972092f78fbf68b1
Headers show

Comments

Simon Heimberg - Nov. 5, 2013, 8:06 a.m.
# HG changeset patch
# User Simon Heimberg <simohe@besonet.ch>
# Date 1383638431 -3600
#      Tue Nov 05 09:00:31 2013 +0100
# Branch stable
# Node ID 2e096bfe9691bc594c925e19bf4f0c5d195b79dc
# Parent  0d56501f3381b0066453cb238ada262bad114b3a
check-code: more replacement characters

for finding '.. note::' (even) more exact by using more characters:
replace '.' with 'p' and ':' with 'q'
Augie Fackler - Nov. 6, 2013, 6:06 p.m.
On Tue, Nov 05, 2013 at 09:06:39AM +0100, Simon Heimberg wrote:
> # HG changeset patch
> # User Simon Heimberg <simohe@besonet.ch>
> # Date 1383638431 -3600
> #      Tue Nov 05 09:00:31 2013 +0100
> # Branch stable
> # Node ID 2e096bfe9691bc594c925e19bf4f0c5d195b79dc
> # Parent  0d56501f3381b0066453cb238ada262bad114b3a
> check-code: more replacement characters

Looks superficially reasonable, but I don't know enough about ReST or
minirst to feel comfortable to actually accept these on my own.

>
> for finding '.. note::' (even) more exact by using more characters:
> replace '.' with 'p' and ':' with 'q'
>
> diff -r 0d56501f3381 -r 2e096bfe9691 contrib/check-code.py
> --- a/contrib/check-code.py	Tue Nov 05 09:00:31 2013 +0100
> +++ b/contrib/check-code.py	Tue Nov 05 09:00:31 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::'"),
>    ]
>  ]
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
Matt Mackall - Nov. 13, 2013, 7:31 p.m.
On Tue, 2013-11-05 at 09:06 +0100, Simon Heimberg wrote:
> # HG changeset patch
> # User Simon Heimberg <simohe@besonet.ch>
> # Date 1383638431 -3600
> #      Tue Nov 05 09:00:31 2013 +0100
> # Branch stable
> # Node ID 2e096bfe9691bc594c925e19bf4f0c5d195b79dc
> # Parent  0d56501f3381b0066453cb238ada262bad114b3a
> check-code: more replacement characters

These are queued for stable, thanks.

Patch

diff -r 0d56501f3381 -r 2e096bfe9691 contrib/check-code.py
--- a/contrib/check-code.py	Tue Nov 05 09:00:31 2013 +0100
+++ b/contrib/check-code.py	Tue Nov 05 09:00:31 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::'"),
   ]
 ]