Patchwork [6,of,9] py3: convert url to str using pycompat.strurl()

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

Comments

Pulkit Goyal - June 15, 2017, 9:34 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1497557909 -19800
#      Fri Jun 16 01:48:29 2017 +0530
# Node ID a7eaba4f05c56f714af870938252ebf7489845f2
# Parent  8c2bdaf9a1901676753ed57df5a99299ded8fa08
py3: convert url to str using pycompat.strurl()

The libraries dealing with opening url online and related stuffs requires url to
be passes as a str.
Yuya Nishihara - June 16, 2017, 2:09 p.m.
On Fri, 16 Jun 2017 03:04:48 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1497557909 -19800
> #      Fri Jun 16 01:48:29 2017 +0530
> # Node ID a7eaba4f05c56f714af870938252ebf7489845f2
> # Parent  8c2bdaf9a1901676753ed57df5a99299ded8fa08
> py3: convert url to str using pycompat.strurl()

> --- a/mercurial/httppeer.py
> +++ b/mercurial/httppeer.py
> @@ -103,6 +103,7 @@
>  
>          self.ui = ui
>          self.ui.debug('using %s\n' % self._url)
> +        self._url = pycompat.strurl(self._url)

It appears we expect bytes self._url several places. Perhaps we'll have to
convert self._url to unicode only when necessary.

> @@ -175,7 +176,7 @@
>              else:
>                  q += sorted(args.items())
>          qs = '?%s' % urlreq.urlencode(q)
> -        cu = "%s%s" % (self._url, qs)
> +        cu = r"%s%s" % (self._url, qs)

It seems wrong to concatenate unicode url and bytes qs.

Patch

diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
--- a/mercurial/httppeer.py
+++ b/mercurial/httppeer.py
@@ -103,6 +103,7 @@ 
 
         self.ui = ui
         self.ui.debug('using %s\n' % self._url)
+        self._url = pycompat.strurl(self._url)
 
         self.urlopener = url.opener(ui, authinfo)
         self.requestbuilder = urlreq.request
@@ -175,7 +176,7 @@ 
             else:
                 q += sorted(args.items())
         qs = '?%s' % urlreq.urlencode(q)
-        cu = "%s%s" % (self._url, qs)
+        cu = r"%s%s" % (self._url, qs)
         size = 0
         if util.safehasattr(data, 'length'):
             size = data.length