summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorOleg Pudeyev <oleg@bsdpower.com>2013-02-28 00:34:01 -0500
committerOleg Pudeyev <oleg@bsdpower.com>2013-04-13 19:23:25 -0400
commitfe2cff2222fadf63f96cc9271cff18feaa4e373a (patch)
treece0ae77f5140a828ea1bacd63ee42132d8702bb2 /python
parent643acb2356d8836e55a3c309e1b352b4cc2bcd3b (diff)
downloadpycurl-fe2cff2222fadf63f96cc9271cff18feaa4e373a.tar.gz
Python 3 compatibility: urllib (src)
Diffstat (limited to 'python')
-rw-r--r--python/curl/__init__.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/python/curl/__init__.py b/python/curl/__init__.py
index 3ab019f..fd179fc 100644
--- a/python/curl/__init__.py
+++ b/python/curl/__init__.py
@@ -6,7 +6,11 @@
#
# By Eric S. Raymond, April 2003.
-import os, sys, urllib, exceptions, mimetools, pycurl
+import os, sys, exceptions, mimetools, pycurl
+try:
+ import urllib.parse as urllib_parse
+except ImportError:
+ import urllib as urllib_parse
try:
from cStringIO import StringIO
except ImportError:
@@ -86,14 +90,14 @@ class Curl:
def get(self, url="", params=None):
"Ship a GET request for a specified URL, capture the response."
if params:
- url += "?" + urllib.urlencode(params)
+ url += "?" + urllib_parse.urlencode(params)
self.set_option(pycurl.HTTPGET, 1)
return self.__request(url)
def post(self, cgi, params):
"Ship a POST request to a specified CGI, capture the response."
self.set_option(pycurl.POST, 1)
- self.set_option(pycurl.POSTFIELDS, urllib.urlencode(params))
+ self.set_option(pycurl.POSTFIELDS, urllib_parse.urlencode(params))
return self.__request(cgi)
def body(self):