ˆOc@sdZddlmZddlmZmZdZdZdddYZddd YZ dd l Z dd l Z dd l Z dd l Z d efd YZdZdefdYZd S(s Implements a simple polling interface for file descriptors that don't work with select() - this is pretty much only useful on Windows. i(t implements(t IConsumert IPushProducerg& .>g?t_PollableResourcecBs eZeZdZdZRS(cCs t|_dS(N(tTruetactive(tself((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pytactivatescCs t|_dS(N(tFalseR(R((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyt deactivates(t__name__t __module__RRRR (((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyRs t _PollingTimercBsYeZdZdZdZdZdZdZdZdZ dZ RS( cCs1||_g|_d|_t|_t|_dS(N(treactort _resourcestNonet _pollTimert MAX_TIMEOUTt_currentTimeoutRt_paused(RR ((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyt__init__#s     cCs|jj||jdS(N(Rtappendt_checkPollingState(Rtres((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyt_addPollableResource*scCs9x2|jD]}|jr |jPq q W|jdS(N(RRt _startPollingt _stopPolling(Rtresource((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyR.s   cCs%|jdkr!|j|_ndS(N(RRt _reschedule(R((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyR6scCs,|jdk r(|jjd|_ndS(N(RRtcancel(R((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyR:s cCs t|_dS(N(RR(R((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyt_pause?scCst|_|jdS(N(RRR(R((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyt_unpauseBs cCs&|js"|jj|j|jSdS(N(RR t callLaterRt _pollEvent(R((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyRFs cCsd}g}xF|jD];}|jr||j7}|jrQ|j|qQqqW|j}|r|j|d}|tkrt}qn"|jd}|tkrt}n||_|r|j|_ndS(Ngg?g@( RRt checkWorkRRt MIN_TIMEOUTRRR(Rt workUnitst anyActiveRt newTimeout((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyR!Js$         ( R R RRRRRRRRR!(((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyR s        Nt_PollableReadPipecBsQeZeedZdZdZdZdZdZ dZ RS(cCs||_||_||_dS(N(tpipetreceivedCallbackt lostCallback(RR(R)R*((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyRns  c Csd}g}xxyWtj|jd\}}}|s:Pntj|j|d\}}|j|Wqtjk rd}PqXqdj |}|r|j |n|r|j nt |S(Niit( t win32pipet PeekNamedPipeR(t win32filetReadFileRRtwin32apiterrortjoinR)tcleanuptlen( Rtfinishedt fullDataReadtbuffert bytesToReadtresultthrtdatatdataBuf((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyR"ts$ cCs|j|jdS(N(R R*(R((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyR3s cCs/ytj|jWntjk r*nXdS(N(R0t CloseHandleR(t pywintypesR1(R((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pytclosescCs|jdS(N(R?(R((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyt stopProducingscCs|jdS(N(R (R((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pytpauseProducingscCs|jdS(N(R(R((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pytresumeProducings( R R RRRR"R3R?R@RARB(((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyR'js       i@it_PollableWritePipecBsleZeedZdZdZdZdZdZ dZ dZ dZ d Z RS( cCswt|_d|_d|_d|_g|_||_||_yt j |t j ddWnt j k rrnXdS(Ni(Rt disconnectingRtproducertproducerPausedtstreamingProducertoutQueuet writePipeR*R,tSetNamedPipeHandleStatet PIPE_NOWAITR>R1(RRIR*((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyRs         cCs t|_dS(N(RRD(R((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyR?scCs,|jdk r(d|_|jjndS(Ni(RERRFRA(R((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyt bufferFulls cCsC|jdk r?|j s"|jr?d|j_|jjtStS(Ni(RERRGRFRBRR(R((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyt bufferEmptys    cCsj|jdk r+td||jfn|jsA|jn%||_||_|sf|jndS(swRegister to receive data from a producer. This sets this selectable to be a consumer for a producer. When this selectable runs out of data on a write() call, it will ask the producer to resumeProducing(). A producer should implement the IProducer interface. FileDescriptor provides some infrastructure for producer methods. sHCannot register producer %s, because producer %s was never unregistered.N(RERt RuntimeErrorRR@RGRB(RREt streaming((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pytregisterProducers     cCs d|_dS(sDStop consuming data from a producer, without disconnecting. N(RRE(R((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pytunregisterProducerscCsC|jytj|jWntjk r4nX|jdS(N(R R0R=RIR>R1R*(R((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pytwriteConnectionLosts  cCs8ttt|kr$tdn|jj|dS(s Append a C{list} or C{tuple} of bytes to the output buffer. @param seq: C{list} or C{tuple} of C{str} instances to be appended to the output buffer. @raise TypeError: If C{seq} contains C{unicode}. s%Unicode not allowed in output buffer.N(tunicodetmapttypet TypeErrorRHtextend(Rtseq((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyt writeSequences cCsjt|trtdn|jr+dS|jj|ttt|jt krf|j ndS(s Append some bytes to the output buffer. @param data: C{str} to be appended to the output buffer. @type data: C{str}. @raise TypeError: If C{data} is C{unicode} instead of C{str}. s%Unicode not allowed in output buffer.N( t isinstanceRSRVRDRHRtsumRTR4tFULL_BUFFER_SIZERL(RR;((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pytwrites  cCs5d}|jse|jr&|jdSytj|jddWqetjk ra|j|SXnx|jr|jj d}d}y"tj|j|d\}}Wnt jk r|jPqhX||7}t ||krh|jj d||PqhqhW|j }| r1|jr1|jn|S(NiR+(RHRDRRR.t WriteFileRIRR>R1tpopR0R4tinsertRM(RtnumBytesWrittenR;terrCodet nBytesWrittentresumed((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyR"s6          (R R RRRR?RLRMRPRQRRRYR]R"(((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyRCs        ((i(t__doc__tzope.interfaceRttwisted.internet.interfacesRRR#RRR R,R.R0R>R'R\RC(((sA/usr/lib/python2.7/dist-packages/twisted/internet/_pollingfile.pyts E    6