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 test_methodWithNonASCIIRejected(self): """ Issuing a request with a method that contains non-ASCII characters fails with a L{ValueError}. """ for c in NONASCII: method = b"GET%s" % (bytearray([c]),) with self.assertRaises(ValueError) as cm: self.attemptRequestWithMaliciousMethod(method) self.assertRegex(str(cm.exception), "^Invalid method")
Issuing a request with a method that contains non-ASCII characters fails with a L{ValueError}.
test_methodWithNonASCIIRejected
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/injectionhelpers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/injectionhelpers.py
MIT
def attemptRequestWithMaliciousURI(self, method): """ Attempt to send a request with the given URI. This should synchronously raise a L{ValueError} if either is invalid. @param uri: the URI. @type method: """ raise NotImplementedError()
Attempt to send a request with the given URI. This should synchronously raise a L{ValueError} if either is invalid. @param uri: the URI. @type method:
attemptRequestWithMaliciousURI
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/injectionhelpers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/injectionhelpers.py
MIT
def test_hostWithCRLFRejected(self): """ Issuing a request with a URI whose host contains a carriage return and line feed fails with a L{ValueError}. """ with self.assertRaises(ValueError) as cm: uri = b"http://twisted\r\n.invalid/path" self.attemptRequestWithMaliciousURI(uri) self.assertRegex(str(cm.exception), "^Invalid URI")
Issuing a request with a URI whose host contains a carriage return and line feed fails with a L{ValueError}.
test_hostWithCRLFRejected
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/injectionhelpers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/injectionhelpers.py
MIT
def test_hostWithWithUnprintableASCIIRejected(self): """ Issuing a request with a URI whose host contains unprintable ASCII characters fails with a L{ValueError}. """ for c in UNPRINTABLE_ASCII: uri = b"http://twisted%s.invalid/OK" % (bytearray([c]),) with self.assertRaises(ValueError) as cm: self.attemptRequestWithMaliciousURI(uri) self.assertRegex(str(cm.exception), "^Invalid URI")
Issuing a request with a URI whose host contains unprintable ASCII characters fails with a L{ValueError}.
test_hostWithWithUnprintableASCIIRejected
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/injectionhelpers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/injectionhelpers.py
MIT
def test_hostWithNonASCIIRejected(self): """ Issuing a request with a URI whose host contains non-ASCII characters fails with a L{ValueError}. """ for c in NONASCII: uri = b"http://twisted%s.invalid/OK" % (bytearray([c]),) with self.assertRaises(ValueError) as cm: self.attemptRequestWithMaliciousURI(uri) self.assertRegex(str(cm.exception), "^Invalid URI")
Issuing a request with a URI whose host contains non-ASCII characters fails with a L{ValueError}.
test_hostWithNonASCIIRejected
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/injectionhelpers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/injectionhelpers.py
MIT
def test_pathWithCRLFRejected(self): """ Issuing a request with a URI whose path contains a carriage return and line feed fails with a L{ValueError}. """ with self.assertRaises(ValueError) as cm: uri = b"http://twisted.invalid/\r\npath" self.attemptRequestWithMaliciousURI(uri) self.assertRegex(str(cm.exception), "^Invalid URI")
Issuing a request with a URI whose path contains a carriage return and line feed fails with a L{ValueError}.
test_pathWithCRLFRejected
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/injectionhelpers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/injectionhelpers.py
MIT
def test_pathWithWithUnprintableASCIIRejected(self): """ Issuing a request with a URI whose path contains unprintable ASCII characters fails with a L{ValueError}. """ for c in UNPRINTABLE_ASCII: uri = b"http://twisted.invalid/OK%s" % (bytearray([c]),) with self.assertRaises(ValueError) as cm: self.attemptRequestWithMaliciousURI(uri) self.assertRegex(str(cm.exception), "^Invalid URI")
Issuing a request with a URI whose path contains unprintable ASCII characters fails with a L{ValueError}.
test_pathWithWithUnprintableASCIIRejected
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/injectionhelpers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/injectionhelpers.py
MIT
def test_pathWithNonASCIIRejected(self): """ Issuing a request with a URI whose path contains non-ASCII characters fails with a L{ValueError}. """ for c in NONASCII: uri = b"http://twisted.invalid/OK%s" % (bytearray([c]),) with self.assertRaises(ValueError) as cm: self.attemptRequestWithMaliciousURI(uri) self.assertRegex(str(cm.exception), "^Invalid URI")
Issuing a request with a URI whose path contains non-ASCII characters fails with a L{ValueError}.
test_pathWithNonASCIIRejected
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/injectionhelpers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/injectionhelpers.py
MIT
def assertFlattensTo(self, root, target): """ Assert that a root element, when flattened, is equal to a string. """ d = flattenString(None, root) d.addCallback(lambda s: self.assertEqual(s, target)) return d
Assert that a root element, when flattened, is equal to a string.
assertFlattensTo
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/_util.py
MIT
def assertFlattensImmediately(self, root, target): """ Assert that a root element, when flattened, is equal to a string, and performs no asynchronus Deferred anything. This version is more convenient in tests which wish to make multiple assertions about flattening, since it can be called multiple times without having to add multiple callbacks. @return: the result of rendering L{root}, which should be equivalent to L{target}. @rtype: L{bytes} """ results = [] it = self.assertFlattensTo(root, target) it.addBoth(results.append) # Do our best to clean it up if something goes wrong. self.addCleanup(it.cancel) if not results: self.fail("Rendering did not complete immediately.") result = results[0] if isinstance(result, Failure): result.raiseException() return results[0]
Assert that a root element, when flattened, is equal to a string, and performs no asynchronus Deferred anything. This version is more convenient in tests which wish to make multiple assertions about flattening, since it can be called multiple times without having to add multiple callbacks. @return: the result of rendering L{root}, which should be equivalent to L{target}. @rtype: L{bytes}
assertFlattensImmediately
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/_util.py
MIT
def assertFlatteningRaises(self, root, exn): """ Assert flattening a root element raises a particular exception. """ d = self.assertFailure(self.assertFlattensTo(root, b''), FlattenerError) d.addCallback(lambda exc: self.assertIsInstance(exc._exception, exn)) return d
Assert flattening a root element raises a particular exception.
assertFlatteningRaises
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/_util.py
MIT
def test_getChild(self): """ L{_HostResource.getChild} returns the proper I{Resource} for the vhost embedded in the URL. Verify that returning the proper I{Resource} required changing the I{Host} in the header. """ bazroot = Data(b'root data', "") bazuri = Data(b'uri data', "") baztest = Data(b'test data', "") bazuri.putChild(b'test', baztest) bazroot.putChild(b'uri', bazuri) hr = _HostResource() root = NameVirtualHost() root.default = Data(b'default data', "") root.addHost(b'baz.com', bazroot) request = DummyRequest([b'uri', b'test']) request.prepath = [b'bar', b'http', b'baz.com'] request.site = Site(root) request.isSecure = lambda: False request.host = b'' step = hr.getChild(b'baz.com', request) # Consumes rest of path self.assertIsInstance(step, Data) request = DummyRequest([b'uri', b'test']) step = root.getChild(b'uri', request) self.assertIsInstance(step, NoResource)
L{_HostResource.getChild} returns the proper I{Resource} for the vhost embedded in the URL. Verify that returning the proper I{Resource} required changing the I{Host} in the header.
test_getChild
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_vhost.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_vhost.py
MIT
def test_renderWithoutHost(self): """ L{NameVirtualHost.render} returns the result of rendering the instance's C{default} if it is not L{None} and there is no I{Host} header in the request. """ virtualHostResource = NameVirtualHost() virtualHostResource.default = Data(b"correct result", "") request = DummyRequest(['']) self.assertEqual( virtualHostResource.render(request), b"correct result")
L{NameVirtualHost.render} returns the result of rendering the instance's C{default} if it is not L{None} and there is no I{Host} header in the request.
test_renderWithoutHost
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_vhost.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_vhost.py
MIT
def test_renderWithoutHostNoDefault(self): """ L{NameVirtualHost.render} returns a response with a status of I{NOT FOUND} if the instance's C{default} is L{None} and there is no I{Host} header in the request. """ virtualHostResource = NameVirtualHost() request = DummyRequest(['']) d = _render(virtualHostResource, request) def cbRendered(ignored): self.assertEqual(request.responseCode, NOT_FOUND) d.addCallback(cbRendered) return d
L{NameVirtualHost.render} returns a response with a status of I{NOT FOUND} if the instance's C{default} is L{None} and there is no I{Host} header in the request.
test_renderWithoutHostNoDefault
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_vhost.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_vhost.py
MIT
def test_renderWithHost(self): """ L{NameVirtualHost.render} returns the result of rendering the resource which is the value in the instance's C{host} dictionary corresponding to the key indicated by the value of the I{Host} header in the request. """ virtualHostResource = NameVirtualHost() virtualHostResource.addHost(b'example.org', Data(b"winner", "")) request = DummyRequest([b'']) request.requestHeaders.addRawHeader(b'host', b'example.org') d = _render(virtualHostResource, request) def cbRendered(ignored, request): self.assertEqual(b''.join(request.written), b"winner") d.addCallback(cbRendered, request) # The port portion of the Host header should not be considered. requestWithPort = DummyRequest([b'']) requestWithPort.requestHeaders.addRawHeader(b'host', b'example.org:8000') dWithPort = _render(virtualHostResource, requestWithPort) def cbRendered(ignored, requestWithPort): self.assertEqual(b''.join(requestWithPort.written), b"winner") dWithPort.addCallback(cbRendered, requestWithPort) return gatherResults([d, dWithPort])
L{NameVirtualHost.render} returns the result of rendering the resource which is the value in the instance's C{host} dictionary corresponding to the key indicated by the value of the I{Host} header in the request.
test_renderWithHost
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_vhost.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_vhost.py
MIT
def test_renderWithUnknownHost(self): """ L{NameVirtualHost.render} returns the result of rendering the instance's C{default} if it is not L{None} and there is no host matching the value of the I{Host} header in the request. """ virtualHostResource = NameVirtualHost() virtualHostResource.default = Data(b"correct data", "") request = DummyRequest([b'']) request.requestHeaders.addRawHeader(b'host', b'example.com') d = _render(virtualHostResource, request) def cbRendered(ignored): self.assertEqual(b''.join(request.written), b"correct data") d.addCallback(cbRendered) return d
L{NameVirtualHost.render} returns the result of rendering the instance's C{default} if it is not L{None} and there is no host matching the value of the I{Host} header in the request.
test_renderWithUnknownHost
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_vhost.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_vhost.py
MIT
def test_renderWithUnknownHostNoDefault(self): """ L{NameVirtualHost.render} returns a response with a status of I{NOT FOUND} if the instance's C{default} is L{None} and there is no host matching the value of the I{Host} header in the request. """ virtualHostResource = NameVirtualHost() request = DummyRequest(['']) request.requestHeaders.addRawHeader(b'host', b'example.com') d = _render(virtualHostResource, request) def cbRendered(ignored): self.assertEqual(request.responseCode, NOT_FOUND) d.addCallback(cbRendered) return d
L{NameVirtualHost.render} returns a response with a status of I{NOT FOUND} if the instance's C{default} is L{None} and there is no host matching the value of the I{Host} header in the request.
test_renderWithUnknownHostNoDefault
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_vhost.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_vhost.py
MIT
def test_getChild(self): """ L{NameVirtualHost.getChild} returns correct I{Resource} based off the header and modifies I{Request} to ensure proper prepath and postpath are set. """ virtualHostResource = NameVirtualHost() leafResource = Data(b"leaf data", "") leafResource.isLeaf = True normResource = Data(b"norm data", "") virtualHostResource.addHost(b'leaf.example.org', leafResource) virtualHostResource.addHost(b'norm.example.org', normResource) request = DummyRequest([]) request.requestHeaders.addRawHeader(b'host', b'norm.example.org') request.prepath = [b''] self.assertIsInstance(virtualHostResource.getChild(b'', request), NoResource) self.assertEqual(request.prepath, [b'']) self.assertEqual(request.postpath, []) request = DummyRequest([]) request.requestHeaders.addRawHeader(b'host', b'leaf.example.org') request.prepath = [b''] self.assertIsInstance(virtualHostResource.getChild(b'', request), Data) self.assertEqual(request.prepath, []) self.assertEqual(request.postpath, [b''])
L{NameVirtualHost.getChild} returns correct I{Resource} based off the header and modifies I{Request} to ensure proper prepath and postpath are set.
test_getChild
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_vhost.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_vhost.py
MIT
def test_getChild(self): """ L{VHostMonsterResource.getChild} returns I{_HostResource} and modifies I{Request} with correct L{Request.isSecure}. """ vhm = VHostMonsterResource() request = DummyRequest([]) self.assertIsInstance(vhm.getChild(b'http', request), _HostResource) self.assertFalse(request.isSecure()) request = DummyRequest([]) self.assertIsInstance(vhm.getChild(b'https', request), _HostResource) self.assertTrue(request.isSecure())
L{VHostMonsterResource.getChild} returns I{_HostResource} and modifies I{Request} with correct L{Request.isSecure}.
test_getChild
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_vhost.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_vhost.py
MIT
def test_implements(self): """L{DummyEndPoint}s implements L{interfaces.IStreamClientEndpoint}""" ep = DummyEndPoint("something") verify.verifyObject(interfaces.IStreamClientEndpoint, ep)
L{DummyEndPoint}s implements L{interfaces.IStreamClientEndpoint}
test_implements
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_client.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_client.py
MIT
def test_repr(self): """connection L{repr()} includes endpoint's L{repr()}""" pool = client.HTTPConnectionPool(reactor=None) ep = DummyEndPoint("this_is_probably_unique") d = pool.getConnection('someplace', ep) result = self.successResultOf(d) representation = repr(result) self.assertIn(repr(ep), representation)
connection L{repr()} includes endpoint's L{repr()}
test_repr
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_client.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_client.py
MIT
def _pathOption(self): """ Helper for the I{--path} tests which creates a directory and creates an L{Options} object which uses that directory as its static filesystem root. @return: A two-tuple of a L{FilePath} referring to the directory and the value associated with the C{'root'} key in the L{Options} instance after parsing a I{--path} option. """ path = FilePath(self.mktemp()) path.makedirs() options = Options() options.parseOptions(['--path', path.path]) root = options['root'] return path, root
Helper for the I{--path} tests which creates a directory and creates an L{Options} object which uses that directory as its static filesystem root. @return: A two-tuple of a L{FilePath} referring to the directory and the value associated with the C{'root'} key in the L{Options} instance after parsing a I{--path} option.
_pathOption
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_path(self): """ The I{--path} option causes L{Options} to create a root resource which serves responses from the specified path. """ path, root = self._pathOption() self.assertIsInstance(root, File) self.assertEqual(root.path, path.path)
The I{--path} option causes L{Options} to create a root resource which serves responses from the specified path.
test_path
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_pathServer(self): """ The I{--path} option to L{makeService} causes it to return a service which will listen on the server address given by the I{--port} option. """ path = FilePath(self.mktemp()) path.makedirs() port = self.mktemp() options = Options() options.parseOptions(['--port', 'unix:' + port, '--path', path.path]) service = makeService(options) service.startService() self.addCleanup(service.stopService) self.assertIsInstance(service.services[0].factory.resource, File) self.assertEqual(service.services[0].factory.resource.path, path.path) self.assertTrue(os.path.exists(port)) self.assertTrue(stat.S_ISSOCK(os.stat(port).st_mode))
The I{--path} option to L{makeService} causes it to return a service which will listen on the server address given by the I{--port} option.
test_pathServer
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_cgiProcessor(self): """ The I{--path} option creates a root resource which serves a L{CGIScript} instance for any child with the C{".cgi"} extension. """ path, root = self._pathOption() path.child("foo.cgi").setContent(b"") self.assertIsInstance(root.getChild("foo.cgi", None), CGIScript)
The I{--path} option creates a root resource which serves a L{CGIScript} instance for any child with the C{".cgi"} extension.
test_cgiProcessor
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_epyProcessor(self): """ The I{--path} option creates a root resource which serves a L{PythonScript} instance for any child with the C{".epy"} extension. """ path, root = self._pathOption() path.child("foo.epy").setContent(b"") self.assertIsInstance(root.getChild("foo.epy", None), PythonScript)
The I{--path} option creates a root resource which serves a L{PythonScript} instance for any child with the C{".epy"} extension.
test_epyProcessor
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_rpyProcessor(self): """ The I{--path} option creates a root resource which serves the C{resource} global defined by the Python source in any child with the C{".rpy"} extension. """ path, root = self._pathOption() path.child("foo.rpy").setContent( b"from twisted.web.static import Data\n" b"resource = Data('content', 'major/minor')\n") child = root.getChild("foo.rpy", None) self.assertIsInstance(child, Data) self.assertEqual(child.data, 'content') self.assertEqual(child.type, 'major/minor')
The I{--path} option creates a root resource which serves the C{resource} global defined by the Python source in any child with the C{".rpy"} extension.
test_rpyProcessor
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_makePersonalServerFactory(self): """ L{makePersonalServerFactory} returns a PB server factory which has as its root object a L{ResourcePublisher}. """ # The fact that this pile of objects can actually be used somehow is # verified by twisted.web.test.test_distrib. site = Site(Data(b"foo bar", "text/plain")) serverFactory = makePersonalServerFactory(site) self.assertIsInstance(serverFactory, PBServerFactory) self.assertIsInstance(serverFactory.root, ResourcePublisher) self.assertIdentical(serverFactory.root.site, site)
L{makePersonalServerFactory} returns a PB server factory which has as its root object a L{ResourcePublisher}.
test_makePersonalServerFactory
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_personalServer(self): """ The I{--personal} option to L{makeService} causes it to return a service which will listen on the server address given by the I{--port} option. """ port = self.mktemp() options = Options() options.parseOptions(['--port', 'unix:' + port, '--personal']) service = makeService(options) service.startService() self.addCleanup(service.stopService) self.assertTrue(os.path.exists(port)) self.assertTrue(stat.S_ISSOCK(os.stat(port).st_mode))
The I{--personal} option to L{makeService} causes it to return a service which will listen on the server address given by the I{--port} option.
test_personalServer
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_defaultPersonalPath(self): """ If the I{--port} option not specified but the I{--personal} option is, L{Options} defaults the port to C{UserDirectory.userSocketName} in the user's home directory. """ options = Options() options.parseOptions(['--personal']) path = os.path.expanduser( os.path.join('~', UserDirectory.userSocketName)) self.assertEqual(options['ports'][0], 'unix:{}'.format(path))
If the I{--port} option not specified but the I{--personal} option is, L{Options} defaults the port to C{UserDirectory.userSocketName} in the user's home directory.
test_defaultPersonalPath
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_defaultPort(self): """ If the I{--port} option is not specified, L{Options} defaults the port to C{8080}. """ options = Options() options.parseOptions([]) self.assertEqual( endpoints._parseServer(options['ports'][0], None)[:2], ('TCP', (8080, None)))
If the I{--port} option is not specified, L{Options} defaults the port to C{8080}.
test_defaultPort
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_twoPorts(self): """ If the I{--http} option is given twice, there are two listeners """ options = Options() options.parseOptions(['--listen', 'tcp:8001', '--listen', 'tcp:8002']) self.assertIn('8001', options['ports'][0]) self.assertIn('8002', options['ports'][1])
If the I{--http} option is given twice, there are two listeners
test_twoPorts
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_wsgi(self): """ The I{--wsgi} option takes the fully-qualifed Python name of a WSGI application object and creates a L{WSGIResource} at the root which serves that application. """ options = Options() options.parseOptions(['--wsgi', __name__ + '.application']) root = options['root'] self.assertTrue(root, WSGIResource) self.assertIdentical(root._reactor, reactor) self.assertTrue(isinstance(root._threadpool, ThreadPool)) self.assertIdentical(root._application, application) # The threadpool should start and stop with the reactor. self.assertFalse(root._threadpool.started) reactor.fireSystemEvent('startup') self.assertTrue(root._threadpool.started) self.assertFalse(root._threadpool.joined) reactor.fireSystemEvent('shutdown') self.assertTrue(root._threadpool.joined)
The I{--wsgi} option takes the fully-qualifed Python name of a WSGI application object and creates a L{WSGIResource} at the root which serves that application.
test_wsgi
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_invalidApplication(self): """ If I{--wsgi} is given an invalid name, L{Options.parseOptions} raises L{UsageError}. """ options = Options() for name in [__name__ + '.nosuchthing', 'foo.']: exc = self.assertRaises( UsageError, options.parseOptions, ['--wsgi', name]) self.assertEqual(str(exc), "No such WSGI application: %r" % (name,))
If I{--wsgi} is given an invalid name, L{Options.parseOptions} raises L{UsageError}.
test_invalidApplication
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_HTTPSFailureOnMissingSSL(self): """ An L{UsageError} is raised when C{https} is requested but there is no support for SSL. """ options = Options() exception = self.assertRaises( UsageError, options.parseOptions, ['--https=443']) self.assertEqual('SSL support not installed', exception.args[0])
An L{UsageError} is raised when C{https} is requested but there is no support for SSL.
test_HTTPSFailureOnMissingSSL
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_HTTPSAcceptedOnAvailableSSL(self): """ When SSL support is present, it accepts the --https option. """ options = Options() options.parseOptions(['--https=443']) self.assertIn('ssl', options['ports'][0]) self.assertIn('443', options['ports'][0])
When SSL support is present, it accepts the --https option.
test_HTTPSAcceptedOnAvailableSSL
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_add_header_parsing(self): """ When --add-header is specific, the value is parsed. """ options = Options() options.parseOptions( ['--add-header', 'K1: V1', '--add-header', 'K2: V2'] ) self.assertEqual(options['extraHeaders'], [('K1', 'V1'), ('K2', 'V2')])
When --add-header is specific, the value is parsed.
test_add_header_parsing
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_add_header_resource(self): """ When --add-header is specified, the resource is a composition that adds headers. """ options = Options() options.parseOptions( ['--add-header', 'K1: V1', '--add-header', 'K2: V2'] ) service = makeService(options) resource = service.services[0].factory.resource self.assertIsInstance(resource, _AddHeadersResource) self.assertEqual(resource._headers, [('K1', 'V1'), ('K2', 'V2')]) self.assertIsInstance(resource._originalResource, demo.Test)
When --add-header is specified, the resource is a composition that adds headers.
test_add_header_resource
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_noTracebacksDeprecation(self): """ Passing --notracebacks is deprecated. """ options = Options() options.parseOptions(["--notracebacks"]) makeService(options) warnings = self.flushWarnings([self.test_noTracebacksDeprecation]) self.assertEqual(warnings[0]['category'], DeprecationWarning) self.assertEqual( warnings[0]['message'], "--notracebacks was deprecated in Twisted 19.7.0" ) self.assertEqual(len(warnings), 1)
Passing --notracebacks is deprecated.
test_noTracebacksDeprecation
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_displayTracebacks(self): """ Passing --display-tracebacks will enable traceback rendering on the generated Site. """ options = Options() options.parseOptions(["--display-tracebacks"]) service = makeService(options) self.assertTrue(service.services[0].factory.displayTracebacks)
Passing --display-tracebacks will enable traceback rendering on the generated Site.
test_displayTracebacks
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_displayTracebacksNotGiven(self): """ Not passing --display-tracebacks will leave traceback rendering on the generated Site off. """ options = Options() options.parseOptions([]) service = makeService(options) self.assertFalse(service.services[0].factory.displayTracebacks)
Not passing --display-tracebacks will leave traceback rendering on the generated Site off.
test_displayTracebacksNotGiven
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_getChildWithDefault(self): """ When getChildWithDefault is invoked, it adds the headers to the response. """ resource = _AddHeadersResource( demo.Test(), [("K1", "V1"), ("K2", "V2"), ("K1", "V3")]) request = DummyRequest([]) resource.getChildWithDefault("", request) self.assertEqual( request.responseHeaders.getRawHeaders("K1"), ["V1", "V3"]) self.assertEqual(request.responseHeaders.getRawHeaders("K2"), ["V2"])
When getChildWithDefault is invoked, it adds the headers to the response.
test_getChildWithDefault
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_tap.py
MIT
def test_noFragments(self): """ L{client._urljoin} does not include a fragment identifier in the resulting URL if neither the base nor the new path include a fragment identifier. """ self.assertEqual( client._urljoin(b'http://foo.com/bar', b'/quux'), b'http://foo.com/quux') self.assertEqual( client._urljoin(b'http://foo.com/bar#', b'/quux'), b'http://foo.com/quux') self.assertEqual( client._urljoin(b'http://foo.com/bar', b'/quux#'), b'http://foo.com/quux')
L{client._urljoin} does not include a fragment identifier in the resulting URL if neither the base nor the new path include a fragment identifier.
test_noFragments
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_preserveFragments(self): """ L{client._urljoin} preserves the fragment identifier from either the new path or the base URL respectively, as specified in the HTTP 1.1 bis draft. @see: U{https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-22#section-7.1.2} """ self.assertEqual( client._urljoin(b'http://foo.com/bar#frag', b'/quux'), b'http://foo.com/quux#frag') self.assertEqual( client._urljoin(b'http://foo.com/bar', b'/quux#frag2'), b'http://foo.com/quux#frag2') self.assertEqual( client._urljoin(b'http://foo.com/bar#frag', b'/quux#frag2'), b'http://foo.com/quux#frag2')
L{client._urljoin} preserves the fragment identifier from either the new path or the base URL respectively, as specified in the HTTP 1.1 bis draft. @see: U{https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-22#section-7.1.2}
test_preserveFragments
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_earlyHeaders(self): """ When a connection is made, L{HTTPPagerGetter} sends the headers from its factory's C{headers} dict. If I{Host} or I{Content-Length} is present in this dict, the values are not sent, since they are sent with special values before the C{headers} dict is processed. If I{User-Agent} is present in the dict, it overrides the value of the C{agent} attribute of the factory. If I{Cookie} is present in the dict, its value is added to the values from the factory's C{cookies} attribute. """ factory = client.HTTPClientFactory( b'http://foo/bar', agent=b"foobar", cookies={b'baz': b'quux'}, postdata=b"some data", headers={ b'Host': b'example.net', b'User-Agent': b'fooble', b'Cookie': b'blah blah', b'Content-Length': b'12981', b'Useful': b'value'}) transport = StringTransport() protocol = client.HTTPPageGetter() protocol.factory = factory protocol.makeConnection(transport) result = transport.value() for expectedHeader in [ b"Host: example.net\r\n", b"User-Agent: foobar\r\n", b"Content-Length: 9\r\n", b"Useful: value\r\n", b"connection: close\r\n", b"Cookie: blah blah; baz=quux\r\n"]: self.assertIn(expectedHeader, result)
When a connection is made, L{HTTPPagerGetter} sends the headers from its factory's C{headers} dict. If I{Host} or I{Content-Length} is present in this dict, the values are not sent, since they are sent with special values before the C{headers} dict is processed. If I{User-Agent} is present in the dict, it overrides the value of the C{agent} attribute of the factory. If I{Cookie} is present in the dict, its value is added to the values from the factory's C{cookies} attribute.
test_earlyHeaders
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_getPageBrokenDownload(self): """ If the connection is closed before the number of bytes indicated by I{Content-Length} have been received, the L{Deferred} returned by L{getPage} fails with L{PartialDownloadError}. """ d = client.getPage(self.getURL("broken")) d = self.assertFailure(d, client.PartialDownloadError) d.addCallback(lambda exc: self.assertEqual(exc.response, b"abc")) return d
If the connection is closed before the number of bytes indicated by I{Content-Length} have been received, the L{Deferred} returned by L{getPage} fails with L{PartialDownloadError}.
test_getPageBrokenDownload
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def checkResponse(response): """ The HTTP status code from the server is propagated through the C{PartialDownloadError}. """ self.assertEqual(response.status, b"200") self.assertEqual(response.message, b"OK") return response
The HTTP status code from the server is propagated through the C{PartialDownloadError}.
test_downloadPageBrokenDownload.checkResponse
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_downloadPageBrokenDownload(self): """ If the connection is closed before the number of bytes indicated by I{Content-Length} have been received, the L{Deferred} returned by L{downloadPage} fails with L{PartialDownloadError}. """ # test what happens when download gets disconnected in the middle path = FilePath(self.mktemp()) d = client.downloadPage(self.getURL("broken"), path.path) d = self.assertFailure(d, client.PartialDownloadError) def checkResponse(response): """ The HTTP status code from the server is propagated through the C{PartialDownloadError}. """ self.assertEqual(response.status, b"200") self.assertEqual(response.message, b"OK") return response d.addCallback(checkResponse) def cbFailed(ignored): self.assertEqual(path.getContent(), b"abc") d.addCallback(cbFailed) return d
If the connection is closed before the number of bytes indicated by I{Content-Length} have been received, the L{Deferred} returned by L{downloadPage} fails with L{PartialDownloadError}.
test_downloadPageBrokenDownload
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_downloadPageLogsFileCloseError(self): """ If there is an exception closing the file being written to after the connection is prematurely closed, that exception is logged. """ exc = IOError(ENOSPC, "No file left on device") class BrokenFile: def write(self, bytes): pass def close(self): raise exc logObserver = EventLoggingObserver() filtered = FilteringLogObserver( logObserver, [LogLevelFilterPredicate(defaultLogLevel=LogLevel.critical)] ) globalLogPublisher.addObserver(filtered) self.addCleanup(lambda: globalLogPublisher.removeObserver(filtered)) d = client.downloadPage(self.getURL("broken"), BrokenFile()) d = self.assertFailure(d, client.PartialDownloadError) def cbFailed(ignored): self.assertEquals(1, len(logObserver)) event = logObserver[0] f = event["log_failure"] self.assertIsInstance(f.value, IOError) self.assertEquals( f.value.args, exc.args ) self.assertEqual(len(self.flushLoggedErrors(IOError)), 1) d.addCallback(cbFailed) return d
If there is an exception closing the file being written to after the connection is prematurely closed, that exception is logged.
test_downloadPageLogsFileCloseError
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_getPage(self): """ L{client.getPage} returns a L{Deferred} which is called back with the body of the response if the default method B{GET} is used. """ d = client.getPage(self.getURL("file")) d.addCallback(self.assertEqual, b"0123456789") return d
L{client.getPage} returns a L{Deferred} which is called back with the body of the response if the default method B{GET} is used.
test_getPage
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_getPageHEAD(self): """ L{client.getPage} returns a L{Deferred} which is called back with the empty string if the method is I{HEAD} and there is a successful response code. """ d = client.getPage(self.getURL("file"), method=b"HEAD") d.addCallback(self.assertEqual, b"") return d
L{client.getPage} returns a L{Deferred} which is called back with the empty string if the method is I{HEAD} and there is a successful response code.
test_getPageHEAD
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_getPageNotQuiteHEAD(self): """ If the request method is a different casing of I{HEAD} (ie, not all capitalized) then it is not a I{HEAD} request and the response body is returned. """ d = client.getPage(self.getURL("miscased-head"), method=b'Head') d.addCallback(self.assertEqual, b"miscased-head content") return d
If the request method is a different casing of I{HEAD} (ie, not all capitalized) then it is not a I{HEAD} request and the response body is returned.
test_getPageNotQuiteHEAD
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_timeoutNotTriggering(self): """ When a non-zero timeout is passed to L{getPage} and the page is retrieved before the timeout period elapses, the L{Deferred} is called back with the contents of the page. """ d = client.getPage(self.getURL("host"), timeout=100) d.addCallback(self.assertEqual, networkString("127.0.0.1:%s" % (self.portno,))) return d
When a non-zero timeout is passed to L{getPage} and the page is retrieved before the timeout period elapses, the L{Deferred} is called back with the contents of the page.
test_timeoutNotTriggering
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_timeoutTriggering(self): """ When a non-zero timeout is passed to L{getPage} and that many seconds elapse before the server responds to the request. the L{Deferred} is errbacked with a L{error.TimeoutError}. """ # This will probably leave some connections around. self.cleanupServerConnections = 1 return self.assertFailure( client.getPage(self.getURL("wait"), timeout=0.000001), defer.TimeoutError)
When a non-zero timeout is passed to L{getPage} and that many seconds elapse before the server responds to the request. the L{Deferred} is errbacked with a L{error.TimeoutError}.
test_timeoutTriggering
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_followRedirect(self): """ By default, L{client.getPage} follows redirects and returns the content of the target resource. """ d = client.getPage(self.getURL("redirect")) d.addCallback(self.assertEqual, b"0123456789") return d
By default, L{client.getPage} follows redirects and returns the content of the target resource.
test_followRedirect
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_noFollowRedirect(self): """ If C{followRedirect} is passed a false value, L{client.getPage} does not follow redirects and returns a L{Deferred} which fails with L{error.PageRedirect} when it encounters one. """ d = self.assertFailure( client.getPage(self.getURL("redirect"), followRedirect=False), error.PageRedirect) d.addCallback(self._cbCheckLocation) return d
If C{followRedirect} is passed a false value, L{client.getPage} does not follow redirects and returns a L{Deferred} which fails with L{error.PageRedirect} when it encounters one.
test_noFollowRedirect
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_infiniteRedirection(self): """ When more than C{redirectLimit} HTTP redirects are encountered, the page request fails with L{InfiniteRedirection}. """ def checkRedirectCount(*a): self.assertEqual(f._redirectCount, 13) self.assertEqual(self.infiniteRedirectResource.count, 13) f = client._makeGetterFactory( self.getURL('infiniteRedirect'), client.HTTPClientFactory, redirectLimit=13) d = self.assertFailure(f.deferred, error.InfiniteRedirection) d.addCallback(checkRedirectCount) return d
When more than C{redirectLimit} HTTP redirects are encountered, the page request fails with L{InfiniteRedirection}.
test_infiniteRedirection
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_isolatedFollowRedirect(self): """ C{client.HTTPPagerGetter} instances each obey the C{followRedirect} value passed to the L{client.getPage} call which created them. """ d1 = client.getPage(self.getURL('redirect'), followRedirect=True) d2 = client.getPage(self.getURL('redirect'), followRedirect=False) d = self.assertFailure(d2, error.PageRedirect ).addCallback(lambda dummy: d1) return d
C{client.HTTPPagerGetter} instances each obey the C{followRedirect} value passed to the L{client.getPage} call which created them.
test_isolatedFollowRedirect
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_afterFoundGet(self): """ Enabling unsafe redirection behaviour overwrites the method of redirected C{POST} requests with C{GET}. """ url = self.getURL('extendedRedirect?code=302') f = client.HTTPClientFactory(url, followRedirect=True, method=b"POST") self.assertFalse( f.afterFoundGet, "By default, afterFoundGet must be disabled") def gotPage(page): self.assertEqual( self.extendedRedirect.lastMethod, b"GET", "With afterFoundGet, the HTTP method must change to GET") d = client.getPage( url, followRedirect=True, afterFoundGet=True, method=b"POST") d.addCallback(gotPage) return d
Enabling unsafe redirection behaviour overwrites the method of redirected C{POST} requests with C{GET}.
test_afterFoundGet
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_downloadAfterFoundGet(self): """ Passing C{True} for C{afterFoundGet} to L{client.downloadPage} invokes the same kind of redirect handling as passing that argument to L{client.getPage} invokes. """ url = self.getURL('extendedRedirect?code=302') def gotPage(page): self.assertEqual( self.extendedRedirect.lastMethod, b"GET", "With afterFoundGet, the HTTP method must change to GET") d = client.downloadPage(url, "downloadTemp", followRedirect=True, afterFoundGet=True, method=b"POST") d.addCallback(gotPage) return d
Passing C{True} for C{afterFoundGet} to L{client.downloadPage} invokes the same kind of redirect handling as passing that argument to L{client.getPage} invokes.
test_downloadAfterFoundGet
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_afterFoundGetMakesOneRequest(self): """ When C{afterFoundGet} is C{True}, L{client.getPage} only issues one request to the server when following the redirect. This is a regression test, see #4760. """ def checkRedirectCount(*a): self.assertEqual(self.afterFoundGetCounter.count, 1) url = self.getURL('afterFoundGetRedirect') d = client.getPage( url, followRedirect=True, afterFoundGet=True, method=b"POST") d.addCallback(checkRedirectCount) return d
When C{afterFoundGet} is C{True}, L{client.getPage} only issues one request to the server when following the redirect. This is a regression test, see #4760.
test_afterFoundGetMakesOneRequest
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_downloadTimeout(self): """ If the timeout indicated by the C{timeout} parameter to L{client.HTTPDownloader.__init__} elapses without the complete response being received, the L{defer.Deferred} returned by L{client.downloadPage} fires with a L{Failure} wrapping a L{defer.TimeoutError}. """ self.cleanupServerConnections = 2 # Verify the behavior if no bytes are ever written. first = client.downloadPage( self.getURL("wait"), self.mktemp(), timeout=0.01) # Verify the behavior if some bytes are written but then the request # never completes. second = client.downloadPage( self.getURL("write-then-wait"), self.mktemp(), timeout=0.01) return defer.gatherResults([ self.assertFailure(first, defer.TimeoutError), self.assertFailure(second, defer.TimeoutError)])
If the timeout indicated by the C{timeout} parameter to L{client.HTTPDownloader.__init__} elapses without the complete response being received, the L{defer.Deferred} returned by L{client.downloadPage} fires with a L{Failure} wrapping a L{defer.TimeoutError}.
test_downloadTimeout
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_downloadTimeoutsWorkWithoutReading(self): """ If the timeout indicated by the C{timeout} parameter to L{client.HTTPDownloader.__init__} elapses without the complete response being received, the L{defer.Deferred} returned by L{client.downloadPage} fires with a L{Failure} wrapping a L{defer.TimeoutError}, even if the remote peer isn't reading data from the socket. """ self.cleanupServerConnections = 1 # The timeout here needs to be slightly longer to give the resource a # change to stop the reading. d = client.downloadPage( self.getURL("never-read"), self.mktemp(), timeout=0.05) return self.assertFailure(d, defer.TimeoutError)
If the timeout indicated by the C{timeout} parameter to L{client.HTTPDownloader.__init__} elapses without the complete response being received, the L{defer.Deferred} returned by L{client.downloadPage} fires with a L{Failure} wrapping a L{defer.TimeoutError}, even if the remote peer isn't reading data from the socket.
test_downloadTimeoutsWorkWithoutReading
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_downloadHeaders(self): """ After L{client.HTTPDownloader.deferred} fires, the L{client.HTTPDownloader} instance's C{status} and C{response_headers} attributes are populated with the values from the response. """ def checkHeaders(factory): self.assertEqual(factory.status, b'200') self.assertEqual(factory.response_headers[b'content-type'][0], b'text/html') self.assertEqual(factory.response_headers[b'content-length'][0], b'10') os.unlink(factory.fileName) factory = client._makeGetterFactory( self.getURL('file'), client.HTTPDownloader, fileOrName=self.mktemp()) return factory.deferred.addCallback(lambda _: checkHeaders(factory))
After L{client.HTTPDownloader.deferred} fires, the L{client.HTTPDownloader} instance's C{status} and C{response_headers} attributes are populated with the values from the response.
test_downloadHeaders
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_downloadCookies(self): """ The C{cookies} dict passed to the L{client.HTTPDownloader} initializer is used to populate the I{Cookie} header included in the request sent to the server. """ output = self.mktemp() factory = client._makeGetterFactory( self.getURL('cookiemirror'), client.HTTPDownloader, fileOrName=output, cookies={b'foo': b'bar'}) def cbFinished(ignored): self.assertEqual( FilePath(output).getContent(), b"[('foo', 'bar')]") factory.deferred.addCallback(cbFinished) return factory.deferred
The C{cookies} dict passed to the L{client.HTTPDownloader} initializer is used to populate the I{Cookie} header included in the request sent to the server.
test_downloadCookies
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_downloadRedirectLimit(self): """ When more than C{redirectLimit} HTTP redirects are encountered, the page request fails with L{InfiniteRedirection}. """ def checkRedirectCount(*a): self.assertEqual(f._redirectCount, 7) self.assertEqual(self.infiniteRedirectResource.count, 7) f = client._makeGetterFactory( self.getURL('infiniteRedirect'), client.HTTPDownloader, fileOrName=self.mktemp(), redirectLimit=7) d = self.assertFailure(f.deferred, error.InfiniteRedirection) d.addCallback(checkRedirectCount) return d
When more than C{redirectLimit} HTTP redirects are encountered, the page request fails with L{InfiniteRedirection}.
test_downloadRedirectLimit
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_setURL(self): """ L{client.HTTPClientFactory.setURL} alters the scheme, host, port and path for absolute URLs. """ url = b'http://example.com' f = client.HTTPClientFactory(url) self.assertEqual( (url, b'http', b'example.com', 80, b'/'), (f.url, f.scheme, f.host, f.port, f.path))
L{client.HTTPClientFactory.setURL} alters the scheme, host, port and path for absolute URLs.
test_setURL
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_setURLRemovesFragment(self): """ L{client.HTTPClientFactory.setURL} removes the fragment identifier from the path component. """ f = client.HTTPClientFactory(b'http://example.com') url = b'https://foo.com:8443/bar;123?a#frag' f.setURL(url) self.assertEqual( (url, b'https', b'foo.com', 8443, b'/bar;123?a'), (f.url, f.scheme, f.host, f.port, f.path))
L{client.HTTPClientFactory.setURL} removes the fragment identifier from the path component.
test_setURLRemovesFragment
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_setURLRelativePath(self): """ L{client.HTTPClientFactory.setURL} alters the path in a relative URL. """ f = client.HTTPClientFactory(b'http://example.com') url = b'/hello' f.setURL(url) self.assertEqual( (url, b'http', b'example.com', 80, b'/hello'), (f.url, f.scheme, f.host, f.port, f.path))
L{client.HTTPClientFactory.setURL} alters the path in a relative URL.
test_setURLRelativePath
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def _getHost(self, bytes): """ Retrieve the value of the I{Host} header from the serialized request given by C{bytes}. """ for line in bytes.split(b'\r\n'): try: name, value = line.split(b':', 1) if name.strip().lower() == b'host': return value.strip() except ValueError: pass
Retrieve the value of the I{Host} header from the serialized request given by C{bytes}.
_getHost
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_HTTPDefaultPort(self): """ No port should be included in the host header when connecting to the default HTTP port. """ factory = client.HTTPClientFactory(b'http://foo.example.com/') proto = factory.buildProtocol(b'127.42.42.42') proto.makeConnection(StringTransport()) self.assertEqual(self._getHost(proto.transport.value()), b'foo.example.com')
No port should be included in the host header when connecting to the default HTTP port.
test_HTTPDefaultPort
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_HTTPPort80(self): """ No port should be included in the host header when connecting to the default HTTP port even if it is in the URL. """ factory = client.HTTPClientFactory(b'http://foo.example.com:80/') proto = factory.buildProtocol('127.42.42.42') proto.makeConnection(StringTransport()) self.assertEqual(self._getHost(proto.transport.value()), b'foo.example.com')
No port should be included in the host header when connecting to the default HTTP port even if it is in the URL.
test_HTTPPort80
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_HTTPNotPort80(self): """ The port should be included in the host header when connecting to the a non default HTTP port. """ factory = client.HTTPClientFactory(b'http://foo.example.com:8080/') proto = factory.buildProtocol('127.42.42.42') proto.makeConnection(StringTransport()) self.assertEqual(self._getHost(proto.transport.value()), b'foo.example.com:8080')
The port should be included in the host header when connecting to the a non default HTTP port.
test_HTTPNotPort80
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_HTTPSDefaultPort(self): """ No port should be included in the host header when connecting to the default HTTPS port. """ factory = client.HTTPClientFactory(b'https://foo.example.com/') proto = factory.buildProtocol('127.42.42.42') proto.makeConnection(StringTransport()) self.assertEqual(self._getHost(proto.transport.value()), b'foo.example.com')
No port should be included in the host header when connecting to the default HTTPS port.
test_HTTPSDefaultPort
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_HTTPSPort443(self): """ No port should be included in the host header when connecting to the default HTTPS port even if it is in the URL. """ factory = client.HTTPClientFactory(b'https://foo.example.com:443/') proto = factory.buildProtocol('127.42.42.42') proto.makeConnection(StringTransport()) self.assertEqual(self._getHost(proto.transport.value()), b'foo.example.com')
No port should be included in the host header when connecting to the default HTTPS port even if it is in the URL.
test_HTTPSPort443
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_HTTPSNotPort443(self): """ The port should be included in the host header when connecting to the a non default HTTPS port. """ factory = client.HTTPClientFactory(b'http://foo.example.com:8080/') proto = factory.buildProtocol('127.42.42.42') proto.makeConnection(StringTransport()) self.assertEqual(self._getHost(proto.transport.value()), b'foo.example.com:8080')
The port should be included in the host header when connecting to the a non default HTTPS port.
test_HTTPSNotPort443
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def makeURIString(self, template): """ Replace the string "HOST" in C{template} with this test's host. Byte strings Python between (and including) versions 3.0 and 3.4 cannot be formatted using C{%} or C{format} so this does a simple replace. @type template: L{bytes} @param template: A string containing "HOST". @rtype: L{bytes} @return: A string where "HOST" has been replaced by C{self.host}. """ self.assertIsInstance(self.host, bytes) self.assertIsInstance(self.uriHost, bytes) self.assertIsInstance(template, bytes) self.assertIn(b"HOST", template) return template.replace(b"HOST", self.uriHost)
Replace the string "HOST" in C{template} with this test's host. Byte strings Python between (and including) versions 3.0 and 3.4 cannot be formatted using C{%} or C{format} so this does a simple replace. @type template: L{bytes} @param template: A string containing "HOST". @rtype: L{bytes} @return: A string where "HOST" has been replaced by C{self.host}.
makeURIString
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def assertURIEquals(self, uri, scheme, netloc, host, port, path, params=b'', query=b'', fragment=b''): """ Assert that all of a L{client.URI}'s components match the expected values. @param uri: U{client.URI} instance whose attributes will be checked for equality. @type scheme: L{bytes} @param scheme: URI scheme specifier. @type netloc: L{bytes} @param netloc: Network location component. @type host: L{bytes} @param host: Host name. @type port: L{int} @param port: Port number. @type path: L{bytes} @param path: Hierarchical path. @type params: L{bytes} @param params: Parameters for last path segment, defaults to C{b''}. @type query: L{bytes} @param query: Query string, defaults to C{b''}. @type fragment: L{bytes} @param fragment: Fragment identifier, defaults to C{b''}. """ self.assertEqual( (scheme, netloc, host, port, path, params, query, fragment), (uri.scheme, uri.netloc, uri.host, uri.port, uri.path, uri.params, uri.query, uri.fragment))
Assert that all of a L{client.URI}'s components match the expected values. @param uri: U{client.URI} instance whose attributes will be checked for equality. @type scheme: L{bytes} @param scheme: URI scheme specifier. @type netloc: L{bytes} @param netloc: Network location component. @type host: L{bytes} @param host: Host name. @type port: L{int} @param port: Port number. @type path: L{bytes} @param path: Hierarchical path. @type params: L{bytes} @param params: Parameters for last path segment, defaults to C{b''}. @type query: L{bytes} @param query: Query string, defaults to C{b''}. @type fragment: L{bytes} @param fragment: Fragment identifier, defaults to C{b''}.
assertURIEquals
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_parseDefaultPort(self): """ L{client.URI.fromBytes} by default assumes port 80 for the I{http} scheme and 443 for the I{https} scheme. """ uri = client.URI.fromBytes(self.makeURIString(b'http://HOST')) self.assertEqual(80, uri.port) # Weird (but commonly accepted) structure uses default port. uri = client.URI.fromBytes(self.makeURIString(b'http://HOST:')) self.assertEqual(80, uri.port) uri = client.URI.fromBytes(self.makeURIString(b'https://HOST')) self.assertEqual(443, uri.port)
L{client.URI.fromBytes} by default assumes port 80 for the I{http} scheme and 443 for the I{https} scheme.
test_parseDefaultPort
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_parseCustomDefaultPort(self): """ L{client.URI.fromBytes} accepts a C{defaultPort} parameter that overrides the normal default port logic. """ uri = client.URI.fromBytes( self.makeURIString(b'http://HOST'), defaultPort=5144) self.assertEqual(5144, uri.port) uri = client.URI.fromBytes( self.makeURIString(b'https://HOST'), defaultPort=5144) self.assertEqual(5144, uri.port)
L{client.URI.fromBytes} accepts a C{defaultPort} parameter that overrides the normal default port logic.
test_parseCustomDefaultPort
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_netlocHostPort(self): """ Parsing a I{URI} splits the network location component into I{host} and I{port}. """ uri = client.URI.fromBytes( self.makeURIString(b'http://HOST:5144')) self.assertEqual(5144, uri.port) self.assertEqual(self.host, uri.host) self.assertEqual(self.uriHost + b':5144', uri.netloc) # Spaces in the hostname are trimmed, the default path is /. uri = client.URI.fromBytes(self.makeURIString(b'http://HOST ')) self.assertEqual(self.uriHost, uri.netloc)
Parsing a I{URI} splits the network location component into I{host} and I{port}.
test_netlocHostPort
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_path(self): """ Parse the path from a I{URI}. """ uri = self.makeURIString(b'http://HOST/foo/bar') parsed = client.URI.fromBytes(uri) self.assertURIEquals( parsed, scheme=b'http', netloc=self.uriHost, host=self.host, port=80, path=b'/foo/bar') self.assertEqual(uri, parsed.toBytes())
Parse the path from a I{URI}.
test_path
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_noPath(self): """ The path of a I{URI} that has no path is the empty string. """ uri = self.makeURIString(b'http://HOST') parsed = client.URI.fromBytes(uri) self.assertURIEquals( parsed, scheme=b'http', netloc=self.uriHost, host=self.host, port=80, path=b'') self.assertEqual(uri, parsed.toBytes())
The path of a I{URI} that has no path is the empty string.
test_noPath
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_emptyPath(self): """ The path of a I{URI} with an empty path is C{b'/'}. """ uri = self.makeURIString(b'http://HOST/') self.assertURIEquals( client.URI.fromBytes(uri), scheme=b'http', netloc=self.uriHost, host=self.host, port=80, path=b'/')
The path of a I{URI} with an empty path is C{b'/'}.
test_emptyPath
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_param(self): """ Parse I{URI} parameters from a I{URI}. """ uri = self.makeURIString(b'http://HOST/foo/bar;param') parsed = client.URI.fromBytes(uri) self.assertURIEquals( parsed, scheme=b'http', netloc=self.uriHost, host=self.host, port=80, path=b'/foo/bar', params=b'param') self.assertEqual(uri, parsed.toBytes())
Parse I{URI} parameters from a I{URI}.
test_param
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_query(self): """ Parse the query string from a I{URI}. """ uri = self.makeURIString(b'http://HOST/foo/bar;param?a=1&b=2') parsed = client.URI.fromBytes(uri) self.assertURIEquals( parsed, scheme=b'http', netloc=self.uriHost, host=self.host, port=80, path=b'/foo/bar', params=b'param', query=b'a=1&b=2') self.assertEqual(uri, parsed.toBytes())
Parse the query string from a I{URI}.
test_query
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_fragment(self): """ Parse the fragment identifier from a I{URI}. """ uri = self.makeURIString(b'http://HOST/foo/bar;param?a=1&b=2#frag') parsed = client.URI.fromBytes(uri) self.assertURIEquals( parsed, scheme=b'http', netloc=self.uriHost, host=self.host, port=80, path=b'/foo/bar', params=b'param', query=b'a=1&b=2', fragment=b'frag') self.assertEqual(uri, parsed.toBytes())
Parse the fragment identifier from a I{URI}.
test_fragment
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_originForm(self): """ L{client.URI.originForm} produces an absolute I{URI} path including the I{URI} path. """ uri = client.URI.fromBytes( self.makeURIString(b'http://HOST/foo')) self.assertEqual(b'/foo', uri.originForm)
L{client.URI.originForm} produces an absolute I{URI} path including the I{URI} path.
test_originForm
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_originFormComplex(self): """ L{client.URI.originForm} produces an absolute I{URI} path including the I{URI} path, parameters and query string but excludes the fragment identifier. """ uri = client.URI.fromBytes( self.makeURIString(b'http://HOST/foo;param?a=1#frag')) self.assertEqual(b'/foo;param?a=1', uri.originForm)
L{client.URI.originForm} produces an absolute I{URI} path including the I{URI} path, parameters and query string but excludes the fragment identifier.
test_originFormComplex
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_originFormNoPath(self): """ L{client.URI.originForm} produces a path of C{b'/'} when the I{URI} specifies no path. """ uri = client.URI.fromBytes(self.makeURIString(b'http://HOST')) self.assertEqual(b'/', uri.originForm)
L{client.URI.originForm} produces a path of C{b'/'} when the I{URI} specifies no path.
test_originFormNoPath
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_originFormEmptyPath(self): """ L{client.URI.originForm} produces a path of C{b'/'} when the I{URI} specifies an empty path. """ uri = client.URI.fromBytes( self.makeURIString(b'http://HOST/')) self.assertEqual(b'/', uri.originForm)
L{client.URI.originForm} produces a path of C{b'/'} when the I{URI} specifies an empty path.
test_originFormEmptyPath
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_externalUnicodeInterference(self): """ L{client.URI.fromBytes} parses the scheme, host, and path elements into L{bytes}, even when passed an URL which has previously been passed to L{urlparse} as a L{unicode} string. """ goodInput = self.makeURIString(b'http://HOST/path') badInput = goodInput.decode('ascii') urlparse(badInput) uri = client.URI.fromBytes(goodInput) self.assertIsInstance(uri.scheme, bytes) self.assertIsInstance(uri.host, bytes) self.assertIsInstance(uri.path, bytes)
L{client.URI.fromBytes} parses the scheme, host, and path elements into L{bytes}, even when passed an URL which has previously been passed to L{urlparse} as a L{unicode} string.
test_externalUnicodeInterference
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_hostBracketIPv6AddressLiteral(self): """ Brackets around IPv6 addresses are stripped in the host field. The host field is then exported with brackets in the output of L{client.URI.toBytes}. """ uri = client.URI.fromBytes(b"http://[::1]:80/index.html") self.assertEqual(uri.host, b"::1") self.assertEqual(uri.netloc, b"[::1]:80") self.assertEqual(uri.toBytes(), b'http://[::1]:80/index.html')
Brackets around IPv6 addresses are stripped in the host field. The host field is then exported with brackets in the output of L{client.URI.toBytes}.
test_hostBracketIPv6AddressLiteral
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_getPageDeprecated(self): """ L{client.getPage} is deprecated. """ port = reactor.listenTCP( 0, server.Site(Data(b'', 'text/plain')), interface="127.0.0.1") portno = port.getHost().port self.addCleanup(port.stopListening) url = networkString("http://127.0.0.1:%d" % (portno,)) d = client.getPage(url) warningInfo = self.flushWarnings([self.test_getPageDeprecated]) self.assertEqual(len(warningInfo), 1) self.assertEqual(warningInfo[0]['category'], DeprecationWarning) self.assertEqual( warningInfo[0]['message'], "twisted.web.client.getPage was deprecated in " "Twisted 16.7.0; please use https://pypi.org/project/treq/ or twisted.web.client.Agent instead") return d.addErrback(lambda _: None)
L{client.getPage} is deprecated.
test_getPageDeprecated
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_downloadPageDeprecated(self): """ L{client.downloadPage} is deprecated. """ port = reactor.listenTCP( 0, server.Site(Data(b'', 'text/plain')), interface="127.0.0.1") portno = port.getHost().port self.addCleanup(port.stopListening) url = networkString("http://127.0.0.1:%d" % (portno,)) path = FilePath(self.mktemp()) d = client.downloadPage(url, path.path) warningInfo = self.flushWarnings([self.test_downloadPageDeprecated]) self.assertEqual(len(warningInfo), 1) self.assertEqual(warningInfo[0]['category'], DeprecationWarning) self.assertEqual( warningInfo[0]['message'], "twisted.web.client.downloadPage was deprecated in " "Twisted 16.7.0; please use https://pypi.org/project/treq/ or twisted.web.client.Agent instead") return d.addErrback(lambda _: None)
L{client.downloadPage} is deprecated.
test_downloadPageDeprecated
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def _testDeprecatedClass(self, klass): """ Assert that accessing the given class was deprecated. @param klass: The class being deprecated. @type klass: L{str} """ getattr(client, klass) warningInfo = self.flushWarnings() self.assertEqual(len(warningInfo), 1) self.assertEqual(warningInfo[0]['category'], DeprecationWarning) self.assertEqual( warningInfo[0]['message'], "twisted.web.client.{} was deprecated in " "Twisted 16.7.0: please use https://pypi.org/project/treq/ or twisted.web.client.Agent instead".format(klass))
Assert that accessing the given class was deprecated. @param klass: The class being deprecated. @type klass: L{str}
_testDeprecatedClass
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_httpPageGetterDeprecated(self): """ L{client.HTTPPageGetter} is deprecated. """ self._testDeprecatedClass("HTTPPageGetter")
L{client.HTTPPageGetter} is deprecated.
test_httpPageGetterDeprecated
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_httpPageDownloaderDeprecated(self): """ L{client.HTTPPageDownloader} is deprecated. """ self._testDeprecatedClass("HTTPPageDownloader")
L{client.HTTPPageDownloader} is deprecated.
test_httpPageDownloaderDeprecated
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_httpClientFactoryDeprecated(self): """ L{client.HTTPClientFactory} is deprecated. """ self._testDeprecatedClass("HTTPClientFactory")
L{client.HTTPClientFactory} is deprecated.
test_httpClientFactoryDeprecated
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT
def test_httpDownloaderDeprecated(self): """ L{client.HTTPDownloader} is deprecated. """ self._testDeprecatedClass("HTTPDownloader")
L{client.HTTPDownloader} is deprecated.
test_httpDownloaderDeprecated
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py
MIT