KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 PHP/5.2.17
System : Linux localhost 2.6.18-419.el5 #1 SMP Fri Feb 24 22:47:42 UTC 2017 x86_64
User : nobody ( 99)
PHP Version : 5.2.17
Disable Function : NONE
Directory :  /proc/21573/task/21573/root/usr/lib/python2.4/site-packages/urlgrabber/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/21573/task/21573/root/usr/lib/python2.4/site-packages/urlgrabber/keepalive.pyo
mò
5Ec@s¹dZdkZdkZdkZdkZdadkZdkZei	djo
da
nda
dfd„ƒYZdfd	„ƒYZd
eei
fd„ƒYZ
deeifd
„ƒYZdeifd„ƒYZdeifd„ƒYZdeifd„ƒYZd„Zd„Zd„Zdd„Zd„Zdd„ZedjoadkZdkZy$eeidƒZeidZWndeidGHqµXeeeƒ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__zs		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_conns

cCs5|ot|ii|gƒƒSnt|iƒSdS(N(RtlistRRtgettdict(RR((Rtget_all«s(
t__name__t
__module__t__doc__R	RRRRRR(((RRus		
			tKeepAliveHandlercBsetZd„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|iƒ}|ptidƒ‚ny×|ii|ƒ}x¾|oQ|i	|||ƒ}|oPn|iƒ|ii|ƒ|ii|ƒ}q>W|i
|ƒ}totid|t|ƒƒn|ii||dƒ|i||ƒ|iƒ}Wn0titifj
o}ti|ƒ‚nX|io|ii|ƒntotid|i|iƒn||_||_|iƒ|_||_ |i|_!|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(&treqtget_hostRturllib2tURLErrorRR!RR't_reuse_connectiontrR(Rt_get_connectiontDEBUGtinfotidRt_start_transactiontgetresponsetsocketterrorthttplibt
HTTPExceptionterrt
will_closetstatustreasont_handlert_hosttget_full_urlt_urlt_connectiontcodetmsgtheaderst
HANDLE_ERRORStparent(RR0R@R'RR5((Rtdo_openÔsJ
	
			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'R0R;R5R<R=R>R?RR7RR9R!RR(tversionR8(RR'R0RR5((RR4s*



	
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(R0thas_datatget_datatdataR't
putrequesttget_selectorRKRt	putheaderR%R<R=R>R?R@R2R3RRMt
addheaderstargsR#tktvt
endheaderstsend(RR'R0RYR@R[RTRZ((RR:/s*
	"


cCstS(N(tNotImplementedError(RR((RR6Fs(RRR	R&R)R+R-R.RNR4R:R6(((RR ±s						0	+	tHTTPHandlercBs#tZd„Zd„Zd„ZRS(NcCsti|ƒdS(N(R R	R(R((RR	JscCs
|i|ƒS(N(RRNR0(RR0((Rt	http_openMscCs
t|ƒS(N(tHTTPConnectionR(RR((RR6Ps(RRR	R`R6(((RR_Is		tHTTPSHandlercBs&tZdd„Zd„Zd„ZRS(NcCs1ti|ƒ|ptiƒ}n||_dS(N(R R	Rtssl_factoryt
sslfactorytget_factoryt_ssl_factory(RRc((RR	Ts
cCs
|i|ƒS(N(RRNR0(RR0((Rt
https_openZscCs|ii|ƒS(N(RRftget_https_connectionR(RR((RR6]s(RRRR	RgR6(((RRbSs	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 (tmethodR>RiR	Rtsockt
debugleveltfilenoRRIt_rbuft	_rbufsizeRDRERGRH(RRlRmtstrictRk((RR	ts						cCsR|ioD|iiƒd|_|io |ii||i|iƒqNndS(N(RtfpR(RRDR-RERH(R((RR(„s

	
cCs-|ii|i|iddƒ|iƒdS(NR(i(RRDR.RERHR((R((RR)ŒscCs|iS(N(RRK(R((RR8scCs|iS(N(RRG(R((Rtgeturl“scCs‰|io\|dj	oOt|iƒ}||jo||8}qf|i| }|i||_|Sn|i|i|ƒ}d|_|S(NRj(RRotamtRR%tLtst	_raw_read(RRtRuRv((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(NRjs
ii(
RTRRotfindtitlimitR%RwRptnew(RR{RzR|RT((Rtreadline¦s$5


'
cCsfd}g}xS|iƒ}|pPn|i|ƒ|t|ƒ7}|o||joPqqW|S(Nii(ttotalRRR}tlineR
R%tsizehint(RR€RRR~((Rt	readlinesµs

(RRRR	R>RiRxRwR(R)R8RsR}R(((RRi`s				RacBstZeZRS(N(RRRitresponse_class(((RRaÂstHTTPSConnectioncBstZeZRS(N(RRRiR‚(((RRƒÆ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(RLtorigR_tkeepalive_handlerR2tbuild_openertopenertinstall_openertposRzturlopenturltfoRxtfooR(RBRCtAttributeErrorRtIOErrorteR&thostsR+(RRBRR’RzRCR‰R‹R“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 readRjiskeepalive readline(tmd5tformatR2RˆR‰RŠRŒRRŽRxRR(R|tmt	hexdigestR_R}tf(RRR–R™R—R‰R•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(
tNRtsyststdouttwriteR2RˆR‰RŠtfetchtt1R_tt2(R›RR¡R R‰((Rtcomps
	
	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›RztdelaytsleepR2RŒRRŽRxRR(R
R%tdifftj(R›RR§R¤RªRzR¥R£R©RRŽ((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(RJRY(RRJRY((Rtdebug2s(RRR¬R8twarningR=(((RR«1s	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(R7tdbbackupR«R2RŒRRŽRxtdata1R(RzRœRRžtflushR£R¨tstderrtdata2(RRzR¯R«R²R®RŽ((Rttest_timeout.s2	
	




	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”RR‘R’RœtexitRšR¢R›R³(RR›R’((RttestPs

t__main__s%s <integer> <url>(ii(RR2R>R<RRR7RdRœtversion_infoRLRR R_RbRiRaRƒR”RšR¢RŸR³RµRR£tinttargvR›R(R³RR”R_R¢RµRiRšRbR2RœRaR›R R>R<RRRdR£RƒRŸ((Rt?ds@						
<˜

b		!		"
		

Anon7 - 2021