summaryrefslogtreecommitdiff
path: root/cloudinit/url_helper.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2015-01-21 17:56:53 -0500
committerBarry Warsaw <barry@python.org>2015-01-21 17:56:53 -0500
commitf895cb12141281702b34da18f2384deb64c881e7 (patch)
tree7a7433752ba1317c370dd3dd815c9ee7331a923b /cloudinit/url_helper.py
parenta64bb4febc79fcf641f6471d8cc00c74ca915f3d (diff)
downloadcloud-init-git-f895cb12141281702b34da18f2384deb64c881e7.tar.gz
Largely merge lp:~harlowja/cloud-init/py2-3 albeit manually because it seemed
to be behind trunk. `tox -e py27` passes full test suite. Now to work on replacing mocker.
Diffstat (limited to 'cloudinit/url_helper.py')
-rw-r--r--cloudinit/url_helper.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/cloudinit/url_helper.py b/cloudinit/url_helper.py
index 3074dd08..62001dff 100644
--- a/cloudinit/url_helper.py
+++ b/cloudinit/url_helper.py
@@ -20,21 +20,29 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import httplib
import time
-import urllib
+
+import six
import requests
from requests import exceptions
-from urlparse import (urlparse, urlunparse)
+from six.moves.urllib.parse import (
+ urlparse, urlunparse,
+ quote as urlquote)
from cloudinit import log as logging
from cloudinit import version
LOG = logging.getLogger(__name__)
-NOT_FOUND = httplib.NOT_FOUND
+if six.PY2:
+ import httplib
+ NOT_FOUND = httplib.NOT_FOUND
+else:
+ import http.client
+ NOT_FOUND = http.client.NOT_FOUND
+
# Check if requests has ssl support (added in requests >= 0.8.8)
SSL_ENABLED = False
@@ -70,7 +78,7 @@ def combine_url(base, *add_ons):
path = url_parsed[2]
if path and not path.endswith("/"):
path += "/"
- path += urllib.quote(str(add_on), safe="/:")
+ path += urlquote(str(add_on), safe="/:")
url_parsed[2] = path
return urlunparse(url_parsed)
@@ -111,7 +119,7 @@ class UrlResponse(object):
@property
def contents(self):
- return self._response.content
+ return self._response.text
@property
def url(self):
@@ -135,7 +143,7 @@ class UrlResponse(object):
return self._response.status_code
def __str__(self):
- return self.contents
+ return self._response.text
class UrlError(IOError):