Patchwork [07,of,10] py3: add compatibilty functions for urllib2.Request.get_{type|host|selector}()

login
register
mail settings
Submitter Pulkit Goyal
Date May 6, 2017, 3:01 a.m.
Message ID <f1f1acda7bc96ab9d65e.1494039679@pulkit-goyal>
Download mbox | patch
Permalink /patch/20475/
State Accepted
Headers show

Comments

Pulkit Goyal - May 6, 2017, 3:01 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1494036346 -19800
#      Sat May 06 07:35:46 2017 +0530
# Node ID f1f1acda7bc96ab9d65e1ae263abc1a10fe7c709
# Parent  6065574d18279e75caa5b1172e4149fc498eccd9
py3: add compatibilty functions for urllib2.Request.get_{type|host|selector}()

urllib2.Request i.e. urllib.request.Request in Py3 had few functions named
get_host(), get_type() and get_selector() which were depreceated in Py3.3
and got removed in Py3.4. This patch adds compatibility functions in
pycompat.py for the same.

Related Link: goo.gl/3quiOR

Patch

diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -215,6 +215,18 @@ 
         ret = shlex.split(s.decode('latin-1'))
         return [a.encode('latin-1') for a in ret]
 
+    def request_type(request):
+        '''returns the scheme of urllib.request.Request class object'''
+        return request.type
+
+    def request_host(request):
+        '''returns the host of urllib.request.Request class object'''
+        return request.host
+
+    def request_selector(request):
+        '''return the URI path of a urllib.request.Request class object'''
+        return request.selector
+
 else:
     import cStringIO
 
@@ -241,6 +253,18 @@ 
     def getoptb(args, shortlist, namelist):
         return getopt.getopt(args, shortlist, namelist)
 
+    def request_type(request):
+        '''returns the scheme of urllib2.Request class object'''
+        return request.get_type()
+
+    def request_host(request):
+        '''returns the host of urllib2.Request class object'''
+        return request.get_host()
+
+    def request_selector(request):
+        '''return the URI path of a urllib2.Request class object'''
+        return request.get_selector()
+
     strkwargs = identity
     byteskwargs = identity