Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two small fixes for improved Python 3 support #2996

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions boto/auth.py
Expand Up @@ -750,7 +750,7 @@ def presign(self, req, expires, iso_date=None):
headers_to_sign = self.headers_to_sign(req)
l = sorted(['%s' % n.lower().strip() for n in headers_to_sign])
params['X-Amz-SignedHeaders'] = ';'.join(l)

req.params.update(params)

cr = self.canonical_request(req)
Expand Down Expand Up @@ -876,8 +876,7 @@ def __init__(self, *args, **kw):
def _calc_signature(self, params, *args):
boto.log.debug('using _calc_signature_1')
hmac = self._get_hmac()
keys = params.keys()
keys.sort(cmp=lambda x, y: cmp(x.lower(), y.lower()))
keys = sorted(params, key=lambda val: val.lower())
pairs = []
for key in keys:
hmac.update(key.encode('utf-8'))
Expand Down
12 changes: 7 additions & 5 deletions boto/fps/connection.py
Expand Up @@ -21,8 +21,10 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

import urllib
import uuid

from six.moves import urllib

from boto.connection import AWSQueryConnection
from boto.fps.exception import ResponseErrorFactory
from boto.fps.response import ResponseFactory
Expand All @@ -42,7 +44,7 @@ def add_attrs_from(func, to):
def complex_amounts(*fields):
def decorator(func):
def wrapper(self, *args, **kw):
for field in filter(kw.has_key, fields):
for field in (i for i in fields if i in kw):
amount = kw.pop(field)
kw[field + '.Value'] = getattr(amount, 'Value', str(amount))
kw[field + '.CurrencyCode'] = getattr(amount, 'CurrencyCode',
Expand All @@ -59,8 +61,8 @@ def requires(*groups):
def decorator(func):

def wrapper(*args, **kw):
hasgroup = lambda x: len(x) == len(filter(kw.has_key, x))
if 1 != len(filter(hasgroup, groups)):
hasgroup = lambda x: len(x) == len([i for i in x if i in kw])
if 1 != len(list(filter(hasgroup, groups))):
message = ' OR '.join(['+'.join(g) for g in groups])
message = "{0} requires {1} argument(s)" \
"".format(getattr(func, 'action', 'Method'), message)
Expand Down Expand Up @@ -212,7 +214,7 @@ def cbui_url(self, **kw):
kw.setdefault('callerKey', self.aws_access_key_id)

safestr = lambda x: x is not None and str(x) or ''
safequote = lambda x: urllib.quote(safestr(x), safe='~')
safequote = lambda x: urllib.parse.quote(safestr(x), safe='~')
payload = sorted([(k, safequote(v)) for k, v in kw.items()])

encoded = lambda p: '&'.join([k + '=' + v for k, v in p])
Expand Down
2 changes: 1 addition & 1 deletion boto/mturk/connection.py
Expand Up @@ -844,7 +844,7 @@ def _process_response(self, response, marker_elems=None):
body = response.read()
if self.debug == 2:
print(body)
if '<Errors>' not in body:
if b'<Errors>' not in body:
rs = ResultSet(marker_elems)
h = handler.XmlHandler(rs, self)
xml.sax.parseString(body, h)
Expand Down