本文整理匯總了Python中cherrypy.Tool方法的典型用法代碼示例。如果您正苦於以下問題:Python cherrypy.Tool方法的具體用法?Python cherrypy.Tool怎麽用?Python cherrypy.Tool使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cherrypy
的用法示例。
在下文中一共展示了cherrypy.Tool方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testWarnToolOn
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import Tool [as 別名]
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.')
示例2: testDecorator
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import Tool [as 別名]
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)
示例3: testWarnToolOn
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import Tool [as 別名]
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.")
示例4: setup_server
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import Tool [as 別名]
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)
示例5: __init__
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import Tool [as 別名]
def __init__(self):
cherrypy.Tool.__init__(self, 'on_end_request', self.record_stop)
示例6: _setup
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import Tool [as 別名]
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()
示例7: setup_server
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import Tool [as 別名]
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())
示例8: __init__
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import Tool [as 別名]
def __init__(self,path):
self.lookup = TemplateLookup(directories=[path], strict_undefined=True)
cherrypy.Tool.__init__(self, 'on_start_resource', self.bind_lookup, priority=1)
示例9: testDecorator
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import Tool [as 別名]
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)
示例10: _setup
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import Tool [as 別名]
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()
示例11: setup_server
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import Tool [as 別名]
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())
示例12: tool_disable_multipart_preprocessing
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import Tool [as 別名]
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)
示例13: _build
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import Tool [as 別名]
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