Пример #1
0
class Application(GunicornApp):
    def init(self, parser, opts, args):
        if len(args) < 1:
            parser.error("No application module specified.")

        self.cfg.set("default_proc_name", args[0])
        self.app_uri = args[0]

        logging.captureWarnings(True)
        if opts.auto_config:
            # Default config_dir
            config_dir = os.path.join(self.cfg.chdir,
                                      'etc',
                                      self.app_uri.split(":", 1)[0])
            if os.path.exists(config_dir):
                self.cfg.set('config_dir', config_dir)  # Define dev etc folder as default config directory

            # generate config_dir directly: egg or chicken problem
            if opts.config_dir:
                self.cfg.set('config_dir', opts.config_dir)

            if not opts.config:
                opts.config = os.path.join(self.cfg.config_dir, 'api_hour/gunicorn_conf.py')

            if not self.cfg.logconfig:
                self.cfg.set('logconfig', os.path.join(self.cfg.config_dir, 'api_hour/logging.ini'))
        else:
            # To avoid with Gunicorn 19 that the console it's empty when you test
            if not opts.errorlog:
                opts.errorlog = '-'
            if not opts.accesslog:
                opts.accesslog = '-'

    def load_default_config(self):
        # init configuration
        self.cfg = Config(self.usage, prog=self.prog)
        self.cfg.set('worker_class', 'api_hour.Worker')  # Define api_hour.Worker as default

    def load_config(self):
        # parse console args
        super().load_config()
        if self.cfg.config_dir:
            self.config = get_config({'config_dir': self.cfg.config_dir})
        else:
            self.config = None
        # import ipdb; ipdb.set_trace()

    def chdir(self):
        # chdir to the configured path before loading,
        # default is the current dir
        os.chdir(self.cfg.chdir)

        # add the path to sys.path
        sys.path.insert(0, self.cfg.chdir)

    def load(self):
        self.chdir()

        # load the app
        return util.import_app(self.app_uri)
Пример #2
0
class PasterServerApplication(Application):
    
    def __init__(self, app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs):
        self.cfg = Config()
        self.app = app
        self.callable = None

        cfg = kwargs.copy()

        if port and not host.startswith("unix:"):
            bind = "%s:%s" % (host, port)
        else:
            bind = host
        cfg["bind"] = bind

        if gcfg:
            for k, v in list(gcfg.items()):
                cfg[k] = v
            cfg["default_proc_name"] = cfg['__file__']

        for k, v in list(cfg.items()):
            if k.lower() in self.cfg.settings and v is not None:
                self.cfg.set(k.lower(), v)

        self.configure_logging()

    def load(self):
        return self.app
Пример #3
0
        class GunicornApplication(BaseApplication):
            def __init__(self, application, options=None):
                if options is None:
                    options = {}

                self.application = app
                self.prog = None
                self.usage = None
                self.callable = None
                self.options = options
                self.do_load_config()

            def load_config(self):
                self.cfg = Config(self.usage, prog=self.prog)
                # optional settings from apps
                cfg = self.init(None, [], [])

                # Load up the any app specific configuration
                if cfg and cfg is not None:
                    for k, v in cfg.items():
                        self.cfg.set(k.lower(), v)

            def init(self, parser, opts, args):
                config = dict(
                    (key, value)
                    for key, value in map(lambda item: (item[0].lower(), item[1]), self.options.iteritems())
                    if key in self.cfg.settings and value is not None
                )
                return config

            def load(self):
                self.application.wsgi_app = ProxyFix(self.application.wsgi_app)
                return self.application
Пример #4
0
class ConfigurableApplication(Application):
    @staticmethod
    def default_cfg():
        return {
            'worker_class': 'sync',
            'workers': 2,
            'secure_scheme_headers': {
                'X-FORWARDED-PROTO': 'https'
            },
            'preload_app': True,
            'user': os.getuid(),
        }

    def __init__(self, app, **config):
        self.app = app
        self._config = config
        super(ConfigurableApplication, self).__init__()

    def load(self):
        return self.app

    def init(self, parser, opts, args):
        self.cfg.set('default_proc_name', 'mtrpc')

    def load_config(self):
        self.cfg = Config()
        for k, v in chain(self.default_cfg().items(), self._config.items()):
            self.cfg.set(k.lower(), v)
Пример #5
0
        class GunicornServer(GunicornApplication):
            def init(self, **kwargs):
                config = {
                    'bind': '{0}:{1}'.format(
                        options['host'],
                        options['port']
                    ),
                    'workers': options['workers'],
                    'worker_class': 'gevent',
                    'accesslog': options['access_logfile'],
                    'max_requests': options['max_requests'],
                }
                return config

            def load(self):
                # Step needed to get around flask's import time side-effects
                from product_identifier.master import Master
                env = Master.instance()
                env.start()
                return env.flask

            def load_config(self):
                # Overriding to prevent Gunicorn from reading
                # the command-line arguments
                self.cfg = GunicornConfig(self.usage, prog=self.prog)
                cfg = self.init()
                if cfg and cfg is not None:
                    for k, v in cfg.items():
                        self.cfg.set(k.lower(), v)
Пример #6
0
class PasterServerApplication(PasterBaseApplication):
    def __init__(self, app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs):
        self.cfg = 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

        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, e:
            sys.stderr.write("\nConfig error: %s\n" % str(e))
            sys.stderr.flush()
            sys.exit(1)
Пример #7
0
class DjangoApplicationCommand(Application):
    
    def __init__(self, options, admin_media_path):
        self.cfg = Config()
        self.callable = None
        
        for k, v in list(options.items()):
            if k.lower() in self.cfg.settings and v is not None:
                self.cfg.set(k.lower(), v)
        
        self.admin_media_path = admin_media_path
        
    def load(self):
        try:
            return  AdminMediaHandler(WSGIHandler(), self.admin_media_path)
        except WSGIServerException, e:
            # Use helpful error messages instead of ugly tracebacks.
            ERRORS = {
                13: "You don't have permission to access that port.",
                98: "That port is already in use.",
                99: "That IP address can't be assigned-to.",
            }
            try:
                error_text = ERRORS[e.args[0].args[0]]
            except (AttributeError, KeyError):
                error_text = str(e)
            sys.stderr.write(self.style.ERROR("Error: %s" % error_text) + '\n')
            sys.exit(1)
Пример #8
0
def test_prefix_multiple_dots():
    c = Config()
    c.set("statsd_prefix", "test...")
    logger = Statsd(c)
    logger.sock = MockSocket(False)

    logger.info("Blah", extra={"mtype": "gauge", "metric": "gunicorn.test", "value": 666})
    t.eq(logger.sock.msgs[0], "test.gunicorn.test:666|g")
Пример #9
0
def test_prefix():
    c = Config()
    c.set("statsd_prefix", "test.")
    logger = Statsd(c)
    logger.sock = MockSocket(False)

    logger.info("Blah", extra={"mtype": "gauge", "metric": "gunicorn.test", "value": 666})
    assert logger.sock.msgs[0] == b"test.gunicorn.test:666|g"
Пример #10
0
def test_dogstatsd_tags():
    c = Config()
    tags = 'yucatan,libertine:rhubarb'
    c.set('dogstatsd_tags', tags)
    logger = Statsd(c)
    logger.sock = MockSocket(False)
    logger.info("Twill", extra={"mtype": "gauge", "metric": "barb.westerly",
                                "value": 2})
    assert logger.sock.msgs[0] == b"barb.westerly:2|g|#" + tags.encode('ascii')
Пример #11
0
class PasterServerApplication(PasterBaseApplication):

    def __init__(self, app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs):
        self.cfg = 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:
            sys.stderr.write("\nConfig error: %s\n" % str(e))
            sys.stderr.flush()
            sys.exit(1)


    def load_config(self):
        if not hasattr(self, "cfgfname"):
            return

        cfg = self.app_config()
        for k,v in cfg.items():
            try:
                self.cfg.set(k.lower(), v)
            except:
                sys.stderr.write("Invalid value for %s: %s\n\n" % (k, v))
                raise

    def load(self):
        if hasattr(self, "cfgfname"):
            return loadapp(self.cfgurl, relative_to=self.relpath)

        return self.app
Пример #12
0
class Application(object):
    """\
    An application interface for configuring and loading
    the various necessities for any given web framework.
    """
    def __init__(self, usage=None):
        self.log = logging.getLogger(__name__)
        self.cfg = Config(usage)
        self.callable = None
        
        parser = self.cfg.parser()
        opts, args = parser.parse_args()
        cfg = self.init(parser, opts, args)
        
        # Load up the any app specific configuration
        if cfg:
            for k, v in list(cfg.items()):
                self.cfg.set(k.lower(), v)
        
        # Load up the config file if its found.
        if opts.config and os.path.exists(opts.config):
            cfg = {
                "__builtins__": __builtins__,
                "__name__": "__config__",
                "__file__": opts.config,
                "__doc__": None,
                "__package__": None
            }
            try:
                execfile(opts.config, cfg, cfg)
            except Exception, e:
                print "Failed to read config file: %s" % opts.config
                traceback.print_exc()
                sys.exit(1)
        
            for k, v in list(cfg.items()):
                # Ignore unknown names
                if k not in self.cfg.settings:
                    continue
                try:
                    self.cfg.set(k.lower(), v)
                except:
                    sys.stderr.write("Invalid value for %s: %s\n\n" % (k, v))
                    raise
            
        # Lastly, update the configuration with any command line
        # settings.
        for k, v in list(opts.__dict__.items()):
            if v is None:
                continue
            self.cfg.set(k.lower(), v)
            
        self.configure_logging()
Пример #13
0
class GunicornApp(VanillaGunicornApp):

    """Implement Gunicorn application."""

    def __init__(self, usage=None, prog=None, config=None):
        """Initialize self."""
        self._cfg = config
        super(GunicornApp, self).__init__(usage=usage, prog=prog)

    def init(self, parser, opts, args):
        """Initialize the application."""
        if len(args) < 1:
            parser.error("No application module specified.")

        self.app_uri = args[0]
        self.cfg.set("default_proc_name", self.app_uri)
        logging.captureWarnings(True)

        if self.cfg.config:
            self.load_config_from_file(self.cfg.config)

    def load_default_config(self):
        """Prepare default configuration."""
        self.cfg = VanillaGunicornConfig(self.usage, prog=self.prog)

        # Remove unused settings
        del self.cfg.settings['paste']
        del self.cfg.settings['django_settings']

        self.cfg.settings['worker_class'].default = 'muffin.worker.GunicornWorker'
        self.cfg.set('worker_class', 'muffin.worker.GunicornWorker')
        if self._cfg:
            self.cfg.set('config', self._cfg)
            os.environ[CONFIGURATION_ENVIRON_VARIABLE] = self._cfg

    def load_config(self):
        """Load configuration."""
        parser = self.cfg.parser()
        args, _ = parser.parse_known_args()
        self.init(parser, args, args.args)

    def load(self):
        """Load a Muffin application."""
        # Fix paths
        os.chdir(self.cfg.chdir)
        sys.path.insert(0, self.cfg.chdir)

        app = self.app_uri
        if not isinstance(app, Application):
            app = import_app(app)

        return app
Пример #14
0
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
Пример #15
0
def test_gunicorn_logger_access_forwarded(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 statsd_metrics[0] == 'gunicorn.count.view.GET.200:1|c'
    assert statsd_metrics[1].startswith('gunicorn.latency.view.GET.200:')
Пример #16
0
def test_prefix_nested():
    c = Config()
    c.set("statsd_prefix", "test.asdf.")
    logger = Statsd(c)
    logger.sock = MockSocket(False)

    logger.info("Blah",
                extra={
                    "mtype": "gauge",
                    "metric": "gunicorn.test",
                    "value": 666
                })
    t.eq(logger.sock.msgs[0], b"test.asdf.gunicorn.test:666|g")
Пример #17
0
def test_gunicorn_logger_access_with_request_id(environ, log):
    rid = 'request-id'
    response, environ, delta, expected = access_extra_args(
        environ, '/')
    expected['request_id'] = rid
    cfg = Config()
    cfg.set('accesslog', '-')
    logger = gunicorn.GunicornLogger(cfg)

    log[:] = []
    with request_id.context(rid):
        logger.access(response, None, environ, delta)
    assert log[0]._structured == expected
Пример #18
0
def test_gunicorn_logger_status_url_enabled(
        environ, log, statsd_metrics, monkeypatch):
    response, environ, delta, expected = access_extra_args(
        environ, '/_status/ping')
    cfg = Config()
    cfg.set('accesslog', '-')
    logger = gunicorn.GunicornLogger(cfg)
    statsd.get_client()  # force the statsd creationg log message
    log[:] = []
    monkeypatch.setitem(os.environ, 'TALISKER_LOGSTATUS', 'true')
    logger.access(response, None, environ, delta)
    assert len(log) == 1
    assert len(statsd_metrics) == 0
def test_dogstatsd_tags():
    c = Config()
    tags = 'yucatan,libertine:rhubarb'
    c.set('dogstatsd_tags', tags)
    logger = Statsd(c)
    logger.sock = MockSocket(False)
    logger.info("Twill",
                extra={
                    "mtype": "gauge",
                    "metric": "barb.westerly",
                    "value": 2
                })
    assert logger.sock.msgs[0] == b"barb.westerly:2|g|#" + tags.encode('ascii')
Пример #20
0
def test_gunicorn_logger_access_no_forwarded(environ, context):
    response, environ, delta, expected = access_extra_args(environ, '/')
    environ.pop('HTTP_X_FORWARDED_FOR')
    response.headers = [('X-View-Name', 'view')]
    expected.pop('forwarded')
    cfg = Config()
    cfg.set('accesslog', '-')
    logger = gunicorn.GunicornLogger(cfg)
    context.logs[:] = []
    logger.access(response, None, environ, delta)
    assert context.logs.exists(msg='GET /', extra=expected)
    assert context.statsd[0] == 'gunicorn.count.view.GET.200:1|c'
    assert context.statsd[1].startswith('gunicorn.latency.view.GET.200:')
def test_prefix_multiple_dots():
    c = Config()
    c.set("statsd_prefix", "test...")
    logger = Statsd(c)
    logger.sock = MockSocket(False)

    logger.info("Blah",
                extra={
                    "mtype": "gauge",
                    "metric": "gunicorn.test",
                    "value": 666
                })
    assert logger.sock.msgs[0] == b"test.gunicorn.test:666|g"
Пример #22
0
class PasterServerApplication(PasterBaseApplication):

    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:
            sys.stderr.write("\nConfig error: %s\n" % str(e))
            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)

    def load(self):
        # chdir to the configured path before loading,
        # default is the current dir
        os.chdir(self.cfg.chdir)

        return self.app
Пример #23
0
def test_gunicorn_logger_access_with_request_content(environ, log):
    response, environ, delta, expected = access_extra_args(
        environ, '/')
    environ['CONTENT_TYPE'] = 'type'
    environ['CONTENT_LENGTH'] = '10'
    expected['request_type'] = 'type'
    expected['request_length'] = 10
    cfg = Config()
    cfg.set('accesslog', '-')
    logger = gunicorn.GunicornLogger(cfg)

    log[:] = []
    logger.access(response, None, environ, delta)
    assert log[0]._structured == expected
Пример #24
0
def test_gunicorn_logger_access_500(environ, context):
    response, environ, delta, expected = access_extra_args(environ, '/')
    response.status_code = 500
    response.status = '500 Server Error'
    expected['status'] = 500
    cfg = Config()
    cfg.set('accesslog', '-')
    logger = gunicorn.GunicornLogger(cfg)
    context.logs[:] = []
    logger.access(response, None, environ, delta)
    assert context.logs.exists(msg='GET /', extra=expected)
    assert context.statsd[0] == 'gunicorn.count.view.GET.500:1|c'
    assert context.statsd[1] == 'gunicorn.errors.view.GET.500:1|c'
    assert context.statsd[2].startswith('gunicorn.latency.view.GET.500:')
Пример #25
0
class PasterServerApplication(PasterBaseApplication):

    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:
            sys.stderr.write("\nConfig error: %s\n" % str(e))
            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)

    def load(self):
        # chdir to the configured path before loading,
        # default is the current dir
        os.chdir(self.cfg.chdir)

        return self.app
Пример #26
0
class GunicornApp(VanillaGunicornApp):
    """ Support Gunicorn. """
    def __init__(self, usage=None, prog=None, config=None):
        self._cfg = config
        super(GunicornApp, self).__init__(usage=usage, prog=prog)

    def init(self, parser, opts, args):
        """ Initialize the application. """
        if len(args) < 1:
            parser.error("No application module specified.")

        self.app_uri = args[0]
        self.cfg.set("default_proc_name", self.app_uri)
        logging.captureWarnings(True)

        if self.cfg.config:
            self.load_config_from_file(self.cfg.config)

    def load_default_config(self):
        """ Prepare default configuration. """
        self.cfg = VanillaGunicornConfig(self.usage, prog=self.prog)

        # Remove unused settings
        del self.cfg.settings['paste']
        del self.cfg.settings['django_settings']

        self.cfg.settings[
            'worker_class'].default = 'muffin.worker.GunicornWorker'
        self.cfg.set('worker_class', 'muffin.worker.GunicornWorker')
        if self._cfg:
            self.cfg.set('config', self._cfg)
            os.environ[CONFIGURATION_ENVIRON_VARIABLE] = self._cfg

    def load_config(self):
        parser = self.cfg.parser()
        args, _ = parser.parse_known_args()
        self.init(parser, args, args.args)

    def load(self):
        """ Load a Muffin application. """
        # Fix paths
        os.chdir(self.cfg.chdir)
        sys.path.insert(0, self.cfg.chdir)

        app = self.app_uri
        if not isinstance(app, Application):
            app = import_app(app)

        return app
Пример #27
0
def test_gunicorn_logger_access_no_forwarded(environ, log, statsd_metrics):
    response, environ, delta, expected = access_extra_args(environ, '/')
    environ.pop('HTTP_X_FORWARDED_FOR')
    response.headers = [('X-View-Name', 'view')]
    expected.pop('forwarded')
    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 statsd_metrics[0] == 'gunicorn.count.view.GET.200:1|c'
    assert statsd_metrics[1].startswith('gunicorn.latency.view.GET.200:')
Пример #28
0
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]
Пример #29
0
def test_gunicorn_logger_access_500(environ, log, statsd_metrics):
    response, environ, delta, expected = access_extra_args(environ, '/')
    response.status_code = 500
    response.status = '500 Server Error'
    expected['status'] = 500
    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 statsd_metrics[0] == 'gunicorn.count.view.GET.500:1|c'
    assert statsd_metrics[1] == 'gunicorn.errors.view.GET.500:1|c'
    assert statsd_metrics[2].startswith('gunicorn.latency.view.GET.500:')
Пример #30
0
class PasterServerApplication(PasterBaseApplication):
    def __init__(self, app, gcfg=None, host="127.0.0.1", port=None, **kwargs):
        # pylint: disable=super-init-not-called
        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)

    def load(self):
        return self.app
Пример #31
0
class WebsocketApp(gunicorn.app.base.Application):
    def __init__(self, app, options=None):
        self.options = options or {}
        self.application = app
        super(WebsocketApp, self).__init__()

    def load_config(self):
        # init configuration
        self.cfg = Config(self.usage, prog=self.prog)

        config = dict([(key, value) for key, value in self.options.items()
                       if key in self.cfg.settings and value is not None])

        for key, value in config.items():
            self.cfg.set(key.lower(), value)

    def load(self):
        return self.application
Пример #32
0
def run_gunicorn(app, host, port):
    try:
        from gunicorn.app.base import Application
        from gunicorn.config import Config
    except:
        print "warning: couldn't import gunicorn -- running flask dev server"
        run_flask(app, host, port)
        return
    class Glapp(Application):
        def init(self, *start):
            pass
        def load(self):
            return app
    glapp = Glapp()
    gonfig = Config()
    gonfig.set('bind', '{}{}'.format(host, ':{}'.format(port) if port else ''))
    glapp.cfg = gonfig
    glapp.run()
Пример #33
0
class DjangoApplicationCommand(Application):
    
    def __init__(self, options, admin_media_path):
        self.log = logging.getLogger(__name__)
        self.usage = None
        self.cfg = None
        self.config_file = options.get("config") or ""
        self.options = options
        self.admin_media_path = admin_media_path
        self.callable = None
        self.load_config()

    def load_config(self):
        self.cfg = Config()
        
        if self.config_file and os.path.exists(self.config_file):
            cfg = {
                "__builtins__": __builtins__,
                "__name__": "__config__",
                "__file__": self.config_file,
                "__doc__": None,
                "__package__": None
            }
            try:
                execfile(self.config_file, cfg, cfg)
            except Exception, e:
                print "Failed to read config file: %s" % self.config_file
                traceback.print_exc()
                sys.exit(1)
        
            for k, v in list(cfg.items()):
                # Ignore unknown names
                if k not in self.cfg.settings:
                    continue
                try:
                    self.cfg.set(k.lower(), v)
                except:
                    sys.stderr.write("Invalid value for %s: %s\n\n" % (k, v))
                    raise
        
        for k, v in list(self.options.items()):
            if k.lower() in self.cfg.settings and v is not None:
                self.cfg.set(k.lower(), v)
Пример #34
0
class PasterServerApplication(PasterBaseApplication):
    def __init__(self,
                 app,
                 gcfg=None,
                 host="127.0.0.1",
                 port=None,
                 *args,
                 **kwargs):
        self.cfg = 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

        if gcfg:
            for k, v in list(gcfg.items()):
                cfg[k] = v
            cfg["default_proc_name"] = cfg['__file__']

        try:
            for k, v in list(cfg.items()):
                if k.lower() in self.cfg.settings and v is not None:
                    self.cfg.set(k.lower(), v)
        except Exception, e:
            sys.stderr.write("\nConfig error: %s\n" % str(e))
            sys.stderr.flush()
            sys.exit(1)

        self.configure_logging()
        class GunicornServer(GunicornApplication):
            def init(self, **kwargs):
                config = {
                    'bind': '{0}:{1}'.format(options['host'], options['port']),
                    'workers': options['workers'],
                    'worker_class': 'gevent',
                    'accesslog': options['access_logfile'],
                    'max_requests': options['max_requests'],
                }
                return config

            def load(self):
                # Step needed to get around flask's import time side-effects
                app = environment_manager_create()
                return app

            def load_config(self):
                # Overriding to prevent Gunicorn from reading
                # the command-line arguments
                self.cfg = GunicornConfig(self.usage, prog=self.prog)
                cfg = self.init()
                if cfg and cfg is not None:
                    for k, v in cfg.items():
                        self.cfg.set(k.lower(), v)
Пример #36
0
from gunicorn.config import Config
from gunicorn.http.errors import LimitRequestHeaders

request = LimitRequestHeaders
cfg = Config()
cfg.set('limit_request_fields', 2)
Пример #37
0
class Application(object):
    """\
    An application interface for configuring and loading
    the various necessities for any given web framework.
    """

    def __init__(self, usage=None, prog=None):
        self.usage = usage
        self.cfg = None
        self.callable = None
        self.prog = prog
        self.logger = None
        self.do_load_config()

    def do_load_config(self):
        try:
            self.load_config()
        except Exception as e:
            sys.stderr.write("\nError: %s\n" % str(e))
            sys.stderr.flush()
            sys.exit(1)

    def load_config(self):
        # init configuration
        self.cfg = Config(self.usage, prog=self.prog)

        # parse console args
        parser = self.cfg.parser()
        args = parser.parse_args()

        # optional settings from apps
        cfg = self.init(parser, args, args.args)

        # Load up the any app specific configuration
        if cfg and cfg is not None:
            for k, v in cfg.items():
                self.cfg.set(k.lower(), v)

        # Load up the config file if its found.
        if args.config and os.path.exists(args.config):
            cfg = {
                "__builtins__": __builtins__,
                "__name__": "__config__",
                "__file__": args.config,
                "__doc__": None,
                "__package__": None
            }
            try:
                execfile_(args.config, cfg, cfg)
            except Exception:
                print("Failed to read config file: %s" % args.config)
                traceback.print_exc()
                sys.exit(1)

            for k, v in cfg.items():
                # Ignore unknown names
                if k not in self.cfg.settings:
                    continue
                try:
                    self.cfg.set(k.lower(), v)
                except:
                    sys.stderr.write("Invalid value for %s: %s\n\n" % (k, v))
                    raise

        # Lastly, update the configuration with any command line
        # settings.
        for k, v in args.__dict__.items():
            if v is None:
                continue
            if k == "args":
                continue
            self.cfg.set(k.lower(), v)

    def init(self, parser, opts, args):
        raise NotImplementedError

    def load(self):
        raise NotImplementedError

    def reload(self):
        self.do_load_config()
        if self.cfg.spew:
            debug.spew()

    def wsgi(self):
        if self.callable is None:
            self.callable = self.load()
        return self.callable

    def run(self):
        if self.cfg.check_config:
            try:
                self.load()
            except:
                sys.stderr.write("\nError while loading the application:\n\n")
                traceback.print_exc()
                sys.stderr.flush()
                sys.exit(1)
            sys.exit(0)

        if self.cfg.spew:
            debug.spew()
        if self.cfg.daemon:
            util.daemonize()

        # set python paths
        if self.cfg.pythonpath and self.cfg.pythonpath is not None:
            paths = self.cfg.pythonpath.split(",")
            for path in paths:
                pythonpath = os.path.abspath(self.cfg.pythonpath)
                if pythonpath not in sys.path:
                    sys.path.insert(0, pythonpath)

        try:
            Arbiter(self).run()
        except RuntimeError as e:
            sys.stderr.write("\nError: %s\n\n" % e)
            sys.stderr.flush()
            sys.exit(1)
Пример #38
0
class DjangoApplicationCommand(Application):
    
    def __init__(self, options, admin_media_path):
        self.usage = None
        self.cfg = None
        self.config_file = options.get("config") or ""
        self.options = options
        self.admin_media_path = admin_media_path
        self.callable = None
        self.do_load_config()

    def load_config(self):
        self.cfg = Config()
        
        if self.config_file and os.path.exists(self.config_file):
            cfg = {
                "__builtins__": __builtins__,
                "__name__": "__config__",
                "__file__": self.config_file,
                "__doc__": None,
                "__package__": None
            }
            try:
                execfile(self.config_file, cfg, cfg)
            except Exception:
                print "Failed to read config file: %s" % self.config_file
                traceback.print_exc()
                sys.exit(1)
        
            for k, v in cfg.items():
                # Ignore unknown names
                if k not in self.cfg.settings:
                    continue
                try:
                    self.cfg.set(k.lower(), v)
                except:
                    sys.stderr.write("Invalid value for %s: %s\n\n" % (k, v))
                    raise
        
        for k, v in self.options.items():
            if k.lower() in self.cfg.settings and v is not None:
                self.cfg.set(k.lower(), v)
        
    def load(self):
        from django.core.servers.basehttp import AdminMediaHandler, WSGIServerException
        from django.core.handlers.wsgi import WSGIHandler
        try:
            return  AdminMediaHandler(WSGIHandler(), self.admin_media_path)
        except WSGIServerException, e:
            # Use helpful error messages instead of ugly tracebacks.
            ERRORS = {
                13: "You don't have permission to access that port.",
                98: "That port is already in use.",
                99: "That IP address can't be assigned-to.",
            }
            try:
                error_text = ERRORS[e.args[0].args[0]]
            except (AttributeError, KeyError):
                error_text = str(e)
            sys.stderr.write(self.style.ERROR("Error: %s" % error_text) + '\n')
            sys.exit(1)
Пример #39
0
class Application(GunicornApp):
    def init(self, parser, opts, args):
        if len(args) < 1:
            parser.error("No application module specified.")

        self.cfg.set("default_proc_name", args[0])
        self.app_uri = args[0]

        logging.captureWarnings(True)
        if opts.auto_config:
            # Default config_dir
            config_dir = os.path.join(self.cfg.chdir, 'etc',
                                      self.app_uri.split(":", 1)[0])
            if os.path.exists(config_dir):
                self.cfg.set(
                    'config_dir', config_dir
                )  # Define dev etc folder as default config directory

            # generate config_dir directly: egg or chicken problem
            if opts.config_dir:
                self.cfg.set('config_dir', opts.config_dir)

            if not opts.config:
                opts.config = os.path.join(self.cfg.config_dir,
                                           'api_hour/gunicorn_conf.py')

            if not self.cfg.logconfig:
                self.cfg.set(
                    'logconfig',
                    os.path.join(self.cfg.config_dir, 'api_hour/logging.ini'))
        else:
            # To avoid with Gunicorn 19 that the console it's empty when you test
            if not opts.errorlog:
                opts.errorlog = '-'
            if not opts.accesslog:
                opts.accesslog = '-'

    def load_default_config(self):
        # init configuration
        self.cfg = Config(self.usage, prog=self.prog)
        self.cfg.set('worker_class',
                     'api_hour.Worker')  # Define api_hour.Worker as default

    def load_config(self):
        # parse console args
        super().load_config()
        if self.cfg.config_dir:
            self.config = get_config({'config_dir': self.cfg.config_dir})
        else:
            self.config = None
        # import ipdb; ipdb.set_trace()

    def chdir(self):
        # chdir to the configured path before loading,
        # default is the current dir
        os.chdir(self.cfg.chdir)

        # add the path to sys.path
        sys.path.insert(0, self.cfg.chdir)

    def load(self):
        self.chdir()

        # load the app
        return util.import_app(self.app_uri)
Пример #40
0
class Application(object):
    """\
    An application interface for configuring and loading
    the various necessities for any given web framework.
    """
    def __init__(self, usage=None):
        self.usage = usage
        self.cfg = None
        self.callable = None
        self.logger = None
        self.do_load_config()

    def do_load_config(self):
        try:
            self.load_config()
        except Exception as e:
            sys.stderr.write("\nError: %s\n" % str(e))
            sys.stderr.flush()
            sys.exit(1)

    def load_config(self):
        # init configuration
        self.cfg = Config(self.usage)

        # parse console args
        parser = self.cfg.parser()
        opts, args = parser.parse_args()

        # optional settings from apps
        cfg = self.init(parser, opts, args)

        # Load up the any app specific configuration
        if cfg and cfg is not None:
            for k, v in cfg.items():
                self.cfg.set(k.lower(), v)

        # Load up the config file if its found.
        if opts.config and os.path.exists(opts.config):
            cfg = {
                "__builtins__": __builtins__,
                "__name__": "__config__",
                "__file__": opts.config,
                "__doc__": None,
                "__package__": None
            }
            try:
                execfile_(opts.config, cfg, cfg)
            except Exception:
                print("Failed to read config file: %s" % opts.config)
                traceback.print_exc()
                sys.exit(1)

            for k, v in cfg.items():
                # Ignore unknown names
                if k not in self.cfg.settings:
                    continue
                try:
                    self.cfg.set(k.lower(), v)
                except:
                    sys.stderr.write("Invalid value for %s: %s\n\n" % (k, v))
                    raise

        # Lastly, update the configuration with any command line
        # settings.
        for k, v in opts.__dict__.items():
            if v is None:
                continue
            self.cfg.set(k.lower(), v)

    def init(self, parser, opts, args):
        raise NotImplementedError

    def load(self):
        raise NotImplementedError

    def reload(self):
        self.do_load_config()
        if self.cfg.spew:
            debug.spew()

    def wsgi(self):
        if self.callable is None:
            self.callable = self.load()
        return self.callable

    def run(self):
        if self.cfg.check_config:
            try:
                self.load()
            except:
                sys.stderr.write("\nError while loading the application:\n\n")
                traceback.print_exc()
                sys.stderr.flush()
                sys.exit(1)
            sys.exit(0)

        if self.cfg.spew:
            debug.spew()
        if self.cfg.daemon:
            util.daemonize()

        # set python paths
        if self.cfg.pythonpath and self.cfg.pythonpath is not None:
            paths = self.cfg.pythonpath.split(",")
            for path in paths:
                pythonpath = os.path.abspath(self.cfg.pythonpath)
                if pythonpath not in sys.path:
                    sys.path.insert(0, pythonpath)

        try:
            Arbiter(self).run()
        except RuntimeError as e:
            sys.stderr.write("\nError: %s\n\n" % e)
            sys.stderr.flush()
            sys.exit(1)
Пример #41
0
class PasterServerApplication(PasterBaseApplication):
    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:
            sys.stderr.write("\nConfig error: %s\n" % str(e))
            sys.stderr.flush()
            sys.exit(1)

    def load_config(self):
        if not hasattr(self, "cfgfname"):
            return

        cfg = self.app_config()
        for k, v in cfg.items():
            try:
                self.cfg.set(k.lower(), v)
            except:
                sys.stderr.write("Invalid value for %s: %s\n\n" % (k, v))
                raise

    def load(self):
        if hasattr(self, "cfgfname"):
            return loadapp(self.cfgurl,
                           relative_to=self.relpath,
                           global_conf=self.gcfg)

        return self.app
Пример #42
0
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
Пример #43
0
class DjangoApplicationCommand(DjangoApplication):
    
    def __init__(self, options, admin_media_path):
        self.usage = None
        self.cfg = None
        self.config_file = options.get("config") or ""
        self.options = options
        self.admin_media_path = admin_media_path
        self.callable = None
        self.settings_modname = os.environ[ENVIRONMENT_VARIABLE]
        self.project_path = os.getcwd()

        self.do_load_config()

    def load_config(self):
        self.cfg = Config()
        
        if self.config_file and os.path.exists(self.config_file):
            cfg = {
                "__builtins__": __builtins__,
                "__name__": "__config__",
                "__file__": self.config_file,
                "__doc__": None,
                "__package__": None
            }
            try:
                execfile(self.config_file, cfg, cfg)
            except Exception:
                print "Failed to read config file: %s" % self.config_file
                traceback.print_exc()
                sys.exit(1)
        
            for k, v in cfg.items():
                # Ignore unknown names
                if k not in self.cfg.settings:
                    continue
                try:
                    self.cfg.set(k.lower(), v)
                except:
                    sys.stderr.write("Invalid value for %s: %s\n\n" % (k, v))
                    raise
        
        for k, v in self.options.items():
            if k.lower() in self.cfg.settings and v is not None:
                self.cfg.set(k.lower(), v)
       
    def setup_environ(self):
        for modname in sys.modules.keys():
            if modname.startswith('django') or \
                    'settings' in modname.split('.'):
                del sys.modules[modname]

        # add the project path to sys.path
        sys.path.insert(0, self.project_path)
        sys.path.append(os.path.normpath(os.path.join(self.project_path,
            os.pardir)))
        super(DjangoApplicationCommand, self).setup_environ()

    def load(self):
        # setup environ
        self.setup_environ()
        self.validate()
        self.activate_translation()

        from django.core.servers.basehttp import AdminMediaHandler, WSGIServerException
        from django.core.handlers.wsgi import WSGIHandler

        try:
            return  AdminMediaHandler(WSGIHandler(), self.admin_media_path)
        except WSGIServerException, e:
            # Use helpful error messages instead of ugly tracebacks.
            ERRORS = {
                13: "You don't have permission to access that port.",
                98: "That port is already in use.",
                99: "That IP address can't be assigned-to.",
            }
            try:
                error_text = ERRORS[e.args[0].args[0]]
            except (AttributeError, KeyError):
                error_text = str(e)
            sys.stderr.write(self.style.ERROR("Error: %s" % error_text) + '\n')
            sys.exit(1)
Пример #44
0
from gunicorn.config import Config
from gunicorn.http.errors import LimitRequestHeaders

cfg = Config()
cfg.set('limit_request_line', 0)
cfg.set('limit_request_field_size', 0)
request = {
    "method": "PUT",
    "uri":
    uri("/q=08aP8931Ltyl9nqyJvjMaRCOgDV3uONtAdHABjoZUG6KAP6h3Vh97O3GJjjovXYgNdrhxc7TriX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Dx7nFzlUSMC1kMvS2ECwvHzSycqHPRwCGipvG6kWz0mGvASXeKjm47iMROoY0MRK0uvgNdTTOTdxkMgOuCDIlxfit5QKjyzaVAg2kDwENfSd6XPMgSprTSLuNDXdg5NHCwUvDbEHVxpMgOItZymPZtPweOrnPdlEB4UwLZ8jqtShi5oDYvhkh85FwwT25OHFvDUWTTCV5n73pQ8kLo8zsB3mbWfGwg62guj3C50Dh42fAZEPBRSHDRTg3r0z39Vyj490lk2UpZeNyylwuEKmuIqEkbE3BRT2YEjTM8a2PU5grCuzculibcoRUpb1sIQiMRTf4wrtT1CnKcoUJ1T28DC04dTJVRcm3w3WzNLdrnovkX6NahblTzDvq5eXkoEaZv6HClmGuho4FH6s6i0OdmmW8qkNOnk7BhexiyAd3UYERlFwvZ6LP55tFOc3vnlhyylx1rTTgu1NFljRNs7rGiT7SnGFaFK7GITEZFEYI7DmOEUZXxDSHjYuOVN0YAJP2cZFgagyMwGJdrpH8S7cewYPMKz2Go2GBKl1OA6pJ8T91tUdEcGVg9JCMQUA4sBtlIuRTVV3cduIhsLCTi2ewItkh9MRP1kevVa9WcXejQQKreZmq5EZtzThW71r7E2tcvwFeqiwv3JZnV16bZ7NwZT6uvSrOnIFUyMsxhh8xCkVY82VLTAZhPXB8t6CbyjZ5stos6WmNZgoEsD8GU8pmzSTubAqQXkTbiODF2pePe6S9uQ9HngGGBnOjY4QUcAcScDsfflyXVqyxgTelGD4vXoba6qRWCqc9LKpyk4jCKYvLX9tzXusO7bhT2KRvF4MObDqdE4KnCCIF3zeVD0vImR20MmRTBHRCNm3s6GfyeTYEAlW3L2igZJ7Myj5zGLccMt2EohGc38HfWZ4mlvXRLHKB233PyKALYifqlAxTXaWUk13o6nACQDvN7DxSCA0daJeuznK1Dr52bC4IXCTahK1An6LkQMfsXb7Qus6ey241Vb4wTgFHqsdCx7qPxeAghmsTOHRVl")
    ],
    "body": ''
}
Пример #45
0
from gunicorn.config import Config
from gunicorn.http.errors import InvalidProxyLine

cfg = Config()
cfg.set("proxy_protocol", True)

request = InvalidProxyLine
Пример #46
0
class DjangoApplicationCommand(DjangoApplication):
    
    def __init__(self, options, admin_media_path):
        self.usage = None
        self.cfg = None
        self.config_file = options.get("config") or ""
        self.options = options
        self.admin_media_path = admin_media_path
        self.callable = None
        self.project_path = None
          
        self.do_load_config()

        for k, v in self.options.items():
            if k.lower() in self.cfg.settings and v is not None:
                self.cfg.set(k.lower(), v)
       
    def load_config(self):
        self.cfg = Config()
        
        if self.config_file and os.path.exists(self.config_file):
            cfg = {
                "__builtins__": __builtins__,
                "__name__": "__config__",
                "__file__": self.config_file,
                "__doc__": None,
                "__package__": None
            }

            try:
                execfile(self.config_file, cfg, cfg)
            except Exception:
                print "Failed to read config file: %s" % self.config_file
                traceback.print_exc()
                sys.exit(1)
        
            for k, v in cfg.items():
                # Ignore unknown names
                if k not in self.cfg.settings:
                    continue
                try:
                    self.cfg.set(k.lower(), v)
                except:
                    sys.stderr.write("Invalid value for %s: %s\n\n" % (k, v))
                    raise
       
        for k, v in self.options.items():
            if k.lower() in self.cfg.settings and v is not None:
                self.cfg.set(k.lower(), v)


    def get_settings_modname(self):
        from django.conf import ENVIRONMENT_VARIABLE

        settings_modname = None
        project_path = os.getcwd()
        try:
            settings_modname = os.environ[ENVIRONMENT_VARIABLE]
        except KeyError:
            settings_path = os.path.join(project_path, "settings.py")
            if not os.path.exists(settings_path):
                return self.no_settings(settings_path)
        
        if not settings_modname:
            project_name = os.path.split(project_path)[-1]
            settings_name, ext  = os.path.splitext(
                    os.path.basename(settings_path))
            settings_modname = "%s.%s" % (project_name, settings_name)
            os.environ[ENVIRONMENT_VARIABLE] = settings_modname

        self.cfg.set("default_proc_name", settings_modname)
        # add the project path to sys.path
        if not project_path in sys.path:
            # remove old project path from sys.path
            if self.project_path is not None:
                idx = sys.path.find(self.project_path)
                if idx >= 0:
                    del sys.path[idx]
            self.project_path = project_path
            sys.path.insert(0, project_path)
            sys.path.append(os.path.normpath(os.path.join(project_path,
                os.pardir)))

        # reload django settings
        self.reload_django_settings(settings_modname)

        return settings_modname

    def reload_django_settings(self, settings_modname):
        from django.conf import settings
        from django.utils import importlib
        
        mod = importlib.import_module(settings_modname)

        # reload module
        reload(mod)

        # reload settings.
        # USe code from django.settings.Settings module.

        # Settings that should be converted into tuples if they're mistakenly entered
        # as strings.
        tuple_settings = ("INSTALLED_APPS", "TEMPLATE_DIRS")

        for setting in dir(mod):
            if setting == setting.upper():
                setting_value = getattr(mod, setting)
                if setting in tuple_settings and type(setting_value) == str:
                    setting_value = (setting_value,) # In case the user forgot the comma.
                setattr(settings, setting, setting_value)

        # Expand entries in INSTALLED_APPS like "django.contrib.*" to a list
        # of all those apps.
        new_installed_apps = []
        for app in settings.INSTALLED_APPS:
            if app.endswith('.*'):
                app_mod = importlib.import_module(app[:-2])
                appdir = os.path.dirname(app_mod.__file__)
                app_subdirs = os.listdir(appdir)
                app_subdirs.sort()
                name_pattern = re.compile(r'[a-zA-Z]\w*')
                for d in app_subdirs:
                    if name_pattern.match(d) and os.path.isdir(os.path.join(appdir, d)):
                        new_installed_apps.append('%s.%s' % (app[:-2], d))
            else:
                new_installed_apps.append(app)
        setattr(settings, "INSTALLED_APPS", new_installed_apps)

        if hasattr(time, 'tzset') and settings.TIME_ZONE:
            # When we can, attempt to validate the timezone. If we can't find
            # this file, no check happens and it's harmless.
            zoneinfo_root = '/usr/share/zoneinfo'
            if (os.path.exists(zoneinfo_root) and not
                    os.path.exists(os.path.join(zoneinfo_root,
                        *(settings.TIME_ZONE.split('/'))))):
                raise ValueError("Incorrect timezone setting: %s" %
                        settings.TIME_ZONE)
            # Move the time zone info into os.environ. See ticket #2315 for why
            # we don't do this unconditionally (breaks Windows).
            os.environ['TZ'] = settings.TIME_ZONE
            time.tzset()

        # Settings are configured, so we can set up the logger if required
        if getattr(settings, 'LOGGING_CONFIG', False):
            # First find the logging configuration function ...
            logging_config_path, logging_config_func_name = settings.LOGGING_CONFIG.rsplit('.', 1)
            logging_config_module = importlib.import_module(logging_config_path)
            logging_config_func = getattr(logging_config_module, logging_config_func_name)

            # ... then invoke it with the logging settings
            logging_config_func(settings.LOGGING)

    def load(self):
        from django.core.handlers.wsgi import WSGIHandler
        
        # reload django settings and setup environ
        self.setup_environ(self.get_settings_modname())

        # validate models and activate translation
        self.validate() 
        self.activate_translation()
        
        from django.core.servers.basehttp import AdminMediaHandler, WSGIServerException

        try:
            return  AdminMediaHandler(WSGIHandler(), self.admin_media_path)
        except WSGIServerException, e:
            # Use helpful error messages instead of ugly tracebacks.
            ERRORS = {
                13: "You don't have permission to access that port.",
                98: "That port is already in use.",
                99: "That IP address can't be assigned-to.",
            }
            try:
                error_text = ERRORS[e.args[0].args[0]]
            except (AttributeError, KeyError):
                error_text = str(e)
            sys.stderr.write(self.style.ERROR("Error: %s" % error_text) + '\n')
            sys.exit(1)
Пример #47
0
from gunicorn.config import Config

cfg = Config()
cfg.set("proxy_protocol", True)

req1 = {
    "method": "GET",
    "uri": uri("/stuff/here?foo=bar"),
    "version": (1, 1),
    "headers": [
        ("SERVER", "http://127.0.0.1:5984"),
        ("CONTENT-TYPE", "application/json"),
        ("CONTENT-LENGTH", "14"),
        ("CONNECTION", "keep-alive")
    ],
    "body": '{"nom": "nom"}'
}


req2 = {
    "method": "POST",
    "uri": uri("/post_chunked_all_your_base"),
    "version": (1, 1),
    "headers": [
        ("TRANSFER-ENCODING", "chunked"),
        ],
    "body": "all your base are belong to us"
}

request = [req1, req2]
Пример #48
0
from gunicorn.config import Config

cfg = Config()
cfg.set('proxy_protocol', True)

request = {
    "method": "GET",
    "uri": uri("/stuff/here?foo=bar"),
    "version": (1, 0),
    "headers": [
        ("SERVER", "http://127.0.0.1:5984"),
        ("CONTENT-TYPE", "application/json"),
        ("CONTENT-LENGTH", "14")
    ],
    "body": b'{"nom": "nom"}'
}
Пример #49
0
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)
Пример #50
0
class NexusServer(gunicorn.app.base.Application):

    def __init__(self, usage=None, prog=None):
        super(NexusServer, self).__init__(usage=usage, prog=prog)

    def load_config(self):
        self.cfg = Config(self.usage, prog=self.prog)
        self.cfg.set("default_proc_name", self.prog)
        self.cfg.set("proc_name", self.prog)
        self.cfg.set("preload_app", True)
        self.cfg.set("chdir", install_path)
        self.cfg.set("bind", pdnsnexus.app.config['SERVER_BIND'])
        self.cfg.set("workers", pdnsnexus.app.config['SERVER_WORKERS'])
        self.cfg.set("max_requests", pdnsnexus.app.config['SERVER_MAX_REQUESTS'])
        parser = argparse.ArgumentParser(prog=self.prog)
        parser.add_argument("--daemon", action='store', type=pdnsnexus.utils.powerbool, default=True,
                            help="Run as background process (default=%(default)s)")
        parser.add_argument("--pid", dest='pidfile', metavar='FILE', action='store',
                            help="If set, write PID to file FILE")
        args = parser.parse_args()
        self.cfg.set("daemon", args.daemon)
        if args.daemon:
            self.cfg.set("logger_class", NexusServerBackgroundLogger)
        self.cfg.set("pidfile", args.pidfile)

    def load(self):
        # bridge gunicorn and pdnsnexus logging together
        for handler in logging.getLogger("gunicorn.error").handlers:
            pdnsnexus.app.logger.addHandler(handler)
        pdnsnexus.app.logger.setLevel(logging.WARN)
        return pdnsnexus.app
Пример #51
0
from gunicorn.config import Config
from gunicorn.http.errors import InvalidSchemeHeaders

request = InvalidSchemeHeaders
cfg = Config()
cfg.set('forwarded_allow_ips', '*')
Пример #52
0
class DjangoApplicationCommand(DjangoApplication):
    
    def __init__(self, options, admin_media_path):
        self.usage = None
        self.cfg = None
        self.config_file = options.get("config") or ""
        self.options = options
        self.admin_media_path = admin_media_path
        self.callable = None
         
        self.init()
        self.do_load_config()

        for k, v in self.options.items():
            if k.lower() in self.cfg.settings and v is not None:
                self.cfg.set(k.lower(), v)
       
    def init(self):
        self.settings_modname = os.environ[ENVIRONMENT_VARIABLE]
        self.project_name = self.settings_modname.split('.')[0]
        self.project_path = os.getcwd()

        # remove all modules related to djano
        #for modname, mod in sys.modules.items():
        #    if 'settings' in modname.split('.') or \
        #            modname.startswith(self.project_name):
        #        del sys.modules[modname] 

        # add the project path to sys.path
        sys.path.insert(0, self.project_path)
        sys.path.append(os.path.normpath(os.path.join(self.project_path,
            os.pardir)))


    def load_config(self):
        self.cfg = Config()
        
        if self.config_file and os.path.exists(self.config_file):
            cfg = {
                "__builtins__": __builtins__,
                "__name__": "__config__",
                "__file__": self.config_file,
                "__doc__": None,
                "__package__": None
            }

            try:
                execfile(self.config_file, cfg, cfg)
            except Exception:
                print "Failed to read config file: %s" % self.config_file
                traceback.print_exc()
                sys.exit(1)
        
            for k, v in cfg.items():
                # Ignore unknown names
                if k not in self.cfg.settings:
                    continue
                try:
                    self.cfg.set(k.lower(), v)
                except:
                    sys.stderr.write("Invalid value for %s: %s\n\n" % (k, v))
                    raise
       
        for k, v in self.options.items():
            if k.lower() in self.cfg.settings and v is not None:
                self.cfg.set(k.lower(), v)

    def load(self):
        from django.conf import ENVIRONMENT_VARIABLE
        from django.core.handlers.wsgi import WSGIHandler
        os.environ[ENVIRONMENT_VARIABLE] = self.settings_modname

        self.setup_environ()
        self.validate() 
        self.activate_translation()
        
        from django.core.servers.basehttp import AdminMediaHandler, WSGIServerException

        try:
            return  AdminMediaHandler(WSGIHandler(), self.admin_media_path)
        except WSGIServerException, e:
            # Use helpful error messages instead of ugly tracebacks.
            ERRORS = {
                13: "You don't have permission to access that port.",
                98: "That port is already in use.",
                99: "That IP address can't be assigned-to.",
            }
            try:
                error_text = ERRORS[e.args[0].args[0]]
            except (AttributeError, KeyError):
                error_text = str(e)
            sys.stderr.write(self.style.ERROR("Error: %s" % error_text) + '\n')
            sys.exit(1)
Пример #53
0
from gunicorn.config import Config
from gunicorn.http.errors import LimitRequestHeaders

request = LimitRequestHeaders
cfg = Config()
cfg.set('limit_request_field_size', 98)