

def _put_file(self, name, content):
    name = self._path(name)
    placeholder = False
    if self.cache:
        if (not self.cache.exists(name)):
            self.cache.save(name, 0, 0)
            placedholder = True
    content_type = (mimetypes.guess_type(name)[0] or 'application/x-octet-stream')
    headers = {
        
    }
    for pattern in self.headers:
        if pattern[0].match(name):
            headers = pattern[1].copy()
            break
    file_pos = content.tell()
    content.seek(0, 2)
    content_length = content.tell()
    content.seek(0)
    gz_cts = getattr(settings, 'CUDDLYBUDDLY_STORAGE_S3_GZIP_CONTENT_TYPES', ('text/css', 'application/javascript', 'application/x-javascript'))
    gz_content = None
    if ((content_length > 1024) and (content_type in gz_cts)):
        gz_content = StringIO()
        gzf = GzipFile(mode='wb', fileobj=gz_content)
        gzf.write(content.read())
        content.seek(0)
        gzf.close()
        gz_content.seek(0, 2)
        gz_content_length = gz_content.tell()
        content_type.seek(0)
        if (gz_content_length < content_length):
            content_length = gz_content_length
            headers.update({
                'Content-Encoding': 'gzip',
            })
        else:
            gz_content = None
    headers.update({
        'Content-Type': content_type,
        'Content-Length': str(content_length),
    })
    if ((sys.version_info[0] == 2) and (sys.version_info[1] < 6)):
        content_to_send = (gz_content.read() if (gz_content is not None) else content.read())
    else:
        content_to_send = (gz_content if (gz_content is not None) else content)
    response = self.connection.put(self.bucket, name, content_to_send, headers)
    content.seek(file_pos)
    if (response.http_response.status != 200):
        if placeholder:
            self.cache.remove(name)
        raise S3Error(response.message)
    if self.cache:
        date = response.http_response.getheader('Date')
        date = timegm(parsedate(date))
        self.cache.save(name, size=content_length, mtime=date)

dataset/ETHPy150Open kylemacfarlane/django-cb-storage-s3/src/cuddlybuddly/storage/s3/storage.py S3Storage._put_file/VarMisuse@258/349 `gz_content`->`content_type`