本文整理汇总了Python中netlib.tutils.treq函数的典型用法代码示例。如果您正苦于以下问题:Python treq函数的具体用法?Python treq怎么用?Python treq使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了treq函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_assemble_request_headers
def test_assemble_request_headers():
# https://github.com/mitmproxy/mitmproxy/issues/186
r = treq(body=b"")
r.headers[b"Transfer-Encoding"] = b"chunked"
c = _assemble_request_headers(r)
assert b"Transfer-Encoding" in c
assert b"Host" in _assemble_request_headers(treq(headers=Headers()))
开发者ID:pombredanne,项目名称:netlib,代码行数:8,代码来源:test_assemble.py
示例2: test_equal
def test_equal(self):
a = tutils.treq(timestamp_start=42, timestamp_end=43)
b = tutils.treq(timestamp_start=42, timestamp_end=43)
assert a == b
assert not a == 'foo'
assert not b == 'foo'
assert not 'foo' == a
assert not 'foo' == b
开发者ID:pombredanne,项目名称:netlib,代码行数:9,代码来源:test_models.py
示例3: test_equal
def test_equal(self):
a = tutils.treq()
b = tutils.treq()
assert a == b
assert not a == 'foo'
assert not b == 'foo'
assert not 'foo' == a
assert not 'foo' == b
开发者ID:fireswood,项目名称:netlib,代码行数:9,代码来源:test_semantics.py
示例4: test_get_form_with_url_encoded
def test_get_form_with_url_encoded(self, mock_method_urlencoded, mock_method_multipart):
req = tutils.treq()
assert req.get_form() == ODict()
req = tutils.treq()
req.body = "foobar"
req.headers["Content-Type"] = HDR_FORM_URLENCODED
req.get_form()
assert req.get_form_urlencoded.called
assert not req.get_form_multipart.called
开发者ID:pombredanne,项目名称:netlib,代码行数:10,代码来源:test_models.py
示例5: test_assemble_request_line
def test_assemble_request_line():
assert _assemble_request_line(treq().data) == b"GET /path HTTP/1.1"
authority_request = treq(method=b"CONNECT", first_line_format="authority").data
assert _assemble_request_line(authority_request) == b"CONNECT address:22 HTTP/1.1"
absolute_request = treq(first_line_format="absolute").data
assert _assemble_request_line(absolute_request) == b"GET http://address:22/path HTTP/1.1"
with raises(RuntimeError):
_assemble_request_line(treq(first_line_format="invalid_form").data)
开发者ID:tempbottle,项目名称:netlib,代码行数:11,代码来源:test_assemble.py
示例6: test_assemble_request
def test_assemble_request():
assert assemble_request(treq()) == (
b"GET /path HTTP/1.1\r\n"
b"header: qvalue\r\n"
b"content-length: 7\r\n"
b"host: address:22\r\n"
b"\r\n"
b"content"
)
with raises(HttpException):
assemble_request(treq(content=None))
开发者ID:thomasbhatia,项目名称:mitmproxy,代码行数:12,代码来源:test_assemble.py
示例7: test_assemble_request
def test_assemble_request():
c = assemble_request(treq()) == (
b"GET /path HTTP/1.1\r\n"
b"header: qvalue\r\n"
b"Host: address:22\r\n"
b"Content-Length: 7\r\n"
b"\r\n"
b"content"
)
with raises(HttpException):
assemble_request(treq(content=CONTENT_MISSING))
开发者ID:tempbottle,项目名称:netlib,代码行数:12,代码来源:test_assemble.py
示例8: test_har_extractor
def test_har_extractor(log):
if sys.version_info >= (3, 0):
with tutils.raises("does not work on Python 3"):
with example("har_extractor.py -"):
pass
return
with tutils.raises(script.ScriptException):
with example("har_extractor.py"):
pass
times = dict(
timestamp_start=746203272,
timestamp_end=746203272,
)
flow = tutils.tflow(
req=netutils.treq(**times),
resp=netutils.tresp(**times)
)
with example("har_extractor.py -") as ex:
ex.run("response", flow)
with open(tutils.test_data.path("data/har_extractor.har")) as fp:
test_data = json.load(fp)
assert json.loads(ex.ns["context"].HARLog.json()) == test_data["test_response"]
开发者ID:christofferqa,项目名称:mitmproxy,代码行数:27,代码来源:test_examples.py
示例9: test_anticache
def test_anticache(self):
req = tutils.treq()
req.headers.add("If-Modified-Since", "foo")
req.headers.add("If-None-Match", "bar")
req.anticache()
assert "If-Modified-Since" not in req.headers
assert "If-None-Match" not in req.headers
开发者ID:gsilverman-memeo-inc,项目名称:netlib,代码行数:7,代码来源:test_semantics.py
示例10: test_set_cookies
def test_set_cookies(self):
r = tutils.treq()
r.headers = Headers(cookie="cookiename=cookievalue")
result = r.get_cookies()
result["cookiename"] = ["foo"]
r.set_cookies(result)
assert r.get_cookies()["cookiename"] == ["foo"]
开发者ID:pombredanne,项目名称:netlib,代码行数:7,代码来源:test_models.py
示例11: test_get_cookies_withequalsign
def test_get_cookies_withequalsign(self):
r = tutils.treq()
r.headers = Headers(cookie="cookiename=coo=kievalue;othercookiename=othercookievalue")
result = r.get_cookies()
assert len(result) == 2
assert result['cookiename'] == ['coo=kievalue']
assert result['othercookiename'] == ['othercookievalue']
开发者ID:pombredanne,项目名称:netlib,代码行数:7,代码来源:test_models.py
示例12: test_get_cookies_double
def test_get_cookies_double(self):
request = treq()
request.headers = Headers(cookie="cookiename=cookievalue;othercookiename=othercookievalue")
result = request.cookies
assert len(result) == 2
assert result['cookiename'] == 'cookievalue'
assert result['othercookiename'] == 'othercookievalue'
开发者ID:AlTune,项目名称:mitmproxy,代码行数:7,代码来源:test_request.py
示例13: test_read_response
def test_read_response():
req = treq()
rfile = BytesIO(b"HTTP/1.1 418 I'm a teapot\r\n\r\nbody")
r = read_response(rfile, req)
assert r.status_code == 418
assert r.content == b"body"
assert r.timestamp_end
开发者ID:007durgesh219,项目名称:mitmproxy,代码行数:7,代码来源:test_read.py
示例14: test_legacy_first_line
def test_legacy_first_line(self):
req = tutils.treq()
assert req.legacy_first_line('relative') == "GET /path HTTP/1.1"
assert req.legacy_first_line('authority') == "GET address:22 HTTP/1.1"
assert req.legacy_first_line('absolute') == "GET http://address:22/path HTTP/1.1"
tutils.raises(http.HttpError, req.legacy_first_line, 'foobar')
开发者ID:fireswood,项目名称:netlib,代码行数:7,代码来源:test_semantics.py
示例15: test_get_form_with_multipart
def test_get_form_with_multipart(self, mock_method_urlencoded, mock_method_multipart):
req = tutils.treq()
req.body = "foobar"
req.headers["Content-Type"] = HDR_FORM_MULTIPART
req.get_form()
assert not req.get_form_urlencoded.called
assert req.get_form_multipart.called
开发者ID:pombredanne,项目名称:netlib,代码行数:7,代码来源:test_models.py
示例16: test_get_cookies_withequalsign
def test_get_cookies_withequalsign(self):
request = treq()
request.headers = Headers(cookie="cookiename=coo=kievalue;othercookiename=othercookievalue")
result = request.cookies
assert len(result) == 2
assert result["cookiename"] == ["coo=kievalue"]
assert result["othercookiename"] == ["othercookievalue"]
开发者ID:ganguera,项目名称:mitmproxy,代码行数:7,代码来源:test_request.py
示例17: test_get_cookies_double
def test_get_cookies_double(self):
r = tutils.treq()
r.headers = http.Headers(cookie="cookiename=cookievalue;othercookiename=othercookievalue")
result = r.get_cookies()
assert len(result) == 2
assert result['cookiename'] == ['cookievalue']
assert result['othercookiename'] == ['othercookievalue']
开发者ID:fireswood,项目名称:netlib,代码行数:7,代码来源:test_semantics.py
示例18: test_har_extractor
def test_har_extractor(self):
if sys.version_info >= (3, 0):
with tutils.raises("does not work on Python 3"):
tscript("har_extractor.py")
return
with tutils.raises(ScriptError):
tscript("har_extractor.py")
with tutils.tmpdir() as tdir:
times = dict(
timestamp_start=746203272,
timestamp_end=746203272,
)
path = os.path.join(tdir, "file")
m, sc = tscript("har_extractor.py", six.moves.shlex_quote(path))
f = tutils.tflow(
req=netutils.treq(**times),
resp=netutils.tresp(**times)
)
self.invoke(m, "response", f)
m.addons.remove(sc)
with open(path, "rb") as f:
test_data = json.load(f)
assert len(test_data["log"]["pages"]) == 1
开发者ID:HuangGuoZhou,项目名称:mitmproxy,代码行数:27,代码来源:test_examples.py
示例19: test_read_chunked
def test_read_chunked():
req = treq(content=None)
req.headers["Transfer-Encoding"] = "chunked"
data = b"1\r\na\r\n0\r\n"
with raises(HttpSyntaxException):
b"".join(_read_chunked(BytesIO(data)))
data = b"1\r\na\r\n0\r\n\r\n"
assert b"".join(_read_chunked(BytesIO(data))) == b"a"
data = b"\r\n\r\n1\r\na\r\n1\r\nb\r\n0\r\n\r\n"
assert b"".join(_read_chunked(BytesIO(data))) == b"ab"
data = b"\r\n"
with raises("closed prematurely"):
b"".join(_read_chunked(BytesIO(data)))
data = b"1\r\nfoo"
with raises("malformed chunked body"):
b"".join(_read_chunked(BytesIO(data)))
data = b"foo\r\nfoo"
with raises(HttpSyntaxException):
b"".join(_read_chunked(BytesIO(data)))
data = b"5\r\naaaaa\r\n0\r\n\r\n"
with raises("too large"):
b"".join(_read_chunked(BytesIO(data), limit=2))
开发者ID:ellerbrock,项目名称:mitmproxy,代码行数:29,代码来源:test_read.py
示例20: test_host
def test_host(self):
if six.PY2:
from unittest import SkipTest
raise SkipTest()
request = treq()
assert request.host == request.data.host.decode("idna")
# Test IDNA encoding
# Set str, get raw bytes
request.host = "ídna.example"
assert request.data.host == b"xn--dna-qma.example"
# Set raw bytes, get decoded
request.data.host = b"xn--idn-gla.example"
assert request.host == "idná.example"
# Set bytes, get raw bytes
request.host = b"xn--dn-qia9b.example"
assert request.data.host == b"xn--dn-qia9b.example"
# IDNA encoding is not bijective
request.host = "fußball"
assert request.host == "fussball"
# Don't fail on garbage
request.data.host = b"foo\xFF\x00bar"
assert request.host.startswith("foo")
assert request.host.endswith("bar")
# foo.bar = foo.bar should not cause any side effects.
d = request.host
request.host = d
assert request.data.host == b"foo\xFF\x00bar"
开发者ID:ganguera,项目名称:mitmproxy,代码行数:31,代码来源:test_request.py
注:本文中的netlib.tutils.treq函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论