ó
	GÏOc           @   sù   d  Z  d d l Z d d l Z d d l m Z d Z d g Z i d d 6d d 6d d	 6d d
 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6Z d e Z	 d d „ Z
 g  d „ Z e d  k rõ e e j d! ƒ n  d S("   sì  
FastCGI (or SCGI, or AJP1.3 ...) server that implements the WSGI protocol.

Uses the flup python package: http://www.saddi.com/software/flup/

This is a adaptation of the flup package to add FastCGI server support
to run Django apps from Web servers that support the FastCGI protocol.
This module can be run standalone or from the django-admin / manage.py
scripts using the "runfcgi" directive.

Run with the extra option "help" for a list of additional options you can
pass to this server.
iÿÿÿÿN(   t	   importlibs   0.1t
   runfastcgit   fcgit   protocolt   hostt   portt   sockett   forkt   methodt	   daemonizet   /t   workdirt   pidfilei   t   maxsparei   t   minsparei2   t   maxchildreni    t   maxrequestst   debugt   outlogt   errlogt   umasksÄ  
  Run this project as a fastcgi (or some other protocol supported
  by flup) application. To do this, the flup package from
  http://www.saddi.com/software/flup/ is required.

   runfcgi [options] [fcgi settings]

Optional Fcgi settings: (setting=value)
  protocol=PROTOCOL    fcgi, scgi, ajp, ... (default %(protocol)s)
  host=HOSTNAME        hostname to listen on.
  port=PORTNUM         port to listen on.
  socket=FILE          UNIX socket to listen on.
  method=IMPL          prefork or threaded (default %(method)s).
  maxrequests=NUMBER   number of requests a child handles before it is
                       killed and a new child is forked (0 = no limit).
  maxspare=NUMBER      max number of spare processes / threads (default %(maxspare)s).
  minspare=NUMBER      min number of spare processes / threads (default %(minspare)s).
  maxchildren=NUMBER   hard limit number of processes / threads (default %(maxchildren)s).
  daemonize=BOOL       whether to detach from terminal.
  pidfile=FILE         write the spawned process-id to this file.
  workdir=DIRECTORY    change to this directory when daemonizing (default %(workdir)s).
  debug=BOOL           set to true to enable flup tracebacks.
  outlog=FILE          write stdout to this file.
  errlog=FILE          write stderr to this file.
  umask=UMASK          umask to use when daemonizing, in octal notation (default 022).

Examples:
  Run a "standard" fastcgi process on a file-descriptor
  (for Web servers which spawn your processes for you)
    $ manage.py runfcgi method=threaded

  Run a scgi server on a TCP host/port
    $ manage.py runfcgi protocol=scgi method=prefork host=127.0.0.1 port=8025

  Run a fastcgi server on a UNIX domain socket (posix platforms only)
    $ manage.py runfcgi method=prefork socket=/tmp/fcgi.sock

  Run a fastCGI as a daemon and write the spawned PID in a file
    $ manage.py runfcgi socket=/tmp/fcgi.sock method=prefork \
        daemonize=true pidfile=/var/run/django-fcgi.pid

c         C   s   t  GH|  r |  GHn  t S(   N(   t   FASTCGI_HELPt   False(   t   message(    (    s4   ../Django//lib/python/django/core/servers/fastcgi.pyt   fastcgi_helpT   s    c         K   s'  t  j ƒ  } | j | ƒ xR |  D]J } d | k rM | j d d ƒ \ } } n | t } } | | | j ƒ  <q  Wd | k r t ƒ  Sy d d  l } Wnh t k
 rû } t	 j
 j d | ƒ t	 j
 j d ƒ t	 j
 j d ƒ t	 j
 j d ƒ t	 j
 j d	 ƒ t SXd
 | d } | d d: k rqi t | d ƒ d 6t | d ƒ d 6t | d ƒ d 6t | d ƒ d 6}	 | d 7} nV | d d; k r½i t | d ƒ d 6t | d ƒ d 6t | d ƒ d 6}	 n
 t d ƒ S| d d  k	 |	 d <y# t j d | d ƒ }
 |
 j } Wn t k
 rd | GHt SXd d  l m } | d! rl| d" rl| d# rl| d! t | d" ƒ f |	 d$ <ni | d# r| d! r| d" r| d# |	 d$ <n8 | d# rË| d! rË| d" rËd  |	 d$ <n
 t d% ƒ S| d& d  k rø|	 d$ d  k	 } nH | d& j ƒ  d< k rt } n) | d& j ƒ  d= k r6t } n
 t d- ƒ Si  } | d. ra| d. | d/ <n  | d0 r|| d0 | d1 <n  | d2 r t | d2 d3 ƒ | d2 <n  | rÍd d4 l m } | d5 | d6 |  n  | d7 rt | d7 d8 ƒ  } | j d9 t j ƒ  ƒ Wd  QXn  | | ƒ  |	  j ƒ  d  S(>   Nt   =i   t   helpiÿÿÿÿs
   ERROR: %s
s;     Unable to load the flup package.  In order to run django
s;     as a FastCGI application, you will need to get flup from
s:     http://www.saddi.com/software/flup/   If you've already
sA     installed flup, then make sure you have it in your PYTHONPATH.
s   server.R   R   t   preforkR   R   t   maxSpareR   t   minSpareR   t   maxChildrenR   t   maxRequestst   _forkt   threadt   threadedt
   maxThreadss7   ERROR: Implementation must be one of prefork or thread.R   s   .%st   flups   Can't import flup.(   t   get_internal_wsgi_applicationR   R   R   t   bindAddresss*   Invalid combination of host, port, socket.R	   t   truet   yest   tt   falset   not   fs.   ERROR: Invalid option for daemonize parameter.R   t   out_logR   t   err_logR   i   (   t   become_daemont   our_home_dirR   R   t   ws   %d
(   R   s   fork(   s   threadR"   (   s   trues   yesR)   (   s   falses   noR,   (   t   FASTCGI_OPTIONSt   copyt   updatet   splitt   Truet   lowerR   R$   t   ImportErrort   syst   stderrt   writeR   t   intt   NoneR    t   import_modulet
   WSGIServert	   Exceptiont   django.core.servers.basehttpR%   t   django.utils.daemonizeR/   t   opent   ost   getpidt   run(   t   argsett   kwargst   optionst   xt   kt   vR$   t   et   flup_modulet	   wsgi_optst   moduleR?   R%   R	   t   daemon_kwargsR/   t   fp(    (    s4   ../Django//lib/python/django/core/servers/fastcgi.pyR   Z   sˆ    
	! !
		




 t   __main__i   (   t   __doc__RD   R9   t   django.utilsR    t   __version__t   __all__R=   R2   R   R   R   t   __name__t   argv(    (    (    s4   ../Django//lib/python/django/core/servers/fastcgi.pyt   <module>   s6   	
,
^