Patchwork [1,of,3,v2] hghave: matchoutput needs to use bytes for regexp

login
register
mail settings
Submitter timeless
Date May 8, 2016, 8:28 p.m.
Message ID <18ef4f2e901adfba7205.1462739327@gcc2-power8.osuosl.org>
Download mbox | patch
Permalink /patch/14969/
State Superseded, archived
Headers show

Comments

timeless - May 8, 2016, 8:28 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1462439221 0
#      Thu May 05 09:07:01 2016 +0000
# Node ID 18ef4f2e901adfba72054641bf5bfa21aa64a17e
# Parent  57a24a85a2bc484cbd7c4b80959dc2d5f0483174
# Available At bb://timeless/mercurial-crew
#              hg pull bb://timeless/mercurial-crew -r 18ef4f2e901a
hghave: matchoutput needs to use bytes for regexp

file output is bytes in py3, so we need to convert the regexp to bytes
Pierre-Yves David - May 9, 2016, 2:28 p.m.
On 05/08/2016 10:28 PM, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1462439221 0
> #      Thu May 05 09:07:01 2016 +0000
> # Node ID 18ef4f2e901adfba72054641bf5bfa21aa64a17e
> # Parent  57a24a85a2bc484cbd7c4b80959dc2d5f0483174
> # Available At bb://timeless/mercurial-crew
> #              hg pull bb://timeless/mercurial-crew -r 18ef4f2e901a
> hghave: matchoutput needs to use bytes for regexp
>
> file output is bytes in py3, so we need to convert the regexp to bytes

Shouln't we ensure the callers are passing bytes instead? (by adding b 
prefix to string).
Implicite conversion of string to bytes in function iternal seems like a 
bad idea.
Yuya Nishihara - May 11, 2016, 12:35 p.m.
On Mon, 9 May 2016 16:28:27 +0200, Pierre-Yves David wrote:
> On 05/08/2016 10:28 PM, timeless wrote:
> > # HG changeset patch
> > # User timeless <timeless@mozdev.org>
> > # Date 1462439221 0
> > #      Thu May 05 09:07:01 2016 +0000
> > # Node ID 18ef4f2e901adfba72054641bf5bfa21aa64a17e
> > # Parent  57a24a85a2bc484cbd7c4b80959dc2d5f0483174
> > # Available At bb://timeless/mercurial-crew
> > #              hg pull bb://timeless/mercurial-crew -r 18ef4f2e901a
> > hghave: matchoutput needs to use bytes for regexp
> >
> > file output is bytes in py3, so we need to convert the regexp to bytes  
> 
> Shouln't we ensure the callers are passing bytes instead? (by adding b 
> prefix to string).
> Implicite conversion of string to bytes in function iternal seems like a 
> bad idea.

+1 for b'' or br''. Anyway, we'll have to do that for all string literals
in the core modules.

Patch

diff -r 57a24a85a2bc -r 18ef4f2e901a tests/hghave.py
--- a/tests/hghave.py	Sat May 07 14:51:32 2016 +0100
+++ b/tests/hghave.py	Thu May 05 09:07:01 2016 +0000
@@ -90,7 +90,7 @@ 
     """Return the match object if cmd executes successfully and its output
     is matched by the supplied regular expression.
     """
-    r = re.compile(regexp)
+    r = re.compile(regexp.encode('utf-8'))
     try:
         p = subprocess.Popen(
             cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)