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


Python BaseRequest.blank方法代码示例

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


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

示例1: test_from_fieldstorage_with_quoted_printable_encoding

# 需要导入模块: from webob.request import BaseRequest [as 别名]
# 或者: from webob.request.BaseRequest import blank [as 别名]
    def test_from_fieldstorage_with_quoted_printable_encoding(self):
        from cgi import FieldStorage
        from webob.request import BaseRequest
        from webob.multidict import MultiDict

        multipart_type = "multipart/form-data; boundary=foobar"
        from io import BytesIO

        body = (
            b"--foobar\r\n"
            b'Content-Disposition: form-data; name="title"\r\n'
            b'Content-type: text/plain; charset="ISO-2022-JP"\r\n'
            b"Content-Transfer-Encoding: quoted-printable\r\n"
            b"\r\n"
            b"=1B$B$3$s$K$A$O=1B(B"
            b"\r\n"
            b"--foobar--"
        )
        multipart_body = BytesIO(body)
        environ = BaseRequest.blank("/").environ
        environ.update(CONTENT_TYPE=multipart_type)
        environ.update(REQUEST_METHOD="POST")
        environ.update(CONTENT_LENGTH=len(body))
        fs = FieldStorage(multipart_body, environ=environ)
        vars = MultiDict.from_fieldstorage(fs)
        self.assertEqual(vars["title"].encode("utf8"), text_("こんにちは", "utf8").encode("utf8"))
开发者ID:B-Rich,项目名称:webob,代码行数:28,代码来源:test_multidict.py

示例2: test_set_response_status_bad

# 需要导入模块: from webob.request import BaseRequest [as 别名]
# 或者: from webob.request.BaseRequest import blank [as 别名]
def test_set_response_status_bad():
    req = BaseRequest.blank('/')
    res = req.get_response(simple_app)
    def status_test():
        res.status = 'ThisShouldFail'

    assert_raises(ValueError, status_test)
开发者ID:dairiki,项目名称:webob,代码行数:9,代码来源:test_response.py

示例3: test_cookies

# 需要导入模块: from webob.request import BaseRequest [as 别名]
# 或者: from webob.request.BaseRequest import blank [as 别名]
def test_cookies():
    res = Response()
    # test unicode value
    res.set_cookie("x", "test")
    # utf8 encoded
    eq_(res.headers.getall("set-cookie"), ["x=test; Path=/"])
    r2 = res.merge_cookies(simple_app)
    r2 = BaseRequest.blank("/").get_response(r2)
    eq_(r2.headerlist, [("Content-Type", "text/html; charset=utf8"), ("Set-Cookie", "x=test; Path=/")])
开发者ID:ckey,项目名称:webob,代码行数:11,代码来源:test_response.py

示例4: test_cookies

# 需要导入模块: from webob.request import BaseRequest [as 别名]
# 或者: from webob.request.BaseRequest import blank [as 别名]
def test_cookies():
    res = Response()
    # test unicode value
    res.set_cookie("x", text_(b"\N{BLACK SQUARE}", "unicode_escape"))
    # utf8 encoded
    eq_(res.headers.getall("set-cookie"), ['x="\\342\\226\\240"; Path=/'])
    r2 = res.merge_cookies(simple_app)
    r2 = BaseRequest.blank("/").get_response(r2)
    eq_(r2.headerlist, [("Content-Type", "text/html; charset=utf8"), ("Set-Cookie", 'x="\\342\\226\\240"; Path=/')])
开发者ID:xpahos,项目名称:webob,代码行数:11,代码来源:test_response.py

示例5: test_set_response_status_bad

# 需要导入模块: from webob.request import BaseRequest [as 别名]
# 或者: from webob.request.BaseRequest import blank [as 别名]
def test_set_response_status_bad():
    req = BaseRequest.blank("/")
    res = req.get_response(simple_app)

    def status_test():
        res.status = "ThisShouldFail"

    with pytest.raises(ValueError):
        status_test()
开发者ID:Pylons,项目名称:webob,代码行数:11,代码来源:test_response.py

示例6: test_cookies

# 需要导入模块: from webob.request import BaseRequest [as 别名]
# 或者: from webob.request.BaseRequest import blank [as 别名]
def test_cookies():
    res = Response()
    # test unicode value
    res.set_cookie('x', "test")
    # utf8 encoded
    assert res.headers.getall('set-cookie') == ['x=test; Path=/']
    r2 = res.merge_cookies(simple_app)
    r2 = BaseRequest.blank('/').get_response(r2)
    assert r2.headerlist == [
        ('Content-Type', 'text/html; charset=utf8'),
        ('Set-Cookie', 'x=test; Path=/'),
        ]
开发者ID:doulbekill,项目名称:webob,代码行数:14,代码来源:test_response.py

示例7: test_cookies

# 需要导入模块: from webob.request import BaseRequest [as 别名]
# 或者: from webob.request.BaseRequest import blank [as 别名]
def test_cookies():
    res = Response()
    # test unicode value
    res.set_cookie('x', text_(b'\N{BLACK SQUARE}', 'unicode_escape'))
    # utf8 encoded
    eq_(res.headers.getall('set-cookie'), ['x="\\342\\226\\240"; Path=/'])
    r2 = res.merge_cookies(simple_app)
    r2 = BaseRequest.blank('/').get_response(r2)
    eq_(r2.headerlist,
        [('Content-Type', 'text/html; charset=utf8'),
        ('Set-Cookie', 'x="\\342\\226\\240"; Path=/'),
        ]
    )
开发者ID:MiCHiLU,项目名称:webob,代码行数:15,代码来源:test_response.py

示例8: test_response

# 需要导入模块: from webob.request import BaseRequest [as 别名]
# 或者: from webob.request.BaseRequest import blank [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

示例9: test_response

# 需要导入模块: from webob.request import BaseRequest [as 别名]
# 或者: from webob.request.BaseRequest import blank [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

示例10: test_from_fieldstorage_with_charset

# 需要导入模块: from webob.request import BaseRequest [as 别名]
# 或者: from webob.request.BaseRequest import blank [as 别名]
 def test_from_fieldstorage_with_charset(self):
     from cgi import FieldStorage
     from webob.request import BaseRequest
     from webob.multidict import MultiDict
     multipart_type = 'multipart/form-data; boundary=foobar'
     from io import BytesIO
     body = (
         b'--foobar\r\n'
         b'Content-Disposition: form-data; name="title"\r\n'
         b'Content-type: text/plain; charset="ISO-2022-JP"\r\n'
         b'\r\n'
         b'\x1b$B$3$s$K$A$O\x1b(B'
         b'\r\n'
         b'--foobar--')
     multipart_body = BytesIO(body)
     environ = BaseRequest.blank('/').environ
     environ.update(CONTENT_TYPE=multipart_type)
     environ.update(REQUEST_METHOD='POST')
     environ.update(CONTENT_LENGTH=len(body))
     fs = FieldStorage(multipart_body, environ=environ)
     vars = MultiDict.from_fieldstorage(fs)
     self.assertEqual(vars['title'].encode('utf8'),
                      text_('こんにちは', 'utf8').encode('utf8'))
开发者ID:SmartTeleMax,项目名称:webob,代码行数:25,代码来源:test_multidict.py

示例11: _makeRequest

# 需要导入模块: from webob.request import BaseRequest [as 别名]
# 或者: from webob.request.BaseRequest import blank [as 别名]
 def _makeRequest(self):
     from webob.request import BaseRequest
     req = BaseRequest.blank('/')
     return req
开发者ID:invisibleroads,项目名称:webob,代码行数:6,代码来源:test_descriptors.py

示例12: test_set_response_status_str_generic_reason

# 需要导入模块: from webob.request import BaseRequest [as 别名]
# 或者: from webob.request.BaseRequest import blank [as 别名]
def test_set_response_status_str_generic_reason():
    req = BaseRequest.blank('/')
    res = req.get_response(simple_app)
    res.status = '299'
    assert res.status_code == 299
    assert res.status == '299 Success'
开发者ID:doulbekill,项目名称:webob,代码行数:8,代码来源:test_response.py

示例13: test_set_response_status_code

# 需要导入模块: from webob.request import BaseRequest [as 别名]
# 或者: from webob.request.BaseRequest import blank [as 别名]
def test_set_response_status_code():
    req = BaseRequest.blank('/')
    res = req.get_response(simple_app)
    res.status_code = 200
    assert res.status_code == 200
    assert res.status == '200 OK'
开发者ID:doulbekill,项目名称:webob,代码行数:8,代码来源:test_response.py

示例14: test_set_response_status_binary

# 需要导入模块: from webob.request import BaseRequest [as 别名]
# 或者: from webob.request.BaseRequest import blank [as 别名]
def test_set_response_status_binary():
    req = BaseRequest.blank('/')
    res = req.get_response(simple_app)
    res.status == b'200 OK'
    assert res.status_int == 200
    assert res.status == '200 OK'
开发者ID:alertedsnake,项目名称:webob,代码行数:8,代码来源:test_response.py

示例15: test_set_response_status_str_no_reason

# 需要导入模块: from webob.request import BaseRequest [as 别名]
# 或者: from webob.request.BaseRequest import blank [as 别名]
def test_set_response_status_str_no_reason():
    req = BaseRequest.blank("/")
    res = req.get_response(simple_app)
    res.status = "200"
    assert res.status_code == 200
    assert res.status == "200 OK"
开发者ID:Pylons,项目名称:webob,代码行数:8,代码来源:test_response.py


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