本文整理汇总了Python中bottle.install方法的典型用法代码示例。如果您正苦于以下问题:Python bottle.install方法的具体用法?Python bottle.install怎么用?Python bottle.install使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bottle
的用法示例。
在下文中一共展示了bottle.install方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import install [as 别名]
def main(argv, cfg):
global authdict, allow_passwordless, db
parser = ArgumentParser(prog=argv.pop(0) + ' urd')
parser.add_argument('--path', type=str, default='urd.db',
help='database directory (can be relative to project directory) (default: urd.db)',
)
parser.add_argument('--allow-passwordless', action='store_true', help='accept any pass for users not in passwd.')
parser.add_argument('--quiet', action='store_true', help='less chatty.')
args = parser.parse_args(argv)
if not args.quiet:
print('-'*79)
print(args)
print()
auth_fn = os.path.join(args.path, 'passwd')
authdict = readauth(auth_fn)
allow_passwordless = args.allow_passwordless
if not authdict and not args.allow_passwordless:
raise Exception('No users in %r and --allow-passwordless not specified.' % (auth_fn,))
db = DB(args.path, not args.quiet)
bottle.install(jsonify)
kw = dict(debug=False, reloader=False, quiet=args.quiet)
listen = cfg.urd_listen
if isinstance(listen, tuple):
kw['host'], kw['port'] = listen
else:
from accelerator.unixhttp import WSGIUnixServer, WSGIUnixRequestHandler
from accelerator.server import check_socket
if listen == 'local':
listen = '.socket.dir/urd'
check_socket(listen)
kw['server_class'] = WSGIUnixServer
kw['handler_class'] = WSGIUnixRequestHandler
kw['host'] = listen
kw['port'] = 0
bottle.run(**kw)
示例2: run_proxy
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import install [as 别名]
def run_proxy(args):
#
# ERROR HANDLERS
#
@error(401)
def error404(error):
return template(error_tpl, headline='Error '+error.status, error=error.body)
@error(500)
def error500(error):
return template(error_tpl, headline='Error '+error.status, error=error.body)
#
# SPECIAL ENDPOINTS
#
@route('/health')
def hello():
return template(healthcheck_tpl, headline='Healthcheck')
@route('/install-success')
def hello():
remote_page_call_status_code = proxy_trough_helper('https://{0}.github.io/{1}/{2}/{3}'.format(args.owner, args.repository, args.obfuscator, '/')).status_code
return template(install_success_tpl, headline='Installation Success', remote_page_call_status_code=remote_page_call_status_code)
#
# make args available in auth callback
#
global owner, auth_type
owner = args.owner
auth_type = args.authType
@route('/<url:re:.+>')
@auth_basic(check_pass)
def proxy_trough(url):
return proxy_trough_helper('https://{0}.github.io/{1}/{2}/{3}'.format(args.owner, args.repository, args.obfuscator, normalize_proxy_url(url)))
@route('/')
@auth_basic(check_pass)
def proxy_trough_root_page():
return proxy_trough_helper('https://{0}.github.io/{1}/{2}/{3}'.format(args.owner, args.repository, args.obfuscator, '/index.html'))
#
# RUN BY ENVIRONMENT
#
if args.environment == 'wsgi':
run(host='localhost', port=args.port, debug=True)
if args.environment == 'heroku':
run(host="0.0.0.0", port=int(args.port))
else:
run(server='cgi')