def _verify_headers(headers, contents): assert "Content-length" in headers assert str(len(contents)) == headers['Content-length'] assert "Content-type" in headers assert "Content-md5" in headers content_md5 = aws_md5(contents.encode("ascii")) assert content_md5 == headers['Content-md5'] assert "Authorization" in headers
def __init__(self, bucket=None, key=None, method="GET", headers={}, args=None, data=None, subresource=None): headers = headers.copy() if data and "Content-MD5" not in headers: headers["Content-MD5"] = aws_md5(data) if "Date" not in headers: headers["Date"] = rfc822_fmtdate() if hasattr(bucket, "name"): bucket = bucket.name self.bucket = bucket self.key = key self.method = method self.headers = headers self.args = args self.data = data self.subresource = subresource
def put(self, key, data=None, acl=None, metadata={}, mimetype=None, transformer=None, headers={}): if isinstance(data, unicode): data = data.encode(self.default_encoding) headers = headers.copy() if mimetype: headers["Content-Type"] = str(mimetype) elif "Content-Type" not in headers: headers["Content-Type"] = guess_mimetype(key) headers.update(metadata_headers(metadata)) if acl: headers["X-AMZ-ACL"] = acl if transformer: data = transformer(headers, data) if "Content-Length" not in headers: headers["Content-Length"] = str(len(data)) if "Content-MD5" not in headers: headers["Content-MD5"] = aws_md5(data) s3req = self.request(method="PUT", key=key, data=data, headers=headers) self.send(s3req).close()
def test_aws_md5_fp(self): val = "Hello world!".encode("ascii") eq_(aws_md5(BytesIO(val)), 'hvsmnRkNLIX24EaM7KQqIA==')
def test_aws_md5_lit(self): val = "Hello!".encode("ascii") eq_(aws_md5(val), 'lS0sVtBIWVgzZ0e83ZhZDQ==')