當前位置: 首頁>>代碼示例>>Python>>正文


Python config.Config方法代碼示例

本文整理匯總了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() 
開發者ID:RoseOu,項目名稱:flasky,代碼行數:20,代碼來源:pasterapp.py

示例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) 
開發者ID:jeamland,項目名稱:guvnor,代碼行數:25,代碼來源:support.py

示例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 
開發者ID:jeamland,項目名稱:guvnor,代碼行數:26,代碼來源:test_asyncio_worker.py

示例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) 
開發者ID:canonical-ols,項目名稱:talisker,代碼行數:8,代碼來源:test_gunicorn.py

示例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 
開發者ID:canonical-ols,項目名稱:talisker,代碼行數:8,代碼來源:test_gunicorn.py

示例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 
開發者ID:canonical-ols,項目名稱:talisker,代碼行數:7,代碼來源:test_gunicorn.py

示例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 
開發者ID:canonical-ols,項目名稱:talisker,代碼行數:10,代碼來源:test_gunicorn.py

示例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] 
開發者ID:canonical-ols,項目名稱:talisker,代碼行數:17,代碼來源:test_gunicorn.py

示例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 
開發者ID:canonical-ols,項目名稱:talisker,代碼行數:15,代碼來源:test_gunicorn.py

示例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] 
開發者ID:canonical-ols,項目名稱:talisker,代碼行數:10,代碼來源:test_gunicorn.py

示例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) 
開發者ID:RoseOu,項目名稱:flasky,代碼行數:43,代碼來源:pasterapp.py

示例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) 
開發者ID:RoseOu,項目名稱:flasky,代碼行數:5,代碼來源:base.py

示例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() 
開發者ID:yt-project,項目名稱:yt,代碼行數:8,代碼來源:bottle.py

示例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) 
開發者ID:openstack,項目名稱:quark,代碼行數:31,代碼來源:gunicorn_server.py


注:本文中的gunicorn.config.Config方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。