Patchwork [2,of,3] py3: appease urllib.request.pathname2url() with a str in Windows

login
register
mail settings
Submitter Matt Harbison
Date Oct. 14, 2018, 4:41 p.m.
Message ID <8b25e88b588d5be2b6a5.1539535314@Envy>
Download mbox | patch
Permalink /patch/36011/
State Accepted
Headers show

Comments

Matt Harbison - Oct. 14, 2018, 4:41 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1539492655 14400
#      Sun Oct 14 00:50:55 2018 -0400
# Node ID 8b25e88b588d5be2b6a511d4f76e3c0230122e10
# Parent  edf769c43bbb10048dceed4cc2ddd46197943ff3
py3: appease urllib.request.pathname2url() with a str in Windows

This fixes test-extdata.t on Windows.  Presumably url2pathname() needs a similar
fix, but that's only used in svn conversions, and I don't have svn installed.
Yuya Nishihara - Oct. 15, 2018, 6:03 a.m.
On Sun, 14 Oct 2018 12:41:54 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1539492655 14400
> #      Sun Oct 14 00:50:55 2018 -0400
> # Node ID 8b25e88b588d5be2b6a511d4f76e3c0230122e10
> # Parent  edf769c43bbb10048dceed4cc2ddd46197943ff3
> py3: appease urllib.request.pathname2url() with a str in Windows
> 
> This fixes test-extdata.t on Windows.  Presumably url2pathname() needs a similar
> fix, but that's only used in svn conversions, and I don't have svn installed.
> 
> diff --git a/mercurial/url.py b/mercurial/url.py
> --- a/mercurial/url.py
> +++ b/mercurial/url.py
> @@ -598,7 +598,8 @@ def open(ui, url_, data=None):
>          url_, authinfo = u.authinfo()
>      else:
>          path = util.normpath(os.path.abspath(url_))
> -        url_ = 'file://' + pycompat.bytesurl(urlreq.pathname2url(path))
> +        p2url = urlreq.pathname2url
> +        url_ = 'file://' + pycompat.bytesurl(p2url(encoding.tonativestr(path)))

Maybe vendor nturl2path.py to make it bytes safe and call our
urllibcompat.quote()?

I think it's better to not do lossy encoding conversion here, but I have
no idea to get around the unicode bytes dance in nturl2path ->
urllib.parse.quote() -> quote_from_bytes().

Patch

diff --git a/mercurial/url.py b/mercurial/url.py
--- a/mercurial/url.py
+++ b/mercurial/url.py
@@ -598,7 +598,8 @@  def open(ui, url_, data=None):
         url_, authinfo = u.authinfo()
     else:
         path = util.normpath(os.path.abspath(url_))
-        url_ = 'file://' + pycompat.bytesurl(urlreq.pathname2url(path))
+        p2url = urlreq.pathname2url
+        url_ = 'file://' + pycompat.bytesurl(p2url(encoding.tonativestr(path)))
         authinfo = None
     return opener(ui, authinfo).open(pycompat.strurl(url_), data)