³ò
OÉcIc           @   sµ   d  Z  d d k Z d d k Z d d k Z e i Z d e f d „  ƒ  YZ d d d „  ƒ  YZ d e f d „  ƒ  YZ	 d	 e f d
 „  ƒ  YZ
 d e f d „  ƒ  YZ d d d „  ƒ  YZ d S(   sÆ   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...

iÿÿÿÿNt   librsyncErrorc           B   s   e  Z d  Z RS(   s   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.

	(   t   __name__t
   __module__t   __doc__(    (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/librsync.pyR        s   t   LikeFilec           B   sY   e  Z d  Z d Z d	 Z d	 d „ Z d	 d „ Z d d „ Z d „  Z	 d „  Z
 d „  Z RS(
   s:   File-like object used by SigFile, DeltaFile, and PatchFilet   rbc         C   sX   |  i  | | ƒ | |  _ d |  _ |  _ d |  _ t i d ƒ |  _ d |  _ |  _	 d S(   s1   LikeFile initializer - zero buffers, set eofs offt    t   cN(
   t
   check_filet   infilet   Nonet   closedt   infile_closedt   inbuft   arrayt   outbuft   eoft
   infile_eof(   t   selfR	   t	   need_seek(    (    s:   /var/lib/python-support/python2.5/rdiff_backup/librsync.pyt   __init__4   s    		c         C   sl   t  | d ƒ p t d ƒ ‚ n t  | d ƒ p t d ƒ ‚ n | o! t  | d ƒ o t d ƒ ‚ n d S(   s:   Raise type error if file doesn't have necessary attributest   reads$   Basis file must have a read() methodt   closes%   Basis file must have a close() methodt   seeks$   Basis file must have a seek() methodN(   t   hasattrt	   TypeError(   R   t   fileR   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/librsync.pyR   =   s    iÿÿÿÿc         C   s¨   | d j o/ x |  i  p |  i ƒ  q Wt |  i ƒ } nL x0 |  i  o$ t |  i ƒ | j  o |  i ƒ  q? Wt | t |  i ƒ ƒ } |  i |  i ƒ  } |  i | 4| S(   s/   Build up self.outbuf, return first length bytesiÿÿÿÿ(   R   t   _add_to_outbuf_oncet   lenR   t   mint   tostring(   R   t   lengtht   real_lent
   return_val(    (    s:   /var/lib/python-support/python2.5/rdiff_backup/librsync.pyR   F   s     
  !
c         C   sŽ   |  i  p |  i ƒ  n y% |  i i |  i ƒ \ |  _ } } Wn* t i j
 o } t t | ƒ ƒ ‚ n X|  i | |  _ |  i	 i
 | ƒ d S(   s.   Add one cycle's worth of output to self.outbufN(   R   t   _add_to_inbuft   makert   cycleR   R   t	   _librsyncR    t   strR   t
   fromstring(   R   t   len_inbuf_readt	   cycle_outt   e(    (    s:   /var/lib/python-support/python2.5/rdiff_backup/librsync.pyR   T   s    
  % c         C   s…   |  i  p t ‚ xl t |  i ƒ t j  oU |  i i t ƒ } | p) d |  _  |  i i ƒ  |  _ d |  _	 Pn |  i | 7_ q Wd S(   s&   Make sure len(self.inbuf) >= blocksizei   N(
   R   t   AssertionErrorR   R   t	   blocksizeR	   R   R   t   infile_closevalR   (   R   t   new_in(    (    s:   /var/lib/python-support/python2.5/rdiff_backup/librsync.pyR"   \   s     		c         C   s/   d |  _  |  i o |  i Sn |  i i ƒ  Sd S(   s+   Close infile and pass on infile close valuei   N(   R   R   R-   R	   R   (   R   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/librsync.pyR   h   s    	
 N(   R   R   R   t   modeR
   R#   R   R   R   R   R"   R   (    (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/librsync.pyR   ,   s   				t   SigFilec           B   s   e  Z d  Z e i d „ Z RS(   sC   File-like object which incrementally generates a librsync signaturec         C   sW   t  i |  | ƒ y t i | ƒ |  _ Wn* t i j
 o } t t | ƒ ƒ ‚ n Xd S(   s¦   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(   R   R   R%   t   new_sigmakerR#   R    R&   (   R   R	   R,   R*   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/librsync.pyR   q   s
      (   R   R   R   R%   t   RS_DEFAULT_BLOCK_LENR   (    (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/librsync.pyR0   o   s   t	   DeltaFilec           B   s   e  Z d  Z d „  Z RS(   s?   File-like object which incrementally generates a librsync deltac         C   s¥   t  i |  | ƒ t | ƒ t i j o
 | } n/ |  i | ƒ | i ƒ  } | i ƒ  p t ‚ y t	 i
 | ƒ |  _ Wn* t	 i j
 o } t t | ƒ ƒ ‚ n Xd S(   sõ   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(   R   R   t   typet   typest
   StringTypeR   R   R   R+   R%   t   new_deltamakerR#   R    R&   (   R   t	   signaturet   new_filet
   sig_stringR*   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/librsync.pyR   ~   s     
  (   R   R   R   R   (    (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/librsync.pyR3   |   s   t   PatchedFilec           B   s   e  Z d  Z d „  Z RS(   s=   File-like object which applies a librsync delta incrementallyc         C   sš   t  i |  | ƒ t | d ƒ o | i } n t | ƒ t i j	 o t d ƒ ‚ n y t i	 | ƒ |  _
 Wn* t i j
 o } t t | ƒ ƒ ‚ n Xd S(   sá   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   s    basis_file must be a (true) fileN(   R   R   R   R   R4   R5   t   FileTypeR   R%   t   new_patchmakerR#   R    R&   (   R   t
   basis_filet
   delta_fileR*   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/librsync.pyR   ’   s      (   R   R   R   R   (    (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/librsync.pyR;      s   t   SigGeneratorc           B   s8   e  Z d  Z e i d „ Z d „  Z d „  Z d „  Z RS(   sy   Calculate signature.

	Input and output is same as SigFile, but the interface is like md5
	module, not filelike object

	c         C   sb   y t  i | ƒ |  _ Wn* t  i j
 o } t t | ƒ ƒ ‚ n Xd |  _ d |  _ d |  _ d S(   s   Return new signature instanceR   N(	   R%   R1   t	   sig_makerR    R&   R
   t   gotsigt   bufferR:   (   R   R,   R*   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/librsync.pyR   ª   s      		c         C   sh   |  i  o t d ƒ ‚ n |  i | 7_ x8 t |  i ƒ t j o! |  i ƒ  o t d ƒ ‚ q, q, Wd S(   s6   Add buf to data that signature will be calculated overs'   SigGenerator already provided signatures%   Premature EOF received from sig_makerN(   RB   R    RC   R   R,   t   process_buffer(   R   t   buf(    (    s:   /var/lib/python-support/python2.5/rdiff_backup/librsync.pyt   update²   s    
 c         C   sr   y" |  i  i |  i ƒ \ } } } Wn* t i j
 o } t t | ƒ ƒ ‚ n X|  i | |  _ |  i | 7_ | S(   s9   Run self.buffer through sig_maker, add to self.sig_string(   RA   R$   RC   R%   R    R&   R:   (   R   R   t   len_buf_readR)   R*   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/librsync.pyRD   »   s     " c         C   s   x |  i  ƒ  p q W|  i S(   s    Return signature over given data(   RD   R:   (   R   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/librsync.pyt   getsigÃ   s      (	   R   R   R   R%   R2   R   RF   RD   RH   (    (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/librsync.pyR@   £   s
   			(    (    (   R   R5   R   R%   t   RS_JOB_BLOCKSIZER,   t	   ExceptionR    R   R0   R3   R;   R@   (    (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/librsync.pys   <module>   s   	C