本文整理汇总了Python中netlib.tutils.tresp函数的典型用法代码示例。如果您正苦于以下问题:Python tresp函数的具体用法?Python tresp怎么用?Python tresp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tresp函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_equal
def test_equal(self):
a = tutils.tresp(timestamp_start=42, timestamp_end=43)
b = tutils.tresp(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
示例2: test_equal
def test_equal(self):
a = tutils.tresp()
b = tutils.tresp()
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
示例3: test_assemble_response
def test_assemble_response():
c = assemble_response(tresp()) == (
b"HTTP/1.1 200 OK\r\n"
b"header-response: svalue\r\n"
b"Content-Length: 7\r\n"
b"\r\n"
b"message"
)
with raises(HttpException):
assemble_response(tresp(content=CONTENT_MISSING))
开发者ID:tempbottle,项目名称:netlib,代码行数:11,代码来源:test_assemble.py
示例4: test_eq_ne
def test_eq_ne(self):
data = tresp(timestamp_start=42, timestamp_end=42).data
same = tresp(timestamp_start=42, timestamp_end=42).data
assert data == same
assert not data != same
other = tresp(content=b"foo").data
assert not data == other
assert data != other
assert data != 0
开发者ID:007durgesh219,项目名称:mitmproxy,代码行数:11,代码来源:test_message.py
示例5: test_assemble_response
def test_assemble_response():
assert assemble_response(tresp()) == (
b"HTTP/1.1 200 OK\r\n"
b"content-length: 7\r\n"
b"header-response: svalue\r\n"
b"\r\n"
b"message"
)
with raises(HttpException):
assemble_response(tresp(content=None))
开发者ID:thomasbhatia,项目名称:mitmproxy,代码行数:11,代码来源:test_assemble.py
示例6: test_none
def test_none(self):
r = tresp(content=None)
assert r.text is None
r.text = u"foo"
assert r.text is not None
r.text = None
assert r.text is None
开发者ID:DrakeCaraker,项目名称:mitmproxy,代码行数:7,代码来源:test_message.py
示例7: test_get_cookies_simple
def test_get_cookies_simple(self):
resp = tutils.tresp()
resp.headers = http.Headers(set_cookie="cookiename=cookievalue")
result = resp.get_cookies()
assert len(result) == 1
assert "cookiename" in result
assert result["cookiename"][0] == ["cookievalue", odict.ODict()]
开发者ID:fireswood,项目名称:netlib,代码行数:7,代码来源:test_semantics.py
示例8: test_unknown_ce
def test_unknown_ce(self):
r = tresp()
r.headers["content-type"] = "text/html; charset=wtf"
r.raw_content = b"foo"
with tutils.raises(ValueError):
assert r.text == u"foo"
assert r.get_text(strict=False) == u"foo"
开发者ID:DrakeCaraker,项目名称:mitmproxy,代码行数:7,代码来源:test_message.py
示例9: test_simple
def test_simple(self):
r = tresp(content=b'\xfc')
assert r.raw_content == b"\xfc"
assert r.content == b"\xfc"
assert r.text == u"ü"
r.encode("gzip")
assert r.text == u"ü"
r.decode()
assert r.text == u"ü"
r.headers["content-type"] = "text/html; charset=latin1"
r.content = b"\xc3\xbc"
assert r.text == u"ü"
r.headers["content-type"] = "text/html; charset=utf8"
assert r.text == u"ü"
r.encode("identity")
r.raw_content = b"foo"
with mock.patch("netlib.encoding.decode") as e:
assert r.text
assert e.call_count == 2
e.reset_mock()
assert r.text
assert e.call_count == 0
开发者ID:DrakeCaraker,项目名称:mitmproxy,代码行数:25,代码来源:test_message.py
示例10: test_get_cookies_simple
def test_get_cookies_simple(self):
resp = tresp()
resp.headers = Headers(set_cookie="cookiename=cookievalue")
result = resp.cookies
assert len(result) == 1
assert "cookiename" in result
assert result["cookiename"][0] == ["cookievalue", ODict()]
开发者ID:tempbottle,项目名称:netlib,代码行数:7,代码来源:test_response.py
示例11: 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
示例12: 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
示例13: test_cannot_encode
def test_cannot_encode(self):
r = tresp()
r.content = None
assert "content-type" not in r.headers
assert r.raw_content is None
r.headers["content-type"] = "text/html; charset=latin1; foo=bar"
r.text = u"☃"
assert r.headers["content-type"] == "text/html; charset=utf-8; foo=bar"
assert r.raw_content == b'\xe2\x98\x83'
r.headers["content-type"] = "gibberish"
r.text = u"☃"
assert r.headers["content-type"] == "text/plain; charset=utf-8"
assert r.raw_content == b'\xe2\x98\x83'
del r.headers["content-type"]
r.text = u"☃"
assert r.headers["content-type"] == "text/plain; charset=utf-8"
assert r.raw_content == b'\xe2\x98\x83'
r.headers["content-type"] = "text/html; charset=latin1"
r.text = u'\udcff'
assert r.headers["content-type"] == "text/html; charset=utf-8"
assert r.raw_content == b'\xed\xb3\xbf' if six.PY2 else b"\xFF"
开发者ID:DrakeCaraker,项目名称:mitmproxy,代码行数:25,代码来源:test_message.py
示例14: test_get_cookies_no_value
def test_get_cookies_no_value(self):
resp = tresp()
resp.headers = Headers(set_cookie="cookiename=; Expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/")
result = resp.cookies
assert len(result) == 1
assert "cookiename" in result
assert result["cookiename"][0][0] == ""
assert len(result["cookiename"][0][1]) == 2
开发者ID:tempbottle,项目名称:netlib,代码行数:8,代码来源:test_response.py
示例15: test_cannot_decode
def test_cannot_decode(self):
r = tresp()
r.headers["content-type"] = "text/html; charset=utf8"
r.raw_content = b"\xFF"
with tutils.raises(ValueError):
assert r.text
assert r.get_text(strict=False) == u'\ufffd' if six.PY2 else '\udcff'
开发者ID:DrakeCaraker,项目名称:mitmproxy,代码行数:8,代码来源:test_message.py
示例16: test_content_length_update
def test_content_length_update(self):
resp = tresp()
resp.content = b"foo"
assert resp.data.content == b"foo"
assert resp.headers["content-length"] == "3"
resp.content = b""
assert resp.data.content == b""
assert resp.headers["content-length"] == "0"
开发者ID:007durgesh219,项目名称:mitmproxy,代码行数:8,代码来源:test_message.py
示例17: test_modify_response_body
def test_modify_response_body(self):
with tutils.raises(ScriptError):
tscript("modify_response_body.py")
m, sc = tscript("modify_response_body.py", "mitmproxy rocks")
f = tutils.tflow(resp=netutils.tresp(content=b"I <3 mitmproxy"))
self.invoke(m, "response", f)
assert f.response.content == b"I <3 rocks"
开发者ID:HuangGuoZhou,项目名称:mitmproxy,代码行数:8,代码来源:test_examples.py
示例18: test_cannot_encode
def test_cannot_encode(self):
r = tresp()
assert r.encode("gzip")
with decoded(r):
r.content = None
assert "content-encoding" not in r.headers
assert r.content is None
开发者ID:007durgesh219,项目名称:mitmproxy,代码行数:8,代码来源:test_message.py
示例19: test_get_cookies_simple
def test_get_cookies_simple(self):
h = odict.ODictCaseless()
h["Set-Cookie"] = ["cookiename=cookievalue"]
resp = tutils.tresp()
resp.headers = h
result = resp.get_cookies()
assert len(result) == 1
assert "cookiename" in result
assert result["cookiename"][0] == ["cookievalue", odict.ODict()]
开发者ID:PidgeyL,项目名称:netlib,代码行数:9,代码来源:test_semantics.py
示例20: test_set_cookies
def test_set_cookies(self):
resp = tutils.tresp()
v = resp.get_cookies()
v.add("foo", ["bar", odict.ODictCaseless()])
resp.set_cookies(v)
v = resp.get_cookies()
assert len(v) == 1
assert v["foo"] == [["bar", odict.ODictCaseless()]]
开发者ID:PidgeyL,项目名称:netlib,代码行数:9,代码来源:test_semantics.py
注:本文中的netlib.tutils.tresp函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论