Пример #1
0
    def from_s3object(cls, obj, **kwargs):
        b = cls(**kwargs)
        b.last_modified = obj.get('LastModified')  # boto3 gives a datetime
        b.contenttype = obj.get('ContentType')
        # NOTE reflects compressed size if compressed
        b.content_length = obj.get('ContentLength')
        b.metadata = obj.get('Metadata', {})
        if obj.get('ContentEncoding') == 'gzip':
            b.contentencoding = obj['ContentEncoding']
            b.content = gunzip(obj['Body'].read())
        else:
            try:
                b.content = obj['Body'].read()
            except AttributeError:
                # no read() attr probably means not a real boto3 response, just
                # a json structure resembling it.
                b.content = obj['Body']

        return b
Пример #2
0
def test_gzip_handling():
    text = 'This is my baño. There are many like it but this one is mine.'
    assert text == gunzip(gzip(text.encode('utf-8'))).decode('utf-8')