本文整理汇总了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)
示例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))
示例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)
示例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)
示例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)
示例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
示例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
示例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
)