Patchwork [6,of,6,py3] schemes: move re construction to module-level and python3-ify

login
register
mail settings
Submitter Augie Fackler
Date March 6, 2017, 11:23 p.m.
Message ID <e36144b27c88bf5a0f2f.1488842590@augie-macbookair2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/18950/
State Accepted
Headers show

Comments

Augie Fackler - March 6, 2017, 11:23 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1488565530 18000
#      Fri Mar 03 13:25:30 2017 -0500
# Node ID e36144b27c88bf5a0f2f520d2f2352c290ea4f15
# Parent  c28e0b997db472d0286927234bf06cc9848b6ff7
schemes: move re construction to module-level and python3-ify

This makes the schemes extension load correctly in Python 3.
Yuya Nishihara - March 7, 2017, 2:03 p.m.
On Mon, 06 Mar 2017 18:23:10 -0500, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1488565530 18000
> #      Fri Mar 03 13:25:30 2017 -0500
> # Node ID e36144b27c88bf5a0f2f520d2f2352c290ea4f15
> # Parent  c28e0b997db472d0286927234bf06cc9848b6ff7
> schemes: move re construction to module-level and python3-ify
> 
> This makes the schemes extension load correctly in Python 3.
> 
> diff --git a/hgext/schemes.py b/hgext/schemes.py
> --- a/hgext/schemes.py
> +++ b/hgext/schemes.py
> @@ -63,6 +63,7 @@ command = cmdutil.command(cmdtable)
>  # leave the attribute unspecified.
>  testedwith = 'ships-with-hg-core'
>  
> +_partre = re.compile(r'\{(\d+)\}'.encode(u'latin1'))

Maybe this could be br'' ?
Augie Fackler - March 7, 2017, 7:18 p.m.
> On Mar 7, 2017, at 9:03 AM, Yuya Nishihara <yuya@tcha.org> wrote:
> 
>> diff --git a/hgext/schemes.py b/hgext/schemes.py
>> --- a/hgext/schemes.py
>> +++ b/hgext/schemes.py
>> @@ -63,6 +63,7 @@ command = cmdutil.command(cmdtable)
>> # leave the attribute unspecified.
>> testedwith = 'ships-with-hg-core'
>> 
>> +_partre = re.compile(r'\{(\d+)\}'.encode(u'latin1'))
> 
> Maybe this could be br'' ?

Very likely it should be. I just was doing enough tap dancing to get a little further on Python 3, hopefully the end of this series will help us make faster progress now that we have --debugger working in Python 3.

Patch

diff --git a/hgext/schemes.py b/hgext/schemes.py
--- a/hgext/schemes.py
+++ b/hgext/schemes.py
@@ -63,6 +63,7 @@  command = cmdutil.command(cmdtable)
 # leave the attribute unspecified.
 testedwith = 'ships-with-hg-core'
 
+_partre = re.compile(r'\{(\d+)\}'.encode(u'latin1'))
 
 class ShortRepository(object):
     def __init__(self, url, scheme, templater):
@@ -70,7 +71,7 @@  class ShortRepository(object):
         self.templater = templater
         self.url = url
         try:
-            self.parts = max(map(int, re.findall(r'\{(\d+)\}', self.url)))
+            self.parts = max(map(int, _partre.findall(self.url)))
         except ValueError:
             self.parts = 0