Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
ó
Ch-_c@sdZddlZddlZddlZddlZdZddlZejdkr`dZ	ndZ	ddd„ƒYZ
d	dd
„ƒYZdeejfd„ƒYZd
eej
fd„ƒYZ
dejfd„ƒYZdejfd„ƒYZdejfd„ƒYZdS(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.

iÿÿÿÿNiiiitConnectionManagercBsGeZdZd„Zd„Zd„Zd„Zd„Zdd„Z	RS(sV
    The connection manager must be able to:
      * keep track of all existing
      cCs.tjƒ|_i|_i|_i|_dS(N(tthreadt
allocate_lockt_lockt_hostmapt_connmapt	_readymap(tself((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyt__init__{s		cCsv|jjƒzT|jj|ƒs2g|j|<n|j|j|ƒ||j|<||j|<Wd|jjƒXdS(N(RtacquireRthas_keytappendRRtrelease(Rthostt
connectiontready((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pytadds

cCs|jjƒzky|j|}Wntk
r4nCX|j|=|j|=|j|j|ƒ|j|sw|j|=nWd|jjƒXdS(N(RR	RtKeyErrorRRtremoveR(RRR
((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyR‹s




cCs)y||j|<Wntk
r$nXdS(N(RR(RRR((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyt	set_readyšs
cCs}d}|jjƒzU|jj|ƒrgx<|j|D]*}|j|r6d|j|<|}Pq6q6WnWd|jjƒX|S(Ni(tNoneRR	RR
RR(RR
tconntc((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pytget_ready_connžs


cCs0|rt|jj|gƒƒSt|jƒSdS(N(tlistRtgettdict(RR
((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pytget_all¬sN(
t__name__t
__module__t__doc__RRRRRRR(((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyRvs		
			tKeepAliveHandlercBseeZd„Zd„Zd„Zd„Zd„Zdd„Zd„Zd„Z	d	„Z
d
„ZRS(cCstƒ|_dS(N(Rt_cm(R((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyR³scCs8g|jjƒjƒD]\}}|t|ƒf^qS(streturn a list of connected hosts and the number of connections
        to each.  [('foo.com:80', 2), ('bar.org', 1)](R Rtitemstlen(RR
tli((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pytopen_connections·scCs;x4|jj|ƒD] }|jj|ƒ|jƒ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(R RRtclose(RR
th((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pytclose_connection¼scCsUxN|jjƒjƒD]7\}}x(|D] }|jj|ƒ|jƒq)WqWdS(sclose all open connectionsN(R RR!RR%(RR
tconnsR&((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyt	close_allÄs"
cCs|jj|dƒdS(sdtells us that this request is now closed and the the
        connection is ready for another requestiN(R R(RtrequestR
R((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyt_request_closedËsicCs'|r|jƒn|jj|ƒdS(N(R%R R(RR
RR%((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyt_remove_connectionÐs
cCs|j}|s!tjdƒ‚nyÑ|jj|ƒ}x¸|r|j|||ƒ}|r^Pn|jƒ|jj|ƒ|jj|ƒ}q9W|j|ƒ}t	r¿t	j
d|t|ƒƒn|jj||dƒ|j
||ƒ|jƒ}Wn.tjtjfk
r"}tj|ƒ‚nXt	rEt	j
d|j|jƒn|jrwt	rdt	j
dƒn|jj|ƒn||_||_||_|jƒ|_|j|_|j|_|j|_|jdksÛtrß|S|jjd|||j|j|jƒSdS(Ns
no host givens"creating new connection to %s (%d)isSTATUS: %s, %ss(server will close connection, discardingiÈthttp( R
turllib2tURLErrorR Rt_reuse_connectionR%Rt_get_connectiontDEBUGtinfotidRt_start_transactiontgetresponsetsocketterrorthttplibt
HTTPExceptiontstatustreasont
will_closet_handlert_hostt_connectiontget_full_urlturltcodetmsgtheaderst
HANDLE_ERRORStparent(RtreqR
R&trterr((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pytdo_openÕsL		
					cCsûy |j||ƒ|jƒ}Wnltjtjfk
rEd}nJtrntjdd|t|ƒƒn|j	j
|ƒ|jƒ‚nX|dksª|jdkrÕtrÌtj
d|t|ƒƒnd}n"tr÷tj
d|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(R5R6R7R8R9R:RR2R4R RR%tversionR3(RR&RHR
RI((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyR0s(	
	
		cCsyã|jr§|j}t|dƒr:|jd|jƒn|jd|jƒƒ|jjdƒsu|jddƒn|jjdƒsâ|jddt|ƒƒqân;t|dƒrÌ|jd|jƒn|jd|jƒƒWn.t	j
tjfk
r}t
j|ƒ‚nXx!|jjD]}|j|Œq!Wx-|jjƒD]\}}|j||ƒqHW|jƒ|jr‹|j|ƒndS(NtselectortPOSTsContent-types!application/x-www-form-urlencodedsContent-lengths%dtGET(tdatathasattrt
putrequestRMtget_selectorRER
t	putheaderR"R7R8R9R:R.R/RGt
addheadersR!t
endheaderstsend(RR&RHRPRJtargstktv((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyR53s.			
 
	cCstS(N(tNotImplementedError(RR
((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyR1Ps(RRRR$R'R)R+R,RKR0R5R1(((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyR²s						3	+	tHTTPHandlercBs#eZd„Zd„Zd„ZRS(cCstj|ƒdS(N(RR(R((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyRTscCs
|j|ƒS(N(RK(RRH((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyt	http_openWscCs
t|ƒS(N(tHTTPConnection(RR
((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyR1Zs(RRRR]R1(((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyR\Ss		tHTTPSHandlercBs&eZdd„Zd„Zd„ZRS(cCsStj|ƒ|sFyddl}|jƒ}WqFtk
rBqFXn||_dS(Niÿÿÿÿ(RRt
sslfactorytget_factorytImportErrort_ssl_factory(Rtssl_factoryR`((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyR^s

cCs
|j|ƒS(N(RK(RRH((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyt
https_openhscCs3y|jj|ƒSWntk
r.t|ƒSXdS(N(Rctget_https_connectiontAttributeErrortHTTPSConnection(RR
((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyR1ks
N(RRRRReR1(((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyR_]s
	tHTTPResponsecBsneZddd
d„ZejjZd„Zd„Z	d„Z
d„Zd
d„Zdd„Zdd	„Z
RS(icCs‡|r"tjj||||ƒntjj|||ƒ|j|_d|_d|_d|_d|_d|_	d|_
d|_dS(Nti (R9RiRtfilenoRRCt_rbuft	_rbufsizeR>R?t_urlR@(Rtsockt
debugleveltstricttmethod((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyRƒs						cCsN|jrJ|jjƒd|_|jrJ|jj||j|jƒqJndS(N(tfpR%RR>R+R?R@(R((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyR%“s	
		cCs-|jj|j|jddƒ|jƒdS(NR%i(R>R,R?R@R%(R((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyR'›scCs|jS(N(RE(R((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyR3ŸscCs|jS(N(Rn(R((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pytgeturl¢scCs„|jra|dk	rat|jƒ}||kr=||8}qa|j| }|j||_|Sn|j|j|ƒ}d|_|S(NRj(RlRR"t	_raw_read(RtamttLts((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pytread¥s

	iÿÿÿÿcCs&d}|jjdƒ}x“|dkr­d|koGt|jƒknr­|j|jƒ}|siPn|jdƒ}|dkrš|t|jƒ}n|j||_qW|dkrÌt|jƒ}n
|d}d|koöt|jƒknr|}n|j| |j|}|_|S(NRjs
ii(RltfindR"RuRm(RtlimitRPtitnew((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pytreadlineµs"5
%	cCs`d}g}xM|jƒ}|s%Pn|j|ƒ|t|ƒ7}|r||krPqqW|S(Ni(R~RR"(RtsizehintttotalRtline((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyt	readlinesÄs
N(RRRRR9RiRyRuR%R'R3RtR~R‚(((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyRios				R^cBseZeZRS((RRRitresponse_class(((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyR^ÑsRhcBseZeZRS((RRRiRƒ(((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyRhÕs(ii(((RR.R9R7RRR2tsystversion_infoRFRRR\R_RiR^Rh(((sG/usr/lib/enigma2/python/Plugins/Extensions/IPTVPlayer/libs/keepalive.pyt<module>gs 	<¡
b