usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyc000064400000050771147206134320021724 0ustar00 abc@sddlZddlZddlZddlZddlZddlZddlmZmZy ej Z Wn e e fk rejZ nXd#Z d$Z eZeZdadefdYZdZejd%krd Zn d Zed d dddgZdefdYZdefdYZeedradefdYZneedrdefdYZneedrdefdYZneedrdefd YZ needse!Znd!Z"d"Z#dS(&iN(t namedtupletMappingiit SelectorErrorcBs#eZdZdZdZRS(cCs tt|j||_dS(N(tsuperRt__init__terrno(tselfterrcode((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyRscCsdj|jS(Ns(tformatR(R((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyt__repr__"scCs |jS(N(R (R((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyt__str__%s(t__name__t __module__RR R (((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyRs  cCst|tr|}nHyt|j}Wn/tttfk r_tdj|nX|dkrtdj|n|S(sl Return a file descriptor from a file object. If given an integer will simply return that integer back. sInvalid file object: {0!r}isInvalid file descriptor: {0}(t isinstancetinttfilenotAttributeErrort TypeErrort ValueErrorR(tfileobjtfd((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyt_fileobj_to_fd)s  iicOsdy|||SWnLtttjfk r_}d}t|drP|j}nt|nXdS(s This is the short-circuit version of the below logic because in Python 3.5+ all system calls automatically restart and recalculate their timeouts. RN(tOSErrortIOErrortselectterrortNonethasattrRR(tfunct_targstkwargsteR((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyt_syscall_wrapper;s c Os|jdd}|dkr-d}t}n.t|}|dkrNd}n t|}t|}|rd|krtdnt}x5|tkry|||}Wqtt t j fk r}d}t |dr|j }nt |dr|jd}n|t jkp8t t do8|t jk} | r|dk rt} | |krwtdt jn|rd|kr|| |d(((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyR4s    t BaseSelectorcBseZdZdZdZd dZdZd dZd dZ dZ dZ d Z d Z d Zd ZRS(s/ Abstract Selector class A selector supports registering file objects to be monitored for specific I/O events. A file object is a file descriptor or any object with a `fileno()` method. An arbitrary object can be attached to the file object which can be used for example to store context info, a callback, etc. A selector can use various implementations (select(), poll(), epoll(), and kqueue()) depending on the platform. The 'DefaultSelector' class uses the most efficient implementation for the current platform. cCsi|_t||_dS(N(R8R4t_map(R((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyRs cCsYyt|SWnDtk rTx-|jjD]}|j|kr.|jSq.WnXdS(sa Return a file descriptor from a file object. This wraps _fileobj_to_fd() to do an exhaustive search in case the object is invalid but we still have it in our map. Used by unregister() so we can unregister an object that was previously registered even if it is closed. It is also used by _SelectorMapping N(RRR8tvaluesRR(RRtkey((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyR:s  cCs| s|ttB@r.tdj|nt||j|||}|j|jkr|tdj||jn||j|j<|S(s8 Register a file object for a set of events to monitor. sInvalid events: {0!r}s${0!r} (FD {1}) is already registered( t EVENT_READt EVENT_WRITERRR1R:RR8R;(RRR2R3RC((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pytregisters cCsy|jj|j|}Wntk rGtdj|ntjk r}|jtjkrqqxV|jj D],}|j |kr|jj|j PqqWtdj|nX|S(s0 Unregister a file object from being monitored. s{0!r} is not registered( R8tpopR:R;RtsocketRRtEBADFRBRR(RRRCR ((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyt unregisters cCsy|j|j|}Wn&tk rBtdj|nX||jkrw|j||j|||}n4||jkr|jd|}||j|j |jj|jn|t@r^|jj|jn|S(N( RRWRFRDRYtaddRRERZ(RRR2R3RC((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyRF&s   cCsBtt|j|}|jj|j|jj|j|S(N(RRWRJRYtdiscardRRZ(RRRC((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyRJ.scCstj||g|S(s? Wrapper for select.select because timeout is a positional arg (R(RtrtwR"((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyt_select4sc Cst|j r$t|j r$gS|dkr6dn t|d}g}t|jt|j|j|\}}}t|}t|}x|||BD]p}d}||kr|t O}n||kr|t O}n|j |}|r|j |||j @fqqW|S(Ngi(R7RYRZRtmaxR!R_tTrueRXRDRERTtappendR2( RR"treadyR]R^RRR2RC((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyR8s$ !      !N( R R R?RRRFRJR_R(((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyRWs     tpollt PollSelectorcBsDeZdZdZddZdZddZddZRS(s Poll-based selector cCs&tt|jtj|_dS(N(RReRRRdt_poll(R((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyRSscCsrtt|j|||}d}|t@r>|tjO}n|t@rX|tjO}n|jj|j ||S(Ni( RReRFRDRtPOLLINREtPOLLOUTRfR(RRR2R3RCt event_mask((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyRFWs  cCs/tt|j|}|jj|j|S(N(RReRJRfR(RRRC((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyRJascCsM|dk r7|dkr!d}q7tj|d}n|jj|}|S(sj Wrapper function for select.poll.poll() so that _syscall_wrapper can work with only seconds. ig@@N(RtmathtceilRfRd(RR"R.((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyt _wrap_pollfs    cCsg}t|jtd|}x|D]z\}}d}|tj@rR|tO}n|tj@rm|tO}n|j|}|r%|j |||j @fq%q%W|S(NR"i( R!RlRaRRgRERhRDRTRbR2(RR"Rct fd_eventsRRiR2RC((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyRts  !N( R R R?RRRFRJRlR(((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyReQs    tepollt EpollSelectorcBsJeZdZdZdZddZdZddZdZ RS(s Epoll-based selector cCs&tt|jtj|_dS(N(RRoRRRnt_epoll(R((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyRscCs |jjS(N(RpR(R((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyRscCsxtt|j|||}d}|t@r>|tjO}n|t@rX|tjO}nt|j jt |j ||S(Ni( RRoRFRDRtEPOLLINREtEPOLLOUTR!RpR%R(RRR2R3RCt events_mask((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyRFs  cCsMtt|j|}yt|jjt|jWntk rHnX|S(N(RRoRJR!RpR%RR(RRRC((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyRJs  c Cs|dk rG|dkr!d}ntj|dd}t|}nd}tt|jd}g}t|jj t d|d|}x|D]z\}}d}|t j @r|t O}n|t j@r|tO}n|j|}|r|j|||j@fqqW|S( Nigg@@gMbP?giR"t maxevents(RRjRkR&R`R7R8R!RpRdRaRRqRERrRDRTRbR2( RR"t max_eventsRcRmRRiR2RC((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyRs*      !cCs$|jjtt|jdS(N(RpRORRo(R((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyROs N( R R R?RRRRFRJRRO(((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyRos   !tkqueuetKqueueSelectorcBsJeZdZdZdZddZdZddZdZ RS(s Kqueue / Kevent-based selector cCs&tt|jtj|_dS(N(RRwRRRvt_kqueue(R((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyRscCs |jjS(N(RxR(R((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyRscCstt|j|||}|t@rhtj|jtjtj}t |j j t |gddn|t @rtj|jtjtj}t |j j t |gddn|S(Ni(RRwRFRDRtkeventRtKQ_FILTER_READt KQ_EV_ADDR!RxtcontrolR%REtKQ_FILTER_WRITE(RRR2R3RCRy((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyRFs   "   "cCstt|j|}|jt@r}tj|jtjtj }y#t |j j t |gddWq}tk ryq}Xn|jt@rtj|jtjtj }y#t |j j t |gddWqtk rqXn|S(Ni(RRwRJR2RDRRyRRzt KQ_EV_DELETER!RxR|R%RRER}(RRRCRy((sF/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/util/selectors.pyRJs$   #    # c Cs9|dk rt|d}nt|jd}i}t|jjtd||}x|D]}|j}|j }d}|t j kr|t O}n|t j kr|tO}n|j|} | r\| j|kr| || j@f|| jsF           814BR