Patchwork [1,of,9] py3: add a new strurl() which will convert a bytes url to str

login
register
mail settings
Submitter Pulkit Goyal
Date June 15, 2017, 9:34 p.m.
Message ID <c860b2b1b6b3cb9464c0.1497562483@workspace>
Download mbox | patch
Permalink /patch/21404/
State Accepted
Headers show

Comments

Pulkit Goyal - June 15, 2017, 9:34 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1497553372 -19800
#      Fri Jun 16 00:32:52 2017 +0530
# Node ID c860b2b1b6b3cb9464c021167bbd85589e091225
# Parent  877b74712132f1e2848174ee49490d328282e00d
py3: add a new strurl() which will convert a bytes url to str
Yuya Nishihara - June 16, 2017, 2:03 p.m.
On Fri, 16 Jun 2017 03:04:43 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1497553372 -19800
> #      Fri Jun 16 00:32:52 2017 +0530
> # Node ID c860b2b1b6b3cb9464c021167bbd85589e091225
> # Parent  877b74712132f1e2848174ee49490d328282e00d
> py3: add a new strurl() which will convert a bytes url to str

Queued 1-5, 7, and 9, thanks.
> 
> diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
> --- a/mercurial/pycompat.py
> +++ b/mercurial/pycompat.py
> @@ -149,6 +149,10 @@
>          def __iter__(self):
>              return iterbytestr(bytes.__iter__(self))
>  
> +    def strurl(url):
> +        """Converts a bytes url back to str"""
> +        return url.decode(u'ascii')

I've moved this next to sysstr() so the order matches with py2 block.

> @@ -244,6 +248,7 @@
>      iterbytestr = iter
>      sysbytes = identity
>      sysstr = identity
> +    strurl = identity

Patch

diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -149,6 +149,10 @@ 
         def __iter__(self):
             return iterbytestr(bytes.__iter__(self))
 
+    def strurl(url):
+        """Converts a bytes url back to str"""
+        return url.decode(u'ascii')
+
     def iterbytestr(s):
         """Iterate bytes as if it were a str object of Python 2"""
         return map(bytechr, s)
@@ -244,6 +248,7 @@ 
     iterbytestr = iter
     sysbytes = identity
     sysstr = identity
+    strurl = identity
 
     # this can't be parsed on Python 3
     exec('def raisewithtb(exc, tb):\n'