Example #1
0
 def get_headers(self):
     """
     Build the list of headers needed in order to perform S3 operations.
     """
     headers = {
         "Content-Length": len(self.data),
         "Content-MD5": calculate_md5(self.data),
         "Date": self.date
     }
     for key, value in self.metadata.iteritems():
         headers["x-amz-meta-" + key] = value
     for key, values in self.amz_headers.iteritems():
         if isinstance(values, tuple):
             headers["x-amz-" + key] = ",".join(values)
         else:
             headers["x-amz-" + key] = values
     # 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()
     if self.content_type is not None:
         headers["Content-Type"] = self.content_type
     if self.creds is not None:
         signature = self.sign(headers)
         headers["Authorization"] = "AWS %s:%s" % (self.creds.access_key,
                                                   signature)
     return headers
Example #2
0
 def get_headers(self):
     """
     Build the list of headers needed in order to perform S3 operations.
     """
     if self.body_producer:
         content_length = self.body_producer.length
     else:
         content_length = len(self.data)
     headers = {"Content-Length": content_length,
                "Date": self.date}
     if self.body_producer is None:
         headers["Content-MD5"] = calculate_md5(self.data)
     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()
     if self.content_type is not None:
         headers["Content-Type"] = self.content_type
     if self.creds is not None:
         signature = self.sign(headers)
         headers["Authorization"] = "AWS %s:%s" % (
             self.creds.access_key, signature)
     return headers
Example #3
0
 def get_headers(self):
     """
     Build the list of headers needed in order to perform S3 operations.
     """
     headers = {"Content-Length": len(self.data),
                "Content-MD5": calculate_md5(self.data),
                "Date": self.date}
     for key, value in self.metadata.iteritems():
         headers["x-amz-meta-" + key] = value
     for key, values in self.amz_headers.iteritems():
         if isinstance(values, tuple):
             headers["x-amz-" + key] = ",".join(values)
         else:
             headers["x-amz-" + key] = values
     # 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()
     if self.content_type is not None:
         headers["Content-Type"] = self.content_type
     if self.creds is not None:
         signature = self.sign(headers)
         headers["Authorization"] = "AWS %s:%s" % (
             self.creds.access_key, signature)
     return headers
Example #4
0
 def test_content_md5(self):
     self.assertEqual(calculate_md5("somedata"), "rvr3UC1SmUw7AZV2NqPN0g==")