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