Django

Code

Ticket #3047: generalize_flup.diff

File generalize_flup.diff, 2.9 kB (added by Barry Pederson <bp@barryp.org>, 2 years ago)

Suggested enhancement

  • django/core/servers/fastcgi.py

    old new  
    11""" 
    2 FastCGI server that implements the WSGI protocol. 
     2FastCGI (or SCGI, or AJP1.3 ...) server that implements the WSGI protocol. 
    33 
    44Uses the flup python package: http://www.saddi.com/software/flup/ 
    55 
     
    1818__all__ = ["runfastcgi"] 
    1919 
    2020FASTCGI_HELP = r"""runfcgi: 
    21   Run this project as a fastcgi application. To do this, the 
    22   flup package from http://www.saddi.com/software/flup/ is 
    23   required. 
     21  Run this project as a fastcgi (or some other protocol supported 
     22  by flup) application. To do this, the flup package from 
     23  http://www.saddi.com/software/flup/ is required. 
    2424 
    2525Usage: 
    2626   django-admin.py runfcgi --settings=yourproject.settings [fcgi settings] 
    2727   manage.py runfcgi [fcgi settings] 
    2828 
    2929Optional Fcgi settings: (setting=value) 
     30  protocol=PROTOCOL    fcgi, scgi, ajp, ... (default fcgi) 
    3031  host=HOSTNAME        hostname to listen on.. 
    3132  port=PORTNUM         port to listen on. 
    3233  socket=FILE          UNIX socket to listen on. 
     
    4546  (for webservers which spawn your processes for you) 
    4647    $ manage.py runfcgi method=threaded 
    4748 
    48   Run a fastcgi server on a TCP host/port 
    49     $ manage.py runfcgi method=prefork host=127.0.0.1 port=8025 
     49  Run a scgi server on a TCP host/port 
     50    $ manage.py runfcgi protocol=scgi method=prefork host=127.0.0.1 port=8025 
    5051 
    5152  Run a fastcgi server on a UNIX domain socket (posix platforms only) 
    5253    $ manage.py runfcgi method=prefork socket=/tmp/fcgi.sock 
     
    5859""" 
    5960 
    6061FASTCGI_OPTIONS = { 
     62    'protocol': 'fcgi', 
    6163    'host': None, 
    6264    'port': None, 
    6365    'socket': None, 
     
    100102        print >> sys.stderr, "  installed flup, then make sure you have it in your PYTHONPATH." 
    101103        return False 
    102104 
     105    flup_module = 'server.' + options['protocol'] 
     106 
    103107    if options['method'] in ('prefork', 'fork'): 
    104         from flup.server.fcgi_fork import WSGIServer 
    105108        wsgi_opts = { 
    106109            'maxSpare': int(options["maxspare"]), 
    107110            'minSpare': int(options["minspare"]), 
    108111            'maxChildren': int(options["maxchildren"]), 
    109112            'maxRequests': int(options["maxrequests"]),  
    110113        } 
     114        flup_module += '_fork' 
    111115    elif options['method'] in ('thread', 'threaded'): 
    112         from flup.server.fcgi import WSGIServer 
    113116        wsgi_opts = { 
    114117            'maxSpare': int(options["maxspare"]), 
    115118            'minSpare': int(options["minspare"]), 
     
    118121    else: 
    119122        return fastcgi_help("ERROR: Implementation must be one of prefork or thread.") 
    120123 
     124    try: 
     125        WSGIServer = getattr(__import__('flup.' + flup_module, '', '', flup_module), 'WSGIServer') 
     126    except: 
     127        print "Can't import flup." + flup_module 
     128        return False 
     129 
    121130    # Prep up and go 
    122131    from django.core.handlers.wsgi import WSGIHandler 
    123132