Patchwork [4,of,4,py3] config: mark parser regexes as bytes explicitly

login
register
mail settings
Submitter Augie Fackler
Date Nov. 9, 2016, 4:23 p.m.
Message ID <6eca307a01fe1331f8a7.1478708621@augie-macbookair2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/17418/
State Accepted
Headers show

Comments

Augie Fackler - Nov. 9, 2016, 4:23 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1476019539 14400
#      Sun Oct 09 09:25:39 2016 -0400
# Node ID 6eca307a01fe1331f8a754d532f89e9c488c3923
# Parent  5f29fffcc722d8993fda4155884c1aae4469d2f3
config: mark parser regexes as bytes explicitly

r-strings are not transformed into bytes by our source transformer magic.
Martijn Pieters - Nov. 9, 2016, 4:26 p.m.
On 9 November 2016 at 16:23, Augie Fackler <raf@durin42.com> wrote:

> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1476019539 14400
> #      Sun Oct 09 09:25:39 2016 -0400
> # Node ID 6eca307a01fe1331f8a754d532f89e9c488c3923
> # Parent  5f29fffcc722d8993fda4155884c1aae4469d2f3
> config: mark parser regexes as bytes explicitly
>
> r-strings are not transformed into bytes by our source transformer magic.
>

+1 on this whole series.



> diff --git a/mercurial/config.py b/mercurial/config.py
> --- a/mercurial/config.py
> +++ b/mercurial/config.py
> @@ -90,13 +90,13 @@ class config(object):
>              self._source.pop((section, item), None)
>
>      def parse(self, src, data, sections=None, remap=None, include=None):
> -        sectionre = util.re.compile(r'\[([^\[]+)\]')
> -        itemre = util.re.compile(r'([^=\s][^=]*?)\s*=\s*(.*\S|)')
> -        contre = util.re.compile(r'\s+(\S|\S.*\S)\s*$')
> -        emptyre = util.re.compile(r'(;|#|\s*$)')
> -        commentre = util.re.compile(r'(;|#)')
> -        unsetre = util.re.compile(r'%unset\s+(\S+)')
> -        includere = util.re.compile(r'%include\s+(\S|\S.*\S)\s*$')
> +        sectionre = util.re.compile(br'\[([^\[]+)\]')
> +        itemre = util.re.compile(br'([^=\s][^=]*?)\s*=\s*(.*\S|)')
> +        contre = util.re.compile(br'\s+(\S|\S.*\S)\s*$')
> +        emptyre = util.re.compile(br'(;|#|\s*$)')
> +        commentre = util.re.compile(br'(;|#)')
> +        unsetre = util.re.compile(br'%unset\s+(\S+)')
> +        includere = util.re.compile(br'%include\s+(\S|\S.*\S)\s*$')
>          section = ""
>          item = None
>          line = 0
> diff --git a/tests/test-check-py3-commands.t b/tests/test-check-py3-
> commands.t
> --- a/tests/test-check-py3-commands.t
> +++ b/tests/test-check-py3-commands.t
> @@ -9,6 +9,6 @@ The full traceback is hidden to have a s
>    >   $PYTHON3 `which hg` $cmd 2>&1 2>&1 | tail -1
>    > done
>    version
> -  TypeError: cannot use a string pattern on a bytes-like object
> +  NameError: name 'basestring' is not defined
>    debuginstall
> -  TypeError: cannot use a string pattern on a bytes-like object
> +  NameError: name 'basestring' is not defined
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
Yuya Nishihara - Nov. 10, 2016, 1:30 p.m.
On Wed, 09 Nov 2016 11:23:41 -0500, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1476019539 14400
> #      Sun Oct 09 09:25:39 2016 -0400
> # Node ID 6eca307a01fe1331f8a754d532f89e9c488c3923
> # Parent  5f29fffcc722d8993fda4155884c1aae4469d2f3
> config: mark parser regexes as bytes explicitly

Queued 2 and 4, thanks.

Patch

diff --git a/mercurial/config.py b/mercurial/config.py
--- a/mercurial/config.py
+++ b/mercurial/config.py
@@ -90,13 +90,13 @@  class config(object):
             self._source.pop((section, item), None)
 
     def parse(self, src, data, sections=None, remap=None, include=None):
-        sectionre = util.re.compile(r'\[([^\[]+)\]')
-        itemre = util.re.compile(r'([^=\s][^=]*?)\s*=\s*(.*\S|)')
-        contre = util.re.compile(r'\s+(\S|\S.*\S)\s*$')
-        emptyre = util.re.compile(r'(;|#|\s*$)')
-        commentre = util.re.compile(r'(;|#)')
-        unsetre = util.re.compile(r'%unset\s+(\S+)')
-        includere = util.re.compile(r'%include\s+(\S|\S.*\S)\s*$')
+        sectionre = util.re.compile(br'\[([^\[]+)\]')
+        itemre = util.re.compile(br'([^=\s][^=]*?)\s*=\s*(.*\S|)')
+        contre = util.re.compile(br'\s+(\S|\S.*\S)\s*$')
+        emptyre = util.re.compile(br'(;|#|\s*$)')
+        commentre = util.re.compile(br'(;|#)')
+        unsetre = util.re.compile(br'%unset\s+(\S+)')
+        includere = util.re.compile(br'%include\s+(\S|\S.*\S)\s*$')
         section = ""
         item = None
         line = 0
diff --git a/tests/test-check-py3-commands.t b/tests/test-check-py3-commands.t
--- a/tests/test-check-py3-commands.t
+++ b/tests/test-check-py3-commands.t
@@ -9,6 +9,6 @@  The full traceback is hidden to have a s
   >   $PYTHON3 `which hg` $cmd 2>&1 2>&1 | tail -1
   > done
   version
-  TypeError: cannot use a string pattern on a bytes-like object
+  NameError: name 'basestring' is not defined
   debuginstall
-  TypeError: cannot use a string pattern on a bytes-like object
+  NameError: name 'basestring' is not defined