当前位置: 首页>>代码示例>>Python>>正文


Python gzip.GZipMiddleware方法代码示例

本文整理汇总了Python中django.middleware.gzip.GZipMiddleware方法的典型用法代码示例。如果您正苦于以下问题:Python gzip.GZipMiddleware方法的具体用法?Python gzip.GZipMiddleware怎么用?Python gzip.GZipMiddleware使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.middleware.gzip的用法示例。


在下文中一共展示了gzip.GZipMiddleware方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: gzip_action

# 需要导入模块: from django.middleware import gzip [as 别名]
# 或者: from django.middleware.gzip import GZipMiddleware [as 别名]
def gzip_action(func):
    gz = GZipMiddleware()

    @wraps(func)
    def wrapper(self, request, *args, **kwargs):
        resp = func(self, request, *args, **kwargs)
        return gz.process_response(request, resp)

    if getattr(settings, 'GZIP_MODELS'):
        return wrapper
    return func 
开发者ID:SubstraFoundation,项目名称:substra-backend,代码行数:13,代码来源:model.py

示例2: test_compress_response

# 需要导入模块: from django.middleware import gzip [as 别名]
# 或者: from django.middleware.gzip import GZipMiddleware [as 别名]
def test_compress_response(self):
        """
        Compression is performed on responses with compressible content.
        """
        r = GZipMiddleware().process_response(self.req, self.resp)
        self.assertEqual(self.decompress(r.content), self.compressible_string)
        self.assertEqual(r.get('Content-Encoding'), 'gzip')
        self.assertEqual(r.get('Content-Length'), str(len(r.content))) 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:tests.py

示例3: test_compress_streaming_response

# 需要导入模块: from django.middleware import gzip [as 别名]
# 或者: from django.middleware.gzip import GZipMiddleware [as 别名]
def test_compress_streaming_response(self):
        """
        Compression is performed on responses with streaming content.
        """
        r = GZipMiddleware().process_response(self.req, self.stream_resp)
        self.assertEqual(self.decompress(b''.join(r)), b''.join(self.sequence))
        self.assertEqual(r.get('Content-Encoding'), 'gzip')
        self.assertFalse(r.has_header('Content-Length')) 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:tests.py

示例4: test_compress_streaming_response_unicode

# 需要导入模块: from django.middleware import gzip [as 别名]
# 或者: from django.middleware.gzip import GZipMiddleware [as 别名]
def test_compress_streaming_response_unicode(self):
        """
        Compression is performed on responses with streaming Unicode content.
        """
        r = GZipMiddleware().process_response(self.req, self.stream_resp_unicode)
        self.assertEqual(
            self.decompress(b''.join(r)),
            b''.join(x.encode() for x in self.sequence_unicode)
        )
        self.assertEqual(r.get('Content-Encoding'), 'gzip')
        self.assertFalse(r.has_header('Content-Length')) 
开发者ID:nesdis,项目名称:djongo,代码行数:13,代码来源:tests.py

示例5: test_compress_file_response

# 需要导入模块: from django.middleware import gzip [as 别名]
# 或者: from django.middleware.gzip import GZipMiddleware [as 别名]
def test_compress_file_response(self):
        """
        Compression is performed on FileResponse.
        """
        with open(__file__, 'rb') as file1:
            file_resp = FileResponse(file1)
            file_resp['Content-Type'] = 'text/html; charset=UTF-8'
            r = GZipMiddleware().process_response(self.req, file_resp)
            with open(__file__, 'rb') as file2:
                self.assertEqual(self.decompress(b''.join(r)), file2.read())
            self.assertEqual(r.get('Content-Encoding'), 'gzip')
            self.assertIsNot(r.file_to_stream, file1) 
开发者ID:nesdis,项目名称:djongo,代码行数:14,代码来源:tests.py

示例6: test_compress_non_200_response

# 需要导入模块: from django.middleware import gzip [as 别名]
# 或者: from django.middleware.gzip import GZipMiddleware [as 别名]
def test_compress_non_200_response(self):
        """
        Compression is performed on responses with a status other than 200
        (#10762).
        """
        self.resp.status_code = 404
        r = GZipMiddleware().process_response(self.req, self.resp)
        self.assertEqual(self.decompress(r.content), self.compressible_string)
        self.assertEqual(r.get('Content-Encoding'), 'gzip') 
开发者ID:nesdis,项目名称:djongo,代码行数:11,代码来源:tests.py

示例7: test_no_compress_compressed_response

# 需要导入模块: from django.middleware import gzip [as 别名]
# 或者: from django.middleware.gzip import GZipMiddleware [as 别名]
def test_no_compress_compressed_response(self):
        """
        Compression isn't performed on responses that are already compressed.
        """
        self.resp['Content-Encoding'] = 'deflate'
        r = GZipMiddleware().process_response(self.req, self.resp)
        self.assertEqual(r.content, self.compressible_string)
        self.assertEqual(r.get('Content-Encoding'), 'deflate') 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:tests.py

示例8: test_no_compress_incompressible_response

# 需要导入模块: from django.middleware import gzip [as 别名]
# 或者: from django.middleware.gzip import GZipMiddleware [as 别名]
def test_no_compress_incompressible_response(self):
        """
        Compression isn't performed on responses with incompressible content.
        """
        self.resp.content = self.incompressible_string
        r = GZipMiddleware().process_response(self.req, self.resp)
        self.assertEqual(r.content, self.incompressible_string)
        self.assertIsNone(r.get('Content-Encoding')) 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:tests.py

示例9: test_compress_deterministic

# 需要导入模块: from django.middleware import gzip [as 别名]
# 或者: from django.middleware.gzip import GZipMiddleware [as 别名]
def test_compress_deterministic(self):
        """
        Compression results are the same for the same content and don't
        include a modification time (since that would make the results
        of compression non-deterministic and prevent
        ConditionalGetMiddleware from recognizing conditional matches
        on gzipped content).
        """
        r1 = GZipMiddleware().process_response(self.req, self.resp)
        r2 = GZipMiddleware().process_response(self.req, self.resp)
        self.assertEqual(r1.content, r2.content)
        self.assertEqual(self.get_mtime(r1.content), 0)
        self.assertEqual(self.get_mtime(r2.content), 0) 
开发者ID:nesdis,项目名称:djongo,代码行数:15,代码来源:tests.py

示例10: test_strong_etag_modified

# 需要导入模块: from django.middleware import gzip [as 别名]
# 或者: from django.middleware.gzip import GZipMiddleware [as 别名]
def test_strong_etag_modified(self):
        """
        GZipMiddleware makes a strong ETag weak.
        """
        request = self.rf.get('/', HTTP_ACCEPT_ENCODING='gzip, deflate')
        response = HttpResponse(self.compressible_string)
        response['ETag'] = '"eggs"'
        gzip_response = GZipMiddleware().process_response(request, response)
        self.assertEqual(gzip_response['ETag'], 'W/"eggs"') 
开发者ID:nesdis,项目名称:djongo,代码行数:11,代码来源:tests.py

示例11: test_weak_etag_not_modified

# 需要导入模块: from django.middleware import gzip [as 别名]
# 或者: from django.middleware.gzip import GZipMiddleware [as 别名]
def test_weak_etag_not_modified(self):
        """
        GZipMiddleware doesn't modify a weak ETag.
        """
        request = self.rf.get('/', HTTP_ACCEPT_ENCODING='gzip, deflate')
        response = HttpResponse(self.compressible_string)
        response['ETag'] = 'W/"eggs"'
        gzip_response = GZipMiddleware().process_response(request, response)
        self.assertEqual(gzip_response['ETag'], 'W/"eggs"') 
开发者ID:nesdis,项目名称:djongo,代码行数:11,代码来源:tests.py


注:本文中的django.middleware.gzip.GZipMiddleware方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。