當前位置: 首頁>>代碼示例>>Python>>正文


Python HTTPResponse.feed方法代碼示例

本文整理匯總了Python中geventhttpclient.response.HTTPResponse.feed方法的典型用法代碼示例。如果您正苦於以下問題:Python HTTPResponse.feed方法的具體用法?Python HTTPResponse.feed怎麽用?Python HTTPResponse.feed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在geventhttpclient.response.HTTPResponse的用法示例。


在下文中一共展示了HTTPResponse.feed方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_read_multiple_header

# 需要導入模塊: from geventhttpclient.response import HTTPResponse [as 別名]
# 或者: from geventhttpclient.response.HTTPResponse import feed [as 別名]
def test_read_multiple_header():
    parser = HTTPResponse()
    parser.feed(MULTI_COOKIE_RESPONSE)
    headers = parser._headers_index
    assert len(headers['set-cookie']) == MULTI_COOKIE_RESPONSE.count('Set-Cookie')
    assert headers['set-cookie'][0].startswith('bb_lastvisit')
    assert headers['set-cookie'][-1].startswith('bb_fbprofilepicurl')
開發者ID:jonozzz,項目名稱:geventhttpclient,代碼行數:9,代碼來源:test_headers.py

示例2: test_incomplete_response

# 需要導入模塊: from geventhttpclient.response import HTTPResponse [as 別名]
# 或者: from geventhttpclient.response.HTTPResponse import feed [as 別名]
def test_incomplete_response():
    response = HTTPResponse()
    response.feed("""HTTP/1.1 200 Ok\r\nContent-Length:10\r\n\r\n1""")
    with pytest.raises(HTTPParseError):
        response.feed("")
    assert response.should_keep_alive()
    assert response.should_close()
開發者ID:handloomweaver,項目名稱:geventhttpclient,代碼行數:9,代碼來源:test_parser.py

示例3: test_simple

# 需要導入模塊: from geventhttpclient.response import HTTPResponse [as 別名]
# 或者: from geventhttpclient.response.HTTPResponse import feed [as 別名]
def test_simple():
    response = HTTPResponse()
    response.feed("""HTTP/1.1 200 Ok\r\nContent-Length: 0\r\n\r\n""")
    assert response.headers_complete
    assert response.message_complete
    assert response.should_keep_alive()
    assert not response.should_close()
    assert response.status_code == 200
開發者ID:KLab,項目名稱:geventhttpclient,代碼行數:10,代碼來源:test_keep_alive.py

示例4: test_close_connection_and_no_content_length

# 需要導入模塊: from geventhttpclient.response import HTTPResponse [as 別名]
# 或者: from geventhttpclient.response.HTTPResponse import feed [as 別名]
def test_close_connection_and_no_content_length():
    response = HTTPResponse()
    response.feed("HTTP/1.1 200 Ok\r\n"
                "Connection: close\r\n\r\n"
                "Hello World!")
    assert response._body_buffer == bytearray("Hello World!")
    assert not response.should_keep_alive()
    assert response.should_close()
開發者ID:KLab,項目名稱:geventhttpclient,代碼行數:10,代碼來源:test_keep_alive.py

示例5: test_keep_alive_bodyless_10x_request_with_body

# 需要導入模塊: from geventhttpclient.response import HTTPResponse [as 別名]
# 或者: from geventhttpclient.response.HTTPResponse import feed [as 別名]
def test_keep_alive_bodyless_10x_request_with_body():
    response = HTTPResponse()
    response.feed("""HTTP/1.1 100 Continue\r\n\r\n""")
    assert response.should_keep_alive()

    response = HTTPResponse()
    response.feed("""HTTP/1.1 100 Continue\r\nTransfer-Encoding: chunked\r\n\r\n""")
    assert response.should_keep_alive()
    assert response.should_close()
開發者ID:KLab,項目名稱:geventhttpclient,代碼行數:11,代碼來源:test_keep_alive.py

示例6: test_keep_alive_http_10

# 需要導入模塊: from geventhttpclient.response import HTTPResponse [as 別名]
# 或者: from geventhttpclient.response.HTTPResponse import feed [as 別名]
def test_keep_alive_http_10():
    response = HTTPResponse()
    response.feed("""HTTP/1.0 200 Ok\r\n\r\n""")
    response.feed("")
    assert response.headers_complete
    assert response.message_complete
    assert not response.should_keep_alive()
    assert response.should_close()
    assert response.status_code == 200
開發者ID:KLab,項目名稱:geventhttpclient,代碼行數:11,代碼來源:test_keep_alive.py

示例7: test_on_body_raises

# 需要導入模塊: from geventhttpclient.response import HTTPResponse [as 別名]
# 或者: from geventhttpclient.response.HTTPResponse import feed [as 別名]
def test_on_body_raises():
    response = HTTPResponse()

    def on_body(buf):
        raise RuntimeError('error')

    response._on_body = on_body
    with pytest.raises(RuntimeError):
        response.feed(RESPONSE)
開發者ID:handloomweaver,項目名稱:geventhttpclient,代碼行數:11,代碼來源:test_parser.py

示例8: test_on_message_begin

# 需要導入模塊: from geventhttpclient.response import HTTPResponse [as 別名]
# 或者: from geventhttpclient.response.HTTPResponse import feed [as 別名]
def test_on_message_begin():
    response = HTTPResponse()

    def on_message_begin():
        raise RuntimeError('error')

    response._on_message_begin = on_message_begin
    with pytest.raises(RuntimeError):
        response.feed(RESPONSE)
開發者ID:handloomweaver,項目名稱:geventhttpclient,代碼行數:11,代碼來源:test_parser.py

示例9: test_keep_alive_bodyless_response_with_body

# 需要導入模塊: from geventhttpclient.response import HTTPResponse [as 別名]
# 或者: from geventhttpclient.response.HTTPResponse import feed [as 別名]
def test_keep_alive_bodyless_response_with_body():
    response = HTTPResponse(method='HEAD')
    response.feed("HTTP/1.1 200 Ok\r\n\r\n")
    assert response.should_keep_alive()

    response = HTTPResponse(method='HEAD')
    with pytest.raises(HTTPParseError):
        response.feed(
            """HTTP/1.1 200 Ok\r\nContent-Length: 10\r\n\r\n0123456789""")
    assert response.should_keep_alive()
    assert response.should_close()
開發者ID:handloomweaver,項目名稱:geventhttpclient,代碼行數:13,代碼來源:test_keep_alive.py

示例10: test_parse_error

# 需要導入模塊: from geventhttpclient.response import HTTPResponse [as 別名]
# 或者: from geventhttpclient.response.HTTPResponse import feed [as 別名]
def test_parse_error():
    response =  HTTPResponse()
    try:
        response.feed("HTTP/1.1 asdf\r\n\r\n")
        response.feed("")
        assert response.status_code, 0
        assert response.message_begun
    except HTTPParseError as e:
        assert 'invalid HTTP status code' in str(e)
    else:
        assert False, "should have raised"
開發者ID:handloomweaver,項目名稱:geventhttpclient,代碼行數:13,代碼來源:test_parser.py

示例11: test_cookielib_compatibility

# 需要導入模塊: from geventhttpclient.response import HTTPResponse [as 別名]
# 或者: from geventhttpclient.response.HTTPResponse import feed [as 別名]
def test_cookielib_compatibility():
    cj = CookieJar()
    # Set time in order to be still valid in some years, when cookie strings expire
    cj._now = cj._policy._now = time.mktime((2012, 1, 1, 0, 0, 0, 0, 0, 0))

    request = Request('http://test.com')
    parser = HTTPResponse()
    parser.feed(MULTI_COOKIE_RESPONSE)
    cookies = cj.make_cookies(parser, request)
    # Don't use extract_cookies directly, as time can not be set there manually for testing
    for cookie in cookies:
        if cj._policy.set_ok(cookie, request):
            cj.set_cookie(cookie)
    # Three valid, not expired cookies placed
    assert len(list(cj)) == 3
開發者ID:jonozzz,項目名稱:geventhttpclient,代碼行數:17,代碼來源:test_headers.py

示例12: test_parse_small_blocks

# 需要導入模塊: from geventhttpclient.response import HTTPResponse [as 別名]
# 或者: from geventhttpclient.response.HTTPResponse import feed [as 別名]
def test_parse_small_blocks():
    parser = HTTPResponse()
    parser.feed(RESPONSE)
    response = StringIO(RESPONSE)
    while not parser.message_complete:
        data = response.read(10)
        parser.feed(data)

    assert parser.message_begun
    assert parser.headers_complete
    assert parser.message_complete
    assert parser.should_keep_alive()
    assert parser.status_code == 301
    assert sorted(parser.items()) == [
        ('cache-control', 'public, max-age=2592000'),
        ('content-length', '218'),
        ('content-type', 'text/html; charset=UTF-8'),
        ('date', 'Thu, 13 Oct 2011 15:03:12 GMT'),
        ('expires', 'Sat, 12 Nov 2011 15:03:12 GMT'),
        ('location', 'http://www.google.fr/'),
        ('server', 'gws'),
        ('x-xss-protection', '1; mode=block'),
    ]
開發者ID:handloomweaver,項目名稱:geventhttpclient,代碼行數:25,代碼來源:test_parser.py

示例13: test_response_too_long

# 需要導入模塊: from geventhttpclient.response import HTTPResponse [as 別名]
# 或者: from geventhttpclient.response.HTTPResponse import feed [as 別名]
def test_response_too_long():
    response = HTTPResponse()
    data = """HTTP/1.1 200 Ok\r\nContent-Length:1\r\n\r\ntoolong"""
    with pytest.raises(HTTPParseError):
        response.feed(data)
開發者ID:handloomweaver,項目名稱:geventhttpclient,代碼行數:7,代碼來源:test_parser.py

示例14: test_compatibility_with_previous_API_read

# 需要導入模塊: from geventhttpclient.response import HTTPResponse [as 別名]
# 或者: from geventhttpclient.response.HTTPResponse import feed [as 別名]
def test_compatibility_with_previous_API_read():
    parser = HTTPResponse()
    parser.feed(MULTI_COOKIE_RESPONSE)
    for single_item in ("content-encoding", "content-type", "content-length", "cache-control", "connection"):
        assert isinstance(parser[single_item], basestring)
        assert isinstance(parser.get(single_item), basestring)
開發者ID:simudream,項目名稱:geventhttpclient,代碼行數:8,代碼來源:test_headers.py

示例15: test_parse

# 需要導入模塊: from geventhttpclient.response import HTTPResponse [as 別名]
# 或者: from geventhttpclient.response.HTTPResponse import feed [as 別名]
def test_parse():
    parser = HTTPResponse()
    assert parser.feed(RESPONSE), len(RESPONSE)
    assert parser.message_begun
    assert parser.headers_complete
    assert parser.message_complete
開發者ID:handloomweaver,項目名稱:geventhttpclient,代碼行數:8,代碼來源:test_parser.py


注:本文中的geventhttpclient.response.HTTPResponse.feed方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。