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


Python Response.encode_content方法代码示例

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


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

示例1: test_encode_content_gzip_buffer_coverage

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import encode_content [as 别名]
def test_encode_content_gzip_buffer_coverage():
    # this test is to provide 100% coverage of
    # Response.encode_content was necessary in order to get
    # request https://github.com/Pylons/webob/pull/85 into upstream
    res = Response()
    DATA = b"abcdefghijklmnopqrstuvwxyz0123456789" * 1000000
    res.app_iter = io.BytesIO(DATA)
    res.encode_content('gzip')
    result = list(res.app_iter)
    assert len(b"".join(result)) < len(DATA)
开发者ID:doulbekill,项目名称:webob,代码行数:12,代码来源:test_response.py

示例2: test_encode_content_gzip_notyet_gzipped

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import encode_content [as 别名]
def test_encode_content_gzip_notyet_gzipped():
    res = Response()
    res.app_iter = io.BytesIO(b"foo")
    result = res.encode_content("gzip")
    eq_(result, None)
    eq_(res.content_length, 23)
    eq_(res.app_iter, [b"\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff", b"K\xcb\xcf\x07\x00", b"!es\x8c\x03\x00\x00\x00"])
开发者ID:ckey,项目名称:webob,代码行数:9,代码来源:test_response.py

示例3: test_response

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import encode_content [as 别名]
def test_response():
    req = BaseRequest.blank("/")
    res = req.get_response(simple_app)
    assert res.status == "200 OK"
    assert res.status_code == 200
    assert res.body == "OK"
    assert res.charset == "UTF-8"
    assert res.content_type == "text/html"
    res.status = 404
    assert res.status == "404 Not Found"
    assert res.status_code == 404
    res.body = b"Not OK"
    assert b"".join(res.app_iter) == b"Not OK"
    res.charset = "iso8859-1"
    assert "text/html; charset=iso8859-1" == res.headers["content-type"]
    res.content_type = "text/xml"
    assert "text/xml; charset=UTF-8" == res.headers["content-type"]
    res.content_type = "text/xml; charset=UTF-8"
    assert "text/xml; charset=UTF-8" == res.headers["content-type"]
    res.headers = {"content-type": "text/html"}
    assert res.headers["content-type"] == "text/html"
    assert res.headerlist == [("content-type", "text/html")]
    res.set_cookie("x", "y")
    assert res.headers["set-cookie"].strip(";") == "x=y; Path=/"
    res.set_cookie(text_("x"), text_("y"))
    assert res.headers["set-cookie"].strip(";") == "x=y; Path=/"
    res = Response("a body", "200 OK", content_type="text/html")
    res.encode_content()
    assert res.content_encoding == "gzip"
    assert (
        res.body
        == b"\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xffKTH\xcaO\xa9\x04\x00\xf6\x86GI\x06\x00\x00\x00"
    )
    res.decode_content()
    assert res.content_encoding is None
    assert res.body == b"a body"
    res.set_cookie("x", text_(b"foo"))  # test unicode value
    with pytest.raises(TypeError):
        Response(app_iter=iter(["a"]), body="somebody")
    del req.environ
    with pytest.raises(TypeError):
        Response(charset=None, content_type="image/jpeg", body=text_(b"unicode body"))
    with pytest.raises(TypeError):
        Response(wrong_key="dummy")
    with pytest.raises(TypeError):
        resp = Response()
        resp.body = text_(b"unicode body")
开发者ID:Pylons,项目名称:webob,代码行数:49,代码来源:test_response.py

示例4: test_response

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import encode_content [as 别名]
def test_response():
    req = BaseRequest.blank('/')
    res = req.get_response(simple_app)
    assert res.status == '200 OK'
    assert res.status_code == 200
    assert res.body == "OK"
    assert res.charset == "UTF-8"
    assert res.content_type == 'text/html'
    res.status = 404
    assert res.status == '404 Not Found'
    assert res.status_code == 404
    res.body = b'Not OK'
    assert b''.join(res.app_iter) == b'Not OK'
    res.charset = 'iso8859-1'
    assert 'text/html; charset=iso8859-1' == res.headers['content-type']
    res.content_type = 'text/xml'
    assert 'text/xml; charset=UTF-8' == res.headers['content-type']
    res.content_type = 'text/xml; charset=UTF-8'
    assert 'text/xml; charset=UTF-8' == res.headers['content-type']
    res.headers = {'content-type': 'text/html'}
    assert res.headers['content-type'] == 'text/html'
    assert res.headerlist == [('content-type', 'text/html')]
    res.set_cookie('x', 'y')
    assert res.headers['set-cookie'].strip(';') == 'x=y; Path=/'
    res.set_cookie(text_('x'), text_('y'))
    assert res.headers['set-cookie'].strip(';') == 'x=y; Path=/'
    res = Response('a body', '200 OK', content_type='text/html')
    res.encode_content()
    assert res.content_encoding == 'gzip'
    assert res.body == b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xffKTH\xcaO\xa9\x04\x00\xf6\x86GI\x06\x00\x00\x00'
    res.decode_content()
    assert res.content_encoding is None
    assert res.body == b'a body'
    res.set_cookie('x', text_(b'foo')) # test unicode value
    with pytest.raises(TypeError):
        Response(app_iter=iter(['a']),
                 body="somebody")
    del req.environ
    with pytest.raises(TypeError):
        Response(charset=None,
                 content_type='image/jpeg',
                 body=text_(b"unicode body"))
    with pytest.raises(TypeError):
        Response(wrong_key='dummy')
    with pytest.raises(TypeError):
        resp = Response()
        resp.body = text_(b"unicode body")
开发者ID:SmartTeleMax,项目名称:webob,代码行数:49,代码来源:test_response.py

示例5: test_encode_content_gzip_notyet_gzipped_lazy

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import encode_content [as 别名]
def test_encode_content_gzip_notyet_gzipped_lazy():
    res = Response()
    res.app_iter = io.BytesIO(b'foo')
    result = res.encode_content('gzip', lazy=True)
    assert result is None
    assert res.content_length is None
    assert list(res.app_iter) == [
        b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff',
        b'K\xcb\xcf\x07\x00',
        b'!es\x8c\x03\x00\x00\x00'
        ]
开发者ID:doulbekill,项目名称:webob,代码行数:13,代码来源:test_response.py

示例6: test_encode_content_gzip_notyet_gzipped_lazy

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import encode_content [as 别名]
def test_encode_content_gzip_notyet_gzipped_lazy():
    res = Response()
    res.app_iter = io.BytesIO(b"foo")
    result = res.encode_content("gzip", lazy=True)
    assert result is None
    assert res.content_length is None
    assert list(res.app_iter) == [
        b"\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff",
        b"K\xcb\xcf\x07\x00",
        b"!es\x8c\x03\x00\x00\x00",
    ]
开发者ID:Pylons,项目名称:webob,代码行数:13,代码来源:test_response.py

示例7: test_encode_content_gzip_notyet_gzipped

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import encode_content [as 别名]
def test_encode_content_gzip_notyet_gzipped():
    res = Response()
    res.app_iter = io.BytesIO(b'foo')
    result = res.encode_content('gzip')
    eq_(result, None)
    eq_(res.content_length, 23)
    eq_(res.app_iter, [
        b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff',
        b'K\xcb\xcf\x07\x00',
        b'!es\x8c\x03\x00\x00\x00'
        ])
开发者ID:perey,项目名称:webob,代码行数:13,代码来源:test_response.py

示例8: test_encode_content_gzip_already_gzipped

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import encode_content [as 别名]
def test_encode_content_gzip_already_gzipped():
    res = Response()
    res.content_encoding = 'gzip'
    result = res.encode_content('gzip')
    assert result is None
开发者ID:doulbekill,项目名称:webob,代码行数:7,代码来源:test_response.py

示例9: test_encode_content_identity

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import encode_content [as 别名]
def test_encode_content_identity():
    res = Response()
    result = res.encode_content('identity')
    assert result is None
开发者ID:doulbekill,项目名称:webob,代码行数:6,代码来源:test_response.py

示例10: test_encode_content_unknown

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import encode_content [as 别名]
def test_encode_content_unknown():
    res = Response()
    with pytest.raises(AssertionError):
        res.encode_content('badencoding')
开发者ID:doulbekill,项目名称:webob,代码行数:6,代码来源:test_response.py

示例11: test_encode_content_gzip_already_gzipped

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import encode_content [as 别名]
def test_encode_content_gzip_already_gzipped():
    res = Response()
    res.content_encoding = 'gzip'
    result = res.encode_content('gzip')
    eq_(result, None)
开发者ID:perey,项目名称:webob,代码行数:7,代码来源:test_response.py

示例12: test_encode_content_identity

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import encode_content [as 别名]
def test_encode_content_identity():
    res = Response()
    result = res.encode_content('identity')
    eq_(result, None)
开发者ID:perey,项目名称:webob,代码行数:6,代码来源:test_response.py


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