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


Python cherrypy.server方法代码示例

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


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

示例1: check_site_config_entries_in_app_config

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import server [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 server [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: _start_http_thread

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import server [as 别名]
def _start_http_thread(self):
        """HTTP servers MUST be running in new threads, so that the
        main thread persists to receive KeyboardInterrupt's. If an
        exception is raised in the httpserver's thread then it's
        trapped here, and the bus (and therefore our httpserver)
        are shut down.
        """
        try:
            self.httpserver.start()
        except KeyboardInterrupt:
            self.bus.log('<Ctrl-C> hit: shutting down HTTP server')
            self.interrupt = sys.exc_info()[1]
            self.bus.exit()
        except SystemExit:
            self.bus.log('SystemExit raised: shutting down HTTP server')
            self.interrupt = sys.exc_info()[1]
            self.bus.exit()
            raise
        except Exception:
            self.interrupt = sys.exc_info()[1]
            self.bus.log('Error in HTTP server: shutting down',
                         traceback=True, level=40)
            self.bus.exit()
            raise 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:26,代码来源:servers.py

示例4: wait

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import server [as 别名]
def wait(self):
        """Wait until the HTTP server is ready to receive requests."""
        while not getattr(self.httpserver, 'ready', False):
            if self.interrupt:
                raise self.interrupt
            time.sleep(.1)

        # bypass check when LISTEN_PID is set
        if os.environ.get('LISTEN_PID', None):
            return

        # bypass check when running via socket-activation
        # (for socket-activation the port will be managed by systemd)
        if not isinstance(self.bind_addr, tuple):
            return

        # wait for port to be occupied
        with _safe_wait(*self.bound_addr):
            portend.occupied(*self.bound_addr, timeout=Timeouts.occupied) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:21,代码来源:servers.py

示例5: start

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import server [as 别名]
def start(self):
        """Start the FCGI server."""
        # We have to instantiate the server class here because its __init__
        # starts a threadpool. If we do it too early, daemonize won't work.
        from flup.server.fcgi import WSGIServer
        self.fcgiserver = WSGIServer(*self.args, **self.kwargs)
        # TODO: report this bug upstream to flup.
        # If we don't set _oldSIGs on Windows, we get:
        #   File "C:\Python24\Lib\site-packages\flup\server\threadedserver.py",
        #   line 108, in run
        #     self._restoreSignalHandlers()
        #   File "C:\Python24\Lib\site-packages\flup\server\threadedserver.py",
        #   line 156, in _restoreSignalHandlers
        #     for signum,handler in self._oldSIGs:
        #   AttributeError: 'WSGIServer' object has no attribute '_oldSIGs'
        self.fcgiserver._installSignalHandlers = lambda: None
        self.fcgiserver._oldSIGs = []
        self.ready = True
        self.fcgiserver.run() 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:21,代码来源:servers.py

示例6: testLastModified

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import server [as 别名]
def testLastModified(self):
        self.getPage('/a.gif')
        self.assertStatus(200)
        self.assertBody(gif_bytes)
        lm1 = self.assertHeader('Last-Modified')

        # this request should get the cached copy.
        self.getPage('/a.gif')
        self.assertStatus(200)
        self.assertBody(gif_bytes)
        self.assertHeader('Age')
        lm2 = self.assertHeader('Last-Modified')
        self.assertEqual(lm1, lm2)

        # this request should match the cached copy, but raise 304.
        self.getPage('/a.gif', [('If-Modified-Since', lm1)])
        self.assertStatus(304)
        self.assertNoHeader('Last-Modified')
        if not getattr(cherrypy.server, 'using_apache', False):
            self.assertHeader('Age') 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:22,代码来源:test_caching.py

示例7: testStatus

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import server [as 别名]
def testStatus(self):
        self.getPage('/status/')
        self.assertBody('normal')
        self.assertStatus(200)

        self.getPage('/status/blank')
        self.assertBody('')
        self.assertStatus(200)

        self.getPage('/status/illegal')
        self.assertStatus(500)
        msg = 'Illegal response status from server (781 is out of range).'
        self.assertErrorPage(500, msg)

        if not getattr(cherrypy.server, 'using_apache', False):
            self.getPage('/status/unknown')
            self.assertBody('funky')
            self.assertStatus(431)

        self.getPage('/status/bad')
        self.assertStatus(500)
        msg = "Illegal response status from server ('error' is non-numeric)."
        self.assertErrorPage(500, msg) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:25,代码来源:test_core.py

示例8: testUnrepr

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import server [as 别名]
def testUnrepr(self):
        self.getPage('/repr?key=neg')
        self.assertBody('-1234')

        self.getPage('/repr?key=filename')
        self.assertBody(repr(os.path.join(sys.prefix, 'hello.py')))

        self.getPage('/repr?key=thing1')
        self.assertBody(repr(cherrypy.lib.httputil.response_codes[404]))

        if not getattr(cherrypy.server, 'using_apache', False):
            # The object ID's won't match up when using Apache, since the
            # server and client are running in different processes.
            self.getPage('/repr?key=thing2')
            from cherrypy.tutorial import thing2
            self.assertBody(repr(thing2))

        self.getPage('/repr?key=complex')
        self.assertBody('(3+2j)')

        self.getPage('/repr?key=mul')
        self.assertBody('18')

        self.getPage('/repr?key=stradd')
        self.assertBody(repr('112233')) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:27,代码来源:test_config.py

示例9: test_malformed_request_line

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import server [as 别名]
def test_malformed_request_line(self):
        if getattr(cherrypy.server, 'using_apache', False):
            return self.skip('skipped due to known Apache differences...')

        # Test missing version in Request-Line
        c = self.make_connection()
        c._output(b'geT /')
        c._send_output()
        if hasattr(c, 'strict'):
            response = c.response_class(c.sock, strict=c.strict, method='GET')
        else:
            # Python 3.2 removed the 'strict' feature, saying:
            # "http.client now always assumes HTTP/1.x compliant servers."
            response = c.response_class(c.sock, method='GET')
        response.begin()
        self.assertEqual(response.status, 400)
        self.assertEqual(response.fp.read(22), b'Malformed Request-Line')
        c.close() 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:20,代码来源:test_http.py

示例10: test_http_over_https

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import server [as 别名]
def test_http_over_https(self):
        if self.scheme != 'https':
            return self.skip('skipped (not running HTTPS)... ')

        # Try connecting without SSL.
        conn = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
        conn.putrequest('GET', '/', skip_host=True)
        conn.putheader('Host', self.HOST)
        conn.endheaders()
        response = conn.response_class(conn.sock, method='GET')
        try:
            response.begin()
            self.assertEqual(response.status, 400)
            self.body = response.read()
            self.assertBody('The client sent a plain HTTP request, but this '
                            'server only speaks HTTPS on this port.')
        except socket.error:
            e = sys.exc_info()[1]
            # "Connection reset by peer" is also acceptable.
            if e.errno != errno.ECONNRESET:
                raise 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:23,代码来源:test_http.py

示例11: _server_namespace_handler

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import server [as 别名]
def _server_namespace_handler(k, v):
    """Config handler for the "server" namespace."""
    atoms = k.split('.', 1)
    if len(atoms) > 1:
        # Special-case config keys of the form 'server.servername.socket_port'
        # to configure additional HTTP servers.
        if not hasattr(cherrypy, 'servers'):
            cherrypy.servers = {}

        servername, k = atoms
        if servername not in cherrypy.servers:
            from cherrypy import _cpserver
            cherrypy.servers[servername] = _cpserver.Server()
            # On by default, but 'on = False' can unsubscribe it (see below).
            cherrypy.servers[servername].subscribe()

        if k == 'on':
            if v:
                cherrypy.servers[servername].subscribe()
            else:
                cherrypy.servers[servername].unsubscribe()
        else:
            setattr(cherrypy.servers[servername], k, v)
    else:
        setattr(cherrypy.server, k, v) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:27,代码来源:_cpconfig.py

示例12: check_site_config_entries_in_app_config

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import server [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

示例13: _populate_known_types

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import server [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

示例14: wait_for_free_port

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import server [as 别名]
def wait_for_free_port(host, port, timeout=None):
    """Wait for the specified port to become free (drop requests)."""
    if not host:
        raise ValueError("Host values of '' or None are not allowed.")
    if timeout is None:
        timeout = free_port_timeout

    for trial in range(50):
        try:
            # we are expecting a free port, so reduce the timeout
            check_port(host, port, timeout=timeout)
        except IOError:
            # Give the old server thread time to free the port.
            time.sleep(timeout)
        else:
            return

    raise IOError("Port %r not free on %r" % (port, host)) 
开发者ID:naparuba,项目名称:opsbro,代码行数:20,代码来源:servers.py

示例15: _server_namespace_handler

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import server [as 别名]
def _server_namespace_handler(k, v):
    """Config handler for the "server" namespace."""
    atoms = k.split(".", 1)
    if len(atoms) > 1:
        # Special-case config keys of the form 'server.servername.socket_port'
        # to configure additional HTTP servers.
        if not hasattr(cherrypy, "servers"):
            cherrypy.servers = {}

        servername, k = atoms
        if servername not in cherrypy.servers:
            from cherrypy import _cpserver
            cherrypy.servers[servername] = _cpserver.Server()
            # On by default, but 'on = False' can unsubscribe it (see below).
            cherrypy.servers[servername].subscribe()

        if k == 'on':
            if v:
                cherrypy.servers[servername].subscribe()
            else:
                cherrypy.servers[servername].unsubscribe()
        else:
            setattr(cherrypy.servers[servername], k, v)
    else:
        setattr(cherrypy.server, k, v) 
开发者ID:naparuba,项目名称:opsbro,代码行数:27,代码来源:_cpconfig.py


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