本文整理汇总了Python中gunicorn.config.Config方法的典型用法代码示例。如果您正苦于以下问题:Python config.Config方法的具体用法?Python config.Config怎么用?Python config.Config使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gunicorn.config
的用法示例。
在下文中一共展示了config.Config方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init
# 需要导入模块: from gunicorn import config [as 别名]
# 或者: from gunicorn.config import Config [as 别名]
def init(self, parser, opts, args):
if len(args) != 1:
parser.error("No application name specified.")
cwd = util.getcwd()
cfgfname = os.path.normpath(os.path.join(cwd, args[0]))
cfgfname = os.path.abspath(cfgfname)
if not os.path.exists(cfgfname):
parser.error("Config file not found: %s" % cfgfname)
self.cfgurl = 'config:%s' % cfgfname
self.relpath = os.path.dirname(cfgfname)
self.cfgfname = cfgfname
sys.path.insert(0, self.relpath)
pkg_resources.working_set.add_entry(self.relpath)
return self.app_config()
示例2: run
# 需要导入模块: from gunicorn import config [as 别名]
# 或者: from gunicorn.config import Config [as 别名]
def run(self):
loop = asyncio.get_event_loop()
age = None
ppid = os.getpid()
sockets = []
self.wsgi, app = make_stub_application(headers=self.response_headers,
body=self.response_body)
timeout = None
cfg = Config()
log = None
sockname = ('127.0.0.1', '80')
reader = asyncio.StreamReader()
def feeder():
reader.feed_data(self.request)
reader.feed_eof()
worker = AsyncioWorker(age, ppid, sockets, app, timeout, cfg, log)
loop.create_task(worker.connection_task(sockname, reader, self.writer))
loop.call_soon(feeder)
run_worker(worker)
示例3: test_worker_creates_servers_for_sockets
# 需要导入模块: from gunicorn import config [as 别名]
# 或者: from gunicorn.config import Config [as 别名]
def test_worker_creates_servers_for_sockets(monkeypatch, mocker):
loop = asyncio.get_event_loop()
calls = []
age = None
ppid = os.getpid()
sockets = [mocker.MagicMock(), mocker.MagicMock()]
app = None
timeout = None
cfg = Config()
log = None
async def start_server(*args, **kwargs):
calls.append((args, kwargs))
if len(calls) == len(sockets):
loop.stop()
monkeypatch.setattr(asyncio, 'start_server', start_server)
worker = AsyncioWorker(age, ppid, sockets, app, timeout, cfg, log)
run_worker(worker)
for call in calls:
assert call[1]['sock'] in sockets
示例4: test_gunicorn_logger_set_formatter_on_access_log
# 需要导入模块: from gunicorn import config [as 别名]
# 或者: from gunicorn.config import Config [as 别名]
def test_gunicorn_logger_set_formatter_on_access_log():
cfg = Config()
cfg.set('accesslog', '/tmp/log')
logger = gunicorn.GunicornLogger(cfg)
access = logger._get_gunicorn_handler(logger.access_log)
assert isinstance(access.formatter, logs.StructuredFormatter)
示例5: test_gunicorn_logger_no_handler_for_stderr_access_log
# 需要导入模块: from gunicorn import config [as 别名]
# 或者: from gunicorn.config import Config [as 别名]
def test_gunicorn_logger_no_handler_for_stderr_access_log():
cfg = Config()
cfg.set('accesslog', '-')
logger = gunicorn.GunicornLogger(cfg)
assert logger.access_log.propagate is True
assert logger._get_gunicorn_handler(logger.access_log) is None
示例6: test_gunicorn_logger_propagate_error_log
# 需要导入模块: from gunicorn import config [as 别名]
# 或者: from gunicorn.config import Config [as 别名]
def test_gunicorn_logger_propagate_error_log():
cfg = Config()
logger = gunicorn.GunicornLogger(cfg)
assert logger.error_log.propagate is True
assert len(logger.error_log.handlers) == 0
示例7: test_gunicorn_logger_get_extra
# 需要导入模块: from gunicorn import config [as 别名]
# 或者: from gunicorn.config import Config [as 别名]
def test_gunicorn_logger_get_extra(environ):
response, environ, delta, expected = access_extra_args(
environ, '/foo?bar=baz')
cfg = Config()
logger = gunicorn.GunicornLogger(cfg)
msg, extra = logger.get_extra(response, None, environ, delta)
assert msg == 'GET /foo?'
assert extra == expected
示例8: test_gunicorn_logger_access
# 需要导入模块: from gunicorn import config [as 别名]
# 或者: from gunicorn.config import Config [as 别名]
def test_gunicorn_logger_access(environ, log, statsd_metrics):
response, environ, delta, expected = access_extra_args(
environ, '/')
cfg = Config()
cfg.set('accesslog', '-')
logger = gunicorn.GunicornLogger(cfg)
log[:] = []
logger.access(response, None, environ, delta)
assert log[0]._structured == expected
assert log[0].msg == 'GET /'
assert 'gunicorn.request.duration:' in statsd_metrics[0]
assert 'gunicorn.requests:1|c' in statsd_metrics[1]
assert 'gunicorn.request.status.200:1|c' in statsd_metrics[2]
示例9: test_gunicorn_logger_access_with_request_id
# 需要导入模块: from gunicorn import config [as 别名]
# 或者: from gunicorn.config import Config [as 别名]
def test_gunicorn_logger_access_with_request_id(environ, log):
rid = 'request-id'
response, environ, delta, expected = access_extra_args(
environ, '/')
response.headers.append(('X-Request-Id', rid))
expected['request_id'] = rid
cfg = Config()
cfg.set('accesslog', '-')
logger = gunicorn.GunicornLogger(cfg)
log[:] = []
logger.access(response, None, environ, delta)
assert log[0]._structured == expected
示例10: test_gunicorn_logger_logging
# 需要导入模块: from gunicorn import config [as 别名]
# 或者: from gunicorn.config import Config [as 别名]
def test_gunicorn_logger_logging(level, statsd_metrics, log):
cfg = Config()
logger = gunicorn.GunicornLogger(cfg)
getattr(logger, level)(level)
expected = 'ERROR' if level == 'exception' else level.upper()
assert log[0].levelname == expected
assert log[0].getMessage() == level
assert 'gunicorn.log.{}:1|c'.format(level) in statsd_metrics[0]
示例11: __init__
# 需要导入模块: from gunicorn import config [as 别名]
# 或者: from gunicorn.config import Config [as 别名]
def __init__(self, app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs):
self.cfg = Config()
self.gcfg = gcfg # need to hold this for app_config
self.app = app
self.callable = None
gcfg = gcfg or {}
cfgfname = gcfg.get("__file__")
if cfgfname is not None:
self.cfgurl = 'config:%s' % cfgfname
self.relpath = os.path.dirname(cfgfname)
self.cfgfname = cfgfname
cfg = kwargs.copy()
if port and not host.startswith("unix:"):
bind = "%s:%s" % (host, port)
else:
bind = host
cfg["bind"] = bind.split(',')
if gcfg:
for k, v in gcfg.items():
cfg[k] = v
cfg["default_proc_name"] = cfg['__file__']
try:
for k, v in cfg.items():
if k.lower() in self.cfg.settings and v is not None:
self.cfg.set(k.lower(), v)
except Exception as e:
print("\nConfig error: %s" % str(e), file=sys.stderr)
sys.stderr.flush()
sys.exit(1)
if cfg.get("config"):
self.load_config_from_file(cfg["config"])
else:
default_config = get_default_config_file()
if default_config is not None:
self.load_config_from_file(default_config)
示例12: load_default_config
# 需要导入模块: from gunicorn import config [as 别名]
# 或者: from gunicorn.config import Config [as 别名]
def load_default_config(self):
# init configuration
self.cfg = Config(self.usage, prog=self.prog)
示例13: run
# 需要导入模块: from gunicorn import config [as 别名]
# 或者: from gunicorn.config import Config [as 别名]
def run(self, handler):
from gunicorn.arbiter import Arbiter
from gunicorn.config import Config
handler.cfg = Config({'bind': "%s:%d" % (self.host, self.port), 'workers': 4})
arbiter = Arbiter(handler)
arbiter.run()
示例14: load_config
# 需要导入模块: from gunicorn import config [as 别名]
# 或者: from gunicorn.config import Config [as 别名]
def load_config(self):
self.cfg = gconfig.Config(self.usage, prog=self.prog)
settings = {'bind': '%s:%s' % (cfg.CONF.bind_host, cfg.CONF.bind_port),
'workers': cfg.CONF.api_workers,
'worker_connections': cfg.CONF.gunicorn.worker_connections,
'worker_class': cfg.CONF.gunicorn.worker_class,
'proc_name': 'neutron-server',
'accesslog': cfg.CONF.gunicorn.access_log,
'errorlog': cfg.CONF.gunicorn.error_log,
'limit_request_line': cfg.CONF.gunicorn.limit_request_line,
'loglevel': cfg.CONF.gunicorn.loglevel,
'access_log_format': ' '.join(('%(h)s',
'%(l)s',
'%(u)s',
'%(t)s',
'"%(r)s"',
'%(s)s',
'%(b)s',
'"%(f)s"',
'"%(a)s"',
'%(T)s',
'%(D)s',
'"%({X_USER_ID}i)s"',
'"%({X_TENANT_ID}i)s"',
'%({X-Forward-For}i)s',)),
}
for k, v in settings.iteritems():
self.cfg.set(k.lower(), v)