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


Python Resource.get方法代碼示例

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


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

示例1: test_cannot_use_unknown_scheme

# 需要導入模塊: from httpstream import Resource [as 別名]
# 或者: from httpstream.Resource import get [as 別名]
def test_cannot_use_unknown_scheme():
    resource = Resource("xxxx://www.example.com/")
    try:
        resource.get()
    except ValueError:
        assert True
    else:
        assert False
開發者ID:zbyufei,項目名稱:httpstream,代碼行數:10,代碼來源:http_test.py

示例2: test_infinity_is_detected

# 需要導入模塊: from httpstream import Resource [as 別名]
# 或者: from httpstream.Resource import get [as 別名]
def test_infinity_is_detected():
    resource = Resource("http://localhost:8080/infinity")
    try:
        resource.get()
    except RedirectionError:
        assert True
    else:
        assert False
開發者ID:zbyufei,項目名稱:httpstream,代碼行數:10,代碼來源:http_test.py

示例3: test_bad_hostname_will_fail

# 需要導入模塊: from httpstream import Resource [as 別名]
# 或者: from httpstream.Resource import get [as 別名]
def test_bad_hostname_will_fail():
    resource = Resource("http://localtoast:6789")
    try:
        resource.get()
    except NetworkAddressError as err:
        assert True
        assert err.host_port == "localtoast:6789"
    else:
        assert False
開發者ID:jayvdb,項目名稱:httpstream,代碼行數:11,代碼來源:resource_test.py

示例4: test_bad_port_will_fail

# 需要導入模塊: from httpstream import Resource [as 別名]
# 或者: from httpstream.Resource import get [as 別名]
def test_bad_port_will_fail():
    resource = Resource("http://localhost:6789")
    try:
        resource.get()
    except SocketError as err:
        assert True
        assert err.code == 111
        assert err.host_port == "localhost:6789"
    else:
        assert False
開發者ID:jayvdb,項目名稱:httpstream,代碼行數:12,代碼來源:resource_test.py

示例5: test_can_set_product_in_user_agent

# 需要導入模塊: from httpstream import Resource [as 別名]
# 或者: from httpstream.Resource import get [as 別名]
def test_can_set_product_in_user_agent():
    test_product = ("FooBar", "1.2.3")
    resource = Resource("http://localhost:8080/user_agent")
    with resource.get(product=test_product) as response:
        assert response.is_text
        bits = response.read().decode(response.encoding).split()
        received_product = tuple(bits[0].split("/"))
        assert received_product == test_product
開發者ID:frankier,項目名稱:httpstream,代碼行數:10,代碼來源:http_test.py

示例6: test_can_get_multi_line_text_resource

# 需要導入模塊: from httpstream import Resource [as 別名]
# 或者: from httpstream.Resource import get [as 別名]
def test_can_get_multi_line_text_resource():
    resource = Resource("http://localhost:8080/lorem_ipsum")
    expected_lines = LOREM_IPSUM.splitlines()
    with resource.get() as response:
        response.chunk_size = 37
        assert response.is_text
        for line in response:
            assert line == expected_lines.pop(0)
開發者ID:frankier,項目名稱:httpstream,代碼行數:10,代碼來源:http_test.py

示例7: test_can_get_multi_line_hebrew_text_resource

# 需要導入模塊: from httpstream import Resource [as 別名]
# 或者: from httpstream.Resource import get [as 別名]
def test_can_get_multi_line_hebrew_text_resource():
    resource = Resource("http://localhost:8080/genesis")
    expected_lines = GENESIS.splitlines()
    with resource.get() as response:
        response.chunk_size = 37
        assert isinstance(response, TextResponse)
        for line in response:
            assert line == expected_lines.pop(0)
開發者ID:zbyufei,項目名稱:httpstream,代碼行數:10,代碼來源:http_test.py

示例8: test_can_get_simple_text_resource_with_caching

# 需要導入模塊: from httpstream import Resource [as 別名]
# 或者: from httpstream.Resource import get [as 別名]
def test_can_get_simple_text_resource_with_caching():
    resource = Resource("http://localhost:8080/hello")
    response = resource.get(cache=True)
    assert isinstance(response, TextResponse)
    assert not response.consumed
    assert response.content == "hello, world"
    assert response.consumed
    assert response.content == "hello, world"
開發者ID:zbyufei,項目名稱:httpstream,代碼行數:10,代碼來源:http_test.py

示例9: test_can_set_product_in_user_agent

# 需要導入模塊: from httpstream import Resource [as 別名]
# 或者: from httpstream.Resource import get [as 別名]
def test_can_set_product_in_user_agent():
    test_product = ("FooBar", "1.2.3")
    resource = Resource("http://localhost:8080/user_agent")
    with resource.get(product=test_product) as response:
        assert isinstance(response, TextResponse)
        bits = response.content.split()
        received_product = tuple(bits[0].split("/"))
        assert received_product == test_product
開發者ID:zbyufei,項目名稱:httpstream,代碼行數:10,代碼來源:http_test.py

示例10: test_can_get_big_resource_with_small_chunk_size

# 需要導入模塊: from httpstream import Resource [as 別名]
# 或者: from httpstream.Resource import get [as 別名]
def test_can_get_big_resource_with_small_chunk_size():
    resource = Resource("http://localhost:8080/lorem_ipsum")
    expected_lines = LOREM_IPSUM.splitlines()
    with resource.get() as response:
        response.chunk_size = 10
        assert isinstance(response, TextResponse)
        for line in response:
            assert line == expected_lines.pop(0)
開發者ID:zbyufei,項目名稱:httpstream,代碼行數:10,代碼來源:http_test.py

示例11: test_can_get_simple_json_resource_with_caching

# 需要導入模塊: from httpstream import Resource [as 別名]
# 或者: from httpstream.Resource import get [as 別名]
def test_can_get_simple_json_resource_with_caching():
    resource = Resource("http://localhost:8080/object")
    with resource.get(cache=True) as response:
        assert isinstance(response, JSONResponse)
        assert not response.consumed
        assert response.content == OBJECT
        assert response.consumed
        assert response.content == OBJECT
開發者ID:zbyufei,項目名稱:httpstream,代碼行數:10,代碼來源:http_test.py

示例12: test_can_get_multi_line_cyrillic_text_resource

# 需要導入模塊: from httpstream import Resource [as 別名]
# 或者: from httpstream.Resource import get [as 別名]
def test_can_get_multi_line_cyrillic_text_resource():
    resource = Resource("http://localhost:8080/war_and_peace")
    expected_lines = WAR_AND_PEACE.splitlines()
    with resource.get() as response:
        response.chunk_size = 37
        assert isinstance(response, TextResponse)
        for line in response:
            assert line == expected_lines.pop(0)
開發者ID:zbyufei,項目名稱:httpstream,代碼行數:10,代碼來源:http_test.py

示例13: test_can_get_simple_uri

# 需要導入模塊: from httpstream import Resource [as 別名]
# 或者: from httpstream.Resource import get [as 別名]
def test_can_get_simple_uri():
    ddg = Resource("http://duckduckgo.com")
    rs = ddg.get()
    assert rs.status_code == 200
開發者ID:frankier,項目名稱:httpstream,代碼行數:6,代碼來源:resource_test.py

示例14: test_can_get_simple_text_resource

# 需要導入模塊: from httpstream import Resource [as 別名]
# 或者: from httpstream.Resource import get [as 別名]
def test_can_get_simple_text_resource():
    resource = Resource("http://localhost:8080/hello")
    response = resource.get()
    assert isinstance(response, TextResponse)
    content = response.read().decode(response.encoding)
    assert content == "hello, world"
開發者ID:zbyufei,項目名稱:httpstream,代碼行數:8,代碼來源:http_test.py

示例15: test_can_get_block_json_resource

# 需要導入模塊: from httpstream import Resource [as 別名]
# 或者: from httpstream.Resource import get [as 別名]
def test_can_get_block_json_resource():
    resource = Resource("http://localhost:8080/object")
    with resource.get() as response:
        assert response.is_json
        assert response.json == OBJECT
開發者ID:frankier,項目名稱:httpstream,代碼行數:7,代碼來源:http_test.py


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