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


Python cherrypy.engine方法代码示例

本文整理汇总了Python中cherrypy.engine方法的典型用法代码示例。如果您正苦于以下问题:Python cherrypy.engine方法的具体用法?Python cherrypy.engine怎么用?Python cherrypy.engine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cherrypy的用法示例。


在下文中一共展示了cherrypy.engine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check_site_config_entries_in_app_config

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import engine [as 别名]
def check_site_config_entries_in_app_config(self):
        """Check for mounted Applications that have site-scoped config."""
        for sn, app in cherrypy.tree.apps.items():
            if not isinstance(app, cherrypy.Application):
                continue

            msg = []
            for section, entries in app.config.items():
                if section.startswith('/'):
                    for key, value in entries.items():
                        for n in ('engine.', 'server.', 'tree.', 'checker.'):
                            if key.startswith(n):
                                msg.append('[%s] %s = %s' %
                                           (section, key, value))
            if msg:
                msg.insert(0,
                           'The application mounted at %r contains the '
                           'following config entries, which are only allowed '
                           'in site-wide config. Move them to a [global] '
                           'section and pass them to cherrypy.config.update() '
                           'instead of tree.mount().' % sn)
                warnings.warn(os.linesep.join(msg)) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:24,代码来源:_cpchecker.py

示例2: _populate_known_types

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import engine [as 别名]
def _populate_known_types(self):
        b = [x for x in vars(builtins).values()
             if type(x) is type(str)]

        def traverse(obj, namespace):
            for name in dir(obj):
                # Hack for 3.2's warning about body_params
                if name == 'body_params':
                    continue
                vtype = type(getattr(obj, name, None))
                if vtype in b:
                    self.known_config_types[namespace + '.' + name] = vtype

        traverse(cherrypy.request, 'request')
        traverse(cherrypy.response, 'response')
        traverse(cherrypy.server, 'server')
        traverse(cherrypy.engine, 'engine')
        traverse(cherrypy.log, 'log') 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:20,代码来源:_cpchecker.py

示例3: setup_server

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import engine [as 别名]
def setup_server():
    class Root:

        @cherrypy.expose
        def index(self):
            return 'Hello World'

        @cherrypy.expose
        def ctrlc(self):
            raise KeyboardInterrupt()

        @cherrypy.expose
        def graceful(self):
            engine.graceful()
            return 'app was (gracefully) restarted succesfully'

    cherrypy.tree.mount(Root())
    cherrypy.config.update({
        'environment': 'test_suite',
    })

    db_connection.subscribe()

# ------------ Enough helpers. Time for real live test cases. ------------ # 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:26,代码来源:test_states.py

示例4: test_5_Start_Error

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import engine [as 别名]
def test_5_Start_Error(self):
        # If test_3 has not been executed, the server won't be stopped,
        # so we'll have to do it.
        if engine.state != engine.states.EXITING:
            engine.exit()

        # If a process errors during start, it should stop the engine
        # and exit with a non-zero exit code.
        p = helper.CPProcess(ssl=(self.scheme.lower() == 'https'),
                             wait=True)
        p.write_conf(
            extra="""starterror: True
test_case_name: "test_5_Start_Error"
"""
        )
        p.start(imports='cherrypy.test._test_states_demo')
        if p.exit_code == 0:
            self.fail('Process failed to return nonzero exit code.') 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:20,代码来源:test_states.py

示例5: _engine_namespace_handler

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import engine [as 别名]
def _engine_namespace_handler(k, v):
    """Config handler for the "engine" namespace."""
    engine = cherrypy.engine

    if k in {'SIGHUP', 'SIGTERM'}:
        engine.subscribe(k, v)
        return

    if '.' in k:
        plugin, attrname = k.split('.', 1)
        plugin = getattr(engine, plugin)
        op = 'subscribe' if v else 'unsubscribe'
        sub_unsub = getattr(plugin, op, None)
        if attrname == 'on' and callable(sub_unsub):
            sub_unsub()
            return
        setattr(plugin, attrname, v)
    else:
        setattr(engine, k, v) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:21,代码来源:_cpconfig.py

示例6: add_server

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import engine [as 别名]
def add_server(self, netloc, path, config):
        """Add a new CherryPy Application for a Virtual Host.
        Creates a new CherryPy WSGI Server instance if the host resolves
        to a different IP address or port.
        """

        from cherrypy._cpwsgi_server import CPWSGIServer
        from cherrypy.process.servers import ServerAdapter

        host, port = urllib.splitnport(netloc, 80)
        host = socket.gethostbyname(host)
        bind_addr = (host, port)
        if bind_addr not in self.servers:
            self.servers.append(bind_addr)
            server = CPWSGIServer()
            server.bind_addr = bind_addr
            adapter = ServerAdapter(cherrypy.engine, server, server.bind_addr)
            adapter.subscribe()
        self.domains[netloc] = cherrypy.Application(root=None,
            config={path.rstrip('/') or '/': config}) 
开发者ID:diegojromerolopez,项目名称:djanban,代码行数:22,代码来源:desktop_app_main.py

示例7: check_site_config_entries_in_app_config

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import engine [as 别名]
def check_site_config_entries_in_app_config(self):
        """Check for mounted Applications that have site-scoped config."""
        for sn, app in iteritems(cherrypy.tree.apps):
            if not isinstance(app, cherrypy.Application):
                continue

            msg = []
            for section, entries in iteritems(app.config):
                if section.startswith('/'):
                    for key, value in iteritems(entries):
                        for n in ("engine.", "server.", "tree.", "checker."):
                            if key.startswith(n):
                                msg.append("[%s] %s = %s" %
                                           (section, key, value))
            if msg:
                msg.insert(0,
                           "The application mounted at %r contains the "
                           "following config entries, which are only allowed "
                           "in site-wide config. Move them to a [global] "
                           "section and pass them to cherrypy.config.update() "
                           "instead of tree.mount()." % sn)
                warnings.warn(os.linesep.join(msg)) 
开发者ID:naparuba,项目名称:opsbro,代码行数:24,代码来源:_cpchecker.py

示例8: _populate_known_types

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import engine [as 别名]
def _populate_known_types(self):
        b = [x for x in vars(builtins).values()
             if type(x) is type(str)]

        def traverse(obj, namespace):
            for name in dir(obj):
                # Hack for 3.2's warning about body_params
                if name == 'body_params':
                    continue
                vtype = type(getattr(obj, name, None))
                if vtype in b:
                    self.known_config_types[namespace + "." + name] = vtype

        traverse(cherrypy.request, "request")
        traverse(cherrypy.response, "response")
        traverse(cherrypy.server, "server")
        traverse(cherrypy.engine, "engine")
        traverse(cherrypy.log, "log") 
开发者ID:naparuba,项目名称:opsbro,代码行数:20,代码来源:_cpchecker.py

示例9: check_site_config_entries_in_app_config

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import engine [as 别名]
def check_site_config_entries_in_app_config(self):
        """Check for mounted Applications that have site-scoped config."""
        for sn, app in iteritems(cherrypy.tree.apps):
            if not isinstance(app, cherrypy.Application):
                continue

            msg = []
            for section, entries in iteritems(app.config):
                if section.startswith('/'):
                    for key, value in iteritems(entries):
                        for n in ('engine.', 'server.', 'tree.', 'checker.'):
                            if key.startswith(n):
                                msg.append('[%s] %s = %s' %
                                           (section, key, value))
            if msg:
                msg.insert(0,
                           'The application mounted at %r contains the '
                           'following config entries, which are only allowed '
                           'in site-wide config. Move them to a [global] '
                           'section and pass them to cherrypy.config.update() '
                           'instead of tree.mount().' % sn)
                warnings.warn(os.linesep.join(msg)) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:24,代码来源:_cpchecker.py

示例10: merge

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import engine [as 别名]
def merge(base, other):
    """Merge one app config (from a dict, file, or filename) into another.

    If the given config is a filename, it will be appended to
    the list of files to monitor for "autoreload" changes.
    """
    if isinstance(other, text_or_bytes):
        cherrypy.engine.autoreload.files.add(other)

    # Load other into base
    for section, value_map in reprconf.as_dict(other).items():
        if not isinstance(value_map, dict):
            raise ValueError(
                'Application config must include section headers, but the '
                "config you tried to merge doesn't have any sections. "
                'Wrap your config in another dict with paths as section '
                "headers, for example: {'/': config}.")
        base.setdefault(section, {}).update(value_map) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:20,代码来源:_cpconfig.py

示例11: _engine_namespace_handler

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import engine [as 别名]
def _engine_namespace_handler(k, v):
    """Config handler for the "engine" namespace."""
    engine = cherrypy.engine

    if k == 'SIGHUP':
        engine.subscribe('SIGHUP', v)
    elif k == 'SIGTERM':
        engine.subscribe('SIGTERM', v)
    elif '.' in k:
        plugin, attrname = k.split('.', 1)
        plugin = getattr(engine, plugin)
        if attrname == 'on':
            if v and hasattr(getattr(plugin, 'subscribe', None), '__call__'):
                plugin.subscribe()
                return
            elif (
                (not v) and
                hasattr(getattr(plugin, 'unsubscribe', None), '__call__')
            ):
                plugin.unsubscribe()
                return
        setattr(plugin, attrname, v)
    else:
        setattr(engine, k, v) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:26,代码来源:_cpconfig.py

示例12: check_site_config_entries_in_app_config

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import engine [as 别名]
def check_site_config_entries_in_app_config(self):
        """Check for mounted Applications that have site-scoped config."""
        for sn, app in six.iteritems(cherrypy.tree.apps):
            if not isinstance(app, cherrypy.Application):
                continue

            msg = []
            for section, entries in six.iteritems(app.config):
                if section.startswith('/'):
                    for key, value in six.iteritems(entries):
                        for n in ('engine.', 'server.', 'tree.', 'checker.'):
                            if key.startswith(n):
                                msg.append('[%s] %s = %s' %
                                           (section, key, value))
            if msg:
                msg.insert(0,
                           'The application mounted at %r contains the '
                           'following config entries, which are only allowed '
                           'in site-wide config. Move them to a [global] '
                           'section and pass them to cherrypy.config.update() '
                           'instead of tree.mount().' % sn)
                warnings.warn(os.linesep.join(msg)) 
开发者ID:Tautulli,项目名称:Tautulli,代码行数:24,代码来源:_cpchecker.py

示例13: check_site_config_entries_in_app_config

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import engine [as 别名]
def check_site_config_entries_in_app_config(self):
        """Check for mounted Applications that have site-scoped config."""
        for sn, app in iteritems(cherrypy.tree.apps):
            if not isinstance(app, cherrypy.Application):
                continue
            
            msg = []
            for section, entries in iteritems(app.config):
                if section.startswith('/'):
                    for key, value in iteritems(entries):
                        for n in ("engine.", "server.", "tree.", "checker."):
                            if key.startswith(n):
                                msg.append("[%s] %s = %s" % (section, key, value))
            if msg:
                msg.insert(0,
                    "The application mounted at %r contains the following "
                    "config entries, which are only allowed in site-wide "
                    "config. Move them to a [global] section and pass them "
                    "to cherrypy.config.update() instead of tree.mount()." % sn)
                warnings.warn(os.linesep.join(msg)) 
开发者ID:binhex,项目名称:moviegrabber,代码行数:22,代码来源:_cpchecker.py

示例14: _populate_known_types

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import engine [as 别名]
def _populate_known_types(self):
        b = [x for x in vars(builtins).values()
             if type(x) is type(str)]
        
        def traverse(obj, namespace):
            for name in dir(obj):
                # Hack for 3.2's warning about body_params
                if name == 'body_params':
                    continue
                vtype = type(getattr(obj, name, None))
                if vtype in b:
                    self.known_config_types[namespace + "." + name] = vtype
        
        traverse(cherrypy.request, "request")
        traverse(cherrypy.response, "response")
        traverse(cherrypy.server, "server")
        traverse(cherrypy.engine, "engine")
        traverse(cherrypy.log, "log") 
开发者ID:binhex,项目名称:moviegrabber,代码行数:20,代码来源:_cpchecker.py

示例15: load

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import engine [as 别名]
def load(self):
        """Copy stored session data into this session instance."""
        data = self._load()
        # data is either None or a tuple (session_data, expiration_time)
        if data is None or data[1] < self.now():
            if self.debug:
                cherrypy.log('Expired session, flushing data', 'TOOLS.SESSIONS')
            self._data = {}
        else:
            self._data = data[0]
        self.loaded = True
        
        # Stick the clean_thread in the class, not the instance.
        # The instances are created and destroyed per-request.
        cls = self.__class__
        if self.clean_freq and not cls.clean_thread:
            # clean_up is in instancemethod and not a classmethod,
            # so that tool config can be accessed inside the method.
            t = cherrypy.process.plugins.Monitor(
                cherrypy.engine, self.clean_up, self.clean_freq * 60,
                name='Session cleanup')
            t.subscribe()
            cls.clean_thread = t
            t.start() 
开发者ID:binhex,项目名称:moviegrabber,代码行数:26,代码来源:sessions.py


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