當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。