Drew Smathers has proposed merging lp:~djfroofy/txaws/640098-amazon-headers into lp:txaws.
Requested reviews: txAWS Developers (txaws-dev) Related bugs: #640098 s3 client should allow passing aws-specific headers https://bugs.launchpad.net/bugs/640098 This allows passing amazon headers (e.g. {'acl':'public-read'}) through s3 client put_object(). -- https://code.launchpad.net/~djfroofy/txaws/640098-amazon-headers/+merge/35880 Your team txAWS Developers is requested to review the proposed merge of lp:~djfroofy/txaws/640098-amazon-headers into lp:txaws.
=== modified file 'txaws/s3/client.py' --- txaws/s3/client.py 2009-11-23 00:55:44 +0000 +++ txaws/s3/client.py 2010-09-17 20:53:26 +0000 @@ -178,7 +178,7 @@ common_prefixes) def put_object(self, bucket, object_name, data, content_type=None, - metadata={}): + metadata={}, amz_headers={}): """ Put an object in a bucket. @@ -187,7 +187,7 @@ query = self.query_factory( action="PUT", creds=self.creds, endpoint=self.endpoint, bucket=bucket, object_name=object_name, data=data, - content_type=content_type, metadata=metadata) + content_type=content_type, metadata=metadata, amz_headers=amz_headers) return query.submit() def get_object(self, bucket, object_name): @@ -225,13 +225,14 @@ """A query for submission to the S3 service.""" def __init__(self, bucket=None, object_name=None, data="", - content_type=None, metadata={}, *args, **kwargs): + content_type=None, metadata={}, amz_headers={}, *args, **kwargs): super(Query, self).__init__(*args, **kwargs) self.bucket = bucket self.object_name = object_name self.data = data self.content_type = content_type self.metadata = metadata + self.amz_headers = amz_headers self.date = datetimeToString() if not self.endpoint or not self.endpoint.host: self.endpoint = AWSServiceEndpoint(S3_ENDPOINT) @@ -257,6 +258,8 @@ "Date": self.date} for key, value in self.metadata.iteritems(): headers["x-amz-meta-" + key] = value + for key, value in self.amz_headers.iteritems(): + headers["x-amz-" + key] = value # Before we check if the content type is set, let's see if we can set # it by guessing the the mimetype. self.set_content_type() === modified file 'txaws/s3/tests/test_client.py' --- txaws/s3/tests/test_client.py 2009-11-23 00:55:44 +0000 +++ txaws/s3/tests/test_client.py 2010-09-17 20:53:26 +0000 @@ -202,11 +202,12 @@ def __init__(query, action, creds, endpoint, bucket=None, object_name=None, data=None, content_type=None, - metadata=None): + metadata=None, amz_headers=None): super(StubQuery, query).__init__( action=action, creds=creds, bucket=bucket, object_name=object_name, data=data, - content_type=content_type, metadata=metadata) + content_type=content_type, metadata=metadata, + amz_headers=amz_headers) self.assertEqual(action, "PUT") self.assertEqual(creds.access_key, "foo") self.assertEqual(creds.secret_key, "bar") @@ -215,6 +216,7 @@ self.assertEqual(query.data, "some data") self.assertEqual(query.content_type, "text/plain") self.assertEqual(query.metadata, {"key": "some meta data"}) + self.assertEqual(query.amz_headers, {"acl": "public-read"}) def submit(query): return succeed(None) @@ -223,7 +225,7 @@ s3 = client.S3Client(creds, query_factory=StubQuery) return s3.put_object( "mybucket", "objectname", "some data", content_type="text/plain", - metadata={"key": "some meta data"}) + metadata={"key": "some meta data"}, amz_headers={'acl':'public-read'}) def test_get_object(self): @@ -231,7 +233,7 @@ def __init__(query, action, creds, endpoint, bucket=None, object_name=None, data=None, content_type=None, - metadata=None): + metadata=None, amz_headers=None): super(StubQuery, query).__init__( action=action, creds=creds, bucket=bucket, object_name=object_name, data=data, @@ -400,7 +402,7 @@ request = client.Query( action="PUT", bucket="somebucket", object_name="object/name/here", data=DATA, content_type="text/plain", metadata={"foo": "bar"}, - creds=self.creds, endpoint=self.endpoint) + amz_headers={"acl":"public-read"}, creds=self.creds, endpoint=self.endpoint) request.sign = lambda headers: "TESTINGSIG=" self.assertEqual(request.action, "PUT") headers = request.get_headers() @@ -411,7 +413,8 @@ "Content-Type": "text/plain", "Content-Length": len(DATA), "Content-MD5": DIGEST, - "x-amz-meta-foo": "bar"}) + "x-amz-meta-foo": "bar", + "x-amz-acl": "public-read"}) self.assertEqual(request.data, "objectData") def test_bucket_query(self):
_______________________________________________ Mailing list: https://launchpad.net/~txaws-dev Post to : txaws-dev@lists.launchpad.net Unsubscribe : https://launchpad.net/~txaws-dev More help : https://help.launchpad.net/ListHelp