code
stringlengths
26
870k
docstring
stringlengths
1
65.6k
func_name
stringlengths
1
194
language
stringclasses
1 value
repo
stringlengths
8
68
path
stringlengths
5
194
url
stringlengths
46
254
license
stringclasses
4 values
def setUp(self): """ Create an L{Agent} wrapped around a fake reactor. """ self.reactor = self.createReactor() self.agent = self.buildAgentForWrapperTest(self.reactor)
Create an L{Agent} wrapped around a fake reactor.
setUp
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_acceptHeaders(self): """ L{client.ContentDecoderAgent} sets the I{Accept-Encoding} header to the names of the available decoder objects. """ agent = client.ContentDecoderAgent( self.agent, [(b'decoder1', Decoder1), (b'decoder2', Decoder2)]) agent.request(b'GET', b'http://example.com/foo') protocol = self.protocol self.assertEqual(len(protocol.requests), 1) req, res = protocol.requests.pop() self.assertEqual(req.headers.getRawHeaders(b'accept-encoding'), [b'decoder1,decoder2'])
L{client.ContentDecoderAgent} sets the I{Accept-Encoding} header to the names of the available decoder objects.
test_acceptHeaders
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_existingHeaders(self): """ If there are existing I{Accept-Encoding} fields, L{client.ContentDecoderAgent} creates a new field for the decoders it knows about. """ headers = http_headers.Headers({b'foo': [b'bar'], b'accept-encoding': [b'fizz']}) agent = client.ContentDecoderAgent( self.agent, [(b'decoder1', Decoder1), (b'decoder2', Decoder2)]) agent.request(b'GET', b'http://example.com/foo', headers=headers) protocol = self.protocol self.assertEqual(len(protocol.requests), 1) req, res = protocol.requests.pop() self.assertEqual( list(sorted(req.headers.getAllRawHeaders())), [(b'Accept-Encoding', [b'fizz', b'decoder1,decoder2']), (b'Foo', [b'bar']), (b'Host', [b'example.com'])])
If there are existing I{Accept-Encoding} fields, L{client.ContentDecoderAgent} creates a new field for the decoders it knows about.
test_existingHeaders
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_plainEncodingResponse(self): """ If the response is not encoded despited the request I{Accept-Encoding} headers, L{client.ContentDecoderAgent} simply forwards the response. """ agent = client.ContentDecoderAgent( self.agent, [(b'decoder1', Decoder1), (b'decoder2', Decoder2)]) deferred = agent.request(b'GET', b'http://example.com/foo') req, res = self.protocol.requests.pop() response = Response((b'HTTP', 1, 1), 200, b'OK', http_headers.Headers(), None) res.callback(response) return deferred.addCallback(self.assertIdentical, response)
If the response is not encoded despited the request I{Accept-Encoding} headers, L{client.ContentDecoderAgent} simply forwards the response.
test_plainEncodingResponse
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_unsupportedEncoding(self): """ If an encoding unknown to the L{client.ContentDecoderAgent} is found, the response is unchanged. """ agent = client.ContentDecoderAgent( self.agent, [(b'decoder1', Decoder1), (b'decoder2', Decoder2)]) deferred = agent.request(b'GET', b'http://example.com/foo') req, res = self.protocol.requests.pop() headers = http_headers.Headers({b'foo': [b'bar'], b'content-encoding': [b'fizz']}) response = Response((b'HTTP', 1, 1), 200, b'OK', headers, None) res.callback(response) return deferred.addCallback(self.assertIdentical, response)
If an encoding unknown to the L{client.ContentDecoderAgent} is found, the response is unchanged.
test_unsupportedEncoding
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_unknownEncoding(self): """ When L{client.ContentDecoderAgent} encounters a decoder it doesn't know about, it stops decoding even if another encoding is known afterwards. """ agent = client.ContentDecoderAgent( self.agent, [(b'decoder1', Decoder1), (b'decoder2', Decoder2)]) deferred = agent.request(b'GET', b'http://example.com/foo') req, res = self.protocol.requests.pop() headers = http_headers.Headers({b'foo': [b'bar'], b'content-encoding': [b'decoder1,fizz,decoder2']}) response = Response((b'HTTP', 1, 1), 200, b'OK', headers, None) res.callback(response) def check(result): self.assertNotIdentical(response, result) self.assertIsInstance(result, Decoder2) self.assertEqual([b'decoder1,fizz'], result.headers.getRawHeaders(b'content-encoding')) return deferred.addCallback(check)
When L{client.ContentDecoderAgent} encounters a decoder it doesn't know about, it stops decoding even if another encoding is known afterwards.
test_unknownEncoding
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def setUp(self): """ Create an L{Agent} wrapped around a fake reactor. """ self.reactor = self.createReactor() agent = self.buildAgentForWrapperTest(self.reactor) self.agent = client.ContentDecoderAgent( agent, [(b"gzip", client.GzipDecoder)])
Create an L{Agent} wrapped around a fake reactor.
setUp
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_gzipEncodingResponse(self): """ If the response has a C{gzip} I{Content-Encoding} header, L{GzipDecoder} wraps the response to return uncompressed data to the user. """ deferred = self.agent.request(b'GET', b'http://example.com/foo') req, res = self.protocol.requests.pop() headers = http_headers.Headers({b'foo': [b'bar'], b'content-encoding': [b'gzip']}) transport = StringTransport() response = Response((b'HTTP', 1, 1), 200, b'OK', headers, transport) response.length = 12 res.callback(response) compressor = zlib.compressobj(2, zlib.DEFLATED, 16 + zlib.MAX_WBITS) data = (compressor.compress(b'x' * 6) + compressor.compress(b'y' * 4) + compressor.flush()) def checkResponse(result): self.assertNotIdentical(result, response) self.assertEqual(result.version, (b'HTTP', 1, 1)) self.assertEqual(result.code, 200) self.assertEqual(result.phrase, b'OK') self.assertEqual(list(result.headers.getAllRawHeaders()), [(b'Foo', [b'bar'])]) self.assertEqual(result.length, UNKNOWN_LENGTH) self.assertRaises(AttributeError, getattr, result, 'unknown') response._bodyDataReceived(data[:5]) response._bodyDataReceived(data[5:]) response._bodyDataFinished() protocol = SimpleAgentProtocol() result.deliverBody(protocol) self.assertEqual(protocol.received, [b'x' * 6 + b'y' * 4]) return defer.gatherResults([protocol.made, protocol.finished]) deferred.addCallback(checkResponse) return deferred
If the response has a C{gzip} I{Content-Encoding} header, L{GzipDecoder} wraps the response to return uncompressed data to the user.
test_gzipEncodingResponse
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_brokenContent(self): """ If the data received by the L{GzipDecoder} isn't valid gzip-compressed data, the call to C{deliverBody} fails with a C{zlib.error}. """ deferred = self.agent.request(b'GET', b'http://example.com/foo') req, res = self.protocol.requests.pop() headers = http_headers.Headers({b'foo': [b'bar'], b'content-encoding': [b'gzip']}) transport = StringTransport() response = Response((b'HTTP', 1, 1), 200, b'OK', headers, transport) response.length = 12 res.callback(response) data = b"not gzipped content" def checkResponse(result): response._bodyDataReceived(data) result.deliverBody(Protocol()) deferred.addCallback(checkResponse) self.assertFailure(deferred, client.ResponseFailed) def checkFailure(error): error.reasons[0].trap(zlib.error) self.assertIsInstance(error.response, Response) return deferred.addCallback(checkFailure)
If the data received by the L{GzipDecoder} isn't valid gzip-compressed data, the call to C{deliverBody} fails with a C{zlib.error}.
test_brokenContent
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_flushData(self): """ When the connection with the server is lost, the gzip protocol calls C{flush} on the zlib decompressor object to get uncompressed data which may have been buffered. """ class decompressobj(object): def __init__(self, wbits): pass def decompress(self, data): return b'x' def flush(self): return b'y' oldDecompressObj = zlib.decompressobj zlib.decompressobj = decompressobj self.addCleanup(setattr, zlib, 'decompressobj', oldDecompressObj) deferred = self.agent.request(b'GET', b'http://example.com/foo') req, res = self.protocol.requests.pop() headers = http_headers.Headers({b'content-encoding': [b'gzip']}) transport = StringTransport() response = Response((b'HTTP', 1, 1), 200, b'OK', headers, transport) res.callback(response) def checkResponse(result): response._bodyDataReceived(b'data') response._bodyDataFinished() protocol = SimpleAgentProtocol() result.deliverBody(protocol) self.assertEqual(protocol.received, [b'x', b'y']) return defer.gatherResults([protocol.made, protocol.finished]) deferred.addCallback(checkResponse) return deferred
When the connection with the server is lost, the gzip protocol calls C{flush} on the zlib decompressor object to get uncompressed data which may have been buffered.
test_flushData
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_flushError(self): """ If the C{flush} call in C{connectionLost} fails, the C{zlib.error} exception is caught and turned into a L{ResponseFailed}. """ class decompressobj(object): def __init__(self, wbits): pass def decompress(self, data): return b'x' def flush(self): raise zlib.error() oldDecompressObj = zlib.decompressobj zlib.decompressobj = decompressobj self.addCleanup(setattr, zlib, 'decompressobj', oldDecompressObj) deferred = self.agent.request(b'GET', b'http://example.com/foo') req, res = self.protocol.requests.pop() headers = http_headers.Headers({b'content-encoding': [b'gzip']}) transport = StringTransport() response = Response((b'HTTP', 1, 1), 200, b'OK', headers, transport) res.callback(response) def checkResponse(result): response._bodyDataReceived(b'data') response._bodyDataFinished() protocol = SimpleAgentProtocol() result.deliverBody(protocol) self.assertEqual(protocol.received, [b'x', b'y']) return defer.gatherResults([protocol.made, protocol.finished]) deferred.addCallback(checkResponse) self.assertFailure(deferred, client.ResponseFailed) def checkFailure(error): error.reasons[1].trap(zlib.error) self.assertIsInstance(error.response, Response) return deferred.addCallback(checkFailure)
If the C{flush} call in C{connectionLost} fails, the C{zlib.error} exception is caught and turned into a L{ResponseFailed}.
test_flushError
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def makeAgent(self): """ @return: a new L{twisted.web.client.ProxyAgent} """ return client.ProxyAgent( TCP4ClientEndpoint(self.reactor, "127.0.0.1", 1234), self.reactor)
@return: a new L{twisted.web.client.ProxyAgent}
makeAgent
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_nonBytesMethod(self): """ L{ProxyAgent.request} raises L{TypeError} when the C{method} argument isn't L{bytes}. """ self.assertRaises(TypeError, self.agent.request, u'GET', b'http://foo.example/')
L{ProxyAgent.request} raises L{TypeError} when the C{method} argument isn't L{bytes}.
test_nonBytesMethod
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_proxyRequest(self): """ L{client.ProxyAgent} issues an HTTP request against the proxy, with the full URI as path, when C{request} is called. """ headers = http_headers.Headers({b'foo': [b'bar']}) # Just going to check the body for identity, so it doesn't need to be # real. body = object() self.agent.request( b'GET', b'http://example.com:1234/foo?bar', headers, body) host, port, factory = self.reactor.tcpClients.pop()[:3] self.assertEqual(host, "bar") self.assertEqual(port, 5678) self.assertIsInstance(factory._wrappedFactory, client._HTTP11ClientFactory) protocol = self.protocol # The request should be issued. self.assertEqual(len(protocol.requests), 1) req, res = protocol.requests.pop() self.assertIsInstance(req, Request) self.assertEqual(req.method, b'GET') self.assertEqual(req.uri, b'http://example.com:1234/foo?bar') self.assertEqual( req.headers, http_headers.Headers({b'foo': [b'bar'], b'host': [b'example.com:1234']})) self.assertIdentical(req.bodyProducer, body)
L{client.ProxyAgent} issues an HTTP request against the proxy, with the full URI as path, when C{request} is called.
test_proxyRequest
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_nonPersistent(self): """ C{ProxyAgent} connections are not persistent by default. """ self.assertEqual(self.agent._pool.persistent, False)
C{ProxyAgent} connections are not persistent by default.
test_nonPersistent
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_connectUsesConnectionPool(self): """ When a connection is made by the C{ProxyAgent}, it uses its pool's C{getConnection} method to do so, with the endpoint it was constructed with and a key of C{("http-proxy", endpoint)}. """ endpoint = DummyEndpoint() class DummyPool(object): connected = False persistent = False def getConnection(this, key, ep): this.connected = True self.assertIdentical(ep, endpoint) # The key is *not* tied to the final destination, but only to # the address of the proxy, since that's where *we* are # connecting: self.assertEqual(key, ("http-proxy", endpoint)) return defer.succeed(StubHTTPProtocol()) pool = DummyPool() agent = client.ProxyAgent(endpoint, self.reactor, pool=pool) self.assertIdentical(pool, agent._pool) agent.request(b'GET', b'http://foo/') self.assertEqual(agent._pool.connected, True)
When a connection is made by the C{ProxyAgent}, it uses its pool's C{getConnection} method to do so, with the endpoint it was constructed with and a key of C{("http-proxy", endpoint)}.
test_connectUsesConnectionPool
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
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)
L{client.RedirectAgent} behaves like L{client.Agent} if the response doesn't contain a redirect.
test_noRedirect
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
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)
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.
_testRedirectDefault
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_redirect301(self): """ L{client.RedirectAgent} follows redirects on status code 301. """ self._testRedirectDefault(301)
L{client.RedirectAgent} follows redirects on status code 301.
test_redirect301
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_redirect302(self): """ L{client.RedirectAgent} follows redirects on status code 302. """ self._testRedirectDefault(302)
L{client.RedirectAgent} follows redirects on status code 302.
test_redirect302
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_redirect307(self): """ L{client.RedirectAgent} follows redirects on status code 307. """ self._testRedirectDefault(307)
L{client.RedirectAgent} follows redirects on status code 307.
test_redirect307
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def _testRedirectToGet(self, code, method): """ L{client.RedirectAgent} changes the method to I{GET} when getting a redirect on a non-I{GET} request. @param code: HTTP status code. @param method: HTTP request method. """ self.agent.request(method, 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), 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)
L{client.RedirectAgent} changes the method to I{GET} when getting a redirect on a non-I{GET} request. @param code: HTTP status code. @param method: HTTP request method.
_testRedirectToGet
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
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')
L{client.RedirectAgent} changes the method to I{GET} when getting a 303 redirect on a I{POST} request.
test_redirect303
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
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)
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.
test_noLocationField
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
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)
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.
_testPageRedirectFailure
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
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')
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.
test_307OnPost
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
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)
If the limit of redirects specified to L{client.RedirectAgent} is reached, the deferred fires with L{ResponseFailed} error wrapping a L{InfiniteRedirection} exception.
test_redirectLimit
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def _testRedirectURI(self, uri, location, finalURI): """ When L{client.RedirectAgent} encounters a relative redirect I{URI}, it is resolved against the request I{URI} before following the redirect. @param uri: Request URI. @param location: I{Location} header redirect URI. @param finalURI: Expected final URI. """ self.agent.request(b'GET', uri) req, res = self.protocol.requests.pop() headers = http_headers.Headers( {b'location': [location]}) response = Response((b'HTTP', 1, 1), 302, b'OK', headers, None) res.callback(response) req2, res2 = self.protocol.requests.pop() self.assertEqual(b'GET', req2.method) self.assertEqual(finalURI, req2.absoluteURI)
When L{client.RedirectAgent} encounters a relative redirect I{URI}, it is resolved against the request I{URI} before following the redirect. @param uri: Request URI. @param location: I{Location} header redirect URI. @param finalURI: Expected final URI.
_testRedirectURI
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
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')
L{client.RedirectAgent} resolves and follows relative I{URI}s in redirects, preserving query strings.
test_relativeURI
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
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')
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}
test_relativeURIPreserveFragments
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
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')
L{client.RedirectAgent} resolves and follows scheme relative I{URI}s in redirects, replacing the hostname and port when required.
test_relativeURISchemeRelative
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
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)
L{Response.response} references the previous L{Response} from a redirect, or L{None} if there was no previous response.
test_responseHistory
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def makeAgent(self): """ @return: a new L{twisted.web.client.RedirectAgent} """ return client.RedirectAgent( self.buildAgentForWrapperTest(self.reactor))
@return: a new L{twisted.web.client.RedirectAgent}
makeAgent
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_301OnPost(self): """ When getting a 301 redirect on a I{POST} request, L{client.RedirectAgent} fails with a L{ResponseFailed} error wrapping a L{error.PageRedirect} exception. """ self._testPageRedirectFailure(301, b'POST')
When getting a 301 redirect on a I{POST} request, L{client.RedirectAgent} fails with a L{ResponseFailed} error wrapping a L{error.PageRedirect} exception.
test_301OnPost
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_302OnPost(self): """ When getting a 302 redirect on a I{POST} request, L{client.RedirectAgent} fails with a L{ResponseFailed} error wrapping a L{error.PageRedirect} exception. """ self._testPageRedirectFailure(302, b'POST')
When getting a 302 redirect on a I{POST} request, L{client.RedirectAgent} fails with a L{ResponseFailed} error wrapping a L{error.PageRedirect} exception.
test_302OnPost
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def makeAgent(self): """ @return: a new L{twisted.web.client.BrowserLikeRedirectAgent} """ return client.BrowserLikeRedirectAgent( self.buildAgentForWrapperTest(self.reactor))
@return: a new L{twisted.web.client.BrowserLikeRedirectAgent}
makeAgent
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_redirectToGet301(self): """ L{client.BrowserLikeRedirectAgent} changes the method to I{GET} when getting a 302 redirect on a I{POST} request. """ self._testRedirectToGet(301, b'POST')
L{client.BrowserLikeRedirectAgent} changes the method to I{GET} when getting a 302 redirect on a I{POST} request.
test_redirectToGet301
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_redirectToGet302(self): """ L{client.BrowserLikeRedirectAgent} changes the method to I{GET} when getting a 302 redirect on a I{POST} request. """ self._testRedirectToGet(302, b'POST')
L{client.BrowserLikeRedirectAgent} changes the method to I{GET} when getting a 302 redirect on a I{POST} request.
test_redirectToGet302
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def abortConnection(self): """ A testable version of the C{ITCPTransport.abortConnection} method. Since this is a special case of closing the connection, C{loseConnection} is also called. """ self.aborting = True self.loseConnection()
A testable version of the C{ITCPTransport.abortConnection} method. Since this is a special case of closing the connection, C{loseConnection} is also called.
abortConnection
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def __init__(self, headers=None, transportFactory=AbortableStringTransport): """ @param headers: The headers for this response. If L{None}, an empty L{Headers} instance will be used. @type headers: L{Headers} @param transportFactory: A callable used to construct the transport. """ if headers is None: headers = Headers() self.headers = headers self.transport = transportFactory()
@param headers: The headers for this response. If L{None}, an empty L{Headers} instance will be used. @type headers: L{Headers} @param transportFactory: A callable used to construct the transport.
__init__
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def deliverBody(self, protocol): """ Record the given protocol and use it to make a connection with L{DummyResponse.transport}. """ self.protocol = protocol self.protocol.makeConnection(self.transport)
Record the given protocol and use it to make a connection with L{DummyResponse.transport}.
deliverBody
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def deliverBody(self, protocol): """ Make the connection, then remove the transport. """ self.protocol = protocol self.protocol.makeConnection(self.transport) self.protocol.transport = None
Make the connection, then remove the transport.
deliverBody
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_success(self): """ L{client.readBody} returns a L{Deferred} which fires with the complete body of the L{IResponse} provider passed to it. """ response = DummyResponse() d = client.readBody(response) response.protocol.dataReceived(b"first") response.protocol.dataReceived(b"second") response.protocol.connectionLost(Failure(ResponseDone())) self.assertEqual(self.successResultOf(d), b"firstsecond")
L{client.readBody} returns a L{Deferred} which fires with the complete body of the L{IResponse} provider passed to it.
test_success
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_cancel(self): """ When cancelling the L{Deferred} returned by L{client.readBody}, the connection to the server will be aborted. """ response = DummyResponse() deferred = client.readBody(response) deferred.cancel() self.failureResultOf(deferred, defer.CancelledError) self.assertTrue(response.transport.aborting)
When cancelling the L{Deferred} returned by L{client.readBody}, the connection to the server will be aborted.
test_cancel
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_withPotentialDataLoss(self): """ If the full body of the L{IResponse} passed to L{client.readBody} is not definitely received, the L{Deferred} returned by L{client.readBody} fires with a L{Failure} wrapping L{client.PartialDownloadError} with the content that was received. """ response = DummyResponse() d = client.readBody(response) response.protocol.dataReceived(b"first") response.protocol.dataReceived(b"second") response.protocol.connectionLost(Failure(PotentialDataLoss())) failure = self.failureResultOf(d) failure.trap(client.PartialDownloadError) self.assertEqual({ "status": failure.value.status, "message": failure.value.message, "body": failure.value.response, }, { "status": b"200", "message": b"OK", "body": b"firstsecond", })
If the full body of the L{IResponse} passed to L{client.readBody} is not definitely received, the L{Deferred} returned by L{client.readBody} fires with a L{Failure} wrapping L{client.PartialDownloadError} with the content that was received.
test_withPotentialDataLoss
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_otherErrors(self): """ If there is an exception other than L{client.PotentialDataLoss} while L{client.readBody} is collecting the response body, the L{Deferred} returned by {client.readBody} fires with that exception. """ response = DummyResponse() d = client.readBody(response) response.protocol.dataReceived(b"first") response.protocol.connectionLost( Failure(ConnectionLost("mystery problem"))) reason = self.failureResultOf(d) reason.trap(ConnectionLost) self.assertEqual(reason.value.args, ("mystery problem",))
If there is an exception other than L{client.PotentialDataLoss} while L{client.readBody} is collecting the response body, the L{Deferred} returned by {client.readBody} fires with that exception.
test_otherErrors
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_deprecatedTransport(self): """ Calling L{client.readBody} with a transport that does not implement L{twisted.internet.interfaces.ITCPTransport} produces a deprecation warning, but no exception when cancelling. """ response = DummyResponse(transportFactory=StringTransport) response.transport.abortConnection = None d = self.assertWarns( DeprecationWarning, 'Using readBody with a transport that does not have an ' 'abortConnection method', __file__, lambda: client.readBody(response)) d.cancel() self.failureResultOf(d, defer.CancelledError)
Calling L{client.readBody} with a transport that does not implement L{twisted.internet.interfaces.ITCPTransport} produces a deprecation warning, but no exception when cancelling.
test_deprecatedTransport
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_deprecatedTransportNoWarning(self): """ Calling L{client.readBody} with a response that has already had its transport closed (eg. for a very small request) will not trigger a deprecation warning. """ response = AlreadyCompletedDummyResponse() client.readBody(response) warnings = self.flushWarnings() self.assertEqual(len(warnings), 0)
Calling L{client.readBody} with a response that has already had its transport closed (eg. for a very small request) will not trigger a deprecation warning.
test_deprecatedTransportNoWarning
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_cacheIsUsed(self): """ Verify that the connection creator is added to the policy's cache, and that it is reused on subsequent calls to creatorForNetLoc. """ trustRoot = CustomOpenSSLTrustRoot() wrappedPolicy = BrowserLikePolicyForHTTPS(trustRoot=trustRoot) policy = HostnameCachingHTTPSPolicy(wrappedPolicy) creator = policy.creatorForNetloc(b"foo", 1589) self.assertTrue(trustRoot.called) trustRoot.called = False self.assertEquals(1, len(policy._cache)) connection = creator.clientConnectionForTLS(None) self.assertIs(trustRoot.context, connection.get_context()) policy.creatorForNetloc(b"foo", 1589) self.assertFalse(trustRoot.called)
Verify that the connection creator is added to the policy's cache, and that it is reused on subsequent calls to creatorForNetLoc.
test_cacheIsUsed
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_cacheRemovesOldest(self): """ Verify that when the cache is full, and a new entry is added, the oldest entry is removed. """ trustRoot = CustomOpenSSLTrustRoot() wrappedPolicy = BrowserLikePolicyForHTTPS(trustRoot=trustRoot) policy = HostnameCachingHTTPSPolicy(wrappedPolicy) for i in range(0, 20): hostname = u"host" + unicode(i) policy.creatorForNetloc(hostname.encode("ascii"), 8675) # Force host0, which was the first, to be the most recently used host0 = u"host0" policy.creatorForNetloc(host0.encode("ascii"), 309) self.assertIn(host0, policy._cache) self.assertEquals(20, len(policy._cache)) hostn = u"new" policy.creatorForNetloc(hostn.encode("ascii"), 309) host1 = u"host1" self.assertNotIn(host1, policy._cache) self.assertEquals(20, len(policy._cache)) self.assertIn(hostn, policy._cache) self.assertIn(host0, policy._cache) # Accessing an item repeatedly does not corrupt the LRU. for _ in range(20): policy.creatorForNetloc(host0.encode("ascii"), 8675) hostNPlus1 = u"new1" policy.creatorForNetloc(hostNPlus1.encode("ascii"), 800) self.assertNotIn(u"host2", policy._cache) self.assertEquals(20, len(policy._cache)) self.assertIn(hostNPlus1, policy._cache) self.assertIn(hostn, policy._cache) self.assertIn(host0, policy._cache)
Verify that when the cache is full, and a new entry is added, the oldest entry is removed.
test_cacheRemovesOldest
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def test_changeCacheSize(self): """ Verify that changing the cache size results in a policy that respects the new cache size and not the default. """ trustRoot = CustomOpenSSLTrustRoot() wrappedPolicy = BrowserLikePolicyForHTTPS(trustRoot=trustRoot) policy = HostnameCachingHTTPSPolicy(wrappedPolicy, cacheSize=5) for i in range(0, 5): hostname = u"host" + unicode(i) policy.creatorForNetloc(hostname.encode("ascii"), 8675) first = u"host0" self.assertIn(first, policy._cache) self.assertEquals(5, len(policy._cache)) hostn = u"new" policy.creatorForNetloc(hostn.encode("ascii"), 309) self.assertNotIn(first, policy._cache) self.assertEquals(5, len(policy._cache)) self.assertIn(hostn, policy._cache)
Verify that changing the cache size results in a policy that respects the new cache size and not the default.
test_changeCacheSize
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def attemptRequestWithMaliciousMethod(self, method): """ Attempt a request with the provided method. @param method: see L{MethodInjectionTestsMixin} """ client.Request( method=method, uri=b"http://twisted.invalid", headers=http_headers.Headers(), bodyProducer=None, )
Attempt a request with the provided method. @param method: see L{MethodInjectionTestsMixin}
attemptRequestWithMaliciousMethod
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def attemptRequestWithMaliciousMethod(self, method): """ Attempt a request with the provided method. @param method: see L{MethodInjectionTestsMixin} """ headers = http_headers.Headers({b"Host": [b"twisted.invalid"]}) req = client.Request( method=b"GET", uri=b"http://twisted.invalid", headers=headers, bodyProducer=None, ) req.method = method req.writeTo(StringTransport())
Attempt a request with the provided method. @param method: see L{MethodInjectionTestsMixin}
attemptRequestWithMaliciousMethod
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def attemptRequestWithMaliciousURI(self, uri): """ Attempt a request with the provided URI. @param method: see L{URIInjectionTestsMixin} """ client.Request( method=b"GET", uri=uri, headers=http_headers.Headers(), bodyProducer=None, )
Attempt a request with the provided URI. @param method: see L{URIInjectionTestsMixin}
attemptRequestWithMaliciousURI
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def attemptRequestWithMaliciousURI(self, uri): """ Attempt a request with the provided method. @param method: see L{URIInjectionTestsMixin} """ headers = http_headers.Headers({b"Host": [b"twisted.invalid"]}) req = client.Request( method=b"GET", uri=b"http://twisted.invalid", headers=headers, bodyProducer=None, ) req.uri = uri req.writeTo(StringTransport())
Attempt a request with the provided method. @param method: see L{URIInjectionTestsMixin}
attemptRequestWithMaliciousURI
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py
MIT
def registerProducer(self, prod, s): """ Call an L{IPullProducer}'s C{resumeProducing} method in a loop until it unregisters itself. @param prod: The producer. @type prod: L{IPullProducer} @param s: Whether or not the producer is streaming. """ # XXX: Handle IPushProducers self.go = 1 while self.go: prod.resumeProducing()
Call an L{IPullProducer}'s C{resumeProducing} method in a loop until it unregisters itself. @param prod: The producer. @type prod: L{IPullProducer} @param s: Whether or not the producer is streaming.
registerProducer
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
MIT
def getAllHeaders(self): """ Return dictionary mapping the names of all received headers to the last value received for each. Since this method does not return all header information, C{self.requestHeaders.getAllRawHeaders()} may be preferred. NOTE: This function is a direct copy of C{twisted.web.http.Request.getAllRawHeaders}. """ headers = {} for k, v in self.requestHeaders.getAllRawHeaders(): headers[k.lower()] = v[-1] return headers
Return dictionary mapping the names of all received headers to the last value received for each. Since this method does not return all header information, C{self.requestHeaders.getAllRawHeaders()} may be preferred. NOTE: This function is a direct copy of C{twisted.web.http.Request.getAllRawHeaders}.
getAllHeaders
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
MIT
def getHeader(self, name): """ Retrieve the value of a request header. @type name: C{bytes} @param name: The name of the request header for which to retrieve the value. Header names are compared case-insensitively. @rtype: C{bytes} or L{None} @return: The value of the specified request header. """ return self.requestHeaders.getRawHeaders(name.lower(), [None])[0]
Retrieve the value of a request header. @type name: C{bytes} @param name: The name of the request header for which to retrieve the value. Header names are compared case-insensitively. @rtype: C{bytes} or L{None} @return: The value of the specified request header.
getHeader
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
MIT
def setHeader(self, name, value): """TODO: make this assert on write() if the header is content-length """ self.responseHeaders.addRawHeader(name, value)
TODO: make this assert on write() if the header is content-length
setHeader
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
MIT
def render(self, resource): """ Render the given resource as a response to this request. This implementation only handles a few of the most common behaviors of resources. It can handle a render method that returns a string or C{NOT_DONE_YET}. It doesn't know anything about the semantics of request methods (eg HEAD) nor how to set any particular headers. Basically, it's largely broken, but sufficient for some tests at least. It should B{not} be expanded to do all the same stuff L{Request} does. Instead, L{DummyRequest} should be phased out and L{Request} (or some other real code factored in a different way) used. """ result = resource.render(self) if result is NOT_DONE_YET: return self.write(result) self.finish()
Render the given resource as a response to this request. This implementation only handles a few of the most common behaviors of resources. It can handle a render method that returns a string or C{NOT_DONE_YET}. It doesn't know anything about the semantics of request methods (eg HEAD) nor how to set any particular headers. Basically, it's largely broken, but sufficient for some tests at least. It should B{not} be expanded to do all the same stuff L{Request} does. Instead, L{DummyRequest} should be phased out and L{Request} (or some other real code factored in a different way) used.
render
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
MIT
def notifyFinish(self): """ Return a L{Deferred} which is called back with L{None} when the request is finished. This will probably only work if you haven't called C{finish} yet. """ finished = Deferred() self._finishedDeferreds.append(finished) return finished
Return a L{Deferred} which is called back with L{None} when the request is finished. This will probably only work if you haven't called C{finish} yet.
notifyFinish
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
MIT
def finish(self): """ Record that the request is finished and callback and L{Deferred}s waiting for notification of this. """ self.finished = self.finished + 1 if self._finishedDeferreds is not None: observers = self._finishedDeferreds self._finishedDeferreds = None for obs in observers: obs.callback(None)
Record that the request is finished and callback and L{Deferred}s waiting for notification of this.
finish
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
MIT
def processingFailed(self, reason): """ Errback and L{Deferreds} waiting for finish notification. """ if self._finishedDeferreds is not None: observers = self._finishedDeferreds self._finishedDeferreds = None for obs in observers: obs.errback(reason)
Errback and L{Deferreds} waiting for finish notification.
processingFailed
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
MIT
def setResponseCode(self, code, message=None): """ Set the HTTP status response code, but takes care that this is called before any data is written. """ assert not self.written, "Response code cannot be set after data has been written: %s." % "@@@@".join(self.written) self.responseCode = code self.responseMessage = message
Set the HTTP status response code, but takes care that this is called before any data is written.
setResponseCode
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
MIT
def getClientIP(self): """ Return the IPv4 address of the client which made this request, if there is one, otherwise L{None}. """ if isinstance(self.client, (IPv4Address, IPv6Address)): return self.client.host return None
Return the IPv4 address of the client which made this request, if there is one, otherwise L{None}.
getClientIP
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
MIT
def getClientAddress(self): """ Return the L{IAddress} of the client that made this request. @return: an address. @rtype: an L{IAddress} provider. """ if self.client is None: return NullAddress() return self.client
Return the L{IAddress} of the client that made this request. @return: an address. @rtype: an L{IAddress} provider.
getClientAddress
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
MIT
def getRequestHostname(self): """ Get a dummy hostname associated to the HTTP request. @rtype: C{bytes} @returns: a dummy hostname """ return self._serverName
Get a dummy hostname associated to the HTTP request. @rtype: C{bytes} @returns: a dummy hostname
getRequestHostname
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
MIT
def getHost(self): """ Get a dummy transport's host. @rtype: C{IPv4Address} @returns: a dummy transport's host """ return IPv4Address('TCP', '127.0.0.1', 80)
Get a dummy transport's host. @rtype: C{IPv4Address} @returns: a dummy transport's host
getHost
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
MIT
def setHost(self, host, port, ssl=0): """ Change the host and port the request thinks it's using. @type host: C{bytes} @param host: The value to which to change the host header. @type ssl: C{bool} @param ssl: A flag which, if C{True}, indicates that the request is considered secure (if C{True}, L{isSecure} will return C{True}). """ self._forceSSL = ssl # set first so isSecure will work if self.isSecure(): default = 443 else: default = 80 if port == default: hostHeader = host else: hostHeader = host + b":" + intToBytes(port) self.requestHeaders.addRawHeader(b"host", hostHeader)
Change the host and port the request thinks it's using. @type host: C{bytes} @param host: The value to which to change the host header. @type ssl: C{bool} @param ssl: A flag which, if C{True}, indicates that the request is considered secure (if C{True}, L{isSecure} will return C{True}).
setHost
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
MIT
def redirect(self, url): """ Utility function that does a redirect. The request should have finish() called after this. """ self.setResponseCode(FOUND) self.setHeader(b"location", url)
Utility function that does a redirect. The request should have finish() called after this.
redirect
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
MIT
def test_getClientIPDeprecated(self): """ L{DummyRequest.getClientIP} is deprecated in favor of L{DummyRequest.getClientAddress} """ request = DummyRequest([]) request.getClientIP() warnings = self.flushWarnings( offendingFunctions=[self.test_getClientIPDeprecated]) self.assertEqual(1, len(warnings)) [warning] = warnings self.assertEqual(warning.get("category"), DeprecationWarning) self.assertEqual( warning.get("message"), ("twisted.web.test.requesthelper.DummyRequest.getClientIP " "was deprecated in Twisted 18.4.0; " "please use getClientAddress instead"), )
L{DummyRequest.getClientIP} is deprecated in favor of L{DummyRequest.getClientAddress}
test_getClientIPDeprecated
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
MIT
def test_getClientIPSupportsIPv6(self): """ L{DummyRequest.getClientIP} supports IPv6 addresses, just like L{twisted.web.http.Request.getClientIP}. """ request = DummyRequest([]) client = IPv6Address("TCP", "::1", 12345) request.client = client self.assertEqual("::1", request.getClientIP())
L{DummyRequest.getClientIP} supports IPv6 addresses, just like L{twisted.web.http.Request.getClientIP}.
test_getClientIPSupportsIPv6
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
MIT
def test_getClientAddressWithoutClient(self): """ L{DummyRequest.getClientAddress} returns an L{IAddress} provider no C{client} has been set. """ request = DummyRequest([]) null = request.getClientAddress() verify.verifyObject(IAddress, null)
L{DummyRequest.getClientAddress} returns an L{IAddress} provider no C{client} has been set.
test_getClientAddressWithoutClient
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
MIT
def test_getClientAddress(self): """ L{DummyRequest.getClientAddress} returns the C{client}. """ request = DummyRequest([]) client = IPv4Address("TCP", "127.0.0.1", 12345) request.client = client address = request.getClientAddress() self.assertIs(address, client)
L{DummyRequest.getClientAddress} returns the C{client}.
test_getClientAddress
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py
MIT
def test_getChild(self): """ The C{getChild} method of L{ErrorPage} returns the L{ErrorPage} it is called on. """ page = self.errorPage(321, "foo", "bar") self.assertIdentical(page.getChild(b"name", object()), page)
The C{getChild} method of L{ErrorPage} returns the L{ErrorPage} it is called on.
test_getChild
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
MIT
def test_errorPageRendering(self): """ L{ErrorPage.render} returns a C{bytes} describing the error defined by the response code and message passed to L{ErrorPage.__init__}. It also uses that response code to set the response code on the L{Request} passed in. """ code = 321 brief = "brief description text" detail = "much longer text might go here" page = self.errorPage(code, brief, detail) self._pageRenderingTest(page, code, brief, detail)
L{ErrorPage.render} returns a C{bytes} describing the error defined by the response code and message passed to L{ErrorPage.__init__}. It also uses that response code to set the response code on the L{Request} passed in.
test_errorPageRendering
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
MIT
def test_noResourceRendering(self): """ L{NoResource} sets the HTTP I{NOT FOUND} code. """ detail = "long message" page = self.noResource(detail) self._pageRenderingTest(page, NOT_FOUND, "No Such Resource", detail)
L{NoResource} sets the HTTP I{NOT FOUND} code.
test_noResourceRendering
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
MIT
def test_forbiddenResourceRendering(self): """ L{ForbiddenResource} sets the HTTP I{FORBIDDEN} code. """ detail = "longer message" page = self.forbiddenResource(detail) self._pageRenderingTest(page, FORBIDDEN, "Forbidden Resource", detail)
L{ForbiddenResource} sets the HTTP I{FORBIDDEN} code.
test_forbiddenResourceRendering
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
MIT
def __init__(self, response): """ @param response: A C{bytes} object giving the value to return from C{render_GET}. """ Resource.__init__(self) self._response = response
@param response: A C{bytes} object giving the value to return from C{render_GET}.
__init__
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
MIT
def render_GET(self, request): """ Render a response to a I{GET} request by returning a short byte string to be written by the server. """ return self._response
Render a response to a I{GET} request by returning a short byte string to be written by the server.
render_GET
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
MIT
def test_staticChildren(self): """ L{Resource.putChild} adds a I{static} child to the resource. That child is returned from any call to L{Resource.getChildWithDefault} for the child's path. """ resource = Resource() child = Resource() sibling = Resource() resource.putChild(b"foo", child) resource.putChild(b"bar", sibling) self.assertIdentical( child, resource.getChildWithDefault(b"foo", DummyRequest([])))
L{Resource.putChild} adds a I{static} child to the resource. That child is returned from any call to L{Resource.getChildWithDefault} for the child's path.
test_staticChildren
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
MIT
def test_dynamicChildren(self): """ L{Resource.getChildWithDefault} delegates to L{Resource.getChild} when the requested path is not associated with any static child. """ path = b"foo" request = DummyRequest([]) resource = DynamicChildren() child = resource.getChildWithDefault(path, request) self.assertIsInstance(child, DynamicChild) self.assertEqual(child.path, path) self.assertIdentical(child.request, request)
L{Resource.getChildWithDefault} delegates to L{Resource.getChild} when the requested path is not associated with any static child.
test_dynamicChildren
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
MIT
def test_staticChildPathType(self): """ Test that passing the wrong type to putChild results in a warning, and a failure in Python 3 """ resource = Resource() child = Resource() sibling = Resource() resource.putChild(u"foo", child) warnings = self.flushWarnings([self.test_staticChildPathType]) self.assertEqual(len(warnings), 1) self.assertIn("Path segment must be bytes", warnings[0]['message']) if _PY3: # We expect an error here because u"foo" != b"foo" on Py3k self.assertIsInstance( resource.getChildWithDefault(b"foo", DummyRequest([])), ErrorPage) resource.putChild(None, sibling) warnings = self.flushWarnings([self.test_staticChildPathType]) self.assertEqual(len(warnings), 1) self.assertIn("Path segment must be bytes", warnings[0]['message'])
Test that passing the wrong type to putChild results in a warning, and a failure in Python 3
test_staticChildPathType
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
MIT
def test_defaultHEAD(self): """ When not otherwise overridden, L{Resource.render} treats a I{HEAD} request as if it were a I{GET} request. """ expected = b"insert response here" request = DummyRequest([]) request.method = b'HEAD' resource = BytesReturnedRenderable(expected) self.assertEqual(expected, resource.render(request))
When not otherwise overridden, L{Resource.render} treats a I{HEAD} request as if it were a I{GET} request.
test_defaultHEAD
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
MIT
def test_explicitAllowedMethods(self): """ The L{UnsupportedMethod} raised by L{Resource.render} for an unsupported request method has a C{allowedMethods} attribute set to the value of the C{allowedMethods} attribute of the L{Resource}, if it has one. """ expected = [b'GET', b'HEAD', b'PUT'] resource = Resource() resource.allowedMethods = expected request = DummyRequest([]) request.method = b'FICTIONAL' exc = self.assertRaises(UnsupportedMethod, resource.render, request) self.assertEqual(set(expected), set(exc.allowedMethods))
The L{UnsupportedMethod} raised by L{Resource.render} for an unsupported request method has a C{allowedMethods} attribute set to the value of the C{allowedMethods} attribute of the L{Resource}, if it has one.
test_explicitAllowedMethods
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
MIT
def test_implicitAllowedMethods(self): """ The L{UnsupportedMethod} raised by L{Resource.render} for an unsupported request method has a C{allowedMethods} attribute set to a list of the methods supported by the L{Resource}, as determined by the I{render_}-prefixed methods which it defines, if C{allowedMethods} is not explicitly defined by the L{Resource}. """ expected = set([b'GET', b'HEAD', b'PUT']) resource = ImplicitAllowedMethods() request = DummyRequest([]) request.method = b'FICTIONAL' exc = self.assertRaises(UnsupportedMethod, resource.render, request) self.assertEqual(expected, set(exc.allowedMethods))
The L{UnsupportedMethod} raised by L{Resource.render} for an unsupported request method has a C{allowedMethods} attribute set to a list of the methods supported by the L{Resource}, as determined by the I{render_}-prefixed methods which it defines, if C{allowedMethods} is not explicitly defined by the L{Resource}.
test_implicitAllowedMethods
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
MIT
def test_exhaustedPostPath(self): """ L{getChildForRequest} returns whatever resource has been reached by the time the request's C{postpath} is empty. """ request = DummyRequest([]) resource = Resource() result = getChildForRequest(resource, request) self.assertIdentical(resource, result)
L{getChildForRequest} returns whatever resource has been reached by the time the request's C{postpath} is empty.
test_exhaustedPostPath
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
MIT
def test_leafResource(self): """ L{getChildForRequest} returns the first resource it encounters with a C{isLeaf} attribute set to C{True}. """ request = DummyRequest([b"foo", b"bar"]) resource = Resource() resource.isLeaf = True result = getChildForRequest(resource, request) self.assertIdentical(resource, result)
L{getChildForRequest} returns the first resource it encounters with a C{isLeaf} attribute set to C{True}.
test_leafResource
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
MIT
def test_postPathToPrePath(self): """ As path segments from the request are traversed, they are taken from C{postpath} and put into C{prepath}. """ request = DummyRequest([b"foo", b"bar"]) root = Resource() child = Resource() child.isLeaf = True root.putChild(b"foo", child) self.assertIdentical(child, getChildForRequest(root, request)) self.assertEqual(request.prepath, [b"foo"]) self.assertEqual(request.postpath, [b"bar"])
As path segments from the request are traversed, they are taken from C{postpath} and put into C{prepath}.
test_postPathToPrePath
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_resource.py
MIT
def test_lookupTag(self): """ HTML tags can be retrieved through C{tags}. """ tag = tags.a self.assertEqual(tag.tagName, "a")
HTML tags can be retrieved through C{tags}.
test_lookupTag
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
MIT
def test_lookupHTML5Tag(self): """ Twisted supports the latest and greatest HTML tags from the HTML5 specification. """ tag = tags.video self.assertEqual(tag.tagName, "video")
Twisted supports the latest and greatest HTML tags from the HTML5 specification.
test_lookupHTML5Tag
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
MIT
def test_lookupTransparentTag(self): """ To support transparent inclusion in templates, there is a special tag, the transparent tag, which has no name of its own but is accessed through the "transparent" attribute. """ tag = tags.transparent self.assertEqual(tag.tagName, "")
To support transparent inclusion in templates, there is a special tag, the transparent tag, which has no name of its own but is accessed through the "transparent" attribute.
test_lookupTransparentTag
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
MIT
def test_lookupInvalidTag(self): """ Invalid tags which are not part of HTML cause AttributeErrors when accessed through C{tags}. """ self.assertRaises(AttributeError, getattr, tags, "invalid")
Invalid tags which are not part of HTML cause AttributeErrors when accessed through C{tags}.
test_lookupInvalidTag
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
MIT
def test_lookupXMP(self): """ As a special case, the <xmp> tag is simply not available through C{tags} or any other part of the templating machinery. """ self.assertRaises(AttributeError, getattr, tags, "xmp")
As a special case, the <xmp> tag is simply not available through C{tags} or any other part of the templating machinery.
test_lookupXMP
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
MIT
def test_missingTemplateLoader(self): """ L{Element.render} raises L{MissingTemplateLoader} if the C{loader} attribute is L{None}. """ element = Element() err = self.assertRaises(MissingTemplateLoader, element.render, None) self.assertIdentical(err.element, element)
L{Element.render} raises L{MissingTemplateLoader} if the C{loader} attribute is L{None}.
test_missingTemplateLoader
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
MIT
def test_missingTemplateLoaderRepr(self): """ A L{MissingTemplateLoader} instance can be repr()'d without error. """ class PrettyReprElement(Element): def __repr__(self): return 'Pretty Repr Element' self.assertIn('Pretty Repr Element', repr(MissingTemplateLoader(PrettyReprElement())))
A L{MissingTemplateLoader} instance can be repr()'d without error.
test_missingTemplateLoaderRepr
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
MIT
def test_missingRendererMethod(self): """ When called with the name which is not associated with a render method, L{Element.lookupRenderMethod} raises L{MissingRenderMethod}. """ element = Element() err = self.assertRaises( MissingRenderMethod, element.lookupRenderMethod, "foo") self.assertIdentical(err.element, element) self.assertEqual(err.renderName, "foo")
When called with the name which is not associated with a render method, L{Element.lookupRenderMethod} raises L{MissingRenderMethod}.
test_missingRendererMethod
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
MIT
def test_missingRenderMethodRepr(self): """ A L{MissingRenderMethod} instance can be repr()'d without error. """ class PrettyReprElement(Element): def __repr__(self): return 'Pretty Repr Element' s = repr(MissingRenderMethod(PrettyReprElement(), 'expectedMethod')) self.assertIn('Pretty Repr Element', s) self.assertIn('expectedMethod', s)
A L{MissingRenderMethod} instance can be repr()'d without error.
test_missingRenderMethodRepr
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
MIT
def test_definedRenderer(self): """ When called with the name of a defined render method, L{Element.lookupRenderMethod} returns that render method. """ class ElementWithRenderMethod(Element): @renderer def foo(self, request, tag): return "bar" foo = ElementWithRenderMethod().lookupRenderMethod("foo") self.assertEqual(foo(None, None), "bar")
When called with the name of a defined render method, L{Element.lookupRenderMethod} returns that render method.
test_definedRenderer
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
MIT
def test_render(self): """ L{Element.render} loads a document from the C{loader} attribute and returns it. """ class TemplateLoader(object): def load(self): return "result" class StubElement(Element): loader = TemplateLoader() element = StubElement() self.assertEqual(element.render(None), "result")
L{Element.render} loads a document from the C{loader} attribute and returns it.
test_render
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_template.py
MIT