本文整理汇总了Python中twisted.web.client.RedirectAgent方法的典型用法代码示例。如果您正苦于以下问题:Python client.RedirectAgent方法的具体用法?Python client.RedirectAgent怎么用?Python client.RedirectAgent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.client
的用法示例。
在下文中一共展示了client.RedirectAgent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_noRedirect
# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import RedirectAgent [as 别名]
def test_noRedirect(self):
"""
L{client.RedirectAgent} behaves like L{client.Agent} if the response
doesn't contain a redirect.
"""
deferred = self.agent.request(b'GET', b'http://example.com/foo')
req, res = self.protocol.requests.pop()
headers = http_headers.Headers()
response = Response((b'HTTP', 1, 1), 200, b'OK', headers, None)
res.callback(response)
self.assertEqual(0, len(self.protocol.requests))
result = self.successResultOf(deferred)
self.assertIdentical(response, result)
self.assertIdentical(result.previousResponse, None)
示例2: test_noLocationField
# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import RedirectAgent [as 别名]
def test_noLocationField(self):
"""
If no L{Location} header field is found when getting a redirect,
L{client.RedirectAgent} fails with a L{ResponseFailed} error wrapping a
L{error.RedirectWithNoLocation} exception.
"""
deferred = self.agent.request(b'GET', b'http://example.com/foo')
req, res = self.protocol.requests.pop()
headers = http_headers.Headers()
response = Response((b'HTTP', 1, 1), 301, b'OK', headers, None)
res.callback(response)
fail = self.failureResultOf(deferred, client.ResponseFailed)
fail.value.reasons[0].trap(error.RedirectWithNoLocation)
self.assertEqual(b'http://example.com/foo',
fail.value.reasons[0].value.uri)
self.assertEqual(301, fail.value.response.code)
示例3: _testPageRedirectFailure
# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import RedirectAgent [as 别名]
def _testPageRedirectFailure(self, code, method):
"""
When getting a redirect on an unsupported request method,
L{client.RedirectAgent} fails with a L{ResponseFailed} error wrapping
a L{error.PageRedirect} exception.
@param code: HTTP status code.
@param method: HTTP request method.
"""
deferred = self.agent.request(method, b'http://example.com/foo')
req, res = self.protocol.requests.pop()
headers = http_headers.Headers()
response = Response((b'HTTP', 1, 1), code, b'OK', headers, None)
res.callback(response)
fail = self.failureResultOf(deferred, client.ResponseFailed)
fail.value.reasons[0].trap(error.PageRedirect)
self.assertEqual(b'http://example.com/foo',
fail.value.reasons[0].value.location)
self.assertEqual(code, fail.value.response.code)
示例4: test_responseHistory
# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import RedirectAgent [as 别名]
def test_responseHistory(self):
"""
L{Response.response} references the previous L{Response} from
a redirect, or L{None} if there was no previous response.
"""
agent = self.buildAgentForWrapperTest(self.reactor)
redirectAgent = client.RedirectAgent(agent)
deferred = redirectAgent.request(b'GET', b'http://example.com/foo')
redirectReq, redirectRes = self.protocol.requests.pop()
headers = http_headers.Headers(
{b'location': [b'http://example.com/bar']})
redirectResponse = Response((b'HTTP', 1, 1), 302, b'OK', headers, None)
redirectRes.callback(redirectResponse)
req, res = self.protocol.requests.pop()
response = Response((b'HTTP', 1, 1), 200, b'OK', headers, None)
res.callback(response)
finalResponse = self.successResultOf(deferred)
self.assertIdentical(finalResponse.previousResponse, redirectResponse)
self.assertIdentical(redirectResponse.previousResponse, None)
示例5: __init__
# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import RedirectAgent [as 别名]
def __init__(self, reactor):
self.reactor = reactor
pool = HTTPConnectionPool(reactor, persistent=True)
pool.maxPersistentPerHost = 1
pool.cachedConnectionTimeout = 600
self.agent = RedirectAgent(Agent(reactor, pool=pool))
self.reqQ = HttpReqQ(self.agent, self.reactor)
self.clientPlaylist = HlsPlaylist()
self.verbose = False
self.download = False
self.outDir = ""
self.encryptionHandled=False
# required for the dump durations functionality
self.dur_dump_file = None
self.dur_avproble_acc = 0
self.dur_vt_acc = 0
self.dur_playlist_acc = 0
示例6: _testRedirectDefault
# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import RedirectAgent [as 别名]
def _testRedirectDefault(self, code):
"""
When getting a redirect, L{client.RedirectAgent} follows the URL
specified in the L{Location} header field and make a new request.
@param code: HTTP status code.
"""
self.agent.request(b'GET', b'http://example.com/foo')
host, port = self.reactor.tcpClients.pop()[:2]
self.assertEqual(EXAMPLE_COM_IP, host)
self.assertEqual(80, port)
req, res = self.protocol.requests.pop()
# If possible (i.e.: SSL support is present), run the test with a
# cross-scheme redirect to verify that the scheme is honored; if not,
# let's just make sure it works at all.
if ssl is None:
scheme = b'http'
expectedPort = 80
else:
scheme = b'https'
expectedPort = 443
headers = http_headers.Headers(
{b'location': [scheme + b'://example.com/bar']})
response = Response((b'HTTP', 1, 1), code, b'OK', headers, None)
res.callback(response)
req2, res2 = self.protocol.requests.pop()
self.assertEqual(b'GET', req2.method)
self.assertEqual(b'/bar', req2.uri)
host, port = self.reactor.tcpClients.pop()[:2]
self.assertEqual(EXAMPLE_COM_IP, host)
self.assertEqual(expectedPort, port)
示例7: test_redirect301
# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import RedirectAgent [as 别名]
def test_redirect301(self):
"""
L{client.RedirectAgent} follows redirects on status code 301.
"""
self._testRedirectDefault(301)
示例8: test_redirect302
# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import RedirectAgent [as 别名]
def test_redirect302(self):
"""
L{client.RedirectAgent} follows redirects on status code 302.
"""
self._testRedirectDefault(302)
示例9: test_redirect307
# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import RedirectAgent [as 别名]
def test_redirect307(self):
"""
L{client.RedirectAgent} follows redirects on status code 307.
"""
self._testRedirectDefault(307)
示例10: test_redirect303
# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import RedirectAgent [as 别名]
def test_redirect303(self):
"""
L{client.RedirectAgent} changes the method to I{GET} when getting a 303
redirect on a I{POST} request.
"""
self._testRedirectToGet(303, b'POST')
示例11: test_307OnPost
# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import RedirectAgent [as 别名]
def test_307OnPost(self):
"""
When getting a 307 redirect on a I{POST} request,
L{client.RedirectAgent} fails with a L{ResponseFailed} error wrapping
a L{error.PageRedirect} exception.
"""
self._testPageRedirectFailure(307, b'POST')
示例12: test_redirectLimit
# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import RedirectAgent [as 别名]
def test_redirectLimit(self):
"""
If the limit of redirects specified to L{client.RedirectAgent} is
reached, the deferred fires with L{ResponseFailed} error wrapping
a L{InfiniteRedirection} exception.
"""
agent = self.buildAgentForWrapperTest(self.reactor)
redirectAgent = client.RedirectAgent(agent, 1)
deferred = redirectAgent.request(b'GET', b'http://example.com/foo')
req, res = self.protocol.requests.pop()
headers = http_headers.Headers(
{b'location': [b'http://example.com/bar']})
response = Response((b'HTTP', 1, 1), 302, b'OK', headers, None)
res.callback(response)
req2, res2 = self.protocol.requests.pop()
response2 = Response((b'HTTP', 1, 1), 302, b'OK', headers, None)
res2.callback(response2)
fail = self.failureResultOf(deferred, client.ResponseFailed)
fail.value.reasons[0].trap(error.InfiniteRedirection)
self.assertEqual(b'http://example.com/foo',
fail.value.reasons[0].value.location)
self.assertEqual(302, fail.value.response.code)
示例13: test_relativeURI
# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import RedirectAgent [as 别名]
def test_relativeURI(self):
"""
L{client.RedirectAgent} resolves and follows relative I{URI}s in
redirects, preserving query strings.
"""
self._testRedirectURI(
b'http://example.com/foo/bar', b'baz',
b'http://example.com/foo/baz')
self._testRedirectURI(
b'http://example.com/foo/bar', b'/baz',
b'http://example.com/baz')
self._testRedirectURI(
b'http://example.com/foo/bar', b'/baz?a',
b'http://example.com/baz?a')
示例14: test_relativeURIPreserveFragments
# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import RedirectAgent [as 别名]
def test_relativeURIPreserveFragments(self):
"""
L{client.RedirectAgent} resolves and follows relative I{URI}s in
redirects, preserving fragments in way that complies with the HTTP 1.1
bis draft.
@see: U{https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-22#section-7.1.2}
"""
self._testRedirectURI(
b'http://example.com/foo/bar#frag', b'/baz?a',
b'http://example.com/baz?a#frag')
self._testRedirectURI(
b'http://example.com/foo/bar', b'/baz?a#frag2',
b'http://example.com/baz?a#frag2')
示例15: test_relativeURISchemeRelative
# 需要导入模块: from twisted.web import client [as 别名]
# 或者: from twisted.web.client import RedirectAgent [as 别名]
def test_relativeURISchemeRelative(self):
"""
L{client.RedirectAgent} resolves and follows scheme relative I{URI}s in
redirects, replacing the hostname and port when required.
"""
self._testRedirectURI(
b'http://example.com/foo/bar', b'//foo.com/baz',
b'http://foo.com/baz')
self._testRedirectURI(
b'http://example.com/foo/bar', b'//foo.com:81/baz',
b'http://foo.com:81/baz')