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


Python serving.run_simple方法代码示例

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


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

示例1: test_app

# 需要导入模块: from werkzeug import serving [as 别名]
# 或者: from werkzeug.serving import run_simple [as 别名]
def test_app(environ, start_response):
    """Simple test application that dumps the environment.  You can use
    it to check if Werkzeug is working properly:

    .. sourcecode:: pycon

        >>> from werkzeug.serving import run_simple
        >>> from werkzeug.testapp import test_app
        >>> run_simple('localhost', 3000, test_app)
         * Running on http://localhost:3000/

    The application displays important information from the WSGI environment,
    the Python interpreter and the installed libraries.
    """
    req = Request(environ, populate_request=False)
    if req.args.get('resource') == 'logo':
        response = logo
    else:
        response = Response(render_testapp(req), mimetype='text/html')
    return response(environ, start_response) 
开发者ID:jpush,项目名称:jbox,代码行数:22,代码来源:testapp.py

示例2: _show_banner_debug

# 需要导入模块: from werkzeug import serving [as 别名]
# 或者: from werkzeug.serving import run_simple [as 别名]
def _show_banner_debug(app, listener):
    # Such banner should be shown after running process of the server is
    # completed, but Flask has not supported to inject function after the
    # server started.
    from werkzeug.serving import is_running_from_reloader
    if is_running_from_reloader():
        # On debug mode, the banner is shown every reloaded.
        # run_simple set reloader type as 'stat' on default
        logger.info(' * Restarning with stat')
        # level warning is followed by werkzeug implementation
        logger.warning(' * Debugger is active!')
        from werkzeug.debug import get_pin_and_cookie_name
        pin, _ = get_pin_and_cookie_name(app)
        if pin is not None:
            logger.info(' * Debugger PIN: {:s}'.format(pin))
        return
    else:
        logger.info(' * Environment: {}'.format(app.config['ENV']))
        logger.info(' * Debug mode: on')
        logger.info(' * Running on http://{}/ (Press CTRL+C to quit)'.format(
            listener)) 
开发者ID:chainer,项目名称:chainerui,代码行数:23,代码来源:app.py

示例3: build_simple_server

# 需要导入模块: from werkzeug import serving [as 别名]
# 或者: from werkzeug.serving import run_simple [as 别名]
def build_simple_server():
    app = load_app()
    # Create the WSGI server and start it
    host, port = CONF.api.host, CONF.api.port

    LOG.info('Starting server in PID %s', os.getpid())
    LOG.info('Configuration:')
    CONF.log_opt_values(LOG, log.INFO)

    if host == '0.0.0.0':
        LOG.info(
            'serving on 0.0.0.0:%(port)s, view at http://127.0.0.1:%(port)s',
            {'port': port})
    else:
        LOG.info('serving on http://%(host)s:%(port)s',
                 {'host': host, 'port': port})

    LOG.info('"DANGER! For testing only, do not use in production"')

    serving.run_simple(host, port,
                       app, processes=CONF.api.workers) 
开发者ID:openstack,项目名称:vitrage,代码行数:23,代码来源:app.py

示例4: startWebServer

# 需要导入模块: from werkzeug import serving [as 别名]
# 或者: from werkzeug.serving import run_simple [as 别名]
def startWebServer(self):
        from bard.web import init_flask_app, app
        from werkzeug.serving import run_simple

        use_ssl = config['use_ssl']
        if use_ssl:
            import ssl
            context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
            certpemfile = config['sslCertificateChainFile']
            serverkeyfile = config['sslCertificateKeyFile']

            print(certpemfile)
            print(serverkeyfile)
            context.load_cert_chain(certpemfile, serverkeyfile)
        else:
            context = None

        app.bard = self
        init_flask_app()
        hostname = config['hostname']
        port = config['port']
        return run_simple(hostname, port, app,
                          use_reloader=True, use_debugger=True,
                          use_evalex=True, ssl_context=context,
                          threaded=True) 
开发者ID:antlarr,项目名称:bard,代码行数:27,代码来源:bard.py

示例5: run_dev_server

# 需要导入模块: from werkzeug import serving [as 别名]
# 或者: from werkzeug.serving import run_simple [as 别名]
def run_dev_server(application):
    servers = []

    def tracking_make_server(*args, **kwargs):
        srv = real_make_server(*args, **kwargs)
        servers.append(srv)
        return srv
    serving.make_server = tracking_make_server
    try:
        t = Thread(target=serving.run_simple,
                   args=('localhost', 0, application))
        t.setDaemon(True)
        t.start()
        time.sleep(0.25)
    finally:
        serving.make_server = real_make_server
    if not servers:
        return None, None
    server, = servers
    ip, port = server.socket.getsockname()[:2]
    if ':' in ip:
        ip = '[%s]' % ip
    return server, '%s:%d'  % (ip, port) 
开发者ID:GeekTrainer,项目名称:Flask,代码行数:25,代码来源:serving.py

示例6: make_ssl_devcert

# 需要导入模块: from werkzeug import serving [as 别名]
# 或者: from werkzeug.serving import run_simple [as 别名]
def make_ssl_devcert(base_path, host=None, cn=None):
    """Creates an SSL key for development.  This should be used instead of
    the ``'adhoc'`` key which generates a new cert on each server start.
    It accepts a path for where it should store the key and cert and
    either a host or CN.  If a host is given it will use the CN
    ``*.host/CN=host``.

    For more information see :func:`run_simple`.

    .. versionadded:: 0.9

    :param base_path: the path to the certificate and key.  The extension
                      ``.crt`` is added for the certificate, ``.key`` is
                      added for the key.
    :param host: the name of the host.  This can be used as an alternative
                 for the `cn`.
    :param cn: the `CN` to use.
    """
    from OpenSSL import crypto

    if host is not None:
        cn = "*.%s/CN=%s" % (host, host)
    cert, pkey = generate_adhoc_ssl_pair(cn=cn)

    cert_file = base_path + ".crt"
    pkey_file = base_path + ".key"

    with open(cert_file, "wb") as f:
        f.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert))
    with open(pkey_file, "wb") as f:
        f.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, pkey))

    return cert_file, pkey_file 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:35,代码来源:serving.py

示例7: make_ssl_devcert

# 需要导入模块: from werkzeug import serving [as 别名]
# 或者: from werkzeug.serving import run_simple [as 别名]
def make_ssl_devcert(base_path, host=None, cn=None):
    """Creates an SSL key for development.  This should be used instead of
    the ``'adhoc'`` key which generates a new cert on each server start.
    It accepts a path for where it should store the key and cert and
    either a host or CN.  If a host is given it will use the CN
    ``*.host/CN=host``.

    For more information see :func:`run_simple`.

    .. versionadded:: 0.9

    :param base_path: the path to the certificate and key.  The extension
                      ``.crt`` is added for the certificate, ``.key`` is
                      added for the key.
    :param host: the name of the host.  This can be used as an alternative
                 for the `cn`.
    :param cn: the `CN` to use.
    """
    from OpenSSL import crypto
    if host is not None:
        cn = '*.%s/CN=%s' % (host, host)
    cert, pkey = generate_adhoc_ssl_pair(cn=cn)

    cert_file = base_path + '.crt'
    pkey_file = base_path + '.key'

    with open(cert_file, 'wb') as f:
        f.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert))
    with open(pkey_file, 'wb') as f:
        f.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, pkey))

    return cert_file, pkey_file 
开发者ID:jpush,项目名称:jbox,代码行数:34,代码来源:serving.py

示例8: main

# 需要导入模块: from werkzeug import serving [as 别名]
# 或者: from werkzeug.serving import run_simple [as 别名]
def main():
    '''A simple command-line interface for :py:func:`run_simple`.'''

    # in contrast to argparse, this works at least under Python < 2.7
    import optparse
    from werkzeug.utils import import_string

    parser = optparse.OptionParser(
        usage='Usage: %prog [options] app_module:app_object')
    parser.add_option('-b', '--bind', dest='address',
                      help='The hostname:port the app should listen on.')
    parser.add_option('-d', '--debug', dest='use_debugger',
                      action='store_true', default=False,
                      help='Use Werkzeug\'s debugger.')
    parser.add_option('-r', '--reload', dest='use_reloader',
                      action='store_true', default=False,
                      help='Reload Python process if modules change.')
    options, args = parser.parse_args()

    hostname, port = None, None
    if options.address:
        address = options.address.split(':')
        hostname = address[0]
        if len(address) > 1:
            port = address[1]

    if len(args) != 1:
        sys.stdout.write('No application supplied, or too much. See --help\n')
        sys.exit(1)
    app = import_string(args[0])

    run_simple(
        hostname=(hostname or '127.0.0.1'), port=int(port or 5000),
        application=app, use_reloader=options.use_reloader,
        use_debugger=options.use_debugger
    ) 
开发者ID:jpush,项目名称:jbox,代码行数:38,代码来源:serving.py


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