o —~µ_("ã@sÔdZddlmZddlmZddlZddlZddlZddlmZej   d¡dkr5ddl Z ddl Z e   ¡e _ejZGd d „d eƒZGd d „d eƒZGd d„deƒZGdd„deƒZGdd„deƒZGdd„deƒZdS)zÆProvides a high-level interface to some librsync functions This is a python wrapper around the lower-level _librsync module, which is written in C. The goal was to use C as little as possible... é)Úobject)ÚstrNé)Ú _librsyncÚ READTHEDOCSÚTruec@seZdZdZdS)Ú librsyncErrora/Signifies error in internal librsync processing (bad signature, etc.) underlying _librsync.librsyncError's are regenerated using this class because the C-created exceptions are by default unPickleable. There is probably a way to fix this in _librsync, but this scheme was easier. N)Ú__name__Ú __module__Ú __qualname__Ú__doc__©r r ú4/usr/lib/python3/dist-packages/duplicity/librsync.pyr.src@sNeZdZdZdZdZddd„Zddd„Zdd d „Zd d „Z d d„Z dd„Z dS)ÚLikeFilez:File-like object used by SigFile, DeltaFile, and PatchFileÚrbNcCs@| ||¡||_d|_|_d|_t d¡|_d|_|_dS)z1LikeFile initializer - zero buffers, set eofs offNóÚb) Ú check_fileÚinfileÚclosedÚ infile_closedÚinbufÚarrayÚoutbufÚeofÚ infile_eof)ÚselfrÚ need_seekr r rÚ__init__Bs   zLikeFile.__init__cCsBt|dƒs tdƒ‚t|dƒstdƒ‚|rt|dƒstdƒ‚dSdS)z:Raise type error if file doesn't have necessary attributesÚreadz$Basis file must have a read() methodÚclosez%Basis file must have a close() methodÚseekz$Basis file must have a seek() methodN)ÚhasattrÚ TypeError)rÚfilerr r rrKs  ÿzLikeFile.check_fileéÿÿÿÿcCsª|dkr|js| ¡|jrt|jƒ}n |js,t|jƒ|kr,| ¡|js,t|jƒ|kst|t|jƒƒ}tjjdkrD|jd|… ¡}n |jd|…  ¡}|jd|…=|S)z/Build up self.outbuf, return first length bytesr%éN) rÚ_add_to_outbuf_onceÚlenrÚminÚsysÚ version_infoÚmajorÚtobytesÚtostring)rÚlengthÚreal_lenÚ return_valr r rrTsÿ ÿ  z LikeFile.readc CsŒ|js| ¡z |j |j¡\|_}}Wntjy'}ztt|ƒƒ‚d}~ww|j|d…|_t j j dkr>|j   |¡dS|j  |¡dS)z.Add one cycle's worth of output to self.outbufNr&)rÚ _add_to_inbufÚmakerÚcyclerrrrrr*r+r,rÚ frombytesÚ fromstring)rÚlen_inbuf_readÚ cycle_outÚer r rr'fs €ÿ zLikeFile._add_to_outbuf_oncecCsj|jrJ‚t|jƒtkr3|j t¡}|s#d|_|j ¡rJ‚d|_dS|j|7_t|jƒtks dSdS)z&Make sure len(self.inbuf) >= blocksizerN)rr(rÚ blocksizerrr r)rÚnew_inr r rr2ts  ùzLikeFile._add_to_inbufcCs|js |j ¡r J‚d|_dS)z Close infilerN)rrr r©rr r rr €s zLikeFile.close)N)r%) r r r r Úmoder3rrrr'r2r r r r rr:s   rc@seZdZdZejfdd„ZdS)ÚSigFilezCFile-like object which incrementally generates a librsync signaturec CsFt ||¡z t |¡|_WdStjy"}ztt|ƒƒ‚d}~ww)z¸SigFile initializer - takes basis file basis file only needs to have read() and close() methods. It will be closed when we come to the end of the signature. N)rrrÚ new_sigmakerr3rr)rrr:r9r r rr‰s  €ÿzSigFile.__init__N)r r r r rÚRS_DEFAULT_BLOCK_LENrr r r rr>‡sr>c@óeZdZdZdd„ZdS)Ú DeltaFilez?File-like object which incrementally generates a librsync deltac Cstt ||¡t|tƒr|}n| |¡| ¡}| ¡rJ‚z t |¡|_ WdStj y9}zt t |ƒƒ‚d}~ww)a DeltaFile initializer - call with signature and new file Signature can either be a string or a file with read() and close() methods. New_file also only needs to have read() and close() methods. It will be closed when self is closed. N) rrÚ isinstanceÚbytesrrr rÚnew_deltamakerr3rr)rÚ signatureÚnew_fileÚ sig_stringr9r r rr™s     €ÿzDeltaFile.__init__N©r r r r rr r r rrB—ó rBc@rA)Ú PatchedFilez=File-like object which applies a librsync delta incrementallyc Csˆt ||¡z| ¡Wn t|dƒr t|jdƒr |j}nttdƒƒ‚Yz t |¡|_ WdStj yC}zt t |ƒƒ‚d}~ww)zùPatchedFile initializer - call with basis delta Here basis_file must be a true Python file, because we may need to seek() around in it a lot, and this is done in C. delta_file only needs read() and close() methods. r$Úfilenozebasis_file must be a (true) file or an object whose file attribute is the underlying true file objectN) rrrLr"r$r#Ú_rÚnew_patchmakerr3rr)rÚ basis_fileÚ delta_filer9r r rr°s   þ €ÿzPatchedFile.__init__NrIr r r rrK®rJrKc@s6eZdZdZejfdd„Zdd„Zdd„Zdd „Z d S) Ú SigGeneratorz‚Calculate signature. Input and output is same as SigFile, but the interface is like md5 module, not filelike object c CsNzt |¡|_Wntjy}ztt|ƒƒ‚d}~wwd|_d|_g|_dS)zReturn new signature instanceNr)rr?Ú sig_makerrrÚgotsigÚbufferÚsigstring_list)rr:r9r r rrÓs €ÿ zSigGenerator.__init__cCsP|jrtdƒ‚|j|7_t|jƒtkr&| ¡rtdƒ‚t|jƒtksdSdS)z6Add buf to data that signature will be calculated overz'SigGenerator already provided signaturez%Premature EOF received from sig_makerN)rSrrTr(r:Úprocess_buffer)rÚbufr r rÚupdateÝsþzSigGenerator.updatec Cs`z |j |j¡\}}}Wntjy}ztt|ƒƒ‚d}~ww|j|d…|_|j |¡|S)z9Run self.buffer through sig_maker, add to self.sig_stringN)rRr4rTrrrrUÚappend)rrÚ len_buf_readr8r9r r rrVæs €ÿ zSigGenerator.process_buffercCs| ¡s | ¡rd |j¡S)z Return signature over given datar)rVÚjoinrUr<r r rÚgetsigðsÿ zSigGenerator.getsigN) r r r r rr@rrXrVr\r r r rrQÌs   rQ)r ÚbuiltinsrrrÚosr*ÚrÚenvironÚgetÚmockÚ duplicityÚ MagicMockÚRS_JOB_BLOCKSIZEr:Ú Exceptionrrr>rBrKrQr r r rÚs$     M