Exemplo n.º 1
0
    def test_success(self):
        """
        If ``WSGI_APPLICATION`` is a dotted path, the referenced object is
        returned.

        """
        app = get_internal_wsgi_application()

        from .wsgi import application

        self.assertTrue(app is application)
Exemplo n.º 2
0
    def test_default(self):
        """
        If ``WSGI_APPLICATION`` is ``None``, the return value of
        ``get_wsgi_application`` is returned.

        """
        # Mock out get_wsgi_application so we know its return value is used
        fake_app = object()
        def mock_get_wsgi_app():
            return fake_app
        from djangocg.core.servers import basehttp
        _orig_get_wsgi_app = basehttp.get_wsgi_application
        basehttp.get_wsgi_application = mock_get_wsgi_app

        try:
            app = get_internal_wsgi_application()

            self.assertTrue(app is fake_app)
        finally:
            basehttp.get_wsgi_application = _orig_get_wsgi_app
Exemplo n.º 3
0
def runfastcgi(argset=[], **kwargs):
    options = FASTCGI_OPTIONS.copy()
    options.update(kwargs)
    for x in argset:
        if "=" in x:
            k, v = x.split('=', 1)
        else:
            k, v = x, True
        options[k.lower()] = v

    if "help" in options:
        return fastcgi_help()

    try:
        import flup
    except ImportError as e:
        sys.stderr.write("ERROR: %s\n" % e)
        sys.stderr.write("  Unable to load the flup package.  In order to run django\n")
        sys.stderr.write("  as a FastCGI application, you will need to get flup from\n")
        sys.stderr.write("  http://www.saddi.com/software/flup/   If you've already\n")
        sys.stderr.write("  installed flup, then make sure you have it in your PYTHONPATH.\n")
        return False

    flup_module = 'server.' + options['protocol']

    if options['method'] in ('prefork', 'fork'):
        wsgi_opts = {
            'maxSpare': int(options["maxspare"]),
            'minSpare': int(options["minspare"]),
            'maxChildren': int(options["maxchildren"]),
            'maxRequests': int(options["maxrequests"]),
        }
        flup_module += '_fork'
    elif options['method'] in ('thread', 'threaded'):
        wsgi_opts = {
            'maxSpare': int(options["maxspare"]),
            'minSpare': int(options["minspare"]),
            'maxThreads': int(options["maxchildren"]),
        }
    else:
        return fastcgi_help("ERROR: Implementation must be one of prefork or "
                            "thread.")

    wsgi_opts['debug'] = options['debug'] is not None

    try:
        module = importlib.import_module('.%s' % flup_module, 'flup')
        WSGIServer = module.WSGIServer
    except Exception:
        print("Can't import flup." + flup_module)
        return False

    # Prep up and go
    from djangocg.core.servers.basehttp import get_internal_wsgi_application

    if options["host"] and options["port"] and not options["socket"]:
        wsgi_opts['bindAddress'] = (options["host"], int(options["port"]))
    elif options["socket"] and not options["host"] and not options["port"]:
        wsgi_opts['bindAddress'] = options["socket"]
    elif not options["socket"] and not options["host"] and not options["port"]:
        wsgi_opts['bindAddress'] = None
    else:
        return fastcgi_help("Invalid combination of host, port, socket.")

    if options["daemonize"] is None:
        # Default to daemonizing if we're running on a socket/named pipe.
        daemonize = (wsgi_opts['bindAddress'] is not None)
    else:
        if options["daemonize"].lower() in ('true', 'yes', 't'):
            daemonize = True
        elif options["daemonize"].lower() in ('false', 'no', 'f'):
            daemonize = False
        else:
            return fastcgi_help("ERROR: Invalid option for daemonize "
                                "parameter.")

    daemon_kwargs = {}
    if options['outlog']:
        daemon_kwargs['out_log'] = options['outlog']
    if options['errlog']:
        daemon_kwargs['err_log'] = options['errlog']
    if options['umask']:
        daemon_kwargs['umask'] = int(options['umask'], 8)

    if daemonize:
        from djangocg.utils.daemonize import become_daemon
        become_daemon(our_home_dir=options["workdir"], **daemon_kwargs)

    if options["pidfile"]:
        with open(options["pidfile"], "w") as fp:
            fp.write("%d\n" % os.getpid())

    WSGIServer(get_internal_wsgi_application(), **wsgi_opts).run()
Exemplo n.º 4
0
 def get_handler(self, *args, **options):
     """
     Returns the default WSGI handler for the runner.
     """
     return get_internal_wsgi_application()
Exemplo n.º 5
0
    def test_bad_name(self):
        with self.assertRaisesRegexp(
            ImproperlyConfigured,
            r"^WSGI application 'regressiontests.wsgi.wsgi.noexist' could not be loaded; can't find 'noexist' in module 'regressiontests.wsgi.wsgi':"):

            get_internal_wsgi_application()
Exemplo n.º 6
0
    def test_bad_module(self):
        with self.assertRaisesRegexp(
            ImproperlyConfigured,
            r"^WSGI application 'regressiontests.wsgi.noexist.app' could not be loaded; could not import module 'regressiontests.wsgi.noexist':"):

            get_internal_wsgi_application()