本文整理汇总了Python中gunicorn.app.base.Application方法的典型用法代码示例。如果您正苦于以下问题:Python base.Application方法的具体用法?Python base.Application怎么用?Python base.Application使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gunicorn.app.base
的用法示例。
在下文中一共展示了base.Application方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _mount_app
# 需要导入模块: from gunicorn.app import base [as 别名]
# 或者: from gunicorn.app.base import Application [as 别名]
def _mount_app(self, prefix, app, **options):
if app in self._mounts or '_mount.app' in app.config:
depr(0, 13, "Application mounted multiple times. Falling back to WSGI mount.",
"Clone application before mounting to a different location.")
return self._mount_wsgi(prefix, app, **options)
if options:
depr(0, 13, "Unsupported mount options. Falling back to WSGI mount.",
"Do not specify any route options when mounting bottle application.")
return self._mount_wsgi(prefix, app, **options)
if not prefix.endswith("/"):
depr(0, 13, "Prefix must end in '/'. Falling back to WSGI mount.",
"Consider adding an explicit redirect from '/prefix' to '/prefix/' in the parent application.")
return self._mount_wsgi(prefix, app, **options)
self._mounts.append(app)
app.config['_mount.prefix'] = prefix
app.config['_mount.app'] = self
for route in app.routes:
route.rule = prefix + route.rule.lstrip('/')
self.add_route(route)
示例2: _make_callback
# 需要导入模块: from gunicorn.app import base [as 别名]
# 或者: from gunicorn.app.base import Application [as 别名]
def _make_callback(self):
callback = self.callback
for plugin in self.all_plugins():
try:
if hasattr(plugin, 'apply'):
api = getattr(plugin, 'api', 1)
context = self if api > 1 else self._context
callback = plugin.apply(callback, context)
else:
callback = plugin(callback)
except RouteReset: # Try again with changed configuration.
return self._make_callback()
if not callback is self.callback:
try_update_wrapper(callback, self.callback)
return callback
###############################################################################
# Application Object ###########################################################
###############################################################################
示例3: save
# 需要导入模块: from gunicorn.app import base [as 别名]
# 或者: from gunicorn.app.base import Application [as 别名]
def save(self, destination, overwrite=False, chunk_size=2 ** 16):
""" Save file to disk or copy its content to an open file(-like) object.
If *destination* is a directory, :attr:`filename` is added to the
path. Existing files are not overwritten by default (IOError).
:param destination: File path, directory or file(-like) object.
:param overwrite: If True, replace existing files. (default: False)
:param chunk_size: Bytes to read at a time. (default: 64kb)
"""
if isinstance(destination, basestring): # Except file-likes here
if os.path.isdir(destination):
destination = os.path.join(destination, self.filename)
if not overwrite and os.path.exists(destination):
raise IOError('File exists.')
with open(destination, 'wb') as fp:
self._copy_file(fp, chunk_size)
else:
self._copy_file(destination, chunk_size)
###############################################################################
# Application Helper ###########################################################
###############################################################################
示例4: __repr__
# 需要导入模块: from gunicorn.app import base [as 别名]
# 或者: from gunicorn.app.base import Application [as 别名]
def __repr__(self):
cb = self.get_undecorated_callback()
return '<%s %r %r>' % (self.method, self.rule, cb)
###############################################################################
# Application Object ###########################################################
###############################################################################
示例5: save
# 需要导入模块: from gunicorn.app import base [as 别名]
# 或者: from gunicorn.app.base import Application [as 别名]
def save(self, destination, overwrite=False, chunk_size=2**16):
''' Save file to disk or copy its content to an open file(-like) object.
If *destination* is a directory, :attr:`filename` is added to the
path. Existing files are not overwritten by default (IOError).
:param destination: File path, directory or file(-like) object.
:param overwrite: If True, replace existing files. (default: False)
:param chunk_size: Bytes to read at a time. (default: 64kb)
'''
if isinstance(destination, basestring): # Except file-likes here
if os.path.isdir(destination):
destination = os.path.join(destination, self.filename)
if not overwrite and os.path.exists(destination):
raise IOError('File exists.')
with open(destination, 'wb') as fp:
self._copy_file(fp, chunk_size)
else:
self._copy_file(destination, chunk_size)
###############################################################################
# Application Helper ###########################################################
###############################################################################
示例6: run
# 需要导入模块: from gunicorn.app import base [as 别名]
# 或者: from gunicorn.app.base import Application [as 别名]
def run(self, handler):
from gunicorn.app.base import Application
config = {'bind': "%s:%d" % (self.host, int(self.port))}
config.update(self.options)
class GunicornApplication(Application):
def init(self, parser, opts, args):
return config
def load(self):
return handler
GunicornApplication().run()
示例7: __repr__
# 需要导入模块: from gunicorn.app import base [as 别名]
# 或者: from gunicorn.app.base import Application [as 别名]
def __repr__(self):
return '<%s %r %r>' % (self.method, self.rule, self.callback)
###############################################################################
# Application Object ###########################################################
###############################################################################
示例8: open
# 需要导入模块: from gunicorn.app import base [as 别名]
# 或者: from gunicorn.app.base import Application [as 别名]
def open(self, name, mode='r', *args, **kwargs):
''' Find a resource and return a file object, or raise IOError. '''
fname = self.lookup(name)
if not fname: raise IOError("Resource %r not found." % name)
return self.opener(name, mode=mode, *args, **kwargs)
###############################################################################
# Application Helper ###########################################################
###############################################################################
示例9: abort
# 需要导入模块: from gunicorn.app import base [as 别名]
# 或者: from gunicorn.app.base import Application [as 别名]
def abort(code=500, text='Unknown Error: Application stopped.'):
""" Aborts execution and causes a HTTP error. """
raise HTTPError(code, text)
示例10: __iter__
# 需要导入模块: from gunicorn.app import base [as 别名]
# 或者: from gunicorn.app.base import Application [as 别名]
def __iter__(self):
read, buff = self.fp.read, self.buffer_size
while True:
part = read(buff)
if not part: break
yield part
###############################################################################
# Application Helper ###########################################################
###############################################################################
示例11: _gunicorn_run
# 需要导入模块: from gunicorn.app import base [as 别名]
# 或者: from gunicorn.app.base import Application [as 别名]
def _gunicorn_run(self):
from gunicorn.app.base import Application
app = self.wsgi_app
class QgGunicornApp(Application):
def init(self, parser, opts, args):
workers = CONF.gunicorn.workers
if workers <= 0:
workers = multiprocessing.cpu_count() * 2 + 1
logger_class = "simple"
if CONF.gunicorn.ignore_healthcheck_accesslog:
logger_class = "qg.web.glogging.GunicornLogger"
return {
'bind': '{0}:{1}'.format(CONF.web.bind, CONF.web.port),
'config': CONF.gunicorn.config,
'workers': workers,
'daemon': CONF.gunicorn.daemon,
'accesslog': CONF.gunicorn.accesslog,
'loglevel': CONF.gunicorn.loglevel,
'timeout': CONF.gunicorn.timeout,
'worker_class': CONF.gunicorn.worker_class,
'logger_class': logger_class
}
def load(self):
return app
# NOTE(zhen.pei): 为了不让gunicorn默认匹配sys.argv[1:]
sys.argv = [sys.argv[0]]
QgGunicornApp().run()
示例12: __repr__
# 需要导入模块: from gunicorn.app import base [as 别名]
# 或者: from gunicorn.app.base import Application [as 别名]
def __repr__(self):
cb = self.get_undecorated_callback()
return '<%s %r %r>' % (self.method, self.rule, cb)
###############################################################################
# Application Object ###########################################################
###############################################################################