Patchwork D890: urllibcompat: new library to help abstract out some python3 urllib2 stuff

login
register
mail settings
Submitter phabricator
Date Oct. 4, 2017, 4:26 p.m.
Message ID <4949ca204c1ece6c2e11289f346f26f8@localhost.localdomain>
Download mbox | patch
Permalink /patch/24505/
State Not Applicable
Headers show

Comments

phabricator - Oct. 4, 2017, 4:26 p.m.
durin42 updated this revision to Diff 2422.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D890?vs=2302&id=2422

REVISION DETAIL
  https://phab.mercurial-scm.org/D890

AFFECTED FILES
  mercurial/urllibcompat.py

CHANGE DETAILS




To: durin42, #hg-reviewers, yuja
Cc: yuja, mercurial-devel

Patch

diff --git a/mercurial/urllibcompat.py b/mercurial/urllibcompat.py
new file mode 100644
--- /dev/null
+++ b/mercurial/urllibcompat.py
@@ -0,0 +1,42 @@ 
+# urllibcompat.py - adapters to ease using urllib2 on Py2 and urllib on Py3
+#
+# Copyright 2017 Google, Inc.
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+from __future__ import absolute_import
+
+from . import pycompat
+
+if pycompat.ispy3:
+
+    def getfullurl(req):
+        return req.full_url
+
+    def gethost(req):
+        return req.host
+
+    def getselector(req):
+        return req.selector
+
+    def getdata(req):
+        return req.data
+
+    def hasdata(req):
+        return req.data is not None
+else:
+
+    def gethost(req):
+        return req.get_host()
+
+    def getselector(req):
+        return req.get_selector()
+
+    def getfullurl(req):
+        return req.get_full_url()
+
+    def getdata(req):
+        return req.get_data()
+
+    def hasdata(req):
+        return req.has_data()