/
opt
/
imh-python
/
lib
/
python3.9
/
site-packages
/
cherrypy
/
test
/
/opt/imh-python/lib/python3.9/site-packages/cherrypy/test
mkdir
upload
Name
Size
Mode
Actions
static/
-
0755
rm
__pycache__/
-
0755
rm
benchmark.py
12563
0644
edit
dl
rm
checkerdemo.py
1861
0644
edit
dl
rm
fastcgi.conf
686
0644
edit
dl
rm
fcgi.conf
486
0644
edit
dl
rm
helper.py
16369
0644
edit
dl
rm
logtest.py
8151
0644
edit
dl
rm
modfastcgi.py
4652
0644
edit
dl
rm
modfcgid.py
4237
0644
edit
dl
rm
modpy.py
4978
0644
edit
dl
rm
modwsgi.py
4834
0644
edit
dl
rm
sessiondemo.py
5425
0644
edit
dl
rm
style.css
17
0644
edit
dl
rm
test.pem
2254
0644
edit
dl
rm
test_auth_basic.py
4499
0644
edit
dl
rm
test_auth_digest.py
4454
0644
edit
dl
rm
test_bus.py
9960
0644
edit
dl
rm
test_caching.py
14386
0644
edit
dl
rm
test_config.py
8836
0644
edit
dl
rm
test_config_server.py
4037
0644
edit
dl
rm
test_conn.py
30744
0644
edit
dl
rm
test_core.py
30408
0644
edit
dl
rm
test_dynamicobjectmapping.py
12331
0644
edit
dl
rm
test_encoding.py
17535
0644
edit
dl
rm
test_etags.py
3093
0644
edit
dl
rm
test_http.py
10939
0644
edit
dl
rm
test_httputil.py
2412
0644
edit
dl
rm
test_iterator.py
5724
0644
edit
dl
rm
test_json.py
2860
0644
edit
dl
rm
test_logging.py
8315
0644
edit
dl
rm
test_mime.py
4538
0644
edit
dl
rm
test_misc_tools.py
7094
0644
edit
dl
rm
test_native.py
971
0644
edit
dl
rm
test_objectmapping.py
14504
0644
edit
dl
rm
test_params.py
1862
0644
edit
dl
rm
test_plugins.py
334
0644
edit
dl
rm
test_proxy.py
5630
0644
edit
dl
rm
test_refleaks.py
1555
0644
edit
dl
rm
test_request_obj.py
37097
0644
edit
dl
rm
test_routes.py
2583
0644
edit
dl
rm
test_session.py
17949
0644
edit
dl
rm
test_sessionauthenticate.py
2013
0644
edit
dl
rm
test_states.py
16703
0644
edit
dl
rm
test_static.py
16702
0644
edit
dl
rm
test_tools.py
17851
0644
edit
dl
rm
test_tutorials.py
6964
0644
edit
dl
rm
test_virtualhost.py
4021
0644
edit
dl
rm
test_wsgiapps.py
3997
0644
edit
dl
rm
test_wsgi_ns.py
2812
0644
edit
dl
rm
test_wsgi_unix_socket.py
2228
0644
edit
dl
rm
test_wsgi_vhost.py
1034
0644
edit
dl
rm
test_xmlrpc.py
4584
0644
edit
dl
rm
webtest.py
262
0644
edit
dl
rm
_test_decorators.py
951
0644
edit
dl
rm
_test_states_demo.py
1876
0644
edit
dl
rm
__init__.py
396
0644
edit
dl
rm
Edit:
/opt/imh-python/lib/python3.9/site-packages/cherrypy/test/test_iterator.py
(5724B)
import cherrypy from cherrypy.test import helper class IteratorBase(object): created = 0 datachunk = 'butternut squash' * 256 @classmethod def incr(cls): cls.created += 1 @classmethod def decr(cls): cls.created -= 1 class OurGenerator(IteratorBase): def __iter__(self): self.incr() try: for i in range(1024): yield self.datachunk finally: self.decr() class OurIterator(IteratorBase): started = False closed_off = False count = 0 def increment(self): self.incr() def decrement(self): if not self.closed_off: self.closed_off = True self.decr() def __iter__(self): return self def __next__(self): if not self.started: self.started = True self.increment() self.count += 1 if self.count > 1024: raise StopIteration return self.datachunk next = __next__ def __del__(self): self.decrement() class OurClosableIterator(OurIterator): def close(self): self.decrement() class OurNotClosableIterator(OurIterator): # We can't close something which requires an additional argument. def close(self, somearg): self.decrement() class OurUnclosableIterator(OurIterator): close = 'close' # not callable! class IteratorTest(helper.CPWebCase): @staticmethod def setup_server(): class Root(object): @cherrypy.expose def count(self, clsname): cherrypy.response.headers['Content-Type'] = 'text/plain' return str(globals()[clsname].created) @cherrypy.expose def getall(self, clsname): cherrypy.response.headers['Content-Type'] = 'text/plain' return globals()[clsname]() @cherrypy.expose @cherrypy.config(**{'response.stream': True}) def stream(self, clsname): return self.getall(clsname) cherrypy.tree.mount(Root()) def test_iterator(self): try: self._test_iterator() except Exception: 'Test fails intermittently. See #1419' def _test_iterator(self): if cherrypy.server.protocol_version != 'HTTP/1.1': return self.skip() self.PROTOCOL = 'HTTP/1.1' # Check the counts of all the classes, they should be zero. closables = ['OurClosableIterator', 'OurGenerator'] unclosables = ['OurUnclosableIterator', 'OurNotClosableIterator'] all_classes = closables + unclosables import random random.shuffle(all_classes) for clsname in all_classes: self.getPage('/count/' + clsname) self.assertStatus(200) self.assertBody('0') # We should also be able to read the entire content body # successfully, though we don't need to, we just want to # check the header. for clsname in all_classes: itr_conn = self.get_conn() itr_conn.putrequest('GET', '/getall/' + clsname) itr_conn.endheaders() response = itr_conn.getresponse() self.assertEqual(response.status, 200) headers = response.getheaders() for header_name, header_value in headers: if header_name.lower() == 'content-length': expected = str(1024 * 16 * 256) assert header_value == expected, header_value break else: raise AssertionError('No Content-Length header found') # As the response should be fully consumed by CherryPy # before sending back, the count should still be at zero # by the time the response has been sent. self.getPage('/count/' + clsname) self.assertStatus(200) self.assertBody('0') # Now we do the same check with streaming - some classes will # be automatically closed, while others cannot. stream_counts = {} for clsname in all_classes: itr_conn = self.get_conn() itr_conn.putrequest('GET', '/stream/' + clsname) itr_conn.endheaders() response = itr_conn.getresponse() self.assertEqual(response.status, 200) response.fp.read(65536) # Let's check the count - this should always be one. self.getPage('/count/' + clsname) self.assertBody('1') # Now if we close the connection, the count should go back # to zero. itr_conn.close() self.getPage('/count/' + clsname) # If this is a response which should be easily closed, then # we will test to see if the value has gone back down to # zero. if clsname in closables: # Sometimes we try to get the answer too quickly - we # will wait for 100 ms before asking again if we didn't # get the answer we wanted. if self.body != '0': import time time.sleep(0.1) self.getPage('/count/' + clsname) stream_counts[clsname] = int(self.body) # Check that we closed off the classes which should provide # easy mechanisms for doing so. for clsname in closables: assert stream_counts[clsname] == 0, ( 'did not close off stream response correctly, expected ' 'count of zero for %s: %s' % (clsname, stream_counts) )
Save
cmd:
run