Skip to content

Commit

Permalink
cloudfront module: add backward-compatible support for Python 3.3+
Browse files Browse the repository at this point in the history
  • Loading branch information
felixonmars committed Jul 3, 2014
1 parent 1ac79d0 commit f929e0c
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ At the moment, boto supports:

* Content Delivery

* Amazon CloudFront
* Amazon CloudFront (Python 3)

* Database

Expand Down
12 changes: 6 additions & 6 deletions boto/cloudfront/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _get_all_objects(self, resource, tags, result_set_class=None,
rs_kwargs = result_set_kwargs or dict()
rs = rs_class(tags, **rs_kwargs)
h = handler.XmlHandler(rs, self)
xml.sax.parseString(body, h)
xml.sax.parseString(body.encode('utf-8'), h)
return rs

def _get_info(self, id, resource, dist_class):
Expand All @@ -94,7 +94,7 @@ def _get_info(self, id, resource, dist_class):
if key.lower() == 'etag':
d.etag = response_headers[key]
h = handler.XmlHandler(d, self)
xml.sax.parseString(body, h)
xml.sax.parseString(body.encode('utf-8'), h)
return d

def _get_config(self, id, resource, config_class):
Expand All @@ -107,7 +107,7 @@ def _get_config(self, id, resource, config_class):
d = config_class(connection=self)
d.etag = self.get_etag(response)
h = handler.XmlHandler(d, self)
xml.sax.parseString(body, h)
xml.sax.parseString(body.encode('utf-8'), h)
return d

def _set_config(self, distribution_id, etag, config):
Expand All @@ -134,7 +134,7 @@ def _create_object(self, config, resource, dist_class):
if response.status == 201:
d = dist_class(connection=self)
h = handler.XmlHandler(d, self)
xml.sax.parseString(body, h)
xml.sax.parseString(body.encode('utf-8'), h)
d.etag = self.get_etag(response)
return d
else:
Expand Down Expand Up @@ -257,7 +257,7 @@ def create_invalidation_request(self, distribution_id, paths,
body = response.read()
if response.status == 201:
h = handler.XmlHandler(paths, self)
xml.sax.parseString(body, h)
xml.sax.parseString(body.encode('utf-8'), h)
return paths
else:
raise CloudFrontServerError(response.status, response.reason, body)
Expand All @@ -272,7 +272,7 @@ def invalidation_request_status(self, distribution_id,
if response.status == 200:
paths = InvalidationBatch([])
h = handler.XmlHandler(paths, self)
xml.sax.parseString(body, h)
xml.sax.parseString(body.encode('utf-8'), h)
return paths
else:
raise CloudFrontServerError(response.status, response.reason, body)
Expand Down
4 changes: 2 additions & 2 deletions boto/cloudfront/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import uuid
import base64
import time
from boto.compat import json
from boto.compat import six, json
from boto.cloudfront.identity import OriginAccessIdentity
from boto.cloudfront.object import Object, StreamingObject
from boto.cloudfront.signers import ActiveTrustedSigners, TrustedSigners
Expand Down Expand Up @@ -665,7 +665,7 @@ def _sign_string(message, private_key_file=None, private_key_string=None):
raise ValueError("You must specify one of private_key_file or private_key_string")
# If private_key_file is a file name, open it and read it
if private_key_string is None:
if isinstance(private_key_file, basestring):
if isinstance(private_key_file, six.string_types):
with open(private_key_file, 'r') as file_handle:
private_key_string = file_handle.read()
# Otherwise, treat it like a file
Expand Down
4 changes: 2 additions & 2 deletions boto/cloudfront/invalidation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
# IN THE SOFTWARE.

import uuid
import urllib

from boto.compat import urllib
from boto.resultset import ResultSet


Expand Down Expand Up @@ -71,7 +71,7 @@ def escape(self, p):
"""Escape a path, make sure it begins with a slash and contains no invalid characters"""
if not p[0] == "/":
p = "/%s" % p
return urllib.quote(p)
return urllib.parse.quote(p)

def to_xml(self):
"""Get this batch as XML"""
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Currently Supported Services

* **Content Delivery**

* :doc:`CloudFront <cloudfront_tut>` -- (:doc:`API Reference <ref/cloudfront>`)
* :doc:`CloudFront <cloudfront_tut>` -- (:doc:`API Reference <ref/cloudfront>`) (Python 3)

* **Database**

Expand Down
1 change: 1 addition & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
PY3_WHITELIST = (
'tests/unit/auth',
'tests/unit/beanstalk',
'tests/unit/cloudfront',
'tests/unit/cloudtrail',
'tests/unit/directconnect',
'tests/unit/elasticache',
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/cloudfront/test_signed_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import simplejson as json
except ImportError:
import json
from cStringIO import StringIO
from boto.compat import StringIO
from textwrap import dedent

from boto.cloudfront.distribution import Distribution
Expand Down

0 comments on commit f929e0c

Please sign in to comment.