コード例 #1
0
 def _s3_delete_bulk_request(self, bucket, keys, quiet):
   content = _render_delete_bulk_content(keys, quiet)
   resp = self._s3_request("POST", bucket, None, {"delete":None}, {}, content)
   if resp.status != http.client.OK:
     raise_http_resp_error(resp)
   results = resp.read() #TODO HAS A PAYLOAD, MAYBE NOT BEST READ CANDIDATE.
   return results
コード例 #2
0
 def _s3_copy_request(self, src_bucket, src_key, dst_bucket, dst_key, headers):
   headers['x-amz-copy-source'] = "/%s/%s" % (src_bucket, src_key)
   headers['x-amz-metadata-directive'] = 'REPLACE'
   resp = self._s3_request("PUT", dst_bucket, dst_key, {}, headers, '')
   if resp.status != http.client.OK:
     raise_http_resp_error(resp)
   return (resp.status, resp.getheaders())
コード例 #3
0
 def _s3_list_request(self, bucket, marker=None, prefix=None, max_keys=None):
   args = {}
   if marker:
     args['marker'] = marker
   if prefix:
     args['prefix'] = prefix
   if max_keys:
     args['max-keys'] = str(max_keys)
   resp = self._s3_request("GET", bucket, None, args, {}, '')
   if resp.status != http.client.OK:
     raise_http_resp_error(resp)
   return resp.read() #TODO HAS A PAYLOAD, MAYBE NOT BEST READ CANDIDATE.
コード例 #4
0
 def _s3_put_request(self, bucket, key, data, headers):
   #TODO add abilityo to pass optional Content-MD5 value.
   args = {}
   if isinstance(data, (str, bytes)):
       content_length = len(data)
   elif hasattr(data, 'fileno'):
       fileno = data.fileno()
       filestat = os.fstat(fileno)
       if stat.S_ISREG(filestat.st_mode):
           # Regular file
           content_length = filestat[stat.ST_SIZE]
       else:
           # Special file, size won't be valid. Lets read the data to get value.
           # We have to encode to utf-8 for later hashing.
           data = data.read().encode('utf-8')
           content_length = len(data)
   headers['content-length'] = content_length
   resp = self._s3_request("PUT", bucket, key, args, headers, data)
   if resp.status != http.client.OK:
     raise_http_resp_error(resp)
   resp.read() #NOTE: Should be zero length response. Required to reset the connection.
   return (resp.status, resp.getheaders())
コード例 #5
0
 def _s3_delete_request(self, bucket, key):
   resp = self._s3_request("DELETE", bucket, key, {}, {}, '')
   if resp.status != http.client.NO_CONTENT:
     raise_http_resp_error(resp)
   resp.read() #NOTE: Should be zero size response. Required to reset the connection
   return (resp.status, resp.getheaders())
コード例 #6
0
 def _s3_head_request(self, bucket, key):
   resp = self._s3_request("HEAD", bucket, key, {}, {}, '')
   if resp.status != http.client.OK:
     raise_http_resp_error(resp)
   resp.read() #NOTE: Should be zero size response. Required to reset the connection.
   return (resp.status, resp.getheaders())
コード例 #7
0
 def _s3_get_request(self, bucket, key):
   resp = self._s3_request("GET", bucket, key, {}, {}, '')
   if resp.status != http.client.OK:
     raise_http_resp_error(resp)
   return resp
コード例 #8
0
 def _s3_get_service_request(self):
   resp = self._s3_request("GET", None, None, {}, {}, '')
   if resp.status != http.client.OK:
     raise_http_resp_error(resp)
   return resp.read() #TODO HAS A PAYLOAD, MAYBE NOT BEST READ CANDIDATE.