Patchwork [08,of,10] py3: implement urllib2.request.{get|add|has}_data() functions to use in Py3

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

Comments

Pulkit Goyal - May 6, 2017, 3:01 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1494037207 -19800
#      Sat May 06 07:50:07 2017 +0530
# Node ID 980cc6b0ab20c38bd0d890e1b2701a3bbb73dfb3
# Parent  f1f1acda7bc96ab9d65e1ae263abc1a10fe7c709
py3: implement urllib2.request.{get|add|has}_data() functions to use in Py3

These functions were deprecated in Py3.3. and were removed in Py3.4. The
functions are implemented so that we can use them in Python 3.5.

Related Links: https://goo.gl/wbBrzs
https://goo.gl/YctG1b

Patch

diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -434,3 +434,15 @@ 
 
     urlreq.quote = quote
     urlreq.urlencode = urlencode
+
+def request_has_data(request):
+    '''implementation of urllib2.request.has_data() from Python 2.7'''
+    return request.data is not None
+
+def request_get_data(request):
+    '''implementation of urllib2.request.get_data() from Python 2.7'''
+    return request.data
+
+def request_add_data(request, data):
+    '''implementation of urllib2.request.add_data() from Python 2.7'''
+    request.data = data