예제 #1
0
 def get_contents_to_file(key, fp, md5=None):
     key.get_contents_to_file(fp)
     if md5 and key.md5 != md5:
         raise S3DataError(
             'MD5 of downloaded did not match given MD5: '
             '%s vs. %s' % (key.md5, md5))
     return key
예제 #2
0
파일: key.py 프로젝트: bopopescu/SparkOpt
 def sender(http_conn, method, path, data, headers):
     http_conn.putrequest(method, path)
     for key in headers:
         http_conn.putheader(key, headers[key])
     http_conn.endheaders()
     fp.seek(0)
     save_debug = self.bucket.connection.debug
     self.bucket.connection.debug = 0
     if cb:
         if num_cb > 2:
             cb_count = self.size / self.BufferSize / (num_cb - 2)
         elif num_cb < 0:
             cb_count = -1
         else:
             cb_count = 0
         i = total_bytes = 0
         cb(total_bytes, self.size)
     l = fp.read(self.BufferSize)
     while len(l) > 0:
         http_conn.send(l)
         if cb:
             total_bytes += len(l)
             i += 1
             if i == cb_count or cb_count == -1:
                 cb(total_bytes, self.size)
                 i = 0
         l = fp.read(self.BufferSize)
     if cb:
         cb(total_bytes, self.size)
     response = http_conn.getresponse()
     body = response.read()
     fp.seek(0)
     self.bucket.connection.debug = save_debug
     if response.status == 500 or response.status == 503 or \
             response.getheader('location'):
         # we'll try again
         return response
     elif response.status >= 200 and response.status <= 299:
         self.etag = response.getheader('etag')
         if self.etag != '"%s"' % self.md5:
             raise S3DataError(
                 'ETag from S3 did not match computed MD5')
         return response
     else:
         raise S3ResponseError(response.status, response.reason, body)