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
182
url
stringlengths
46
251
license
stringclasses
4 values
def proxy(self, factory=None): """ Return a new xmlrpc.Proxy for the test site created in setUp(), using the given factory as the queryFactory, or self.queryFactory if no factory is provided. """ p = xmlrpc.Proxy(networkString("http://127.0.0.1:%d/" % self.port)) if factory is None: p.queryFactory = self.queryFactory else: p.queryFactory = factory return p
Return a new xmlrpc.Proxy for the test site created in setUp(), using the given factory as the queryFactory, or self.queryFactory if no factory is provided.
proxy
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_headers(self): """ Verify that headers sent from the client side and the ones we get back from the server side are correct. """ d = self.proxy().callRemote("snowman", u"\u2603") def check_server_headers(ing): self.assertEqual( self.factories[0].headers[b'content-type'], b'text/xml; charset=utf-8') self.assertEqual( self.factories[0].headers[b'content-length'], b'129') def check_client_headers(ign): self.assertEqual( self.factories[0].sent_headers[b'user-agent'], b'Twisted/XMLRPClib') self.assertEqual( self.factories[0].sent_headers[b'content-type'], b'text/xml; charset=utf-8') self.assertEqual( self.factories[0].sent_headers[b'content-length'], b'155') d.addCallback(check_server_headers) d.addCallback(check_client_headers) return d
Verify that headers sent from the client side and the ones we get back from the server side are correct.
test_headers
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_errors(self): """ Verify that for each way a method exposed via XML-RPC can fail, the correct 'Content-type' header is set in the response and that the client-side Deferred is errbacked with an appropriate C{Fault} instance. """ logObserver = EventLoggingObserver() filtered = FilteringLogObserver( logObserver, [LogLevelFilterPredicate(defaultLogLevel=LogLevel.critical)] ) globalLogPublisher.addObserver(filtered) self.addCleanup(lambda: globalLogPublisher.removeObserver(filtered)) dl = [] for code, methodName in [(666, "fail"), (666, "deferFail"), (12, "fault"), (23, "noSuchMethod"), (17, "deferFault"), (42, "SESSION_TEST")]: d = self.proxy().callRemote(methodName) d = self.assertFailure(d, xmlrpc.Fault) d.addCallback(lambda exc, code=code: self.assertEqual(exc.faultCode, code)) dl.append(d) d = defer.DeferredList(dl, fireOnOneErrback=True) def cb(ign): for factory in self.factories: self.assertEqual(factory.headers[b'content-type'], b'text/xml; charset=utf-8') self.assertEquals(2, len(logObserver)) f1 = logObserver[0]["log_failure"].value f2 = logObserver[1]["log_failure"].value if isinstance(f1, TestValueError): self.assertIsInstance(f2, TestRuntimeError) else: self.assertIsInstance(f1, TestRuntimeError) self.assertIsInstance(f2, TestValueError) self.flushLoggedErrors(TestRuntimeError, TestValueError) d.addCallback(cb) return d
Verify that for each way a method exposed via XML-RPC can fail, the correct 'Content-type' header is set in the response and that the client-side Deferred is errbacked with an appropriate C{Fault} instance.
test_errors
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_cancel(self): """ A deferred from the Proxy can be cancelled, disconnecting the L{twisted.internet.interfaces.IConnector}. """ def factory(*args, **kw): factory.f = TestQueryFactoryCancel(*args, **kw) return factory.f d = self.proxy(factory).callRemote('add', 2, 3) self.assertNotEqual(factory.f.connector.state, "disconnected") d.cancel() self.assertEqual(factory.f.connector.state, "disconnected") d = self.assertFailure(d, defer.CancelledError) return d
A deferred from the Proxy can be cancelled, disconnecting the L{twisted.internet.interfaces.IConnector}.
test_cancel
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_errorGet(self): """ A classic GET on the xml server should return a NOT_ALLOWED. """ agent = client.Agent(reactor) d = agent.request(b"GET", networkString("http://127.0.0.1:%d/" % (self.port,))) def checkResponse(response): self.assertEqual(response.code, http.NOT_ALLOWED) d.addCallback(checkResponse) return d
A classic GET on the xml server should return a NOT_ALLOWED.
test_errorGet
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_errorXMLContent(self): """ Test that an invalid XML input returns an L{xmlrpc.Fault}. """ agent = client.Agent(reactor) d = agent.request( uri=networkString("http://127.0.0.1:%d/" % (self.port,)), method=b"POST", bodyProducer=client.FileBodyProducer(BytesIO(b"foo"))) d.addCallback(client.readBody) def cb(result): self.assertRaises(xmlrpc.Fault, xmlrpclib.loads, result) d.addCallback(cb) return d
Test that an invalid XML input returns an L{xmlrpc.Fault}.
test_errorXMLContent
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_datetimeRoundtrip(self): """ If an L{xmlrpclib.DateTime} is passed as an argument to an XML-RPC call and then returned by the server unmodified, the result should be equal to the original object. """ when = xmlrpclib.DateTime() d = self.proxy().callRemote("echo", when) d.addCallback(self.assertEqual, when) return d
If an L{xmlrpclib.DateTime} is passed as an argument to an XML-RPC call and then returned by the server unmodified, the result should be equal to the original object.
test_datetimeRoundtrip
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_doubleEncodingError(self): """ If it is not possible to encode a response to the request (for example, because L{xmlrpclib.dumps} raises an exception when encoding a L{Fault}) the exception which prevents the response from being generated is logged and the request object is finished anyway. """ logObserver = EventLoggingObserver() filtered = FilteringLogObserver( logObserver, [LogLevelFilterPredicate(defaultLogLevel=LogLevel.critical)] ) globalLogPublisher.addObserver(filtered) self.addCleanup(lambda: globalLogPublisher.removeObserver(filtered)) d = self.proxy().callRemote("echo", "") # *Now* break xmlrpclib.dumps. Hopefully the client already used it. def fakeDumps(*args, **kwargs): raise RuntimeError("Cannot encode anything at all!") self.patch(xmlrpclib, 'dumps', fakeDumps) # It doesn't matter how it fails, so long as it does. Also, it happens # to fail with an implementation detail exception right now, not # something suitable as part of a public interface. d = self.assertFailure(d, Exception) def cbFailed(ignored): # The fakeDumps exception should have been logged. self.assertEquals(1, len(logObserver)) self.assertIsInstance( logObserver[0]["log_failure"].value, RuntimeError ) self.assertEqual(len(self.flushLoggedErrors(RuntimeError)), 1) d.addCallback(cbFailed) return d
If it is not possible to encode a response to the request (for example, because L{xmlrpclib.dumps} raises an exception when encoding a L{Fault}) the exception which prevents the response from being generated is logged and the request object is finished anyway.
test_doubleEncodingError
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_closeConnectionAfterRequest(self): """ The connection to the web server is closed when the request is done. """ d = self.proxy().callRemote('echo', '') def responseDone(ignored): [factory] = self.factories self.assertFalse(factory.transport.connected) self.assertTrue(factory.transport.disconnected) return d.addCallback(responseDone)
The connection to the web server is closed when the request is done.
test_closeConnectionAfterRequest
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_tcpTimeout(self): """ For I{HTTP} URIs, L{xmlrpc.Proxy.callRemote} passes the value it received for the C{connectTimeout} parameter as the C{timeout} argument to the underlying connectTCP call. """ reactor = MemoryReactor() proxy = xmlrpc.Proxy(b"http://127.0.0.1:69", connectTimeout=2.0, reactor=reactor) proxy.callRemote("someMethod") self.assertEqual(reactor.tcpClients[0][3], 2.0)
For I{HTTP} URIs, L{xmlrpc.Proxy.callRemote} passes the value it received for the C{connectTimeout} parameter as the C{timeout} argument to the underlying connectTCP call.
test_tcpTimeout
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_sslTimeout(self): """ For I{HTTPS} URIs, L{xmlrpc.Proxy.callRemote} passes the value it received for the C{connectTimeout} parameter as the C{timeout} argument to the underlying connectSSL call. """ reactor = MemoryReactor() proxy = xmlrpc.Proxy(b"https://127.0.0.1:69", connectTimeout=3.0, reactor=reactor) proxy.callRemote("someMethod") self.assertEqual(reactor.sslClients[0][4], 3.0)
For I{HTTPS} URIs, L{xmlrpc.Proxy.callRemote} passes the value it received for the C{connectTimeout} parameter as the C{timeout} argument to the underlying connectSSL call.
test_sslTimeout
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_lookupProcedure(self): """ A subclass of L{XMLRPC} can override C{lookupProcedure} to find procedures that are not defined using a C{xmlrpc_}-prefixed method name. """ self.createServer(TestLookupProcedure()) what = "hello" d = self.proxy.callRemote("echo", what) d.addCallback(self.assertEqual, what) return d
A subclass of L{XMLRPC} can override C{lookupProcedure} to find procedures that are not defined using a C{xmlrpc_}-prefixed method name.
test_lookupProcedure
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_errors(self): """ A subclass of L{XMLRPC} can override C{lookupProcedure} to raise L{NoSuchFunction} to indicate that a requested method is not available to be called, signalling a fault to the XML-RPC client. """ self.createServer(TestLookupProcedure()) d = self.proxy.callRemote("xxxx", "hello") d = self.assertFailure(d, xmlrpc.Fault) return d
A subclass of L{XMLRPC} can override C{lookupProcedure} to raise L{NoSuchFunction} to indicate that a requested method is not available to be called, signalling a fault to the XML-RPC client.
test_errors
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_listMethods(self): """ A subclass of L{XMLRPC} can override C{listProcedures} to define Overriding listProcedures should prevent introspection from being broken. """ resource = TestListProcedures() addIntrospection(resource) self.createServer(resource) d = self.proxy.callRemote("system.listMethods") def listed(procedures): # The list will also include other introspection procedures added by # addIntrospection. We just want to see "foo" from our customized # listProcedures. self.assertIn('foo', procedures) d.addCallback(listed) return d
A subclass of L{XMLRPC} can override C{listProcedures} to define Overriding listProcedures should prevent introspection from being broken.
test_listMethods
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def setUp(self): """ Create a new XML-RPC server with C{allowNone} set to C{True}. """ kwargs = {self.flagName: True} self.p = reactor.listenTCP( 0, server.Site(Test(**kwargs)), interface="127.0.0.1") self.addCleanup(self.p.stopListening) self.port = self.p.getHost().port self.proxy = xmlrpc.Proxy( networkString("http://127.0.0.1:%d/" % (self.port,)), **kwargs)
Create a new XML-RPC server with C{allowNone} set to C{True}.
setUp
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_roundtripValue(self): """ C{self.value} can be round-tripped over an XMLRPC method call/response. """ d = self.proxy.callRemote('defer', self.value) d.addCallback(self.assertEqual, self.value) return d
C{self.value} can be round-tripped over an XMLRPC method call/response.
test_roundtripValue
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_roundtripNestedValue(self): """ A C{dict} which contains C{self.value} can be round-tripped over an XMLRPC method call/response. """ d = self.proxy.callRemote('defer', {'a': self.value}) d.addCallback(self.assertEqual, {'a': self.value}) return d
A C{dict} which contains C{self.value} can be round-tripped over an XMLRPC method call/response.
test_roundtripNestedValue
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_longPassword(self): """ C{QueryProtocol} uses the C{base64.b64encode} function to encode user name and password in the I{Authorization} header, so that it doesn't embed new lines when using long inputs. """ longPassword = self.password * 40 p = xmlrpc.Proxy(networkString("http://127.0.0.1:%d/" % ( self.port,)), self.user, longPassword) d = p.callRemote("authinfo") d.addCallback(self.assertEqual, [self.user, longPassword]) return d
C{QueryProtocol} uses the C{base64.b64encode} function to encode user name and password in the I{Authorization} header, so that it doesn't embed new lines when using long inputs.
test_longPassword
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_erroneousResponse(self): """ Test that calling the xmlrpc client on a static http server raises an exception. """ proxy = xmlrpc.Proxy(networkString("http://127.0.0.1:%d/" % (self.port.getHost().port,))) return self.assertFailure(proxy.callRemote("someMethod"), ValueError)
Test that calling the xmlrpc client on a static http server raises an exception.
test_erroneousResponse
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_parseResponseCallbackSafety(self): """ We can safely call L{_QueryFactory.clientConnectionLost} as a callback of L{_QueryFactory.parseResponse}. """ d = self.queryFactory.deferred # The failure mode is that this callback raises an AlreadyCalled # error. We have to add it now so that it gets called synchronously # and triggers the race condition. d.addCallback(self.queryFactory.clientConnectionLost, self.reason) self.queryFactory.parseResponse(self.goodContents) return d
We can safely call L{_QueryFactory.clientConnectionLost} as a callback of L{_QueryFactory.parseResponse}.
test_parseResponseCallbackSafety
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_parseResponseErrbackSafety(self): """ We can safely call L{_QueryFactory.clientConnectionLost} as an errback of L{_QueryFactory.parseResponse}. """ d = self.queryFactory.deferred # The failure mode is that this callback raises an AlreadyCalled # error. We have to add it now so that it gets called synchronously # and triggers the race condition. d.addErrback(self.queryFactory.clientConnectionLost, self.reason) self.queryFactory.parseResponse(self.badContents) return d
We can safely call L{_QueryFactory.clientConnectionLost} as an errback of L{_QueryFactory.parseResponse}.
test_parseResponseErrbackSafety
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_badStatusErrbackSafety(self): """ We can safely call L{_QueryFactory.clientConnectionLost} as an errback of L{_QueryFactory.badStatus}. """ d = self.queryFactory.deferred # The failure mode is that this callback raises an AlreadyCalled # error. We have to add it now so that it gets called synchronously # and triggers the race condition. d.addErrback(self.queryFactory.clientConnectionLost, self.reason) self.queryFactory.badStatus('status', 'message') return d
We can safely call L{_QueryFactory.clientConnectionLost} as an errback of L{_QueryFactory.badStatus}.
test_badStatusErrbackSafety
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_parseResponseWithoutData(self): """ Some server can send a response without any data: L{_QueryFactory.parseResponse} should catch the error and call the result errback. """ content = """ <methodResponse> <params> <param> </param> </params> </methodResponse>""" d = self.queryFactory.deferred self.queryFactory.parseResponse(content) return self.assertFailure(d, IndexError)
Some server can send a response without any data: L{_QueryFactory.parseResponse} should catch the error and call the result errback.
test_parseResponseWithoutData
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def test_withRequest(self): """ When an XML-RPC method is called and the implementation is decorated with L{withRequest}, the request object is passed as the first argument. """ request = DummyRequest('/RPC2') request.method = "POST" request.content = NativeStringIO(xmlrpclib.dumps( ("foo",), 'withRequest')) def valid(n, request): data = xmlrpclib.loads(request.written[0]) self.assertEqual(data, (('POST foo',), None)) d = request.notifyFinish().addCallback(valid, request) self.resource.render_POST(request) return d
When an XML-RPC method is called and the implementation is decorated with L{withRequest}, the request object is passed as the first argument.
test_withRequest
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_xmlrpc.py
MIT
def assertSanitized(testCase, components, expected): """ Assert that the components are sanitized to the expected value as both a header name and value, across all of L{Header}'s setters and getters. @param testCase: A test case. @param components: A sequence of values that contain linear whitespace to use as header names and values; see C{textLinearWhitespaceComponents} and C{bytesLinearWhitespaceComponents} @param expected: The expected sanitized form of the component for both headers names and their values. """ for component in components: headers = [] headers.append(Headers({component: [component]})) added = Headers() added.addRawHeader(component, component) headers.append(added) setHeader = Headers() setHeader.setRawHeaders(component, [component]) headers.append(setHeader) for header in headers: testCase.assertEqual(list(header.getAllRawHeaders()), [(expected, [expected])]) testCase.assertEqual(header.getRawHeaders(expected), [expected])
Assert that the components are sanitized to the expected value as both a header name and value, across all of L{Header}'s setters and getters. @param testCase: A test case. @param components: A sequence of values that contain linear whitespace to use as header names and values; see C{textLinearWhitespaceComponents} and C{bytesLinearWhitespaceComponents} @param expected: The expected sanitized form of the component for both headers names and their values.
assertSanitized
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_sanitizeLinearWhitespace(self): """ Linear whitespace in header names or values is replaced with a single space. """ assertSanitized(self, bytesLinearWhitespaceComponents, sanitizedBytes)
Linear whitespace in header names or values is replaced with a single space.
test_sanitizeLinearWhitespace
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_initializer(self): """ The header values passed to L{Headers.__init__} can be retrieved via L{Headers.getRawHeaders}. """ h = Headers({b'Foo': [b'bar']}) self.assertEqual(h.getRawHeaders(b'foo'), [b'bar'])
The header values passed to L{Headers.__init__} can be retrieved via L{Headers.getRawHeaders}.
test_initializer
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_setRawHeaders(self): """ L{Headers.setRawHeaders} sets the header values for the given header name to the sequence of byte string values. """ rawValue = [b"value1", b"value2"] h = Headers() h.setRawHeaders(b"test", rawValue) self.assertTrue(h.hasHeader(b"test")) self.assertTrue(h.hasHeader(b"Test")) self.assertEqual(h.getRawHeaders(b"test"), rawValue)
L{Headers.setRawHeaders} sets the header values for the given header name to the sequence of byte string values.
test_setRawHeaders
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_rawHeadersTypeChecking(self): """ L{Headers.setRawHeaders} requires values to be of type list. """ h = Headers() self.assertRaises(TypeError, h.setRawHeaders, b'key', {b'Foo': b'bar'})
L{Headers.setRawHeaders} requires values to be of type list.
test_rawHeadersTypeChecking
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_addRawHeader(self): """ L{Headers.addRawHeader} adds a new value for a given header. """ h = Headers() h.addRawHeader(b"test", b"lemur") self.assertEqual(h.getRawHeaders(b"test"), [b"lemur"]) h.addRawHeader(b"test", b"panda") self.assertEqual(h.getRawHeaders(b"test"), [b"lemur", b"panda"])
L{Headers.addRawHeader} adds a new value for a given header.
test_addRawHeader
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_getRawHeadersNoDefault(self): """ L{Headers.getRawHeaders} returns L{None} if the header is not found and no default is specified. """ self.assertIsNone(Headers().getRawHeaders(b"test"))
L{Headers.getRawHeaders} returns L{None} if the header is not found and no default is specified.
test_getRawHeadersNoDefault
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_getRawHeadersDefaultValue(self): """ L{Headers.getRawHeaders} returns the specified default value when no header is found. """ h = Headers() default = object() self.assertIdentical(h.getRawHeaders(b"test", default), default)
L{Headers.getRawHeaders} returns the specified default value when no header is found.
test_getRawHeadersDefaultValue
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_getRawHeadersWithDefaultMatchingValue(self): """ If the object passed as the value list to L{Headers.setRawHeaders} is later passed as a default to L{Headers.getRawHeaders}, the result nevertheless contains encoded values. """ h = Headers() default = [u"value"] h.setRawHeaders(b"key", default) self.assertIsInstance(h.getRawHeaders(b"key", default)[0], bytes) self.assertEqual(h.getRawHeaders(b"key", default), [b"value"])
If the object passed as the value list to L{Headers.setRawHeaders} is later passed as a default to L{Headers.getRawHeaders}, the result nevertheless contains encoded values.
test_getRawHeadersWithDefaultMatchingValue
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_getRawHeaders(self): """ L{Headers.getRawHeaders} returns the values which have been set for a given header. """ h = Headers() h.setRawHeaders(b"test", [b"lemur"]) self.assertEqual(h.getRawHeaders(b"test"), [b"lemur"]) self.assertEqual(h.getRawHeaders(b"Test"), [b"lemur"])
L{Headers.getRawHeaders} returns the values which have been set for a given header.
test_getRawHeaders
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_hasHeaderTrue(self): """ Check that L{Headers.hasHeader} returns C{True} when the given header is found. """ h = Headers() h.setRawHeaders(b"test", [b"lemur"]) self.assertTrue(h.hasHeader(b"test")) self.assertTrue(h.hasHeader(b"Test"))
Check that L{Headers.hasHeader} returns C{True} when the given header is found.
test_hasHeaderTrue
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_hasHeaderFalse(self): """ L{Headers.hasHeader} returns C{False} when the given header is not found. """ self.assertFalse(Headers().hasHeader(b"test"))
L{Headers.hasHeader} returns C{False} when the given header is not found.
test_hasHeaderFalse
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_removeHeader(self): """ Check that L{Headers.removeHeader} removes the given header. """ h = Headers() h.setRawHeaders(b"foo", [b"lemur"]) self.assertTrue(h.hasHeader(b"foo")) h.removeHeader(b"foo") self.assertFalse(h.hasHeader(b"foo")) h.setRawHeaders(b"bar", [b"panda"]) self.assertTrue(h.hasHeader(b"bar")) h.removeHeader(b"Bar") self.assertFalse(h.hasHeader(b"bar"))
Check that L{Headers.removeHeader} removes the given header.
test_removeHeader
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_removeHeaderDoesntExist(self): """ L{Headers.removeHeader} is a no-operation when the specified header is not found. """ h = Headers() h.removeHeader(b"test") self.assertEqual(list(h.getAllRawHeaders()), [])
L{Headers.removeHeader} is a no-operation when the specified header is not found.
test_removeHeaderDoesntExist
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_canonicalNameCaps(self): """ L{Headers._canonicalNameCaps} returns the canonical capitalization for the given header. """ h = Headers() self.assertEqual(h._canonicalNameCaps(b"test"), b"Test") self.assertEqual(h._canonicalNameCaps(b"test-stuff"), b"Test-Stuff") self.assertEqual(h._canonicalNameCaps(b"content-md5"), b"Content-MD5") self.assertEqual(h._canonicalNameCaps(b"dnt"), b"DNT") self.assertEqual(h._canonicalNameCaps(b"etag"), b"ETag") self.assertEqual(h._canonicalNameCaps(b"p3p"), b"P3P") self.assertEqual(h._canonicalNameCaps(b"te"), b"TE") self.assertEqual(h._canonicalNameCaps(b"www-authenticate"), b"WWW-Authenticate") self.assertEqual(h._canonicalNameCaps(b"x-xss-protection"), b"X-XSS-Protection")
L{Headers._canonicalNameCaps} returns the canonical capitalization for the given header.
test_canonicalNameCaps
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_getAllRawHeaders(self): """ L{Headers.getAllRawHeaders} returns an iterable of (k, v) pairs, where C{k} is the canonicalized representation of the header name, and C{v} is a sequence of values. """ h = Headers() h.setRawHeaders(b"test", [b"lemurs"]) h.setRawHeaders(b"www-authenticate", [b"basic aksljdlk="]) allHeaders = set([(k, tuple(v)) for k, v in h.getAllRawHeaders()]) self.assertEqual(allHeaders, set([(b"WWW-Authenticate", (b"basic aksljdlk=",)), (b"Test", (b"lemurs",))]))
L{Headers.getAllRawHeaders} returns an iterable of (k, v) pairs, where C{k} is the canonicalized representation of the header name, and C{v} is a sequence of values.
test_getAllRawHeaders
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_headersComparison(self): """ A L{Headers} instance compares equal to itself and to another L{Headers} instance with the same values. """ first = Headers() first.setRawHeaders(b"foo", [b"panda"]) second = Headers() second.setRawHeaders(b"foo", [b"panda"]) third = Headers() third.setRawHeaders(b"foo", [b"lemur", b"panda"]) self.assertEqual(first, first) self.assertEqual(first, second) self.assertNotEqual(first, third)
A L{Headers} instance compares equal to itself and to another L{Headers} instance with the same values.
test_headersComparison
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_otherComparison(self): """ An instance of L{Headers} does not compare equal to other unrelated objects. """ h = Headers() self.assertNotEqual(h, ()) self.assertNotEqual(h, object()) self.assertNotEqual(h, b"foo")
An instance of L{Headers} does not compare equal to other unrelated objects.
test_otherComparison
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_repr(self): """ The L{repr} of a L{Headers} instance shows the names and values of all the headers it contains. """ foo = b"foo" bar = b"bar" baz = b"baz" self.assertEqual( repr(Headers({foo: [bar, baz]})), "Headers({%r: [%r, %r]})" % (foo, bar, baz))
The L{repr} of a L{Headers} instance shows the names and values of all the headers it contains.
test_repr
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_reprWithRawBytes(self): """ The L{repr} of a L{Headers} instance shows the names and values of all the headers it contains, not attempting to decode any raw bytes. """ # There's no such thing as undecodable latin-1, you'll just get # some mojibake foo = b"foo" # But this is invalid UTF-8! So, any accidental decoding/encoding will # throw an exception. bar = b"bar\xe1" baz = b"baz\xe1" self.assertEqual( repr(Headers({foo: [bar, baz]})), "Headers({%r: [%r, %r]})" % (foo, bar, baz))
The L{repr} of a L{Headers} instance shows the names and values of all the headers it contains, not attempting to decode any raw bytes.
test_reprWithRawBytes
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_subclassRepr(self): """ The L{repr} of an instance of a subclass of L{Headers} uses the name of the subclass instead of the string C{"Headers"}. """ foo = b"foo" bar = b"bar" baz = b"baz" class FunnyHeaders(Headers): pass self.assertEqual( repr(FunnyHeaders({foo: [bar, baz]})), "FunnyHeaders({%r: [%r, %r]})" % (foo, bar, baz))
The L{repr} of an instance of a subclass of L{Headers} uses the name of the subclass instead of the string C{"Headers"}.
test_subclassRepr
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_copy(self): """ L{Headers.copy} creates a new independent copy of an existing L{Headers} instance, allowing future modifications without impacts between the copies. """ h = Headers() h.setRawHeaders(b'test', [b'foo']) i = h.copy() self.assertEqual(i.getRawHeaders(b'test'), [b'foo']) h.addRawHeader(b'test', b'bar') self.assertEqual(i.getRawHeaders(b'test'), [b'foo']) i.addRawHeader(b'test', b'baz') self.assertEqual(h.getRawHeaders(b'test'), [b'foo', b'bar'])
L{Headers.copy} creates a new independent copy of an existing L{Headers} instance, allowing future modifications without impacts between the copies.
test_copy
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_initializer(self): """ The header values passed to L{Headers.__init__} can be retrieved via L{Headers.getRawHeaders}. If a L{bytes} argument is given, it returns L{bytes} values, and if a L{unicode} argument is given, it returns L{unicode} values. Both are the same header value, just encoded or decoded. """ h = Headers({u'Foo': [u'bar']}) self.assertEqual(h.getRawHeaders(b'foo'), [b'bar']) self.assertEqual(h.getRawHeaders(u'foo'), [u'bar'])
The header values passed to L{Headers.__init__} can be retrieved via L{Headers.getRawHeaders}. If a L{bytes} argument is given, it returns L{bytes} values, and if a L{unicode} argument is given, it returns L{unicode} values. Both are the same header value, just encoded or decoded.
test_initializer
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_setRawHeaders(self): """ L{Headers.setRawHeaders} sets the header values for the given header name to the sequence of strings, encoded. """ rawValue = [u"value1", u"value2"] rawEncodedValue = [b"value1", b"value2"] h = Headers() h.setRawHeaders("test", rawValue) self.assertTrue(h.hasHeader(b"test")) self.assertTrue(h.hasHeader(b"Test")) self.assertTrue(h.hasHeader("test")) self.assertTrue(h.hasHeader("Test")) self.assertEqual(h.getRawHeaders("test"), rawValue) self.assertEqual(h.getRawHeaders(b"test"), rawEncodedValue)
L{Headers.setRawHeaders} sets the header values for the given header name to the sequence of strings, encoded.
test_setRawHeaders
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_nameNotEncodable(self): """ Passing L{unicode} to any function that takes a header name will encode said header name as ISO-8859-1, and if it cannot be encoded, it will raise a L{UnicodeDecodeError}. """ h = Headers() # Only these two functions take names with self.assertRaises(UnicodeEncodeError): h.setRawHeaders(u"\u2603", [u"val"]) with self.assertRaises(UnicodeEncodeError): h.hasHeader(u"\u2603")
Passing L{unicode} to any function that takes a header name will encode said header name as ISO-8859-1, and if it cannot be encoded, it will raise a L{UnicodeDecodeError}.
test_nameNotEncodable
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_nameEncoding(self): """ Passing L{unicode} to any function that takes a header name will encode said header name as ISO-8859-1. """ h = Headers() # We set it using a Unicode string. h.setRawHeaders(u"\u00E1", [b"foo"]) # It's encoded to the ISO-8859-1 value, which we can use to access it self.assertTrue(h.hasHeader(b"\xe1")) self.assertEqual(h.getRawHeaders(b"\xe1"), [b'foo']) # We can still access it using the Unicode string.. self.assertTrue(h.hasHeader(u"\u00E1"))
Passing L{unicode} to any function that takes a header name will encode said header name as ISO-8859-1.
test_nameEncoding
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_rawHeadersValueEncoding(self): """ Passing L{unicode} to L{Headers.setRawHeaders} will encode the name as ISO-8859-1 and values as UTF-8. """ h = Headers() h.setRawHeaders(u"\u00E1", [u"\u2603", b"foo"]) self.assertTrue(h.hasHeader(b"\xe1")) self.assertEqual(h.getRawHeaders(b"\xe1"), [b'\xe2\x98\x83', b'foo'])
Passing L{unicode} to L{Headers.setRawHeaders} will encode the name as ISO-8859-1 and values as UTF-8.
test_rawHeadersValueEncoding
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_getRawHeadersWithDefaultMatchingValue(self): """ If the object passed as the value list to L{Headers.setRawHeaders} is later passed as a default to L{Headers.getRawHeaders}, the result nevertheless contains decoded values. """ h = Headers() default = [b"value"] h.setRawHeaders(b"key", default) self.assertIsInstance(h.getRawHeaders(u"key", default)[0], unicode) self.assertEqual(h.getRawHeaders(u"key", default), [u"value"])
If the object passed as the value list to L{Headers.setRawHeaders} is later passed as a default to L{Headers.getRawHeaders}, the result nevertheless contains decoded values.
test_getRawHeadersWithDefaultMatchingValue
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_repr(self): """ The L{repr} of a L{Headers} instance shows the names and values of all the headers it contains. This shows only reprs of bytes values, as undecodable headers may cause an exception. """ foo = u"foo\u00E1" bar = u"bar\u2603" baz = u"baz" fooEncoded = "'foo\\xe1'" barEncoded = "'bar\\xe2\\x98\\x83'" if _PY3: fooEncoded = "b" + fooEncoded barEncoded = "b" + barEncoded self.assertEqual( repr(Headers({foo: [bar, baz]})), "Headers({%s: [%s, %r]})" % (fooEncoded, barEncoded, baz.encode('utf8')))
The L{repr} of a L{Headers} instance shows the names and values of all the headers it contains. This shows only reprs of bytes values, as undecodable headers may cause an exception.
test_repr
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_http_headers.py
MIT
def test_renderNotFound(self): """ L{ResourceScriptDirectory.render} sets the HTTP response code to I{NOT FOUND}. """ resource = ResourceScriptDirectory(self.mktemp()) request = DummyRequest([b'']) d = _render(resource, request) def cbRendered(ignored): self.assertEqual(request.responseCode, NOT_FOUND) d.addCallback(cbRendered) return d
L{ResourceScriptDirectory.render} sets the HTTP response code to I{NOT FOUND}.
test_renderNotFound
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_script.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_script.py
MIT
def test_notFoundChild(self): """ L{ResourceScriptDirectory.getChild} returns a resource which renders an response with the HTTP I{NOT FOUND} status code if the indicated child does not exist as an entry in the directory used to initialized the L{ResourceScriptDirectory}. """ path = self.mktemp() os.makedirs(path) resource = ResourceScriptDirectory(path) request = DummyRequest([b'foo']) child = resource.getChild("foo", request) d = _render(child, request) def cbRendered(ignored): self.assertEqual(request.responseCode, NOT_FOUND) d.addCallback(cbRendered) return d
L{ResourceScriptDirectory.getChild} returns a resource which renders an response with the HTTP I{NOT FOUND} status code if the indicated child does not exist as an entry in the directory used to initialized the L{ResourceScriptDirectory}.
test_notFoundChild
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_script.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_script.py
MIT
def test_render(self): """ L{ResourceScriptDirectory.getChild} returns a resource which renders a response with the HTTP 200 status code and the content of the rpy's C{request} global. """ tmp = FilePath(self.mktemp()) tmp.makedirs() tmp.child("test.rpy").setContent(b""" from twisted.web.resource import Resource class TestResource(Resource): isLeaf = True def render_GET(self, request): return b'ok' resource = TestResource()""") resource = ResourceScriptDirectory(tmp._asBytesPath()) request = DummyRequest([b'']) child = resource.getChild(b"test.rpy", request) d = _render(child, request) def cbRendered(ignored): self.assertEqual(b"".join(request.written), b"ok") d.addCallback(cbRendered) return d
L{ResourceScriptDirectory.getChild} returns a resource which renders a response with the HTTP 200 status code and the content of the rpy's C{request} global.
test_render
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_script.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_script.py
MIT
def test_notFoundRender(self): """ If the source file a L{PythonScript} is initialized with doesn't exist, L{PythonScript.render} sets the HTTP response code to I{NOT FOUND}. """ resource = PythonScript(self.mktemp(), None) request = DummyRequest([b'']) d = _render(resource, request) def cbRendered(ignored): self.assertEqual(request.responseCode, NOT_FOUND) d.addCallback(cbRendered) return d
If the source file a L{PythonScript} is initialized with doesn't exist, L{PythonScript.render} sets the HTTP response code to I{NOT FOUND}.
test_notFoundRender
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_script.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_script.py
MIT
def test_headRequest(self): """ L{Data.render} returns an empty response body for a I{HEAD} request. """ data = static.Data(b"foo", "bar") request = DummyRequest(['']) request.method = b'HEAD' d = _render(data, request) def cbRendered(ignored): self.assertEqual(b''.join(request.written), b"") d.addCallback(cbRendered) return d
L{Data.render} returns an empty response body for a I{HEAD} request.
test_headRequest
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_invalidMethod(self): """ L{Data.render} raises L{UnsupportedMethod} in response to a non-I{GET}, non-I{HEAD} request. """ data = static.Data(b"foo", b"bar") request = DummyRequest([b'']) request.method = b'POST' self.assertRaises(UnsupportedMethod, data.render, request)
L{Data.render} raises L{UnsupportedMethod} in response to a non-I{GET}, non-I{HEAD} request.
test_invalidMethod
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_ignoredExtTrue(self): """ Passing C{1} as the value to L{File}'s C{ignoredExts} argument issues a warning and sets the ignored extensions to the wildcard C{"*"}. """ with warnings.catch_warnings(record=True) as caughtWarnings: file = static.File(self.mktemp(), ignoredExts=1) self.assertEqual(file.ignoredExts, ["*"]) self.assertEqual(len(caughtWarnings), 1)
Passing C{1} as the value to L{File}'s C{ignoredExts} argument issues a warning and sets the ignored extensions to the wildcard C{"*"}.
test_ignoredExtTrue
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_ignoredExtFalse(self): """ Passing C{1} as the value to L{File}'s C{ignoredExts} argument issues a warning and sets the ignored extensions to the empty list. """ with warnings.catch_warnings(record=True) as caughtWarnings: file = static.File(self.mktemp(), ignoredExts=0) self.assertEqual(file.ignoredExts, []) self.assertEqual(len(caughtWarnings), 1)
Passing C{1} as the value to L{File}'s C{ignoredExts} argument issues a warning and sets the ignored extensions to the empty list.
test_ignoredExtFalse
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_allowExt(self): """ Passing C{1} as the value to L{File}'s C{allowExt} argument issues a warning and sets the ignored extensions to the wildcard C{*}. """ with warnings.catch_warnings(record=True) as caughtWarnings: file = static.File(self.mktemp(), ignoredExts=True) self.assertEqual(file.ignoredExts, ["*"]) self.assertEqual(len(caughtWarnings), 1)
Passing C{1} as the value to L{File}'s C{allowExt} argument issues a warning and sets the ignored extensions to the wildcard C{*}.
test_allowExt
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_invalidMethod(self): """ L{File.render} raises L{UnsupportedMethod} in response to a non-I{GET}, non-I{HEAD} request. """ request = DummyRequest([b'']) request.method = b'POST' path = FilePath(self.mktemp()) path.setContent(b"foo") file = static.File(path.path) self.assertRaises(UnsupportedMethod, file.render, request)
L{File.render} raises L{UnsupportedMethod} in response to a non-I{GET}, non-I{HEAD} request.
test_invalidMethod
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_notFound(self): """ If a request is made which encounters a L{File} before a final segment which does not correspond to any file in the path the L{File} was created with, a not found response is sent. """ base = FilePath(self.mktemp()) base.makedirs() file = static.File(base.path) request = DummyRequest([b'foobar']) child = resource.getChildForRequest(file, request) d = self._render(child, request) def cbRendered(ignored): self.assertEqual(request.responseCode, 404) d.addCallback(cbRendered) return d
If a request is made which encounters a L{File} before a final segment which does not correspond to any file in the path the L{File} was created with, a not found response is sent.
test_notFound
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_emptyChild(self): """ The C{''} child of a L{File} which corresponds to a directory in the filesystem is a L{DirectoryLister}. """ base = FilePath(self.mktemp()) base.makedirs() file = static.File(base.path) request = DummyRequest([b'']) child = resource.getChildForRequest(file, request) self.assertIsInstance(child, static.DirectoryLister) self.assertEqual(child.path, base.path)
The C{''} child of a L{File} which corresponds to a directory in the filesystem is a L{DirectoryLister}.
test_emptyChild
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_emptyChildUnicodeParent(self): """ The C{u''} child of a L{File} which corresponds to a directory whose path is text is a L{DirectoryLister} that renders to a binary listing. @see: U{https://twistedmatrix.com/trac/ticket/9438} """ textBase = FilePath(self.mktemp()).asTextMode() textBase.makedirs() textBase.child(u"text-file").open('w').close() textFile = static.File(textBase.path) request = DummyRequest([b'']) child = resource.getChildForRequest(textFile, request) self.assertIsInstance(child, static.DirectoryLister) nativePath = compat.nativeString(textBase.path) self.assertEqual(child.path, nativePath) response = child.render(request) self.assertIsInstance(response, bytes)
The C{u''} child of a L{File} which corresponds to a directory whose path is text is a L{DirectoryLister} that renders to a binary listing. @see: U{https://twistedmatrix.com/trac/ticket/9438}
test_emptyChildUnicodeParent
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_securityViolationNotFound(self): """ If a request is made which encounters a L{File} before a final segment which cannot be looked up in the filesystem due to security considerations, a not found response is sent. """ base = FilePath(self.mktemp()) base.makedirs() file = static.File(base.path) request = DummyRequest([b'..']) child = resource.getChildForRequest(file, request) d = self._render(child, request) def cbRendered(ignored): self.assertEqual(request.responseCode, 404) d.addCallback(cbRendered) return d
If a request is made which encounters a L{File} before a final segment which cannot be looked up in the filesystem due to security considerations, a not found response is sent.
test_securityViolationNotFound
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_forbiddenResource(self): """ If the file in the filesystem which would satisfy a request cannot be read, L{File.render} sets the HTTP response code to I{FORBIDDEN}. """ base = FilePath(self.mktemp()) base.setContent(b'') # Make sure we can delete the file later. self.addCleanup(base.chmod, 0o700) # Get rid of our own read permission. base.chmod(0) file = static.File(base.path) request = DummyRequest([b'']) d = self._render(file, request) def cbRendered(ignored): self.assertEqual(request.responseCode, 403) d.addCallback(cbRendered) return d
If the file in the filesystem which would satisfy a request cannot be read, L{File.render} sets the HTTP response code to I{FORBIDDEN}.
test_forbiddenResource
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_undecodablePath(self): """ A request whose path cannot be decoded as UTF-8 receives a not found response, and the failure is logged. """ path = self.mktemp() if isinstance(path, bytes): path = path.decode('ascii') base = FilePath(path) base.makedirs() file = static.File(base.path) request = DummyRequest([b"\xff"]) child = resource.getChildForRequest(file, request) d = self._render(child, request) def cbRendered(ignored): self.assertEqual(request.responseCode, 404) self.assertEqual(len(self.flushLoggedErrors(UnicodeDecodeError)), 1) d.addCallback(cbRendered) return d
A request whose path cannot be decoded as UTF-8 receives a not found response, and the failure is logged.
test_undecodablePath
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_forbiddenResource_default(self): """ L{File.forbidden} defaults to L{resource.ForbiddenResource}. """ self.assertIsInstance( static.File(b'.').forbidden, resource.ForbiddenResource)
L{File.forbidden} defaults to L{resource.ForbiddenResource}.
test_forbiddenResource_default
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_forbiddenResource_customize(self): """ The resource rendered for forbidden requests is stored as a class member so that users can customize it. """ base = FilePath(self.mktemp()) base.setContent(b'') markerResponse = b'custom-forbidden-response' def failingOpenForReading(): raise IOError(errno.EACCES, "") class CustomForbiddenResource(resource.Resource): def render(self, request): return markerResponse class CustomStaticFile(static.File): forbidden = CustomForbiddenResource() fileResource = CustomStaticFile(base.path) fileResource.openForReading = failingOpenForReading request = DummyRequest([b'']) result = fileResource.render(request) self.assertEqual(markerResponse, result)
The resource rendered for forbidden requests is stored as a class member so that users can customize it.
test_forbiddenResource_customize
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_indexNames(self): """ If a request is made which encounters a L{File} before a final empty segment, a file in the L{File} instance's C{indexNames} list which exists in the path the L{File} was created with is served as the response to the request. """ base = FilePath(self.mktemp()) base.makedirs() base.child("foo.bar").setContent(b"baz") file = static.File(base.path) file.indexNames = ['foo.bar'] request = DummyRequest([b'']) child = resource.getChildForRequest(file, request) d = self._render(child, request) def cbRendered(ignored): self.assertEqual(b''.join(request.written), b'baz') self.assertEqual( request.responseHeaders.getRawHeaders(b'content-length')[0], b'3') d.addCallback(cbRendered) return d
If a request is made which encounters a L{File} before a final empty segment, a file in the L{File} instance's C{indexNames} list which exists in the path the L{File} was created with is served as the response to the request.
test_indexNames
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_staticFile(self): """ If a request is made which encounters a L{File} before a final segment which names a file in the path the L{File} was created with, that file is served as the response to the request. """ base = FilePath(self.mktemp()) base.makedirs() base.child("foo.bar").setContent(b"baz") file = static.File(base.path) request = DummyRequest([b'foo.bar']) child = resource.getChildForRequest(file, request) d = self._render(child, request) def cbRendered(ignored): self.assertEqual(b''.join(request.written), b'baz') self.assertEqual( request.responseHeaders.getRawHeaders(b'content-length')[0], b'3') d.addCallback(cbRendered) return d
If a request is made which encounters a L{File} before a final segment which names a file in the path the L{File} was created with, that file is served as the response to the request.
test_staticFile
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_staticFileUnicodeFileName(self): """ A request for a existing unicode file path encoded as UTF-8 returns the contents of that file. """ name = u"\N{GREEK SMALL LETTER ETA WITH PERISPOMENI}" content = b"content" base = FilePath(self.mktemp()) base.makedirs() base.child(name).setContent(content) file = static.File(base.path) request = DummyRequest([name.encode('utf-8')]) child = resource.getChildForRequest(file, request) d = self._render(child, request) def cbRendered(ignored): self.assertEqual(b''.join(request.written), content) self.assertEqual( request.responseHeaders.getRawHeaders(b'content-length')[0], networkString(str(len(content)))) d.addCallback(cbRendered) return d
A request for a existing unicode file path encoded as UTF-8 returns the contents of that file.
test_staticFileUnicodeFileName
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_staticFileDeletedGetChild(self): """ A L{static.File} created for a directory which does not exist should return childNotFound from L{static.File.getChild}. """ staticFile = static.File(self.mktemp()) request = DummyRequest([b'foo.bar']) child = staticFile.getChild(b"foo.bar", request) self.assertEqual(child, staticFile.childNotFound)
A L{static.File} created for a directory which does not exist should return childNotFound from L{static.File.getChild}.
test_staticFileDeletedGetChild
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_staticFileDeletedRender(self): """ A L{static.File} created for a file which does not exist should render its C{childNotFound} page. """ staticFile = static.File(self.mktemp()) request = DummyRequest([b'foo.bar']) request2 = DummyRequest([b'foo.bar']) d = self._render(staticFile, request) d2 = self._render(staticFile.childNotFound, request2) def cbRendered2(ignored): def cbRendered(ignored): self.assertEqual(b''.join(request.written), b''.join(request2.written)) d.addCallback(cbRendered) return d d2.addCallback(cbRendered2) return d2
A L{static.File} created for a file which does not exist should render its C{childNotFound} page.
test_staticFileDeletedRender
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_getChildChildNotFound_customize(self): """ The resource rendered for child not found requests can be customize using a class member. """ base = FilePath(self.mktemp()) base.setContent(b'') markerResponse = b'custom-child-not-found-response' class CustomChildNotFoundResource(resource.Resource): def render(self, request): return markerResponse class CustomStaticFile(static.File): childNotFound = CustomChildNotFoundResource() fileResource = CustomStaticFile(base.path) request = DummyRequest([b'no-child.txt']) child = fileResource.getChild(b'no-child.txt', request) result = child.render(request) self.assertEqual(markerResponse, result)
The resource rendered for child not found requests can be customize using a class member.
test_getChildChildNotFound_customize
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_headRequest(self): """ L{static.File.render} returns an empty response body for I{HEAD} requests. """ path = FilePath(self.mktemp()) path.setContent(b"foo") file = static.File(path.path) request = DummyRequest([b'']) request.method = b'HEAD' d = _render(file, request) def cbRendered(ignored): self.assertEqual(b"".join(request.written), b"") d.addCallback(cbRendered) return d
L{static.File.render} returns an empty response body for I{HEAD} requests.
test_headRequest
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_processors(self): """ If a request is made which encounters a L{File} before a final segment which names a file with an extension which is in the L{File}'s C{processors} mapping, the processor associated with that extension is used to serve the response to the request. """ base = FilePath(self.mktemp()) base.makedirs() base.child("foo.bar").setContent( b"from twisted.web.static import Data\n" b"resource = Data(b'dynamic world', 'text/plain')\n") file = static.File(base.path) file.processors = {'.bar': script.ResourceScript} request = DummyRequest([b"foo.bar"]) child = resource.getChildForRequest(file, request) d = self._render(child, request) def cbRendered(ignored): self.assertEqual(b''.join(request.written), b'dynamic world') self.assertEqual( request.responseHeaders.getRawHeaders(b'content-length')[0], b'13') d.addCallback(cbRendered) return d
If a request is made which encounters a L{File} before a final segment which names a file with an extension which is in the L{File}'s C{processors} mapping, the processor associated with that extension is used to serve the response to the request.
test_processors
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_ignoreExt(self): """ The list of ignored extensions can be set by passing a value to L{File.__init__} or by calling L{File.ignoreExt} later. """ file = static.File(b".") self.assertEqual(file.ignoredExts, []) file.ignoreExt(".foo") file.ignoreExt(".bar") self.assertEqual(file.ignoredExts, [".foo", ".bar"]) file = static.File(b".", ignoredExts=(".bar", ".baz")) self.assertEqual(file.ignoredExts, [".bar", ".baz"])
The list of ignored extensions can be set by passing a value to L{File.__init__} or by calling L{File.ignoreExt} later.
test_ignoreExt
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_ignoredExtensionsIgnored(self): """ A request for the I{base} child of a L{File} succeeds with a resource for the I{base<extension>} file in the path the L{File} was created with if such a file exists and the L{File} has been configured to ignore the I{<extension>} extension. """ base = FilePath(self.mktemp()) base.makedirs() base.child('foo.bar').setContent(b'baz') base.child('foo.quux').setContent(b'foobar') file = static.File(base.path, ignoredExts=(".bar",)) request = DummyRequest([b"foo"]) child = resource.getChildForRequest(file, request) d = self._render(child, request) def cbRendered(ignored): self.assertEqual(b''.join(request.written), b'baz') d.addCallback(cbRendered) return d
A request for the I{base} child of a L{File} succeeds with a resource for the I{base<extension>} file in the path the L{File} was created with if such a file exists and the L{File} has been configured to ignore the I{<extension>} extension.
test_ignoredExtensionsIgnored
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_directoryWithoutTrailingSlashRedirects(self): """ A request for a path which is a directory but does not have a trailing slash will be redirected to a URL which does have a slash by L{File}. """ base = FilePath(self.mktemp()) base.makedirs() base.child('folder').makedirs() file = static.File(base.path) request = DummyRequest([b"folder"]) request.uri = b"http://dummy/folder#baz?foo=bar" child = resource.getChildForRequest(file, request) self.successResultOf(self._render(child, request)) self.assertEqual(request.responseCode, FOUND) self.assertEqual(request.responseHeaders.getRawHeaders(b"location"), [b"http://dummy/folder/#baz?foo=bar"])
A request for a path which is a directory but does not have a trailing slash will be redirected to a URL which does have a slash by L{File}.
test_directoryWithoutTrailingSlashRedirects
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def _makeFilePathWithStringIO(self): """ Create a L{File} that when opened for reading, returns a L{StringIO}. @return: 2-tuple of the opened "file" and the L{File}. @rtype: L{tuple} """ fakeFile = StringIO() path = FilePath(self.mktemp()) path.touch() file = static.File(path.path) # Open our file instead of a real one file.open = lambda: fakeFile return fakeFile, file
Create a L{File} that when opened for reading, returns a L{StringIO}. @return: 2-tuple of the opened "file" and the L{File}. @rtype: L{tuple}
_makeFilePathWithStringIO
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_HEADClosesFile(self): """ A HEAD request opens the file, gets the size, and then closes it after the request. """ fakeFile, file = self._makeFilePathWithStringIO() request = DummyRequest(['']) request.method = b'HEAD' self.successResultOf(_render(file, request)) self.assertEqual(b''.join(request.written), b'') self.assertTrue(fakeFile.closed)
A HEAD request opens the file, gets the size, and then closes it after the request.
test_HEADClosesFile
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_cachedRequestClosesFile(self): """ A GET request that is cached closes the file after the request. """ fakeFile, file = self._makeFilePathWithStringIO() request = DummyRequest(['']) request.method = b'GET' # This request will always return saying that it is cached request.setLastModified = lambda _: http.CACHED self.successResultOf(_render(file, request)) self.assertEqual(b''.join(request.written), b'') self.assertTrue(fakeFile.closed)
A GET request that is cached closes the file after the request.
test_cachedRequestClosesFile
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def makeResourceWithContent(self, content, type=None, encoding=None): """ Make a L{static.File} resource that has C{content} for its content. @param content: The L{bytes} to use as the contents of the resource. @param type: Optional value for the content type of the resource. """ fileName = FilePath(self.mktemp()) fileName.setContent(content) resource = static.File(fileName._asBytesPath()) resource.encoding = encoding resource.type = type return resource
Make a L{static.File} resource that has C{content} for its content. @param content: The L{bytes} to use as the contents of the resource. @param type: Optional value for the content type of the resource.
makeResourceWithContent
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def contentHeaders(self, request): """ Extract the content-* headers from the L{DummyRequest} C{request}. This returns the subset of C{request.outgoingHeaders} of headers that start with 'content-'. """ contentHeaders = {} for k, v in request.responseHeaders.getAllRawHeaders(): if k.lower().startswith(b'content-'): contentHeaders[k.lower()] = v[0] return contentHeaders
Extract the content-* headers from the L{DummyRequest} C{request}. This returns the subset of C{request.outgoingHeaders} of headers that start with 'content-'.
contentHeaders
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_noRangeHeaderGivesNoRangeStaticProducer(self): """ makeProducer when no Range header is set returns an instance of NoRangeStaticProducer. """ resource = self.makeResourceWithContent(b'') request = DummyRequest([]) with resource.openForReading() as file: producer = resource.makeProducer(request, file) self.assertIsInstance(producer, static.NoRangeStaticProducer)
makeProducer when no Range header is set returns an instance of NoRangeStaticProducer.
test_noRangeHeaderGivesNoRangeStaticProducer
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_noRangeHeaderSets200OK(self): """ makeProducer when no Range header is set sets the responseCode on the request to 'OK'. """ resource = self.makeResourceWithContent(b'') request = DummyRequest([]) with resource.openForReading() as file: resource.makeProducer(request, file) self.assertEqual(http.OK, request.responseCode)
makeProducer when no Range header is set sets the responseCode on the request to 'OK'.
test_noRangeHeaderSets200OK
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_noRangeHeaderSetsContentHeaders(self): """ makeProducer when no Range header is set sets the Content-* headers for the response. """ length = 123 contentType = "text/plain" contentEncoding = 'gzip' resource = self.makeResourceWithContent( b'a'*length, type=contentType, encoding=contentEncoding) request = DummyRequest([]) with resource.openForReading() as file: resource.makeProducer(request, file) self.assertEqual( {b'content-type': networkString(contentType), b'content-length': intToBytes(length), b'content-encoding': networkString(contentEncoding)}, self.contentHeaders(request))
makeProducer when no Range header is set sets the Content-* headers for the response.
test_noRangeHeaderSetsContentHeaders
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_singleRangeGivesSingleRangeStaticProducer(self): """ makeProducer when the Range header requests a single byte range returns an instance of SingleRangeStaticProducer. """ request = DummyRequest([]) request.requestHeaders.addRawHeader(b'range', b'bytes=1-3') resource = self.makeResourceWithContent(b'abcdef') with resource.openForReading() as file: producer = resource.makeProducer(request, file) self.assertIsInstance(producer, static.SingleRangeStaticProducer)
makeProducer when the Range header requests a single byte range returns an instance of SingleRangeStaticProducer.
test_singleRangeGivesSingleRangeStaticProducer
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_singleRangeSets206PartialContent(self): """ makeProducer when the Range header requests a single, satisfiable byte range sets the response code on the request to 'Partial Content'. """ request = DummyRequest([]) request.requestHeaders.addRawHeader(b'range', b'bytes=1-3') resource = self.makeResourceWithContent(b'abcdef') with resource.openForReading() as file: resource.makeProducer(request, file) self.assertEqual( http.PARTIAL_CONTENT, request.responseCode)
makeProducer when the Range header requests a single, satisfiable byte range sets the response code on the request to 'Partial Content'.
test_singleRangeSets206PartialContent
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_singleRangeSetsContentHeaders(self): """ makeProducer when the Range header requests a single, satisfiable byte range sets the Content-* headers appropriately. """ request = DummyRequest([]) request.requestHeaders.addRawHeader(b'range', b'bytes=1-3') contentType = "text/plain" contentEncoding = 'gzip' resource = self.makeResourceWithContent(b'abcdef', type=contentType, encoding=contentEncoding) with resource.openForReading() as file: resource.makeProducer(request, file) self.assertEqual( {b'content-type': networkString(contentType), b'content-encoding': networkString(contentEncoding), b'content-range': b'bytes 1-3/6', b'content-length': b'3'}, self.contentHeaders(request))
makeProducer when the Range header requests a single, satisfiable byte range sets the Content-* headers appropriately.
test_singleRangeSetsContentHeaders
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_singleUnsatisfiableRangeReturnsSingleRangeStaticProducer(self): """ makeProducer still returns an instance of L{SingleRangeStaticProducer} when the Range header requests a single unsatisfiable byte range. """ request = DummyRequest([]) request.requestHeaders.addRawHeader(b'range', b'bytes=4-10') resource = self.makeResourceWithContent(b'abc') with resource.openForReading() as file: producer = resource.makeProducer(request, file) self.assertIsInstance(producer, static.SingleRangeStaticProducer)
makeProducer still returns an instance of L{SingleRangeStaticProducer} when the Range header requests a single unsatisfiable byte range.
test_singleUnsatisfiableRangeReturnsSingleRangeStaticProducer
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_singleUnsatisfiableRangeSets416ReqestedRangeNotSatisfiable(self): """ makeProducer sets the response code of the request to of 'Requested Range Not Satisfiable' when the Range header requests a single unsatisfiable byte range. """ request = DummyRequest([]) request.requestHeaders.addRawHeader(b'range', b'bytes=4-10') resource = self.makeResourceWithContent(b'abc') with resource.openForReading() as file: resource.makeProducer(request, file) self.assertEqual( http.REQUESTED_RANGE_NOT_SATISFIABLE, request.responseCode)
makeProducer sets the response code of the request to of 'Requested Range Not Satisfiable' when the Range header requests a single unsatisfiable byte range.
test_singleUnsatisfiableRangeSets416ReqestedRangeNotSatisfiable
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_singleUnsatisfiableRangeSetsContentHeaders(self): """ makeProducer when the Range header requests a single, unsatisfiable byte range sets the Content-* headers appropriately. """ request = DummyRequest([]) request.requestHeaders.addRawHeader(b'range', b'bytes=4-10') contentType = "text/plain" resource = self.makeResourceWithContent(b'abc', type=contentType) with resource.openForReading() as file: resource.makeProducer(request, file) self.assertEqual( {b'content-type': b'text/plain', b'content-length': b'0', b'content-range': b'bytes */3'}, self.contentHeaders(request))
makeProducer when the Range header requests a single, unsatisfiable byte range sets the Content-* headers appropriately.
test_singleUnsatisfiableRangeSetsContentHeaders
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_singlePartiallyOverlappingRangeSetsContentHeaders(self): """ makeProducer when the Range header requests a single byte range that partly overlaps the resource sets the Content-* headers appropriately. """ request = DummyRequest([]) request.requestHeaders.addRawHeader(b'range', b'bytes=2-10') contentType = "text/plain" resource = self.makeResourceWithContent(b'abc', type=contentType) with resource.openForReading() as file: resource.makeProducer(request, file) self.assertEqual( {b'content-type': b'text/plain', b'content-length': b'1', b'content-range': b'bytes 2-2/3'}, self.contentHeaders(request))
makeProducer when the Range header requests a single byte range that partly overlaps the resource sets the Content-* headers appropriately.
test_singlePartiallyOverlappingRangeSetsContentHeaders
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_multipleRangeGivesMultipleRangeStaticProducer(self): """ makeProducer when the Range header requests a single byte range returns an instance of MultipleRangeStaticProducer. """ request = DummyRequest([]) request.requestHeaders.addRawHeader(b'range', b'bytes=1-3,5-6') resource = self.makeResourceWithContent(b'abcdef') with resource.openForReading() as file: producer = resource.makeProducer(request, file) self.assertIsInstance(producer, static.MultipleRangeStaticProducer)
makeProducer when the Range header requests a single byte range returns an instance of MultipleRangeStaticProducer.
test_multipleRangeGivesMultipleRangeStaticProducer
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_multipleRangeSets206PartialContent(self): """ makeProducer when the Range header requests a multiple satisfiable byte ranges sets the response code on the request to 'Partial Content'. """ request = DummyRequest([]) request.requestHeaders.addRawHeader(b'range', b'bytes=1-3,5-6') resource = self.makeResourceWithContent(b'abcdef') with resource.openForReading() as file: resource.makeProducer(request, file) self.assertEqual( http.PARTIAL_CONTENT, request.responseCode)
makeProducer when the Range header requests a multiple satisfiable byte ranges sets the response code on the request to 'Partial Content'.
test_multipleRangeSets206PartialContent
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT
def test_multipleUnsatisfiableRangesReturnsMultipleRangeStaticProducer(self): """ makeProducer still returns an instance of L{SingleRangeStaticProducer} when the Range header requests multiple ranges, none of which are satisfiable. """ request = DummyRequest([]) request.requestHeaders.addRawHeader(b'range', b'bytes=10-12,15-20') resource = self.makeResourceWithContent(b'abc') with resource.openForReading() as file: producer = resource.makeProducer(request, file) self.assertIsInstance(producer, static.MultipleRangeStaticProducer)
makeProducer still returns an instance of L{SingleRangeStaticProducer} when the Range header requests multiple ranges, none of which are satisfiable.
test_multipleUnsatisfiableRangesReturnsMultipleRangeStaticProducer
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_static.py
MIT