Permalink
Browse files

Fix test.py imports

Result of first pass of manual merge from branch_master_python3k.

Actually passes SDB tests on both 2.x and 3.x.

Basic S3 operations are now working.

Simple dynamodb requests now working in both versions.
  • Loading branch information...
1 parent 63530ee commit d9b1e1e3601a1a589a972b948457d48d2c063ce4 @gholms gholms committed with garnaat Mar 11, 2012
Showing with 608 additions and 521 deletions.
  1. +2 −2 boto/__init__.py
  2. +23 −18 boto/auth.py
  3. +122 −0 boto/compat.py
  4. +18 −24 boto/connection.py
  5. +1 −0 boto/dynamodb/layer1.py
  6. +3 −2 boto/dynamodb/types.py
  7. +2 −2 boto/ec2/autoscale/__init__.py
  8. +4 −4 boto/ec2/buyreservation.py
  9. +1 −1 boto/ec2/cloudwatch/alarm.py
  10. +1 −2 boto/ec2/connection.py
  11. +8 −8 boto/ec2/elb/loadbalancer.py
  12. +0 −9 boto/ec2/reservedinstance.py
  13. +2 −2 boto/ecs/item.py
  14. +5 −5 boto/emr/connection.py
  15. +3 −2 boto/file/key.py
  16. +4 −5 boto/fps/connection.py
  17. +3 −3 boto/gs/key.py
  18. +12 −13 boto/gs/resumable_upload_handler.py
  19. +6 −6 boto/https_connection.py
  20. +7 −7 boto/manage/cmdshell.py
  21. +5 −5 boto/manage/propget.py
  22. +17 −16 boto/manage/server.py
  23. +3 −2 boto/manage/task.py
  24. +14 −14 boto/manage/test_manage.py
  25. +4 −4 boto/manage/volume.py
  26. +0 −1 boto/mashups/server.py
  27. +2 −1 boto/mturk/connection.py
  28. +1 −4 boto/provider.py
  29. +12 −12 boto/pyami/config.py
  30. +11 −11 boto/pyami/launch_ami.py
  31. +0 −1 boto/rds/__init__.py
  32. +5 −16 boto/rds/parametergroup.py
  33. +10 −10 boto/roboto/awsqueryrequest.py
  34. +4 −3 boto/roboto/awsqueryservice.py
  35. +3 −3 boto/route53/connection.py
  36. +11 −11 boto/s3/bucket.py
  37. +8 −8 boto/s3/bucketlogging.py
  38. +7 −6 boto/s3/connection.py
  39. +11 −16 boto/s3/key.py
  40. +6 −7 boto/s3/resumable_download_handler.py
  41. +3 −5 boto/sdb/connection.py
  42. +3 −1 boto/sdb/db/blob.py
  43. +1 −1 boto/sdb/db/manager/xmlmanager.py
  44. +38 −36 boto/sdb/domain.py
  45. +1 −2 boto/services/result.py
  46. +2 −1 boto/ses/connection.py
  47. +2 −2 boto/sqs/message.py
  48. +4 −4 boto/sqs/queue.py
  49. +29 −41 boto/utils.py
  50. +2 −2 tests/autoscale/test_connection.py
  51. +22 −21 tests/cloudfront/test_signed_urls.py
  52. +2 −2 tests/db/test_lists.py
  53. +1 −1 tests/db/test_query.py
  54. +7 −7 tests/db/test_sequence.py
  55. +5 −5 tests/devpay/test_s3.py
  56. +2 −2 tests/dynamodb/test_layer1.py
  57. +5 −3 tests/dynamodb/test_layer2.py
  58. +2 −2 tests/ec2/cloudwatch/test_connection.py
  59. +3 −3 tests/ec2/test_connection.py
  60. +1 −1 tests/emr/test_emr_responses.py
  61. +8 −8 tests/mturk/cleanup_tests.py
  62. +1 −1 tests/mturk/create_hit_with_qualifications.py
  63. +2 −2 tests/mturk/selenium_support.py
  64. +3 −3 tests/s3/mock_storage_service.py
  65. +1 −1 tests/s3/test_bucket.py
  66. +9 −9 tests/s3/test_connection.py
  67. +2 −2 tests/s3/test_encryption.py
  68. +3 −3 tests/s3/test_gsconnection.py
  69. +8 −8 tests/s3/test_key.py
  70. +5 −4 tests/s3/test_mfa.py
  71. +2 −2 tests/s3/test_multidelete.py
  72. +9 −9 tests/s3/test_multipart.py
  73. +7 −9 tests/s3/test_pool.py
  74. +8 −8 tests/s3/test_resumable_downloads.py
  75. +8 −8 tests/s3/test_resumable_uploads.py
  76. +6 −6 tests/s3/test_versioning.py
  77. +3 −3 tests/sdb/test_connection.py
  78. +2 −2 tests/sqs/test_connection.py
  79. +2 −2 tests/sts/test_session_token.py
  80. +23 −23 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,7 +35,7 @@
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
@@ -79,10 +80,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)
+ sk = self._provider.secret_key.encode('utf-8')
+ self._hmac = hmac.new(sk, digestmod=sha)
if sha256:
- self._hmac_256 = hmac.new(self._provider.secret_key,
- digestmod=sha256)
+ self._hmac_256 = hmac.new(sk, digestmod=sha256)
else:
self._hmac_256 = None
@@ -97,8 +98,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):
"""
@@ -252,6 +255,7 @@ 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)
+ string_to_sign = string_to_sign.encode('utf-8')
hash_value = sha256(string_to_sign).digest()
b64_hmac = self.sign_string(hash_value)
s = "AWS3 AWSAccessKeyId=%s," % self._provider.access_key
@@ -279,15 +283,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 +303,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 +324,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 +354,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
@@ -0,0 +1,122 @@
+# Copyright (c) 2012 Mitch Garnaat http://garnaat.org/
+# Copyright (c) 2012 Amazon.com, Inc. or its affiliates.
+# All Rights Reserved
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish, dis-
+# tribute, sublicense, and/or sell copies of the Software, and to permit
+# persons to whom the Software is furnished to do so, subject to the fol-
+# lowing conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
+# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+#
+import sys
+import os
+import types
+
+# True if we are running on Python 3.
+PY3 = sys.version_info[0] == 3
+
+if PY3:
+ string_types = str,
+ integer_types = int,
+ class_types = type,
+ text_type = str
+ binary_type = bytes
+else:
+ string_types = basestring,
+ integer_types = (int, long)
+ class_types = (type, types.ClassType)
+ text_type = unicode
+ binary_type = str
+
+try:
+ import urllib.parse as urlparse
+except ImportError:
+ import urlparse
+
+try:
+ from urllib.parse import quote, quote_plus, unquote
+except ImportError:
+ from urllib import quote, quote_plus, unquote
+
+try:
+ from urllib.request import urlopen, Request, build_opener, install_opener
+except ImportError:
+ from urllib2 import urlopen, Request
+
+try:
+ from urllib.request import HTTPPasswordMgrWithDefaultRealm
+except ImportError:
+ from urllib2 import HTTPPasswordMgrWithDefaultRealm
+
+try:
+ from urllib.request import HTTPBasicAuthHandler, HTTPError
+except ImportError:
+ from urllib2 import HTTPBasicAuthHandler
+
+try:
+ from hashlib import md5
+except ImportError:
+ from md5 import md5
+
+try:
+ import http.client as httplib
+except ImportError:
+ import httplib
+
+try:
+ import configparser
+except ImportError:
+ import ConfigParser as configparser
+
+if PY3:
+ import io
+ StringIO = io.StringIO
+else:
+ import StringIO
+ StringIO = StringIO.StringIO
+
+if PY3:
+ raw_input = input
+else:
+ raw_input = raw_input
+
+try:
+ # Python 3.x
+ from email.mime.multipart import MIMEMultipart
+ from email.mime.base import MIMEBase
+ from email.mime.text import MIMEText
+ from email.utils import formatdate
+ import email.encoders as Encoders
+ unicode = str
+except ImportError:
+ # Python 2.x
+ from email.MIMEMultipart import MIMEMultipart
+ from email.MIMEBase import MIMEBase
+ from email.MIMEText import MIMEText
+ from email.utils import formatdate
+ from email import Encoders
+
+
+def on_appengine():
+ return all(key in os.environ for key in ('USER_IS_ADMIN',
+ 'CURRENT_VERSION_ID',
+ 'APPLICATION_ID'))
+
+
+def httplib_ssl_hack(port):
+ return ((on_appengine and sys.version[:3] == '2.5') or
+ sys.version.startswith('3') or
+ sys.version[:3] in ('2.6', '2.7')) and port == 443
Oops, something went wrong.

0 comments on commit d9b1e1e

Please sign in to comment.