Permalink
Browse files

Merge branch 'gholms-futureproof' into neo

  • Loading branch information...
2 parents 99e06a5 + c6e06d6 commit 5aa93b79df6721f4c35b577f4e32b3ae21314bfd @garnaat garnaat committed Mar 27, 2012
Showing with 1,057 additions and 996 deletions.
  1. +2 −2 boto/__init__.py
  2. +28 −52 boto/auth.py
  3. +1 −1 boto/auth_handler.py
  4. +1 −1 boto/cloudformation/__init__.py
  5. +7 −10 boto/cloudformation/connection.py
  6. +1 −1 boto/cloudfront/origin.py
  7. +156 −0 boto/compat.py
  8. +24 −30 boto/connection.py
  9. +16 −18 boto/dynamodb/layer1.py
  10. +3 −2 boto/dynamodb/types.py
  11. +2 −2 boto/ec2/autoscale/__init__.py
  12. +4 −4 boto/ec2/buyreservation.py
  13. +3 −5 boto/ec2/cloudwatch/__init__.py
  14. +3 −7 boto/ec2/cloudwatch/alarm.py
  15. +2 −3 boto/ec2/connection.py
  16. +8 −8 boto/ec2/elb/loadbalancer.py
  17. +3 −3 boto/ec2/image.py
  18. +1 −1 boto/ec2/keypair.py
  19. +0 −9 boto/ec2/reservedinstance.py
  20. +2 −2 boto/ec2/snapshot.py
  21. +2 −2 boto/ecs/item.py
  22. +3 −3 boto/emr/__init__.py
  23. +12 −13 boto/emr/connection.py
  24. +6 −6 boto/exception.py
  25. +3 −3 boto/file/__init__.py
  26. +1 −1 boto/file/bucket.py
  27. +1 −1 boto/file/connection.py
  28. +3 −2 boto/file/key.py
  29. +6 −7 boto/fps/connection.py
  30. +2 −2 boto/gs/acl.py
  31. +3 −3 boto/gs/key.py
  32. +18 −19 boto/gs/resumable_upload_handler.py
  33. +6 −6 boto/https_connection.py
  34. +1 −1 boto/iam/__init__.py
  35. +1 −1 boto/jsonresponse.py
  36. +10 −9 boto/manage/cmdshell.py
  37. +5 −5 boto/manage/propget.py
  38. +21 −20 boto/manage/server.py
  39. +3 −2 boto/manage/task.py
  40. +14 −14 boto/manage/test_manage.py
  41. +8 −8 boto/manage/volume.py
  42. +0 −1 boto/mashups/server.py
  43. +4 −3 boto/mturk/connection.py
  44. +3 −6 boto/provider.py
  45. +1 −1 boto/pyami/bootstrap.py
  46. +14 −24 boto/pyami/config.py
  47. +1 −1 boto/pyami/installers/ubuntu/ebs.py
  48. +11 −11 boto/pyami/launch_ami.py
  49. +1 −1 boto/pyami/startup.py
  50. +0 −1 boto/rds/__init__.py
  51. +10 −21 boto/rds/parametergroup.py
  52. +15 −15 boto/roboto/awsqueryrequest.py
  53. +5 −4 boto/roboto/awsqueryservice.py
  54. +1 −1 boto/route53/__init__.py
  55. +6 −6 boto/route53/connection.py
  56. +11 −11 boto/s3/bucket.py
  57. +8 −8 boto/s3/bucketlogging.py
  58. +7 −6 boto/s3/connection.py
  59. +14 −19 boto/s3/key.py
  60. +2 −2 boto/s3/multipart.py
  61. +10 −11 boto/s3/resumable_download_handler.py
  62. +1 −1 boto/sdb/__init__.py
  63. +4 −6 boto/sdb/connection.py
  64. +3 −1 boto/sdb/db/blob.py
  65. +4 −4 boto/sdb/db/key.py
  66. +4 −4 boto/sdb/db/manager/__init__.py
  67. +5 −5 boto/sdb/db/manager/pgmanager.py
  68. +12 −12 boto/sdb/db/manager/sdbmanager.py
  69. +4 −4 boto/sdb/db/manager/xmlmanager.py
  70. +4 −4 boto/sdb/db/model.py
  71. +26 −26 boto/sdb/db/property.py
  72. +6 −6 boto/sdb/db/sequence.py
  73. +39 −37 boto/sdb/domain.py
  74. +1 −1 boto/sdb/item.py
  75. +3 −4 boto/services/result.py
  76. +2 −2 boto/services/service.py
  77. +1 −1 boto/ses/__init__.py
  78. +2 −1 boto/ses/connection.py
  79. +1 −1 boto/sns/__init__.py
  80. +16 −18 boto/sns/connection.py
  81. +1 −1 boto/sqs/__init__.py
  82. +3 −6 boto/sqs/jsonmessage.py
  83. +6 −4 boto/sqs/message.py
  84. +4 −4 boto/sqs/queue.py
  85. +1 −1 boto/sts/__init__.py
  86. +1 −1 boto/sts/connection.py
  87. +5 −7 boto/sts/credentials.py
  88. +33 −37 boto/swf/layer1.py
  89. +32 −44 boto/utils.py
  90. +1 −1 boto/vpc/dhcpoptions.py
  91. +1 −1 docs/source/conf.py
  92. +2 −2 tests/autoscale/test_connection.py
  93. +22 −21 tests/cloudfront/test_signed_urls.py
  94. +2 −2 tests/db/test_lists.py
  95. +1 −1 tests/db/test_query.py
  96. +7 −7 tests/db/test_sequence.py
  97. +5 −5 tests/devpay/test_s3.py
  98. +3 −3 tests/dynamodb/test_layer1.py
  99. +10 −8 tests/dynamodb/test_layer2.py
  100. +2 −2 tests/ec2/cloudwatch/test_connection.py
  101. +5 −5 tests/ec2/test_connection.py
  102. +1 −1 tests/emr/test_emr_responses.py
  103. +24 −24 tests/mturk/_init_environment.py
  104. +5 −5 tests/mturk/all_tests.py
  105. +9 −9 tests/mturk/cleanup_tests.py
  106. +44 −44 tests/mturk/common.py
  107. +1 −1 tests/mturk/create_hit_external.py
  108. +21 −21 tests/mturk/create_hit_test.py
  109. +1 −1 tests/mturk/create_hit_with_qualifications.py
  110. +27 −27 tests/mturk/hit_persistence.py
  111. +3 −3 tests/mturk/selenium_support.py
  112. +11 −11 tests/mturk/test_disable_hit.py
  113. +3 −3 tests/s3/mock_storage_service.py
  114. +1 −1 tests/s3/test_bucket.py
  115. +9 −9 tests/s3/test_connection.py
  116. +2 −2 tests/s3/test_encryption.py
  117. +3 −3 tests/s3/test_gsconnection.py
  118. +8 −8 tests/s3/test_key.py
  119. +5 −4 tests/s3/test_mfa.py
  120. +2 −2 tests/s3/test_multidelete.py
  121. +9 −9 tests/s3/test_multipart.py
  122. +7 −9 tests/s3/test_pool.py
  123. +14 −14 tests/s3/test_resumable_downloads.py
  124. +19 −19 tests/s3/test_resumable_uploads.py
  125. +7 −7 tests/s3/test_versioning.py
  126. +3 −3 tests/sdb/test_connection.py
  127. +8 −8 tests/sqs/test_connection.py
  128. +2 −2 tests/sts/test_session_token.py
  129. +3 −3 tests/test.py
View
@@ -29,8 +29,8 @@
import os, re, sys
import logging
import logging.config
-import urlparse
from boto.exception import InvalidUriError
+import boto.compat as compat
__version__ = '2.3.0'
Version = __version__ # for backware compatibility
@@ -391,7 +391,7 @@ def connect_ec2_endpoint(url, aws_access_key_id=None, aws_secret_access_key=None
"""
from boto.ec2.regioninfo import RegionInfo
- purl = urlparse.urlparse(url)
+ purl = compat.urlparse(url)
kwargs['port'] = purl.port
kwargs['host'] = purl.hostname
kwargs['path'] = purl.path
View
@@ -1,5 +1,6 @@
# Copyright 2010 Google Inc.
-# Copyright (c) 2011 Mitch Garnaat http://garnaat.org/
+# Copyright (c) 2012 Mitch Garnaat http://garnaat.org/
+# Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# Copyright (c) 2011, Eucalyptus Systems, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a
@@ -34,40 +35,11 @@
import boto.utils
import hmac
import sys
-import urllib
+import boto.compat as compat
from email.utils import formatdate
from boto.auth_handler import AuthHandler
from boto.exception import BotoClientError
-#
-# the following is necessary because of the incompatibilities
-# between Python 2.4, 2.5, and 2.6 as well as the fact that some
-# people running 2.4 have installed hashlib as a separate module
-# this fix was provided by boto user mccormix.
-# see: http://code.google.com/p/boto/issues/detail?id=172
-# for more details.
-#
-try:
- from hashlib import sha1 as sha
- from hashlib import sha256 as sha256
-
- if sys.version[:3] == "2.4":
- # we are using an hmac that expects a .new() method.
- class Faker:
- def __init__(self, which):
- self.which = which
- self.digest_size = self.which().digest_size
-
- def new(self, *args, **kwargs):
- return self.which(*args, **kwargs)
-
- sha = Faker(sha)
- sha256 = Faker(sha256)
-
-except ImportError:
- import sha
- sha256 = None
-
class HmacKeys(object):
"""Key based Auth handler helper."""
@@ -79,10 +51,10 @@ def __init__(self, host, config, provider):
def update_provider(self, provider):
self._provider = provider
- self._hmac = hmac.new(self._provider.secret_key, digestmod=sha)
- if sha256:
- self._hmac_256 = hmac.new(self._provider.secret_key,
- digestmod=sha256)
+ sk = self._provider.secret_key.encode('utf-8')
+ self._hmac = hmac.new(sk, digestmod=compat.sha)
+ if compat.sha256:
+ self._hmac_256 = hmac.new(sk, digestmod=compat.sha256)
else:
self._hmac_256 = None
@@ -97,8 +69,10 @@ def sign_string(self, string_to_sign):
hmac = self._hmac_256.copy()
else:
hmac = self._hmac.copy()
+ if not isinstance(string_to_sign, compat.binary_type):
+ string_to_sign = string_to_sign.encode('utf-8')
hmac.update(string_to_sign)
- return base64.encodestring(hmac.digest()).strip()
+ return base64.b64encode(hmac.digest()).strip().decode('utf-8')
class AnonAuthHandler(AuthHandler, HmacKeys):
"""
@@ -127,7 +101,7 @@ def add_auth(self, http_request, **kwargs):
headers = http_request.headers
method = http_request.method
auth_path = http_request.auth_path
- if not headers.has_key('Date'):
+ if 'Date' not in headers:
headers['Date'] = formatdate(usegmt=True)
if self._provider.security_token:
@@ -156,7 +130,7 @@ def __init__(self, host, config, provider):
def add_auth(self, http_request, **kwargs):
headers = http_request.headers
- if not headers.has_key('Date'):
+ if 'Date' not in headers:
headers['Date'] = formatdate(usegmt=True)
b64_hmac = self.sign_string(headers['Date'])
@@ -176,7 +150,7 @@ def __init__(self, host, config, provider):
def add_auth(self, http_request, **kwargs):
headers = http_request.headers
- if not headers.has_key('Date'):
+ if 'Date' not in headers:
headers['Date'] = formatdate(usegmt=True)
b64_hmac = self.sign_string(headers['Date'])
@@ -252,7 +226,8 @@ def add_auth(self, req, **kwargs):
req.headers['X-Amz-Security-Token'] = self._provider.security_token
string_to_sign, headers_to_sign = self.string_to_sign(req)
boto.log.debug('StringToSign:\n%s' % string_to_sign)
- hash_value = sha256(string_to_sign).digest()
+ string_to_sign = string_to_sign.encode('utf-8')
+ hash_value = compat.sha256(string_to_sign).digest()
b64_hmac = self.sign_string(hash_value)
s = "AWS3 AWSAccessKeyId=%s," % self._provider.access_key
s += "Algorithm=%s," % self.algorithm()
@@ -279,15 +254,15 @@ def add_auth(self, http_request, **kwargs):
boto.log.debug('query_string: %s Signature: %s' % (qs, signature))
if http_request.method == 'POST':
headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
- http_request.body = qs + '&Signature=' + urllib.quote_plus(signature)
+ http_request.body = qs + '&Signature=' + compat.quote_plus(signature)
http_request.headers['Content-Length'] = str(len(http_request.body))
else:
http_request.body = ''
# if this is a retried request, the qs from the previous try will
# already be there, we need to get rid of that and rebuild it
http_request.path = http_request.path.split('?')[0]
http_request.path = (http_request.path + '?' + qs +
- '&Signature=' + urllib.quote_plus(signature))
+ '&Signature=' + compat.quote_plus(signature))
class QuerySignatureV0AuthHandler(QuerySignatureHelper, AuthHandler):
"""Provides Signature V0 Signing"""
@@ -299,13 +274,13 @@ def _calc_signature(self, params, *args):
boto.log.debug('using _calc_signature_0')
hmac = self._hmac.copy()
s = params['Action'] + params['Timestamp']
+ s = s.encode('utf-8')
hmac.update(s)
- keys = params.keys()
- keys.sort(cmp = lambda x, y: cmp(x.lower(), y.lower()))
+ keys = sorted(params, key = str.lower)
pairs = []
for key in keys:
val = boto.utils.get_utf8_value(params[key])
- pairs.append(key + '=' + urllib.quote(val))
+ pairs.append(key + '=' + compat.quote(val))
qs = '&'.join(pairs)
return (qs, base64.b64encode(hmac.digest()))
@@ -320,14 +295,15 @@ class QuerySignatureV1AuthHandler(QuerySignatureHelper, AuthHandler):
def _calc_signature(self, params, *args):
boto.log.debug('using _calc_signature_1')
hmac = self._hmac.copy()
- keys = params.keys()
- keys.sort(cmp = lambda x, y: cmp(x.lower(), y.lower()))
+ keys = sorted(params, key = str.lower)
pairs = []
for key in keys:
+ key = key.encode('utf-8')
hmac.update(key)
val = boto.utils.get_utf8_value(params[key])
+ val = val.encode('utf-8')
hmac.update(val)
- pairs.append(key + '=' + urllib.quote(val))
+ pairs.append(key + '=' + compat.quote(val))
qs = '&'.join(pairs)
return (qs, base64.b64encode(hmac.digest()))
@@ -349,17 +325,17 @@ def _calc_signature(self, params, verb, path, server_name):
params['SignatureMethod'] = 'HmacSHA1'
if self._provider.security_token:
params['SecurityToken'] = self._provider.security_token
- keys = params.keys()
- keys.sort()
+ keys = sorted(params)
pairs = []
for key in keys:
val = boto.utils.get_utf8_value(params[key])
- pairs.append(urllib.quote(key, safe='') + '=' +
- urllib.quote(val, safe='-_~'))
+ pairs.append(compat.quote(key, safe='') + '=' +
+ compat.quote(val, safe='-_~'))
qs = '&'.join(pairs)
boto.log.debug('query string: %s' % qs)
string_to_sign += qs
boto.log.debug('string_to_sign: %s' % string_to_sign)
+ string_to_sign = string_to_sign.encode('utf-8')
hmac.update(string_to_sign)
b64 = base64.b64encode(hmac.digest())
boto.log.debug('len(b64)=%d' % len(b64))
View
@@ -23,7 +23,7 @@
Defines an interface which all Auth handlers need to implement.
"""
-from plugin import Plugin
+from .plugin import Plugin
class NotReadyToAuthenticate(Exception):
pass
@@ -22,4 +22,4 @@
# this is here for backward compatibility
# originally, the SNSConnection class was defined here
-from connection import CloudFormationConnection
+from .connection import CloudFormationConnection
@@ -19,17 +19,14 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
-try:
- import simplejson as json
-except:
- import json
-
import boto
from boto.cloudformation.stack import Stack, StackSummary, StackEvent
from boto.cloudformation.stack import StackResource, StackResourceSummary
from boto.cloudformation.template import Template
from boto.connection import AWSQueryConnection
from boto.regioninfo import RegionInfo
+import boto.compat as compat
+
class CloudFormationConnection(AWSQueryConnection):
@@ -135,7 +132,7 @@ def create_stack(self, stack_name, template_body=None, template_url=None,
response = self.make_request('CreateStack', params, '/', 'POST')
body = response.read()
if response.status == 200:
- body = json.loads(body)
+ body = compat.json.loads(body)
return body['CreateStackResponse']['CreateStackResult']['StackId']
else:
boto.log.error('%s %s' % (response.status, response.reason))
@@ -202,7 +199,7 @@ def update_stack(self, stack_name, template_body=None, template_url=None,
response = self.make_request('UpdateStack', params, '/', 'POST')
body = response.read()
if response.status == 200:
- body = json.loads(body)
+ body = compat.json.loads(body)
return body['UpdateStackResponse']['UpdateStackResult']['StackId']
else:
boto.log.error('%s %s' % (response.status, response.reason))
@@ -215,7 +212,7 @@ def delete_stack(self, stack_name_or_id):
response = self.make_request('DeleteStack', params, '/', 'GET')
body = response.read()
if response.status == 200:
- return json.loads(body)
+ return compat.json.loads(body)
else:
boto.log.error('%s %s' % (response.status, response.reason))
boto.log.error('%s' % body)
@@ -237,7 +234,7 @@ def describe_stack_resource(self, stack_name_or_id, logical_resource_id):
'/', 'GET')
body = response.read()
if response.status == 200:
- return json.loads(body)
+ return compat.json.loads(body)
else:
boto.log.error('%s %s' % (response.status, response.reason))
boto.log.error('%s' % body)
@@ -267,7 +264,7 @@ def get_template(self, stack_name_or_id):
response = self.make_request('GetTemplate', params, '/', 'GET')
body = response.read()
if response.status == 200:
- return json.loads(body)
+ return compat.json.loads(body)
else:
boto.log.error('%s %s' % (response.status, response.reason))
boto.log.error('%s' % body)
@@ -20,7 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
-from identity import OriginAccessIdentity
+from .identity import OriginAccessIdentity
def get_oai_value(origin_access_identity):
if isinstance(origin_access_identity, OriginAccessIdentity):
Oops, something went wrong.

0 comments on commit 5aa93b7

Please sign in to comment.