@retry(socket.error, tries=5, delay=3, backoff=2)
    def upload(self, bucket):

        self.lastUpload = 0
        headers = {'Cache-Control': 'max-age=%s' % self.CACHE_EXPIRATION}

        if self.shouldCompress():
            headers['Content-Encoding'] = 'gzip'

        changed = self.checksum() != self.remoteChecksum()

        if changed:

            # Show progress if the file size is big
            progressCallback = None
            progressCallbackCount = int(len(self.payload()) / (1024 * 1024))

            if len(self.payload()) > self.PROGRESS_MIN_SIZE:
                def progressCallback(current, total):
                    if current > self.lastUpload:
                        uploadPercentage = (float(current) / float(total)) * 100
                        logging.info('+ %s upload progress %.1f%%' % (self.path, uploadPercentage))
                        self.lastUpload = current

            # Create a new key from the file path and guess the mime type
            key = bucket.new_key(self.path)
            mimeType = mimetypes.guess_type(self.path)

            if mimeType:
                if type(mimeType) == tuple or type(mimeType) == list:
                    mimeType = mimeType[0]
                key.content_type = mimeType

            # Upload the data
            key.set_contents_from_string(self.payload(), headers,
                                         policy='public-read',
                                         cb=progressCallback,
                                         num_cb=progressCallbackCount)

        op1 = '+' if changed else '-'
        op2 = ' (%s compressed)' % (fileSize(len(self.payload()))) if self.shouldCompress() else ''

        logging.info('%s %s - %s%s' % (op1, self.path, fileSize(len(self.data())), op2))

        return {'changed': changed, 'size': len(self.payload())}
dataset/ETHPy150Open randomknowledge/Cactus_Refactored/cactus/s3/file.py/File.upload/original