mò Mã¸Ec@sšdkZdkZdkZdkZdkZdkZdkZdkZdkZdk Z dk l Z dk l Z lZdklZdklZdklZlZdklZlZdZdZd Zd ahZeeƒZeid ƒZ d „Z!ei"d e!ƒZ#e#i$e%ƒe#i&ƒdfd„ƒYZ'de'fd„ƒYZ(de i)e*fd„ƒYZ+de+fd„ƒYZ,de+fd„ƒYZ-dS(N(ssmac(s ZRPCErrorsDisconnectedError(s Marshaller(strigger(s short_reprslog(sBLATHERsTRACEs.replyif30.0isZEO.zrpc.client_loopc CsFt}ti}ti}ti}d}x|oyqttƒ} }g} |i ƒD]$\}}|iƒo | |qUqU~ } y%ti| | |tƒ\} } }WnÂtij o³}|dtijo“|dtijoxg} | D]}|tjo | |qðqð~ ow*ng} | D]}|tjo | |q*q*~ ow*q]n‚qlw*nX| p | p|pfxRtiƒD]D}t|tƒo.y|iddƒWqÒtj oqÒXqŽqŽWtd7aw*nx;| D]3}|i|ƒ}|djoqîn||ƒqîWx;| D]3}|i|ƒ}|djoq,n||ƒq,Wx;|D]3}|i|ƒ}|djoqjn||ƒqjWWq*ti ddt!i"ƒƒxy|i#ƒD]g\}}|t$joqÎny|i%i&i'ƒWqÎ|i(|dƒti ddt!i"ƒƒqÎXqÎWq*Xq*WdS(NiiÿÿÿÿisThe ZEO cient loop failed.texc_infosCouldn't close a dispatcher.()t client_maptmaptasyncoretreadtwritet _exceptiont loop_failurestlisttrtet_[1]t iteritemstfdtobjtwritabletwtselecttclient_timeoutterrorterrterrnotEINTRtEBADFt itervaluest isinstancet Connectiont send_replytNonetDisconnectedErrortclient_timeout_counttgett client_loggertcriticaltsysRtitemstclient_triggertmgrtclienttclosetpop( RRRRRR R RRR R R((t2/data/zmath/zope/lib/python/ZEO/zrpc/connection.pyt client_loop+s~   >%33           ttargettDelaycBs)tZdZd„Zd„Zd„ZRS(sóUsed to delay response to client for synchronous calls. When a synchronous call is made and the original handler returns without handling the call, it returns a Delay object that prevents the mainloop from sending a response. cCs||_||_||_dS(N(tmsgidtselfRt return_error(R.R-RR/((R)t set_sender‡s  cCs|i|i|ƒdS(N(R.RR-R(R.R((R)treplyŒscCs4tdtidtƒ|i|id|d ŒdS(NsError raised in delayed methodRii(tlogtloggingtERRORtTrueR.R/R-R(R.R((R)Rs(t__name__t __module__t__doc__R0R1R(((R)R,s   tMTDelaycBs,tZd„Zd„Zd„Zd„ZRS(NcCstiƒ|_dS(N(t threadingtEventR.tready(R.((R)t__init__•scCs'ti||||ƒ|iiƒdS(N(R,R0R.R-RR/R<tset(R.R-RR/((R)R0˜scCs!|iiƒti||ƒdS(N(R.R<twaitR,R1R(R.R((R)R1œs cCs!|iiƒti||ƒdS(N(R.R<R?R,RR(R.R((R)R s (R6R7R=R0R1R(((R)R9“s   RcBsstZdZeiiZeiiZeii Z dZ e gZ dde gZ ed„Zd„ZeZeed„Zd„Zd„Zd „Zd „Zd „Zd „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Z d„Zd„Z d„Z!d„Z"d„Z#d„Z$d„Z%d„Z&d„Z'dd„Z(d„Z)d „Z*d!„Z+d"d#„Z,RS($sÇDispatcher for RPC on object on both sides of socket. The connection supports synchronous calls, which expect a return, and asynchronous calls, which do not. It uses the Marshaller class to handle encoding and decoding of method calls and arguments. Marshaller uses pickle to encode arbitrary Python objects. The code here doesn't ever see the wire format. A Connection is designed for use in a multithreaded application, where a synchronous call must block until a response is ready. A socket connection between a client and a server allows either side to invoke methods on the other side. The processes on each end of the socket use a Connection object to manage communication. The Connection deals with decoded RPC messages. They are represented as four-tuples containing: msgid, flags, method name, and a tuple of method arguments. The msgid starts at zero and is incremented by one each time a method call message is sent. Each side of the connection has a separate msgid state. When one side of the connection (the client) calls a method, it sends a message with a new msgid. The other side (the server), replies with a message that has the same msgid, the string ".reply" (the global variable REPLY) as the method name, and the actual return value in the args position. Note that each side of the Connection can initiate a call, in which case it will be the client for that particular call. The protocol also supports asynchronous calls. The client does not wait for a return value for an asynchronous call. The only defined flag is ASYNC. If a method call message has the ASYNC flag set, the server will raise an exception. If a method call raises an Exception, the exception is propagated back to the client via the REPLY message. The client side will raise any exception it receives instead of returning the value to the caller. tZ303tZ200tZ201cCsqd|_tƒ|_t|_d|_|djpt ‚||_t i d|ƒ|_ t |tiƒod||_nd||_h}|i||d|ƒt|_d|_|iƒh|i|<|_d|_tiƒ|_tiƒ|_h|_ t|_!d|_"|i#|ƒ|i$|_%|i&ƒ|djo t(i)}n||_*|i+|ƒdS(NtCSsZEO.zrpc.Connection(%c)s(%s:%d) s(%s) Ri(,RR.Rt MarshallertmarshaltFalsetclosedtpeer_protocol_versionttagtAssertionErrorR3t getLoggertloggerRtaddrttypest TupleTypet log_labeltourmapt_Connection__super_inittsockt thr_asyncttriggert_prepare_asynct_filenot _singletonR-R:tLockt msgid_lockt Conditiont replies_condtrepliestwaiting_for_replyt delay_sesskeytregister_objecttrecv_handshaket message_inputt handshakeRRt socket_mapt_maptupdate(R.RSRMRRIRRQ((R)R=Ls:                   cCsd|ii|ifS(Ns<%s %s>(R.t __class__R6RM(R.((R)t__repr__¡scCs$|ii||i|d|ƒdS(NR(R.RLR2tlevelRPtmessageR(R.RjRiR((R)R2¦scCs@|iodSn|iiƒt|_|iƒ|iƒdS(N(R.RGRXtclearR5t_Connection__super_closet close_trigger(R.((R)R'©s     cCs2|idj o|iiƒ|iiƒndS(N(R.RURt pull_triggerR'(R.((R)Rm±s cCs ||_dS(s5Register obj as the true object to invoke methods on.N(RR.(R.R((R)R`·scCs t‚dS(N(tNotImplementedError(R.((R)RcÃscCs«|`||_|idjo |i}n!|idjpt‚|i}||jo|i d|dt i ƒn1|i dt |ƒdt i ƒtd|ƒ‚dS(NtCtSsreceived handshake %rRisbad handshake %ssbad handshake %r(R.RbtprotoRHRItservers_we_can_talk_tot good_protosRJtclients_we_can_talk_toR2R3tINFOt short_reprR4t ZRPCError(R.RrRt((R)RaÌs     cCs|ii|ƒ\}}}}to-|i d|||t |ƒfdt ƒn|t jo|i |||ƒn|i||||ƒdS(s*Decode an incoming message and dispatch itsrecv msg: %s, %s, %s, %sRiN(R.REtdecodeRjR-tflagstnametargst __debug__R2RwtTRACEtREPLYt handle_replythandle_request(R.RjR{R-R|Rz((R)RbÞs cCswto*|id||t|ƒfdtƒn|ii ƒz$||f|i |<|ii ƒWd|ii ƒXdS(Nsrecv reply: %s, %s, %sRi( R}R.R2R-RzRwR|R~R\tacquireR]t notifyAlltrelease(R.R-RzR|((R)R€ïs c Csñ|i|ƒp)d|t|iƒf}t|ƒ‚nto*|id|t |ƒfdt i ƒnt |i|ƒ}y*t|_z||Œ}Wdt|_XWnvttfj o ‚n\tj oO}|id||ft idtƒtiƒd }|i|||ŒSnX|t@o1|dj o td|t |ƒfƒ‚qÆnlto'|id|t |ƒft i ƒnt|t ƒo|i!||i"|iƒn|i"||ƒ|i#o|i$|i#ƒd|_#ndS( NsInvalid method name: %s on %ss calling %s%sRis%s() raised exception: %sRis!async method %s returned value %ss %s returns %s(%R.t check_methodR{treprRtmsgRxR}R2RwR|R3tDEBUGtgetattrtmethR5R^tretRFt SystemExittKeyboardInterruptt ExceptionRvR"RRR/R-RztASYNCRRR,R0RR_t _Connection__super_setSessionKey( R.R-RzR{R|RŠR‹R‡R((R)Rús@    $ cCsQtiƒdtjotiƒ‚n|iddtidtƒ|iƒdS(NisError caught in asyncoreRiR( R"RRŒR.R2R3R4R5R'(R.((R)t handle_error"s  cCs(|idƒodSnt|i|ƒS(Nt_(R{t startswithRthasattrR.R(R.R{((R)R…)scCs•y|ii|dt|ƒ}WnXyt|ƒ}Wn d}nXt d|ƒ}|ii|dtt |fƒ}nX|i |ƒ|i ƒdS(Nis sCouldn't pickle return %.100s( R.REtencodeR-RR‹R‡RwR RxRtmessage_outputtpoll(R.R-R‹RR R‡((R)R/s % cCsô|t@o(|id|dtidtƒdSnt|ƒt i j o||f}ny%|i i |dt||fƒ}WnXyt|ƒ}Wn d}nXtd|ƒ}|i i |dtt|fƒ}nX|i|ƒ|iƒdS(Ns&Asynchronous call raised exception: %sRiRis sCouldn't pickle error %.100s(RzRR.R2R3R4R5ttypet err_valueRNt InstanceTypeterr_typeRER•R-RR‡RwR RxRR–R—(R.R-RzR›R™RR R‡((R)R/@s"  % % cCs(|io ||_n|i|ƒdS(N(R.R^tkeyR_R(R.Rœ((R)t setSessionKeyXs  cCs’|iiƒz|i}|id|_Wd|iiƒXto$|id|||fdt ƒn|i i ||||ƒ}|i|ƒ|S(Nissend msg: %d, %d, %s, ...Ri(R.RZR‚R-R„R}R2RztmethodR~RER•R|tbufR–(R.RžR|RzRŸR-((R)t send_callas   cGs±|io tƒ‚n|i||dƒ}|i|ƒ\}}t |t i ƒoUt |ƒdjoBt|dƒt ijo(t|dtƒo|d}|‚n|SdS(Nii(R.RGRR RžR|R-R?tr_flagstr_argsRRNROtlenR˜t ClassTypet issubclassRŽtinst(R.RžR|R-R¢R¡R¦((R)tcallps  T  cGsa|io tƒ‚n|i||dƒ}|iƒo|ii ƒnt i d|i ƒ|S(Nif0.01( R.RGRR RžR|R-tis_asyncRURnRR—RX(R.RžR|R-((R)t_deferred_call€s   cCsr|i|ƒ\}}t|tiƒoBt|dƒti jo(t |dt ƒo|d}|‚n|SdS(Nii( R.R?R-R¡R¢RRNROR˜R¤R¥RŽR¦(R.R-R¢R¡R¦((R)t_deferred_waitŠs A  cGs8|io tƒ‚n|i||tƒ|iƒdS(N(R.RGRR RžR|RR—(R.RžR|((R)t callAsync”s  cGs.|io tƒ‚n|i||tƒdS(N(R.RGRR RžR|R(R.RžR|((R)tcallAsyncNoPollšs  cCst|_ti|iƒdS(N(RFR.RTt ThreadedAsynctregister_loop_callbackt set_async(R.((R)RV¤s cCstƒ|_t|_dS(N(RUR.R5RT(R.R((R)R¯ªs cCs|iodSndSdS(Nii(R.RT(R.((R)R¨®s i cCsiy|iiƒWnQtj oE|iiƒtƒ|_|djo|id|dƒqenXdS(Nittryagaini(R.RURntOSErrorR'R°t _pull_trigger(R.R°((R)R²µs   cCsÌto'|id||iƒfdtƒn|iƒo|iƒnd}|ii ƒz[xT|i o t ƒ‚n|i i |ƒ}|d j o@|i |=to'|id|t|ƒfdtƒn|Sn|iƒo|iidƒqb|iiƒzšyZto!|id||fdtƒnti||iƒ|djo||7}nWn9tij o*}|id |dtƒ|iƒnXWd |ii ƒXqbWWd |iiƒXd S( s,Invoke asyncore mainloop and wait for reply.swait(%d), async=%dRif0.001iswait(%d): reply=%sf10.0swait(%d): asyncore.poll(%s)f1.0s$Closing. asyncore.poll() raised %s.N(R}R.R2R-R¨R~R²tdelayR\R‚RGRR]RR1RRwR?R„RR—RXRRRtBLATHERR'(R.R-RR³R1((R)R?¾sN           cCs;to|idƒnx|iƒo|iƒqWdS(s/Invoke poll() until the output buffer is empty.tflushN(R}R.R2RR—(R.((R)Rµës  cCsZto!|id|iƒdtƒn|iƒo|iƒntid|iƒdS(s4Invoke asyncore mainloop to get pending message out.spoll(), async=%dRif0.0N( R}R.R2R¨R~R²RR—RX(R.((R)R—òs ! ic Csˆto!|id|iƒdtƒn|iƒodSn|ig}}g}x.|o&|i o|i ƒo|ig}ng}y%t i ||||ƒ\}}}Wn<t ij o-}|dtijo d}qVqõ‚nXd}|o>y|iƒWq:tij o ‚q:|iƒq:Xn|o>y|iƒWqtij o ‚q|iƒqXqVqVWdS(s7Invoke mainloop until any pending messages are handled.spending(), async=%dRiNi(R}R.R2R¨R~RWR tr_intx_inRGRtw_inRttimeoutRtxRRRRthandle_read_eventRtExitNowR‘thandle_write_event( R.R¹RRR·R RºR¶R¸((R)t_pendingûsD!   % (-R6R7R8tsmactSizedMessageAsyncConnectionR=RRR'RlRRtcurrent_protocolRsRuRRht__str__R´RFR2RmR`RcRaRbR€RR‘R…RR/R R§R©RªR«R¬RVR¯R¨R²R?RµR—R¾(((R)RàsL +     U      (           -  tManagedServerConnectioncBs;tZdZeiZeiZd„Zd„Zd„ZRS(s Server-side Connection subclass.cCs3||_|i|||dƒ|ii|ƒdS(NRq(R%R.t$_ManagedServerConnection__super_initRSRMRtnotifyConnected(R.RSRMRR%((R)R=5s cCs|i|iƒdS(N(R.R–RÁ(R.((R)Rc:scCs+|iiƒ|ii|ƒ|iƒdS(N(R.RtnotifyDisconnectedR%t close_connt%_ManagedServerConnection__super_close(R.((R)R'>s ( R6R7R8RR=RÄR'RÈRc(((R)RÃ0s     tManagedClientConnectioncBsztZdZeiZeiZeiZ d„Zd„Zd„Z d„Z d„Z d„Z d„Zd„Zd „ZRS( s Client-side Connection subclass.cCsi||_tiƒ|_t|_g|_|i|||dddt ƒt|_ t|_tiƒdS(NRIRpR(R%R.R:RYt output_lockR5t queue_outputtqueued_messagest$_ManagedClientConnection__super_initRSRMRRRTR$RURn(R.RSRMRR%((R)R=Is     cCsc|iiƒzA|io|ii|ƒn |i pt‚|i|ƒWd|ii ƒXdS(N( R.RÊR‚RËRÌtappendRjRJtbase_message_outputR„(R.Rj((R)R–as  cCs|ipt‚dS(N(R.RËRJ(R.((R)RclscCsˆt||iƒ}ti||ƒ|iiƒzD|i|ƒx|i D]}|i|ƒqIWg|_ t |_ Wd|ii ƒXdS(N(tminRrR.RÁRRaRÊR‚RÏRÌRjRFRËR„(R.RrRj((R)Rass     cCs|iiƒdS(N(R.RURn(R.((R)Rm‹scCsdS(N((R.R((R)R¯“scCsdS(N((R.((R)RV–scCstS(N(R5(R.((R)R¨šscCs|ii|ƒ|iƒdS(N(R.R%RÇt%_ManagedClientConnection__super_close(R.((R)R's(R6R7R8RR=RÍR'RÑR–RÏRcRaRmR¯RVR¨(((R)RÉCs           (.RRRR"R:RNR3t tracebackttimeR­tZEO.zrpcR¿tZEO.zrpc.errorRxRtZEO.zrpc.marshalRDtZEO.zrpc.triggerRUt ZEO.zrpc.logRwR2tZODB.loglevelsR´R~RRRRRR$RKR R*tThreadt client_threadt setDaemonR5tstartR,R9RÀtobjectRRÃRÉ( RÃRRR¿R,R9RRRwR2R:RRÛRR*RUR­RxRR"RÉRR RRNR´R3R~RÒRDRÓR$((R)t?s@             N  MÿÿR