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

login
register
mail settings
Submitter Augie Fackler
Date Oct. 9, 2016, 2:16 p.m.
Message ID <e89f400277d564c4a576.1476022612@augie-macbookair2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/17006/
State Accepted
Headers show

Comments

Augie Fackler - Oct. 9, 2016, 2:16 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1476019539 14400
#      Sun Oct 09 09:25:39 2016 -0400
# Node ID e89f400277d564c4a576ad8e4a6003a201993639
# Parent  f3b993e256a8aeba26d2f927da9cf4428f7f1585
config: mark parser regexes as bytes explicitly

r-strings are not transformed into bytes by our source transformer magic.
Yuya Nishihara - Oct. 10, 2016, 7:48 p.m.
On Sun, 09 Oct 2016 10:16:52 -0400, 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 e89f400277d564c4a576ad8e4a6003a201993639
> # Parent  f3b993e256a8aeba26d2f927da9cf4428f7f1585
> config: mark parser regexes as bytes explicitly
> 
> r-strings are not transformed into bytes by our source transformer magic.
> 
> 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(rb'\[([^\[]+)\]')
> +        itemre = util.re.compile(rb'([^=\s][^=]*?)\s*=\s*(.*\S|)')
> +        contre = util.re.compile(rb'\s+(\S|\S.*\S)\s*$')
> +        emptyre = util.re.compile(rb'(;|#|\s*$)')
> +        commentre = util.re.compile(rb'(;|#)')
> +        unsetre = util.re.compile(rb'%unset\s+(\S+)')
> +        includere = util.re.compile(rb'%include\s+(\S|\S.*\S)\s*$')

It appears Py2 hates rb''. br'' works.

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(rb'\[([^\[]+)\]')
+        itemre = util.re.compile(rb'([^=\s][^=]*?)\s*=\s*(.*\S|)')
+        contre = util.re.compile(rb'\s+(\S|\S.*\S)\s*$')
+        emptyre = util.re.compile(rb'(;|#|\s*$)')
+        commentre = util.re.compile(rb'(;|#)')
+        unsetre = util.re.compile(rb'%unset\s+(\S+)')
+        includere = util.re.compile(rb'%include\s+(\S|\S.*\S)\s*$')
         section = ""
         item = None
         line = 0