当前位置: 首页>>代码示例>>Python>>正文


Python cherrypy.Tool方法代码示例

本文整理汇总了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.') 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:18,代码来源:test_tools.py

示例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) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:18,代码来源:test_tools.py

示例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.") 
开发者ID:binhex,项目名称:moviegrabber,代码行数:18,代码来源:test_tools.py

示例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) 
开发者ID:binhex,项目名称:moviegrabber,代码行数:19,代码来源:test_core.py

示例5: __init__

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import Tool [as 别名]
def __init__(self):
        cherrypy.Tool.__init__(self, 'on_end_request', self.record_stop) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:4,代码来源:cpstats.py

示例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() 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:11,代码来源:cpstats.py

示例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()) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:32,代码来源:test_sessionauthenticate.py

示例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) 
开发者ID:SecPi,项目名称:SecPi,代码行数:6,代码来源:mako_template_tool.py

示例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) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:16,代码来源:test_tools.py

示例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() 
开发者ID:binhex,项目名称:moviegrabber,代码行数:11,代码来源:cpstats.py

示例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()) 
开发者ID:binhex,项目名称:moviegrabber,代码行数:31,代码来源:test_sessionauthenticate.py

示例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) 
开发者ID:zstackio,项目名称:zstack-utility,代码行数:6,代码来源:http.py

示例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 
开发者ID:zstackio,项目名称:zstack-utility,代码行数:47,代码来源:http.py


注:本文中的cherrypy.Tool方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。