%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/227033/root/opt/alt/python27/lib/python2.7/site-packages/paste/
Upload File :
Create Path :
Current File : //proc/227033/root/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyc

�
a�Nc@sDdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddlmZmZddlmZddlmZddlZyddlmZWnek
reZnXdd	d
dgZdZd
efd��YZdfd��YZy2ddlm Z m!Z!ej"e j#e j$fZ%Wn9ek
r�eZ ej"fZ%defd��YZ&n6Xdefd��YZ'defd��YZ&d�Z(d
eefd��YZ)defd��YZ*defd��YZ+defd��YZ,de&fd��YZ-d	ee-fd ��YZ.d!e,e-fd"��YZ/d#e0fd$��YZ1eeeeeeee2eeed%ed&d'�Z3d(�Z4e3jp�d)d*e4_e5d+kr@dd,l6m7Z7e3e7d-d.d/d0d1d2�ndS(3s�
WSGI HTTP Server

This is a minimalistic WSGI server using Python's built-in BaseHTTPServer;
if pyOpenSSL is installed, it also provides SSL capabilities.
i����N(tcount(tBaseHTTPRequestHandlert
HTTPServer(tThreadingMixIn(t
converters(t
killthreadtWSGIHandlerMixint
WSGIServertWSGIHandlertserves0.5tContinueHookcBsDeZdZd�Zd�Zdd�Zdd�Zdd�ZRS(sN
    When a client request includes a 'Expect: 100-continue' header, then
    it is the responsibility of the server to send 100 Continue when it
    is ready for the content body.  This allows authentication, access
    levels, and other exceptions to be detected *before* bandwith is
    spent on the request body.

    This is a rfile wrapper that implements this functionality by
    sending 100 Continue to the client immediately after the user
    requests the content via a read() operation on the rfile stream.
    After this response is sent, it becomes a pass-through object.
    cCs�||_||_x9dD]1}t||�rt||t||��qqWx=d
D]5}t||�rUt||t|d|��qUqUWdS(Ntclosetclosedtfilenotflushtmodetbufsizet	softspacetreadtreadlinet	readlinest_ContinueFile_(sclosesclosedsfilenosflushsmodesbufsizes	softspace(sreadsreadlines	readlines(t_ContinueFile_rfilet_ContinueFile_writethasattrtsetattrtgetattr(tselftrfiletwritetattr((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyt__init__7s		
 
cCsV|jd�|j}x9dD]1}t||�rt||t||��qqWdS(NsHTTP/1.1 100 Continue

RRR(sreadsreadlines	readlines(RRRRR(RRR((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyt_ContinueFile_sendBs

	
i����cCs|j�|jj|�S(N(R RR(Rtsize((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyt_ContinueFile_readIs
cCs|j�|jj|�S(N(R RR(RR!((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyt_ContinueFile_readlineMs
icCs|j�|jj|�S(N(R RR(Rtsizehint((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyt_ContinueFile_readlinesQs
(t__name__t
__module__t__doc__RR R"R#R%(((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR
)s		cBsheZdZeZd�Zd�Zd�Zd�Zd	d�Z
d	d�Zd	d�Zd	d�Z
RS(
s�
    WSGI mix-in for HTTPRequestHandler

    This class is a mix-in to provide WSGI functionality to any
    HTTPRequestHandler derivative (as provided in Python's BaseHTTPServer).
    This assumes a ``wsgi_application`` handler on ``self.server``.
    cOsdS(s� disable success request logging

        Logging transactions should not be part of a WSGI server,
        if you want logging; look at paste.translogger
        N((Rtargstkwargs((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pytlog_request_scOsdS(s� disable error message logging

        Logging transactions should not be part of a WSGI server,
        if you want logging; look at paste.translogger
        N((RR)R*((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pytlog_messagegscCs&|js|jS|jd|jSdS(s. behavior that BaseHTTPServer should have had t N(tsys_versiontserver_version(R((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pytversion_stringos	c
Cs6|jr#|jr#td��n|js"t|_|j\}}|jdd�\}}|jt|�|�t}xx|D]p\}}|j�}	d|	kr�t}nd|	kr�d|j�kr�d|_	t}q�n|j
||�qW|rd|_	|j
dd�n|j�n|jj
|�dS(	sn
        Write a chunk of the output stream; send headers if they
        have not already been sent.
        s-Content returned before start_response calledR-iscontent-lengtht
connectionRt
ConnectionN(twsgi_headers_senttwsgi_curr_headerstRuntimeErrortTruetsplitt
send_responsetinttlowertFalsetclose_connectiontsend_headertend_headerstwfileR(
Rtchunktstatustheaderstcodetmessaget
send_closetktvtlk((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pytwsgi_write_chunkvs.					
cCso|r;z(|jr-|d|d|d�nWdd}Xn|jrYdsYtd��n||f|_|jS(Niiis4Attempt to set headers a second time w/o an exc_info(R3tNoneR4tAssertionErrorRI(RRAtresponse_headerstexc_info((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pytwsgi_start_response�s	
	cCs�tj|j�\}}}}}tj|�}|jd�}tj|�}|rm|dkrm|d7}n|jj	d \}}	|j
}
yt|jj
dd��}Wntk
r�d}nXd|jj
dd�j�krtt|
|jj�|�}
n$t|jd	�s+t|
|�}
n|jd}id0d6dd
6|
d6tjd6td6td6td6|jd6dd6|d6|d6|jj
dd�d6|jj
dd�d6|d6t|	�d6|jd6|d6|_|r�||jd<n|r||jd<n|jri|j d �sf|j d!�sf|j d"�rJqid/}
|
ri|
|jd#<qint|jd$�r�|j|jj"j#t$j%�d
<|jj"|jd%<nxm|jj&�D]\\}}d&|j'd'd(�j(�}|d1kr�q�nd+j)|jj*|��|j|<q�Wt|jd	�rCd,|jd
<n|r�t+|t,�s^t-�|jj.|�d-|j
d.�kr�d,|jd
<q�nd/|_/t|_0d/S(2s
        Setup the member variables used by this WSGI mixin, including
        the ``environ`` and status member variables.

        After the basic environment is created; the optional ``environ``
        argument can be used to override any settings.
        t/isContent-Lengtht0is100-continuetExpectttget_contextiswsgi.versionthttpswsgi.url_schemes
wsgi.inputswsgi.errorsswsgi.multithreadswsgi.multiprocesss
wsgi.run_oncetREQUEST_METHODtSCRIPT_NAMEt	PATH_INFOtQUERY_STRINGsContent-TypetCONTENT_TYPEtCONTENT_LENGTHtSERVER_NAMEtSERVER_PORTtSERVER_PROTOCOLtREMOTE_ADDRspaste.httpserver.proxy.schemespaste.httpserver.proxy.hosts192.168.s10.s172.16.tREMOTE_HOSTtthread_poolspaste.httpserver.thread_pooltHTTP_t-t_tHTTP_CONTENT_TYPEtHTTP_CONTENT_LENGTHt,thttpstontHTTPSN(ii(RdRe(1turlparseturlsplittpathturllibtunquotetendswitht	posixpathtnormpathtservertserver_addressRR9RBtgett
ValueErrorR:tLimitedLengthFileR
R?RRR1tclient_addresstsyststderrR6R;tcommandtstrtrequest_versiontwsgi_environtlookup_addressest
startswithRJR`tworker_trackertthreadt	get_identtitemstreplacetuppertjoint
getheaderst
isinstancetdictRKtupdateR4R3(RtenvirontschemetnetlocRltquerytfragmenttendslashtserver_nametserver_portRtcontent_lengthtremote_addresstaddress_stringRFRGtkey((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyt
wsgi_setup�s�	!
	

!!





	 &	cCsdS(s�
        Override this if you're interested in socket exceptions, such
        as when the user clicks 'Cancel' during a file download.
        N((RtexceR�((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pytwsgi_connection_dropscCs
|j|�y�|jj|j|j�}z;x|D]}|j|�q5W|jse|jd�nWdt|d�r�|j�nd}XWnvt
jk
r�}|j||�dS|js�d}dd	dt
t|��fgf|_|jd�n�nXdS(
s;
        Invoke the server's ``wsgi_application``.
        RRNRsInternal Server Error
s500 Internal Server ErrorsContent-types
text/plainsContent-length(sContent-types
text/plain(R�Rrtwsgi_applicationR}RNRIR3RRRJtsocketterrorR�R{tlenR4(RR�tresultR@R�t	error_msg((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pytwsgi_executes.

	
	!N(R&R'R(R6R~R+R,R0RIRJRNR�R�R�(((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyRUs				"d(tSSLttsafetSecureHTTPServercBseZddd�ZRS(cCsC|std��tj|||�|r?|jj|�ndS(NspyOpenSSL not installed(RKRRR�tlisten(RRstRequestHandlerClasstssl_contexttrequest_queue_size((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyRDsN(R&R'RJR(((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR�Cst
_ConnFixercBs)eZdZd�Zd�Zd�ZRS(s5 wraps a socket connection so it implements makefile cCs
||_dS(N(t_ConnFixer__conn(Rtconn((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyRNscCstj|j||�S(N(R�t_fileobjectR�(RRR((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pytmakefilePscCst|j|�S(N(RR�(Rtattrib((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyt__getattr__Rs(R&R'R(RR�R�(((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR�Ls		cBs&eZdZddd�Zd�ZRS(s�
        Provides SSL server functionality on top of the BaseHTTPServer
        by overriding _private_ members of Python's standard
        distribution. The interface for this instance only changes by
        adding a an optional ssl_context attribute to the constructor:

              cntx = SSL.Context(SSL.SSLv23_METHOD)
              cntx.use_privatekey_file("host.pem")
              cntx.use_certificate_file("host.pem")

        cCs�tj|||�tj|j|j�|_||_|rndtjfd��Y}|||j�|_n|j�|r�|jj	|�n|j
�dS(NtTSafeConnectioncBseZd�Zd�ZRS(cWs6|jj�z|jj|�SWd|jj�XdS(N(t_locktacquiret	_ssl_connt
settimeouttrelease(RR)((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR�ms
cSs3|jj�z|jj�SWd|jj�XdS(N(R�R�R�t
gettimeoutR�(R((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR�ss
(R&R'R�R�(((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR�ls	(RRR�taddress_familytsocket_typeR�R�R2tserver_bindR�tserver_activate(RRsR�R�R�R�((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyRbs	

cCs7|jj�\}}|jr-t|�}n||fS(N(R�tacceptR�R�(RR�tinfo((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pytget_requests	N(R&R'R(RJRR�(((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR�UscCsddl}ddl}ddl}|jj�}|j|jjd�|jj�}|j|j	dt
j��|jd�|j
d�d|j�_d|j�_d	|j�_d
|j�_|j|�|j|d�tjtj�}|j|�|j|�|S(Ni����iii<iimt*sDummy CertificatesUntrusted AuthoritysSelf-Signedtmd5ii�Qi�3�(tOpenSSLttimetrandomtcryptotPKeytgenerate_keytTYPE_RSAtX509tset_serial_numbertrandintRxtmaxinttgmtime_adj_notBeforetgmtime_adj_notAftertget_subjecttCNtOt
get_issuert
set_pubkeytsignR�tContextt
SSLv23_METHODtuse_privatekeytuse_certificate(R�R�R�tpkeytcerttctx((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyt_auto_ssl_context�s"$




cBs3eZdZdeZd�Zd�Zd�ZRS(sy
    A WSGI handler that overrides POST, GET and HEAD to delegate
    requests to the server's ``wsgi_application``.
    sPasteWSGIServer/cCsF|jj�|_|js(d|_dS|j�s8dS|j�dS(s�Handle a single HTTP request.

        You normally don't need to override this method; see the class
        __doc__ string for information on how to handle specific HTTP
        commands such as GET and POST.

        iN(RRtraw_requestlineR<t
parse_requestR�(R((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pythandle_one_request�s		cCs8ytj|�Wn tk
r3}|j|�nXdS(N(RthandletSocketErrorsR�(RR�((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR��scCsdS(syReturn the client address formatted for logging.

        This is overridden so that no hostname lookup is done.
        RR((R((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR��s(R&R'R(t__version__R/R�R�R�(((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR�s

		RvcBs_eZd�Zd�Zd	d�Zd�Zd	d�Zd�Zd�Z	d�Z
d�ZRS(
cCs@||_||_d|_t|jd�r<|j|_ndS(Nitseek(tfiletlengtht	_consumedRt_seekR�(RR�R�((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR�s
			cCs"t|j�}|d d|jS(Ni����s length=%s>(treprR�R�(Rt	base_repr((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyt__repr__�scCsi|j|j}|dkr%|}nt||�}|s>dS|jj|�}|jt|�7_|S(NRR(R�R�RJtminR�RR�(RR�tlefttdata((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR�s	cGs]|j|j}t|�r2t|d|�}n|jj|�}|jt|�7_|S(Ni(R�R�R�R�R�R(RR)tmax_readR�((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR�scCs<|jj|�}x#|D]}|jt|�7_qW|S(N(R�RR�R�(RthintR�R@((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR�s
cCs|S(N((R((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyt__iter__�scCs)|j|jdkrt�n|j�S(Ni(R�R�t
StopIterationR(R((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pytnext�s	cCs|jj|�||_dS(N(R�R�R�(Rtplace((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR��scCs*t|jd�r|jj�S|jSdS(Nttell(RR�R�R�(R((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR��s
N(R&R'RR�RJRRRR�R�R�R�(((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyRv�s		
				t
ThreadPoolcBs�eZdZe�Zdedddddddddd�Zd	�Zd
�Z	d�Z
d�Zd
�Zd�Z
d�Zdd�Zdd�Zded�ZRS(s0
    Generic thread pool with a queue of callables to consume.

    Keeps a notion of the status of its worker threads:

    idle: worker thread with nothing to do

    busy: worker thread doing its job

    hung: worker thread that's been doing a job for too long

    dying: a hung thread that has been killed, but hasn't died quite
    yet.

    zombie: what was a worker thread that we've tried to kill but
    isn't dead yet.

    At any time you can call track_threads, to get a dictionary with
    these keys and lists of thread_ids that fall in that status.  All
    keys will be present, even if they point to emty lists.

    hung threads are threads that have been busy more than
    hung_thread_limit seconds.  Hung threads are killed when they live
    longer than kill_thread_limit seconds.  A thread is then
    considered dying for dying_limit seconds, if it is still alive
    after that it is considered a zombie.

    When there are no idle workers and a request comes in, another
    worker *may* be spawned.  If there are less than spawn_if_under
    threads in the busy state, another thread will be spawned.  So if
    the limit is 5, and there are 4 hung threads and 6 busy threads,
    no thread will be spawned.

    When there are more than max_zombie_threads_before_die zombie
    threads, a SystemExit exception will be raised, stopping the
    server.  Use 0 or None to never raise this exception.  Zombie
    threads *should* get cleaned up, but killing threads is no
    necessarily reliable.  This is turned off by default, since it is
    only a good idea if you've deployed the server with some process
    watching from above (something similar to daemontools or zdaemon).

    Each worker thread only processes ``max_requests`` tasks before it
    dies and replaces itself with a new worker thread.
    R�idiii,iic
Cs�||_||_||_tj�|_g|_||_|dkrZtj	d�}nt
|t�r{tj	|�}n||_||_
t�|_|s�||ks�td||f��ts�d}|jjd�n||_||_||_||kstd||f��||_|	|_|
|_d|_i|_g|_i|_d|_|stj|j �nx't!|j�D]}
|j"dd�q�WdS(	sD
        Create thread pool with `nworkers` worker threads.
        spaste.httpserver.ThreadPoolsCkill_thread_limit (%s) should be higher than hung_thread_limit (%s)isBCannot use kill_thread_limit as ctypes/killthread is not availables5spawn_if_under (%s) should be less than nworkers (%s)RDsInitial worker poolN(#tnworkerstmax_requeststnametQueuetqueuetworkerstdaemonRJtloggingt	getLoggerR�t
basestringtloggerterror_emailRt
_worker_countRKRR�tkill_thread_limittdying_limitthung_thread_limittspawn_if_undertmax_zombie_threads_before_diethung_check_periodtrequests_since_last_hung_checkR�tidle_workerst
dying_threadst_last_added_new_idle_workerstatexittregistertshutdowntrangetadd_worker_thread(RR�R�R�R�RRRRRRR�R�ti((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR0sN								
											cCsk|jjd|jj��|jr_|jd7_|j|jkr_d|_|j�q_n|jr�|jr�d}t	j	�}|jjd�xs|j
D]h}t|d�s�q�n|jj
|jd�\}}|d
k	r�|||jkr|d7}qq�q�W||jkrv|jjd||j|�t	j	�|_xAt|j|�D]}|jdd�qYWq�|jjd	|�nt|j
�|jkrWt|j�d
krWt	j	�|j|jkrW|jjdt|j
�|jt|j��|jjd|j�x:tt|j
�|j�D]}|jj|j�q7Wn|jj|�d
S(s)
        Add a task to the queue
        sAdded task (%i tasks queued)iisBNo idle workers for task; checking if we need to make more workerst	thread_ids=No idle tasks, and only %s busy tasks; adding %s more workersRDs Response to lack of idle workerss)No extra workers needed (%s busy workers)is2Culling %s extra workers (%s idle workers present)sIdle workers: %sN(NN(R�tdebugR�tqsizeRRtkill_hung_threadsRRR�R�RR�RtRRJRR�R	R
RR�R�tputtSHUTDOWN(Rttasktbusytnowtworkerttime_startedR�R((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pytadd_tasknsN				
	#	
#cCs~tdgdgdgdgdg�}tj�}x�|jD]�}t|d�sXq=n|jj|jd	�\}}|dk	r�|||jkr�|dj	|�q�|dj	|�q=|dj	|�q=Wx�|j
j�D]�\}\}}|j|�s>|j
jd|�y|j
|=Wq�tk
r7q�Xq�n|||jkre|dj	|�q�|dj	|�q�W|S(
sw
        Return a dict summarizing the threads in the pool (as
        described in the ThreadPool docstring).
        tidleRthungtdyingtzombieRs!Killed thread %s no longer aroundN(NN(R�R�R�RR�RtRRJRtappendRR�t
thread_existsR�R�tKeyErrorR(RR�RRRR�Rttime_killed((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyt
track_threads�s2'"
cCs�tdkrtd��ntjj|�}tj|t�y|j|=Wnt	k
r^nX|j
jd|�||jkr�|jj
|�ntj�|f|j|<|jdd|�dS(s�
        Removes the worker with the given thread_id from the pool, and
        replaces it with a new worker thread.

        This should only be done for mis-behaving workers.
        s3Cannot kill worker; killthread/ctypes not availablesKilling thread %sRDs Replacement for killed thread %sN(RRJR5t	threadingt_activeRttasync_raiset
SystemExitR�R"R�R�R�tremoveR�RR(RRt
thread_obj((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pytkill_worker�s
cCs
|tjkS(sH
        Returns true if a thread with this id is still running
        (R%R&(RR((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR!�sc
OsX|jj�}tjd|jd|d|dd|�}|j|j�|j�dS(NttargetR)R*R�s	worker %d(R�R�R%tThreadtworker_thread_callbackt	setDaemonR�tstart(RR)R*tindexR((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR�s
cCs|js
dStj�}d}d}d}d}d}d}xj|jD]_}t|d�sl|d7}qGn|jj|jd�\}	}
|	dkr�|d7}qGn|d7}t|||	�}|||	7}||	|jkrG|j	j
d|j||	�yddl}|j|
�}Wn0t
�}
tjd|
�d|
j�}nX|jd	td|jd
||	d|jd|��|j|j�|d7}qGqGW|r�t|�|}d
|}nd}|j	jd|||||||||f�|j�dS(s0
        Tries to kill any hung threads
        NiRis/Thread %s hung (working on task for %i seconds)i����R�s	Error:
%ss�Killing worker thread (id=%(thread_id)s) because it has been 
working on task for %(time)s seconds (limit is %(limit)s)
Info on task:
%(info)sR�tlimitR�s%.2fsecsN/Asxkill_hung_threads status: %s threads (%s working, %s idle, %s starting) ave time %s, max time %.2fsec, killed %s workers(NN(RR�R�RR�RtRRJtmaxR�twarningtpprinttpformattStringIOt	tracebackt	print_exctgetvaluetnotify_problemR�R+tfloatR�tcheck_max_zombies(RRtmax_timet
total_timeRtstarting_workerstworking_workerstkilled_workersRRR�R5t	info_desctouttave_time((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR�sd	


		
	
		cCse|js
dSg}tj�}x}|jj�D]l\}\}}|j|�sxy|j|=Wq/tk
rqq/Xq/n|||jkr/|j|�q/q/W|r�|jj	d|�nt
|�|jkra|jjdt
|�|j�|jdt
dt
|�d|jddjtt|���d	d
�|jd�dGtj�GHtd
��ndS(ss
        Check if we've reached max_zombie_threads_before_die; if so
        then kill the entire process.
        NsFound %s zombie threadss?Exiting process because %s zombie threads is more than %s limitsmExiting process because %(found)s zombie threads (more than limit of %(limit)s)
Bad threads (ids):
  %(ids)s
tfoundR2tidss
  tsubjects)Process restart (too many zombie threads)i
s
Shutting downi(RR�RR�R!R"RR R�R�R�tfatalR;R�R�tmapR{RR%t
currentThreadt
ServerExit(RRFRRR#R((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR='s8	"
		
c	Csttj�}tj�}|_|jj|�|jj|�d}t}|j	j
d||�zZxStr�|jr�|j|kr�|j	j
d|||jf�t}Pn|j
j�}|tjkr�|j	j
d|�Pny|jj|�Wntk
rnXtj�dg|j|<|d7}zGy|�Wn"tjd|IJtj�nX||jkruPnWdy|j|=Wntk
r�nXtj�X|jj|�qgWWdy|j|=Wntk
r�nXy|jj|�Wntk
rnXy|jj|�Wntk
r/nXy|j|=Wntk
rQnX|ro|jdd	|�nXdS(
sd
        Worker thread should call this method to get and process queued
        callables.
        isStarted new worker %s: %ss;Thread %s processed %i requests (limit %s); stopping threadsWorker %s asked to SHUTDOWNis!Unexpected exception in worker %rNRDs#Voluntary replacement for thread %s(R%RKR�R�RR�R RR;R�RR6R�R�RtR�RR)RuR�RJR�RxRyR8R9RR"t	exc_clearR(RRDR*Rtrequests_processedtadd_replacement_workertrunnable((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR.Msr	







cCsw|jjd�x0tt|j��D]}|jjtj�q&Wg}x:|jD]/}|j	d�|j
�rS|j|�qSqSWg}x0|jD]%}|j
|�r�|j|�q�q�W|s�|rc|jjdt|�t|��|r'x|D]}|j|j�q�W|jjd�n|rsg}t}t|�}	xX|jD]M}
|r~|j
�r~t}|j	|�n|j
�rOd|GHt}	qOqOW|	rMddl}xyt|j�D]h}t|dd	d�}
|
s�q�nt|
d
i�}|jd�}|dkr�|jj|�q�q�W|j�d
GHtjd�q`|jjd�qsn|jjd�dS(sL
        Shutdown the queue (after finishing any pending requests).
        sShutting down threadpoolg�?s/%s workers didn't stop properly, and %s zombiessWorkers killed forcefullysWorker %s won't diei����Nitim_functfunc_globalsR&R%sForcefully exiting processisAll workers eventually killedsAll workers stopped(R�R�R
R�R�R�RR�RR�tisAliveR RR!R+RR;tboolR6R
tlistt
_exithandlersRRJRtR)t_run_exitfuncstost_exit(Rtforce_quit_timeoutRthung_workersRtzombiesRRt	timed_outtneed_force_quitR�R
tcallbacktfunctglobstmod((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR�sZ

	

c
Cs�|js
dS|rEtjd|jd||tf�}|j�dSd}|s~|j�j�d}|d }d|}nd|jd	|d
|g}ydjt	j
��}Wn
d}nXd
td|dtj
d�dt	j�d|dt	jjt��}dj|�d|}	ddl}
|
jd�}g|jjd�D]}|j�rP|j�^qP}
|j||
|	�|j�dG|
G|	GHdS(s�
        Called when there's a substantial problem.  msg contains the
        body of the notification, subject the summary.

        If spawn_thread is true, then the email will be send in
        another thread (so this doesn't block).
        NR,R)serrors@localhostii2s[http threadpool] %ssTo: %ssFrom: %ssSubject: %sR-s	(unknown)s�An error has occurred in the paste.httpserver.ThreadPool
Error:
  %(msg)s
Occurred at: %(time)s
PID: %(pid)s
System: %(system)s
Server .py file: %(file)s
tmsgR�s%ctpidtsystemR�s
s

i����t	localhostRfs
email sent to(R�R%R-R;R;R0tstript
splitlinesR�RXtunameR�R�tstrftimetgetpidRltabspatht__file__tsmtplibtSMTPR7tsendmailtquit(RRcRHtspawn_threadtttfrom_addressRBRetbodyRDRnRrteterror_emails((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR;�sD			






N(R&R'R(tobjectRR;RJRRR$R+R!RRR=R.RR6R;(((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR��s,,	4	1	%				?	&G7tThreadPoolMixIncBsPeZdZed�Zd�Zd�Zd�Zd�Zd�Z	d�Z
RS(s=
    Mix-in class to process requests from a thread pool
    cKsMt|_|dks!td��t|d|j|jf||�|_dS(Nis5ThreadPoolMixIn servers must have at least one workers$ThreadPoolMixIn HTTP server on %s:%d(R6trunningRKR�R�R�R`(RR�R�tthreadpool_options((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyRs	cs0�jd��jj���fd��dS(sT
        Queue the request to be processed by on of the thread pool threads
        ics�j���S(N(tprocess_request_in_thread((RwtrequestR(sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyt<lambda>sN(tsetblockingR`R(RR}Rw((RwR}RsA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pytprocess_requests
	cCs@tj�\}}}|tkr'�ntt|�j||�S(N(RxRMRLtsuperRythandle_error(RR}Rwt	exc_classtexcttb((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR�scCswy!|j||�|j|�WnO|j||�|j|�tj�d}t|ttf�rs�qsnXdS(s�
        The worker thread should call back here to do the rest of the
        request processing. Error handling normaller done in 'handle_request'
        must be done here.
        iN(tfinish_requestt
close_requestR�RxRMR�tMemoryErrortKeyboardInterrupt(RR}RwR�((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR|$s
cCsNz9x2|jr7y|j�Wqtjk
r3qXqWWd|jj�XdS(sP
        Overrides `serve_forever` to shut the threadpool down cleanly.
        N(Rzthandle_requestR�ttimeoutR`R(R((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyt
serve_forever4scCs|jjd�dS(sR
        Overrides server_activate to set timeout on our listener socket.
        iN(R�R�(R((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR�CscCs*t|_|jj�|jjd�dS(sB
        Finish pending requests and shutdown the server.
        i<N(R;RzR�RR`R(R((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pytserver_closeJs	
(R&R'R(R;RR�R�R|R�R�R�(((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyRys	
				tWSGIServerBasecBs#eZdddd�Zd�ZRS(cCs2tj||||d|�||_d|_dS(NR�(R�RR�RJtwsgi_socket_timeout(RR�RsR�R�R�((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyRSs
		cCs;tj|�\}}|jr1|j|j�n||fS(N(R�R�R�R�(RR�R�((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR�\s	N(R&R'RJRR�(((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR�RscBseZeZRS((R&R'R;tdaemon_threads(((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyRcstWSGIThreadPoolServercBs#eZdddeddd�ZRS(i
c		CsNtj|||||d|�|dkr4i}ntj||||�dS(NR�(R�RRJRy(	RR�RsR�R�R�R�R{R�((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyRgs		N(R&R'RJR;R(((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR�fsRLcBseZdZRS(sV
    Raised to tell the server to really exit (SystemExit is normally
    caught)
    (R&R'R((((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyRLssi
icCs]t}|s|r�ts$td��t}t|p6d�}|s�|dkrZt�}q�tjtj�}|j|�|j	|�q�n|p�d}|dkr�d|kr�|jdd�\}}q�d}n|t|�f}|s�t}n|r||_
d|_n|r4|dks(t�||_n|dkrIt}ntj|�r�t||||t|�|	d|
d|�}n-t||||d|�}|	r�|	|_n|
r�t|
�|_ntj|�rY|r�d
p�d}|jd \}}|dkr"d|||fGHnd|||fGHy|j�WqYtk
rUqYXn|S(sc
    Serves your ``application`` over HTTP(S) via WSGI interface

    ``host``

        This is the ipaddress to bind to (or a hostname if your
        nameserver is properly configured).  This defaults to
        127.0.0.1, which is not a public interface.

    ``port``

        The port to run on, defaults to 8080 for HTTP, or 4443 for
        HTTPS. This can be a string or an integer value.

    ``handler``

        This is the HTTP request handler to use, it defaults to
        ``WSGIHandler`` in this module.

    ``ssl_pem``

        This an optional SSL certificate file (via OpenSSL). You can
        supply ``*`` and a development-only certificate will be
        created for you, or you can generate a self-signed test PEM
        certificate file as follows::

            $ openssl genrsa 1024 > host.key
            $ chmod 400 host.key
            $ openssl req -new -x509 -nodes -sha1 -days 365  \
                          -key host.key > host.cert
            $ cat host.cert host.key > host.pem
            $ chmod 400 host.pem

    ``ssl_context``

        This an optional SSL context object for the server.  A SSL
        context will be automatically constructed for you if you supply
        ``ssl_pem``.  Supply this to use a context of your own
        construction.

    ``server_version``

        The version of the server as reported in HTTP response line. This
        defaults to something like "PasteWSGIServer/0.5".  Many servers
        hide their code-base identity with a name like 'Amnesiac/1.0'

    ``protocol_version``

        This sets the protocol used by the server, by default
        ``HTTP/1.0``. There is some support for ``HTTP/1.1``, which
        defaults to nicer keep-alive connections.  This server supports
        ``100 Continue``, but does not yet support HTTP/1.1 Chunked
        Encoding. Hence, if you use HTTP/1.1, you're somewhat in error
        since chunked coding is a mandatory requirement of a HTTP/1.1
        server.  If you specify HTTP/1.1, every response *must* have a
        ``Content-Length`` and you must be careful not to read past the
        end of the socket.

    ``start_loop``

        This specifies if the server loop (aka ``server.serve_forever()``)
        should be called; it defaults to ``True``.

    ``daemon_threads``

        This flag specifies if when your webserver terminates all
        in-progress client connections should be droppped.  It defaults
        to ``False``.   You might want to set this to ``True`` if you
        are using ``HTTP/1.1`` and don't set a ``socket_timeout``.

    ``socket_timeout``

        This specifies the maximum amount of time that a connection to a
        given client will be kept open.  At this time, it is a rude
        disconnect, but at a later time it might follow the RFC a bit
        more closely.

    ``use_threadpool``

        Server requests from a pool of worker threads (``threadpool_workers``)
        rather than creating a new thread for each request. This can
        substantially reduce latency since there is a high cost associated
        with thread creation.

    ``threadpool_workers``

        Number of worker threads to create when ``use_threadpool`` is true. This
        can be a string or an integer value.

    ``threadpool_options``

        A dictionary of options to be used when instantiating the
        threadpool.  See paste.httpserver.ThreadPool for specific
        options (``threadpool_workers`` is a specific option that can
        also go here).

    ``request_queue_size``

        The 'backlog' argument to socket.listen(); specifies the
        maximum number of queued connections.

    spyOpenSSL is not installedi[R�s	127.0.0.1t:ii�sHTTP/0.9sHTTP/1.0sHTTP/1.1R{R�RgRTis0.0.0.0s/serving on 0.0.0.0:%s view at %s://127.0.0.1:%ssserving on %s://%s:%sN(sHTTP/0.9sHTTP/1.0sHTTP/1.1(R;R�RKR6R9R�R�R�tuse_privatekey_filetuse_certificate_chain_fileRJR7RR/R.tprotocol_versionRtasboolR�RR�R�RsR�R�(tapplicationthosttportthandlertssl_pemR�R/R�t
start_loopR�tsocket_timeouttuse_threadpooltthreadpool_workersR{R�tis_sslRsRrtprotocol((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyR	ysfk
					
cKs?ddlm}xRddddddd	d
ddd
gD])}||kr8t||�||<q8q8Wx7ddgD])}||krr|||�||<qrqrWi}xS|j�D]E\}}|jd�r�|dkr�|||td�<||=q�q�Wd|kr$d|kr$|d|d<n||d<t||�dS(Ni����(R�R�R�R�tthreadpool_hung_thread_limittthreadpool_kill_thread_limittthreadpool_dying_limittthreadpool_spawn_if_undert(threadpool_max_zombie_threads_before_dietthreadpool_hung_check_periodtthreadpool_max_requestsR�R�R�tthreadpool_R�R{(tpaste.deploy.convertersR�R9R�RR�R	(twsgi_apptglobal_confR*R�R�R{tvalue((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyt
server_runner&s.
RRs		

    You can also set these threadpool options:

    ``threadpool_max_requests``:

        The maximum number of requests a worker thread will process
        before dying (and replacing itself with a new worker thread).
        Default 100.

    ``threadpool_hung_thread_limit``:

        The number of seconds a thread can work on a task before it is
        considered hung (stuck).  Default 30 seconds.

    ``threadpool_kill_thread_limit``:

        The number of seconds a thread can work before you should kill it
        (assuming it will never finish).  Default 600 seconds (10 minutes).

    ``threadpool_dying_limit``:

        The length of time after killing a thread that it should actually
        disappear.  If it lives longer than this, it is considered a
        "zombie".  Note that even in easy situations killing a thread can
        be very slow.  Default 300 seconds (5 minutes).

    ``threadpool_spawn_if_under``:

        If there are no idle threads and a request comes in, and there are
        less than this number of *busy* threads, then add workers to the
        pool.  Busy threads are threads that have taken less than
        ``threadpool_hung_thread_limit`` seconds so far.  So if you get
        *lots* of requests but they complete in a reasonable amount of time,
        the requests will simply queue up (adding more threads probably
        wouldn't speed them up).  But if you have lots of hung threads and
        one more request comes in, this will add workers to handle it.
        Default 5.

    ``threadpool_max_zombie_threads_before_die``:

        If there are more zombies than this, just kill the process.  This is
        only good if you have a monitor that will automatically restart
        the server.  This can clean up the mess.  Default 0 (disabled).

    `threadpool_hung_check_period``:

        Every X requests, check for hung threads that need to be killed,
        or for zombie threads that should cause a restart.  Default 100
        requests.

    ``threadpool_logger``:

        Logging messages will go the logger named here.

    ``threadpool_error_email`` (or global ``error_email`` setting):

        When threads are killed or the process restarted, this email
        address will be contacted (using an SMTP server on localhost).

t__main__(tdump_environR/sWombles/1.0R�sHTTP/1.1R�t8888(8R(R
R8R�RxR%RjR�RmRpR�R�RXt	itertoolsRtBaseHTTPServerRRtSocketServerRt
paste.utilRR�RtImportErrorRJt__all__R�RxR
RR�R�R�R�tZeroReturnErrortSysCallErrorR�R�R�R�RRvR�RyR�RR�R(RLR6R	R�R&t
paste.wsgilibR�(((sA/opt/alt/python27/lib/python2.7/site-packages/paste/httpserver.pyt<module>shH

,�
		3	%;��Q
		�	<


Zerion Mini Shell 1.0