Python cherrypy.Tool() Examples
The following are 25
code examples of cherrypy.Tool().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cherrypy
, or try the search function
.
Example #1
Source File: test_core.py From moviegrabber with GNU General Public License v3.0 | 6 votes |
def setup_server(): def break_header(): # Add a header after finalize that is invalid cherrypy.serving.response.header_list.append((2, 3)) cherrypy.tools.break_header = cherrypy.Tool('on_end_resource', break_header) class Root: def index(self): return "hello" index.exposed = True def start_response_error(self): return "salud!" start_response_error._cp_config = {'tools.break_header.on': True} root = Root() cherrypy.tree.mount(root)
Example #2
Source File: test_tools.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testWarnToolOn(self): # get try: cherrypy.tools.numerify.on except AttributeError: pass else: raise AssertionError('Tool.on did not error as it should have.') # set try: cherrypy.tools.numerify.on = True except AttributeError: pass else: raise AssertionError('Tool.on did not error as it should have.')
Example #3
Source File: test_tools.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testDecorator(self): @cherrypy.tools.register('on_start_resource') def example(): pass self.assertTrue(isinstance(cherrypy.tools.example, cherrypy.Tool)) self.assertEqual(cherrypy.tools.example._point, 'on_start_resource') @cherrypy.tools.register( # noqa: F811 'before_finalize', name='renamed', priority=60, ) def example(): pass self.assertTrue(isinstance(cherrypy.tools.renamed, cherrypy.Tool)) self.assertEqual(cherrypy.tools.renamed._point, 'before_finalize') self.assertEqual(cherrypy.tools.renamed._name, 'renamed') self.assertEqual(cherrypy.tools.renamed._priority, 60)
Example #4
Source File: test_tools.py From moviegrabber with GNU General Public License v3.0 | 6 votes |
def testWarnToolOn(self): # get try: numon = cherrypy.tools.numerify.on except AttributeError: pass else: raise AssertionError("Tool.on did not error as it should have.") # set try: cherrypy.tools.numerify.on = True except AttributeError: pass else: raise AssertionError("Tool.on did not error as it should have.")
Example #5
Source File: test_tools.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def testDecorator(self): @cherrypy.tools.register('on_start_resource') def example(): pass self.assertTrue(isinstance(cherrypy.tools.example, cherrypy.Tool)) self.assertEqual(cherrypy.tools.example._point, 'on_start_resource') @cherrypy.tools.register( # noqa: F811 'before_finalize', name='renamed', priority=60, ) def example(): pass self.assertTrue(isinstance(cherrypy.tools.renamed, cherrypy.Tool)) self.assertEqual(cherrypy.tools.renamed._point, 'before_finalize') self.assertEqual(cherrypy.tools.renamed._name, 'renamed') self.assertEqual(cherrypy.tools.renamed._priority, 60)
Example #6
Source File: test_tools.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def testWarnToolOn(self): # get try: cherrypy.tools.numerify.on except AttributeError: pass else: raise AssertionError('Tool.on did not error as it should have.') # set try: cherrypy.tools.numerify.on = True except AttributeError: pass else: raise AssertionError('Tool.on did not error as it should have.')
Example #7
Source File: test_tools.py From bazarr with GNU General Public License v3.0 | 6 votes |
def testWarnToolOn(self): # get try: cherrypy.tools.numerify.on except AttributeError: pass else: raise AssertionError('Tool.on did not error as it should have.') # set try: cherrypy.tools.numerify.on = True except AttributeError: pass else: raise AssertionError('Tool.on did not error as it should have.')
Example #8
Source File: cpstats.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _setup(self): """Hook this tool into cherrypy.request. The standard CherryPy request object will automatically call this method when the tool is "turned on" in config. """ if appstats.get('Enabled', False): cherrypy.Tool._setup(self) self.record_start()
Example #9
Source File: http.py From zstack-utility with Apache License 2.0 | 5 votes |
def tool_disable_multipart_preprocessing(): """A cherrypy Tool extension to disable default multipart processing""" cherrypy.request.body.processors.pop('multipart', None) cherrypy.request.body.processors.pop('multipart/form-data', None)
Example #10
Source File: test_sessionauthenticate.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
def setup_server(): def check(username, password): # Dummy check_username_and_password function if username != 'test' or password != 'password': return 'Wrong login/password' def augment_params(): # A simple tool to add some things to request.params # This is to check to make sure that session_auth can handle request # params (ticket #780) cherrypy.request.params["test"] = "test" cherrypy.tools.augment_params = cherrypy.Tool('before_handler', augment_params, None, priority=30) class Test: _cp_config = {'tools.sessions.on': True, 'tools.session_auth.on': True, 'tools.session_auth.check_username_and_password': check, 'tools.augment_params.on': True, } def index(self, **kwargs): return "Hi %s, you are logged in" % cherrypy.request.login index.exposed = True cherrypy.tree.mount(Test())
Example #11
Source File: cpstats.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
def _setup(self): """Hook this tool into cherrypy.request. The standard CherryPy request object will automatically call this method when the tool is "turned on" in config. """ if appstats.get('Enabled', False): cherrypy.Tool._setup(self) self.record_start()
Example #12
Source File: cpstats.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
def __init__(self): cherrypy.Tool.__init__(self, 'on_end_request', self.record_stop)
Example #13
Source File: test_sessionauthenticate.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def setup_server(): def check(username, password): # Dummy check_username_and_password function if username != 'test' or password != 'password': return 'Wrong login/password' def augment_params(): # A simple tool to add some things to request.params # This is to check to make sure that session_auth can handle # request params (ticket #780) cherrypy.request.params['test'] = 'test' cherrypy.tools.augment_params = cherrypy.Tool( 'before_handler', augment_params, None, priority=30) class Test: _cp_config = { 'tools.sessions.on': True, 'tools.session_auth.on': True, 'tools.session_auth.check_username_and_password': check, 'tools.augment_params.on': True, } @cherrypy.expose def index(self, **kwargs): return 'Hi %s, you are logged in' % cherrypy.request.login cherrypy.tree.mount(Test())
Example #14
Source File: cpstats.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def _setup(self): """Hook this tool into cherrypy.request. The standard CherryPy request object will automatically call this method when the tool is "turned on" in config. """ if appstats.get('Enabled', False): cherrypy.Tool._setup(self) self.record_start()
Example #15
Source File: cpstats.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def __init__(self): cherrypy.Tool.__init__(self, 'on_end_request', self.record_stop)
Example #16
Source File: test_tools.py From bazarr with GNU General Public License v3.0 | 5 votes |
def testDecorator(self): @cherrypy.tools.register('on_start_resource') def example(): pass self.assertTrue(isinstance(cherrypy.tools.example, cherrypy.Tool)) self.assertEqual(cherrypy.tools.example._point, 'on_start_resource') @cherrypy.tools.register('before_finalize', name='renamed', priority=60) def example(): pass self.assertTrue(isinstance(cherrypy.tools.renamed, cherrypy.Tool)) self.assertEqual(cherrypy.tools.renamed._point, 'before_finalize') self.assertEqual(cherrypy.tools.renamed._name, 'renamed') self.assertEqual(cherrypy.tools.renamed._priority, 60)
Example #17
Source File: test_sessionauthenticate.py From bazarr with GNU General Public License v3.0 | 5 votes |
def setup_server(): def check(username, password): # Dummy check_username_and_password function if username != 'test' or password != 'password': return 'Wrong login/password' def augment_params(): # A simple tool to add some things to request.params # This is to check to make sure that session_auth can handle # request params (ticket #780) cherrypy.request.params['test'] = 'test' cherrypy.tools.augment_params = cherrypy.Tool( 'before_handler', augment_params, None, priority=30) class Test: _cp_config = { 'tools.sessions.on': True, 'tools.session_auth.on': True, 'tools.session_auth.check_username_and_password': check, 'tools.augment_params.on': True, } @cherrypy.expose def index(self, **kwargs): return 'Hi %s, you are logged in' % cherrypy.request.login cherrypy.tree.mount(Test())
Example #18
Source File: cpstats.py From bazarr with GNU General Public License v3.0 | 5 votes |
def _setup(self): """Hook this tool into cherrypy.request. The standard CherryPy request object will automatically call this method when the tool is "turned on" in config. """ if appstats.get('Enabled', False): cherrypy.Tool._setup(self) self.record_start()
Example #19
Source File: cpstats.py From bazarr with GNU General Public License v3.0 | 5 votes |
def __init__(self): cherrypy.Tool.__init__(self, 'on_end_request', self.record_stop)
Example #20
Source File: cpstats.py From opsbro with MIT License | 5 votes |
def _setup(self): """Hook this tool into cherrypy.request. The standard CherryPy request object will automatically call this method when the tool is "turned on" in config. """ if appstats.get('Enabled', False): cherrypy.Tool._setup(self) self.record_start()
Example #21
Source File: cpstats.py From opsbro with MIT License | 5 votes |
def __init__(self): cherrypy.Tool.__init__(self, 'on_end_request', self.record_stop)
Example #22
Source File: mako_template_tool.py From SecPi with GNU General Public License v3.0 | 5 votes |
def __init__(self,path): self.lookup = TemplateLookup(directories=[path], strict_undefined=True) cherrypy.Tool.__init__(self, 'on_start_resource', self.bind_lookup, priority=1)
Example #23
Source File: test_sessionauthenticate.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def setup_server(): def check(username, password): # Dummy check_username_and_password function if username != 'test' or password != 'password': return 'Wrong login/password' def augment_params(): # A simple tool to add some things to request.params # This is to check to make sure that session_auth can handle # request params (ticket #780) cherrypy.request.params['test'] = 'test' cherrypy.tools.augment_params = cherrypy.Tool( 'before_handler', augment_params, None, priority=30) class Test: _cp_config = { 'tools.sessions.on': True, 'tools.session_auth.on': True, 'tools.session_auth.check_username_and_password': check, 'tools.augment_params.on': True, } @cherrypy.expose def index(self, **kwargs): return 'Hi %s, you are logged in' % cherrypy.request.login cherrypy.tree.mount(Test())
Example #24
Source File: cpstats.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self): cherrypy.Tool.__init__(self, 'on_end_request', self.record_stop)
Example #25
Source File: http.py From zstack-utility with Apache License 2.0 | 4 votes |
def _build(self): for akey in self.async_uri_handlers.keys(): aval = self.async_uri_handlers[akey] self._add_mapping(aval) for skey in self.sync_uri_handlers.keys(): sval = self.sync_uri_handlers[skey] self._add_mapping(sval) for skey in self.raw_uri_handlers.keys(): sval = self.raw_uri_handlers[skey] self._add_mapping(sval) self.server_conf = {'request.dispatch': self.mapper} cherrypy.engine.autoreload.unsubscribe() site_config = {} site_config['server.socket_host'] = '0.0.0.0' site_config['server.socket_port'] = self.port site_config['server.thread_pool'] = int(os.getenv('POOLSIZE', '10')) # remove limitation of request body size, default is 100MB. site_config['server.max_request_body_size'] = 0 # disable cherrypy multipart preprocessing cherrypy.tools.disable_multipart = cherrypy.Tool( 'on_start_resource', tool_disable_multipart_preprocessing) site_config['tools.disable_multipart.on'] = True site_config['engine.timeout_monitor.on'] = False cherrypy.config.update(site_config) cherrypy.log.error_log.propagate = 0 # NOTE(weiw): disable cherrypy logging self.server = cherrypy.tree.mount(root=None, config={'/' : self.server_conf}) if not self.logfile_path: self.logfile_path = '/var/log/zstack/zstack.log' cherrypy.log.error_file = "" cherrypy.log.access_file = "" cherrypy.log.screen = False self.server.log.error_file = '' self.server.log.access_file = '' self.server.log.screen = False self.server.log.access_log = logger self.server.log.error_log = logger