Ë –B'棴µÞãóø—dZddl­ddl­ddlmZddl­ddlmZddlZddlZddl Z ddl Z ddl Z e jd«Z Gd„d e«ZGd „d e«ZGd „d e«ZGd„de«ZGd„de«Zy)aKThis module implements all contexts for state handling during uploads and downloads, the main interface to which being the TftpContext base class. The concept is simple. Each context object represents a single upload or download, and the state object in the context object represents the current state of that transfer. The state object has a handle() method that expects the next packet in the transfer, and returns a state object until the transfer is complete, at which point it returns None. That is, unless there is a fatal error, in which case a TftpException is returned instead.é)Ú*)ÚTftpPacketFactory)ÚcompatéNztftpy.TftpContextcó"—eZdZdZd„Zd„Zd„Zy)Ú TftpMetricsz-A class representing metrics of the transfer.có�—d|_d|_i|_d|_d|_d|_d|_d|_d|_d|_ y)Nr) ÚbytesÚ resent_bytesÚdupsÚdupcountÚ start_timeÚend_timeÚdurationÚbpsÚkbpsÚerrors©Úselfs ú7/usr/lib/python3.12/site-packages/tftpy/TftpContexts.pyÚ__init__zTftpMetrics.__init__!sI€àˆŒ àˆÔàˆŒ ؈Œ àˆŒØˆŒ ؈Œ àˆŒØˆŒ àˆ� ócó¼—|j|jz |_|jdk(rd|_tj d|j«|j dz|jz |_|j dz |_tj d|j«|jD]$}|xj|j|z c_ Œ&y)Nrrz#TftpMetrics.compute: duration is %sg @g�@zTftpMetrics.compute: kbps is %s) rrrÚlogÚdebugr rrr r )rÚkeys rÚcomputezTftpMetrics.compute3sœ€àŸ ™ ¨¯©Ñ7ˆŒ Ø �=‰=˜AÒ ØˆDŒMÜ � ‰ Ð7¸¿¹ÔGØ—J‘J Ñ$¨¯ © Ñ5ˆŒØ—H‘H˜vÑ%ˆŒ Ü � ‰ Ð3°T·Y±YÔ?Ø—9”9ˆCØ �MŠM˜TŸY™Y s™^Ñ +ŽMñrcóð—tjd|«t|«}||jvr|j|xxdz cc<nd|j|<t |j|t kd«y)z3This method adds a dup for a packet to the metrics.zRecording a dup of %srzMax duplicates reachedN)rrÚstrr Ú tftpassertÚMAX_DUPS)rÚpktÚss rÚadd_dupzTftpMetrics.add_dup?s\€ä � ‰ Ð)¨3Ô/Ü �‹HˆØ �— ‘ ‰>Ø �I‰I�a‹L˜AÑ ŒLàˆD�I‰I�a‰LÜ�4—9‘9˜Q‘<¤(Ñ*Ð,DÕErN)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrr$©rrrrs„Ù7òò$ ,óFrrcó~—eZdZdZedfd„Zd„Zd„Zd„Zd„Z dd„Z d „Z d „Z e e e «Zd „Zd „Ze ee«Zd „Zy)Ú TftpContextzThe base class of the contexts.Úcóú—d|_d|_d|_d|_t jtj tj «|_|dk7r|jj|df«|jj|«||_ ||_ d|_ d|_ t«|_||_||_d|_t'«|_d|_d|_d|_d|_y)zLConstructor for the base context, setting shared instance variables.Nr,rF)Úfile_to_transferÚfileobjÚoptionsÚ packethookÚsocketÚAF_INETÚ SOCK_DGRAMÚsockÚbindÚ settimeoutÚtimeoutÚretriesÚstateÚ next_blockrÚfactoryÚhostÚportÚtidportrÚmetricsÚpending_completeÚ last_updateÚlast_pktÚ retry_count)rr=r>r8r9Úlocalips rrzTftpContext.__init__PsÏ€ð!%ˆÔ؈Œ ؈Œ ؈ŒÜ—M‘M¤&§.¡.´&×2CÑ2CÓDˆŒ Ø �bŠ=Ø �I‰I�N‰N˜G Q˜<Ô (Ø � ‰ ×јWÔ%؈Œ ؈Œ ؈Œ ؈ŒÜ(Ó*ˆŒ àˆŒ ؈Œ àˆŒ ä"“}ˆŒ à %ˆÔðˆÔàˆŒ àˆÕrcóL—t|jjdd««S)z-Fetch the current blocksize for this session.Úblksizei)Úintr0Úgetrs rÚ getBlocksizezTftpContext.getBlocksizeqs€ä�4—<‘<×#Ñ# I¨sÓ3Ó4Ð4rcó$—|j«y)z˜Simple destructor to try to call housekeeping in the end method if not called explicitely. Leaking file descriptors is not a good thing.N)Úendrs rÚ__del__zTftpContext.__del__us €ð �‰� rcó~—tjd|«||jz |jkDr t d«‚y)zjCompare current time with last_update time, and raise an exception if we're over the timeout time.z"checking for timeout on session %szTimeout waiting for trafficN)rrrBr8Ú TftpTimeout)rÚnows rÚ checkTimeoutzTftpContext.checkTimeout{s;€ô � ‰ Ð6¸Ô=Ø �×!Ñ!Ñ ! D§L¡LÒ 0ÜÐ;Ó<Ð <ð 1rcó—td«‚)NzAbstract method)ÚNotImplementedErrorrs rÚstartzTftpContext.start‚s€Ü!Ð"3Ó4Ð4rcó—tjd«|jj«|rT|j�G|jj s0tjd«|jj«yyyy)záPerform session cleanup, since the end method should always be called explicitely by the calling code, this works better than the destructor. Set close_fileobj to False so fileobj can be returned open.z#in TftpContext.end - closing socketNzself.fileobj is open - closing)rrr5Úcloser/Úclosed)rÚ close_fileobjs rrLzTftpContext.end…s_€ô � ‰ Ð7Ô8Ø � ‰ �‰ÔÙ ˜TŸ\™\Ð5¸d¿l¹l×>QÒ>QÜ �I‰IÐ6Ô 7Ø �L‰L× Ñ Õ ð?RÐ5ˆ=rcó—|jS)z+Simple getter method for use in a property.)Ú_TftpContext__hostrs rÚgethostzTftpContext.gethost�s €à�{‰{ÐrcóF—||_tj|«|_y)z^Setter method that also sets the address property as a result of the host that is set.N)rZr2Ú gethostbynameÚaddress)rr=s rÚsethostzTftpContext.sethost”s€ðˆŒ Ü×+Ñ+¨DÓ1ˆ� rcóJ—|dk\rtjd«d}||_y)Niz Block number rollover to 0 againr)rrÚ_TftpContext__eblock)rÚblocks rÚ setNextBlockzTftpContext.setNextBlockœs#€Ø �GÒ Ü �I‰IÐ8Ô 9؈E؈� rcó—|jS©N)rars rÚ getNextBlockzTftpContext.getNextBlock¢s €Ø�}‰}Ðrc ó— |jjt«\}\}}t jdt|«||«tj«|_ |jj|«}||jk7r&t j d|›d|j›d�«|j rE|j |k7r6t j d|›d|›d|j›d|j ›d � «|j"r|j#|«|j$j'|||«|_d |_y #tj$r!t j d«td«‚wxYw) z�Here we wait for a response from the server after sending it something, and dispatch appropriate action to that response.z(Timeout waiting for traffic, retrying...zTimed-out waiting for trafficzReceived %d bytes from %s:%szReceived traffic from z, expected host z . DiscardingÚ:z but we're connected to z . Discarding.rN)r5ÚrecvfromÚ MAX_BLKSIZEr2r8rÚwarningrOrÚlenÚtimerBr<Úparser^r=r?r1r:ÚhandlerD)rÚbufferÚraddressÚrportÚrecvpkts rÚcyclezTftpContext.cycle§s0€ð ?Ø*.¯)©)×*<Ñ*<¼[Ó*IÑ 'ˆVÑ&�h ô � ‰ Ð0ܘF›  X¨uô 6ô Ÿ9™9›;ˆÔð—,‘,×$Ñ$ VÓ,ˆð �t—|‘|Ò #Ü �KŠKÚ# T§Y£Yð0ô 1ð �<Š<˜DŸL™L¨EÒ1Ü �KŠKâ#¢UØŸ ›  4§<£<ð1ô 2ð �?Š?Ø �O‰O˜GÔ $ð—Z‘Z×&Ñ& w°¸%Ó@ˆŒ ðˆÕøôG�~‰~ò ?Ü �K‰KÐBÔ CÜÐ=Ó>Ð >ð ?ús ‚%E Å 4E=N)T)r%r&r'r(ÚDEF_TIMEOUT_RETRIESrrJrMrQrTrLr[r_Úpropertyr=rcrfr;rtr)rrr+r+Ms_„Ù)à4GÐSUóòB5òò =ò5ó !òò2ñ �G˜WÓ %€Dòò ñ˜,¨ Ó5€Jó(rr+có0—eZdZdZddefd„Zd„Zd„Zd„Zy)ÚTftpContextServerzThe context for the server.Ncó€—tj|||||«t|«|_||_||_||_yre)r+rÚTftpStateServerStartr:ÚrootÚ dyn_file_funcÚ upload_open)rr=r>r8r{r|r}r9s rrzTftpContextServer.__init__ÓsE€ô ×јTØ!Ø!Ø$Ø$ô  ô*¨$Ó/ˆŒ àˆŒ Ø*ˆÔØ&ˆÕrcóR—|j›d|j›d|j›�S©NrhÚ ©r=r>r:rs rÚ__str__zTftpContextServer.__str__éó€Ø!ŸY›Y¨¯ « °4·:²:Ð>Ð>rcóÈ—tjd«tj«|j_tjd|jj«tj«|_|j j|«}tjd|«|jj||j|j«|_y)zãStart the state cycle. Note that the server context receives an initial packet in its start method. Also note that the server does not loop on cycle(), as it expects the TftpServer object to manage that.zIn TftpContextServer.startúSet metrics.start_time to %sz1TftpContextServer.start() - factory returned a %sN) rrrmr@rrBr<rnr:ror=r>)rrpr"s rrTzTftpContextServer.startìs•€ô � ‰ Ð.Ô/Ü"&§)¡)£+ˆ� ‰ ÔÜ � ‰ Ð0°$·,±,×2IÑ2IÔJäŸ9™9›;ˆÔà�l‰l× Ñ  Ó(ˆÜ � ‰ ÐEÀsÔKð—Z‘Z×&Ñ& sØ'+§y¡yØ'+§y¡yó2ˆ� rcóü—tj|«tj«|j_t j d|jj«|jj«y©zFinish up the context.zSet metrics.end_time to %sN©r+rLrmr@rrrrrs rrLzTftpContextServer.endsI€ä�‰˜ÔÜ $§ ¡ £ ˆ� ‰ ÔÜ � ‰ Ð.°· ± ×0EÑ0EÔFØ � ‰ ×ÑÕr© r%r&r'r(rurr‚rTrLr)rrrxrxÑs$„Ù%ð $Ø!Ø,ó'ò,?ò2ó(rrxcó.—eZdZdZedfd„Zd„Zd„Zd„Zy)ÚTftpContextClientUploadzkThe upload context for the client during an upload. Note: If input is a hyphen, then we will use stdin.r,c ór—tj|||||| «||_||_||_t |d«r||_n0|dk(rtj«|_nt|d«|_tjd«tjd|j›d|j›�«y)NÚreadÚ-Úrbz"TftpContextClientUpload.__init__()úfile_to_transfer = ú , options = ) r+rr.r0r1Úhasattrr/rÚ binary_stdinÚopenrr) rr=r>ÚfilenameÚinputr0r1r8r9rEs rrz TftpContextClientUpload.__init__ s €ô ×јTØ!Ø!Ø$Ø$Ø$ô  &ð !)ˆÔ؈Œ Ø$ˆŒô �5˜&Ô !Ø ˆD�LØ �cŠ\Ü!×.Ñ.Ó0ˆD�Lä  tÓ,ˆDŒLä � ‰ Ð6Ô7Ü � Š Ø × "Ó " D§L¢Lð2õ 3rcóR—|j›d|j›d|j›�Srr�rs rr‚zTftpContextClientUpload.__str__*rƒrcóŒ—tjd|jz«tjd|jz«tjd|jz«t j «|j _tjd|j jz«t«}|j|_ d|_ |j|_|jj|j«j|j|j f«d|_||_t'|«|_|j(rA tjd|j(z«|j+«|j(rŒ@yy#t,$r›}tj/t1|««|xj2dz c_|j2|j4k\rtjd«‚tj7d «|j(j9«Yd}~Œ®d}~wwxYw) Nz!Sending tftp upload request to %sú filename -> %sú options -> %sr…Úoctetrú State is %súhit max retries, giving upúresending last packet)rÚinfor=r.r0rmr@rrÚ TftpPacketWRQr•Úmoder5ÚsendtoÚencoderpr>r;rCÚTftpStateSentWRQr:rtrOÚerrorrrDr9rkÚ resendLast©rr"Úerrs rrTzTftpContextClientUpload.start-s�€Ü �‰Ð4°t·y±yÑ@ÔAÜ �‰Ð%¨×(=Ñ(=Ñ=Ô>Ü �‰Ð$ t§|¡|Ñ3Ô4ä"&§)¡)£+ˆ� ‰ ÔÜ � ‰ Ð0°4·<±<×3JÑ3JÑJÔKô‹oˆØ×,Ñ,ˆŒ ؈ŒØ—l‘lˆŒ Ø � ‰ ×јŸ™›×,Ñ,¨t¯y©y¸$¿)¹)Ð.DÔE؈ŒØˆŒ ô& dÓ+ˆŒ à�jŠjð ,Ü— ‘ ˜-¨$¯*©*Ñ4Ô5Ø— ‘ ” ð�j�jøôò ,Ü— ‘ œ#˜c›(Ô#Ø× Ò  AÑ%Õ Ø×#Ñ# t§|¡|Ò3Ü—I‘IÐ:Ô;Øä—K‘KÐ 7Ô8Ø—J‘J×)Ñ)×+Ñ+ûð ,úsÅ2FÆ IÆ(BH>È>Icó—tj|«tj«|j_t j d|jjz«|jj«yr‡rˆrs rrLzTftpContextClientUpload.endPsL€ä�‰˜ÔÜ $§ ¡ £ ˆ� ‰ ÔÜ � ‰ Ð.°·±×1FÑ1FÑFÔGØ � ‰ ×ÑÕrNr‰r)rrr‹r‹s%„ñ;ð-Øó3ò@?ò!,óFrr‹có.—eZdZdZedfd„Zd„Zd„Zd„Zy)ÚTftpContextClientDownloadzThe download context for the client during a download. Note: If output is a hyphen, then the output will be sent to stdout.r,c ó”—tj|||||| «||_||_||_d|_t |d«r||_d|_n3|dk(rtj|_d|_nt|d«|_tjd«tjd|j›d|j›�«y) NFÚwriteTrŽÚwbz$TftpContextClientDownload.__init__()r�r‘) r+rr.r0r1Úfilelike_fileobjr’r/ÚsysÚstdoutr”rr) rr=r>r•Úoutputr0r1r8r9rEs rrz"TftpContextClientDownload.__init__[s³€ô ×јTØ!Ø!Ø$Ø$Ø$ô  &ð!)ˆÔ؈Œ Ø$ˆŒØ %ˆÔô �6˜7Ô #Ø!ˆDŒLØ$(ˆDÕ !à �sŠ]ÜŸ:™:ˆDŒLØ$(ˆDÕ !ä ¨Ó-ˆDŒLä � ‰ Ð8Ô9Ü � Š Ø × "Ó " D§L¢Lð2õ 3rcóR—|j›d|j›d|j›�Srr�rs rr‚z!TftpContextClientDownload.__str__€rƒrcó —tjd|jz«tjd|jz«tjd|jz«t j «|j _tjd|j jz«t«}|j|_ d|_ |j|_|jj|j«j|j|j f«d|_||_t'|«|_|j(rA tjd|j(z«|j+«|j(rŒ@y y #t,$r›}tj/t1|««|xj2dz c_|j2|j4k\rtjd«‚tj7d «|j(j9«Yd }~Œ®d }~wt:$r¹}tj/d «|j<�’|j>s†t@jBjE|j<jF«rStjd |j<jF«tAjH|j<jF«‚d }~wwxYw) zInitiate the download.z#Sending tftp download request to %sr™ršr…r›rrœr�ržNzReceived File not found errorzunlinking output file of %s)%rrŸr=r.r0rmr@rrÚ TftpPacketRRQr•r¡r5r¢r£rpr>r;rCÚTftpStateSentRRQr:rtrOr¥rrDr9rkr¦ÚTftpFileNotFoundErrorr/r¯ÚosÚpathÚexistsÚnameÚunlinkr§s rrTzTftpContextClientDownload.startƒs€ä �‰Ð6¸¿¹ÑBÔCÜ �‰Ð%¨×(=Ñ(=Ñ=Ô>Ü �‰Ð$ t§|¡|Ñ3Ô4ä"&§)¡)£+ˆ� ‰ ÔÜ � ‰ Ð0°4·<±<×3JÑ3JÑJÔKô‹oˆØ×,Ñ,ˆŒ ؈ŒØ—l‘lˆŒ Ø � ‰ ×јŸ™›×,Ñ,¨t¯y©y¸$¿)¹)Ð.DÔE؈ŒØˆŒ ä% dÓ+ˆŒ à�jŠjð Ü— ‘ ˜-¨$¯*©*Ñ4Ô5Ø— ‘ ” ð�j�jøôò ,Ü— ‘ œ#˜c›(Ô#Ø× Ò  AÑ%Õ Ø×#Ñ# t§|¡|Ò3Ü—I‘IÐ:Ô;Øä—K‘KÐ 7Ô8Ø—J‘J×)Ñ)×+Ñ+ûÜ(ò ô— ‘ Ð9Ô:Ø—<‘<Ð+°D×4IÒ4IÜ—w‘w—~‘~ d§l¡l×&7Ñ&7Ô8ÜŸ ™ Ð"?ÀÇÁ×ARÑARÔSÜŸ ™  $§,¡,×"3Ñ"3Ô4àûð ús&Å2FÆ LÆ(BH>È> LÉ B4K>Ë>Lcó—tj||j «tj«|j_t jd|jj z«|jj«yr‡) r+rLr¯rmr@rrrrrs rrLzTftpContextClientDownload.end°sW€ä�‰˜ $×"7Ñ"7Ð7Ô8Ü $§ ¡ £ ˆ� ‰ ÔÜ � ‰ Ð.°·±×1FÑ1FÑFÔGØ � ‰ ×ÑÕrNr‰r)rrr«r«Xs&„ñLð-Øó#3òJ?ò+óZrr«)r(Ú TftpSharedÚTftpPacketTypesrÚ TftpStatesr,rr2rmr°r¸ÚloggingÚ getLoggerrÚobjectrr+rxr‹r«r)rrÚrÄs…ðñ=ôÜÝ0ÜÝÛ Û Û Û Ûà€g×ÑÐ+Ó,€ô (F�&ô(Fô\B�&ôBôH4˜ ô4ôlN˜kôNôb]  õ]r