Patchwork [2,of,9] py3: add a new bytesurl() to convert a str url into bytes

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

Comments

Pulkit Goyal - June 15, 2017, 9:34 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1497553577 -19800
#      Fri Jun 16 00:36:17 2017 +0530
# Node ID 8a4aa371b00bd7a7533459ee6ac8a3a07f0fa98e
# Parent  c860b2b1b6b3cb9464c021167bbd85589e091225
py3: add a new bytesurl() to convert a str url into bytes

Patch

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