³ò
OÉcIc           @   sF  d  Z  d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d e	 f d „  ƒ  YZ
 d d d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d d 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 d k Z d S(   s3   Convert an iterator to a file object and vice-versaiÿÿÿÿNt   IterFileExceptionc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR       s    t
   UnwrapFilec           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sA   Contains some basic methods for parsing a file containing an iterc         C   s   | |  _  d  S(   N(   t   file(   t   selfR   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyt   __init__   s    c         C   sS   t  | ƒ d j p t ‚ d } x, t d ƒ D] } | d t | | ƒ } q- W| S(   s   Convert string to long inti   l    i   (   t   lent   AssertionErrort   ranget   ord(   R   t   st   lt   i(    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyt   _s2l_old!   s      c         C   sÏ   |  i  i d ƒ } | p d Sn t | ƒ d j o% d
 p t d | t | ƒ f ‚ n | d t i | d ƒ } } |  i  i | ƒ } | d j o | t i | ƒ f Sn | d j p t ‚ | | f Sd
 S(   s  Return pair (type, data) next in line on the file

		type is a single character which is either
		"o" for an object,
		"f" for file,
		"c" for a continution of a file,
		"h" for the close value of a file
		"e" for an exception, or
		None if no more data can be read.

		Data is either the file's data, if type is "c" or "f", or the
		actual object if the type is "o", "e", or "r"

		i   s   Header %s is only %d bytesi    i   t   ot   et   ht   ft   cN(   NN(   R   R   R   (   R   R   (	   R   t   readt   NoneR   R   t   Ct   str2longt   cPicklet   loads(   R   t   headert   typet   lengtht   buf(    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyt   _get(   s     % (   R   R   t   __doc__R   R   R   (    (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR      s   		t   IterWrappingFilec           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s‡   An iterator generated from a file.

	Initialize with a file type object, and then it will return the
	elements of the file in order.

	c         C   s   t  i |  | ƒ d  |  _ d  S(   N(   R   R   R   t   currently_in_file(   R   R   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR   J   s    c         C   s   |  S(   N(    (   R   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyt   __iter__N   s    c         C   s’   |  i  o |  i  i ƒ  n |  i ƒ  \ } } | p
 t ‚ n | d j p | d j o | Sn/ | d j o t |  | ƒ Sn t d | ƒ ‚ d  S(   NR   R   R   s   Bad file type %s(   R!   t   closeR   t   StopIterationt   IterVirtualFileR    (   R   R   t   data(    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyt   nextP   s    
 
  (   R   R   R   R   R"   R'   (    (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR    C   s   		R%   c           B   s>   e  Z d  Z d „  Z d d „ Z d „  Z d „  Z d „  Z RS(   s    Another version of a pretend file

	This is returned by IterWrappingFile when a file is embedded in
	the main file that the IterWrappingFile is based around.

	c         C   sP   t  i |  | i ƒ | |  _ |  | _ | |  _ d |  _ | p |  i ƒ  n d S(   s’   Initializer

		initial_data is the data from the first block of the file.
		iwf is the iter wrapping file that spawned this
		IterVirtualFile.

		N(	   R   R   R   t   iwfR!   t   bufferR   t   closedt   set_close_val(   R   R(   t   initial_data(    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR   a   s    				 iÿÿÿÿc         C   sÜ   |  i  p t ‚ |  i i o„ | d j oL x- | t |  i ƒ j o |  i ƒ  p Pq/ q/ Wt | t |  i ƒ ƒ } q» x |  i ƒ  p Pq{ q{ t |  i ƒ } n t | t |  i ƒ ƒ } |  i |  } |  i | |  _ | S(   s>   Read length bytes from the file, updating buffers as necessaryi    (   R*   R   R(   R!   R   R)   t   addtobuffert   min(   R   R   t   real_lent
   return_val(    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR   p   s       
 c         C   s—   |  i  i p t ‚ |  i  i ƒ  \ } } | d j o d |  i  _ | ‚ n | d j p t d | ‚ | o |  i | 7_ d Sn |  i ƒ  d Sd S(   s3   Read a chunk from the file and add it to the bufferR   R   s   Type is %s instead of ci   N(   R(   R!   R   R   R   R)   R+   (   R   R   R&   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR-   ‚   s    

c         C   sY   |  i  i p t ‚ d |  i  _ |  i  i ƒ  \ } } | d j p
 t | ‚ | |  _ d S(   s0   Read the close value and clear currently_in_fileR   N(   R(   R!   R   R   R   t   close_value(   R   R   t   object(    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR+   ‘   s
    c         C   s8   x% |  i  i o |  i ƒ  d |  _ q Wd |  _ |  i S(   s/   Currently just reads whats left and discards itt    i   (   R(   R!   R-   R)   R*   R1   (   R   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR#   ™   s     
	(   R   R   R   R   R   R-   R+   R#   (    (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR%   Z   s   			t   FileWrappingIterc           B   sM   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s,  A file interface wrapping around an iterator

	This is initialized with an iterator, and then converts it into a
	stream of characters.  The object will evaluate as little of the
	iterator as is necessary to provide the requested bytes.

	The actual file is a sequence of marshaled objects, each preceded
	by 8 bytes which identifies the following the type of object, and
	specifies its length.  File objects are not marshalled, but the
	data is written in chunks of Globals.blocksize, and the following
	blocks can identify themselves as continuations.

	c         C   s1   | |  _  t i d ƒ |  _ d |  _ d |  _ d S(   s   Initialize with iterR   N(   t   itert   arrayt	   array_bufR   R!   R*   (   R   R5   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR   °   s    		c         C   sc   |  i  p t ‚ x- t |  i ƒ | j  o |  i ƒ  p Pq q W|  i |  i ƒ  } |  i | 4| S(   s    Return next length bytes in file(   R*   R   R   R7   R-   t   tostring(   R   R   t   result(    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR   ·   s      

c         C   sÝ   |  i  o |  i d ƒ n¿ y |  i i ƒ  } Wn t j
 o d Sn Xt | d ƒ o* t | d ƒ o | |  _  |  i d ƒ nX t i | d ƒ } |  i	 i
 d ƒ |  i	 i
 t i t t | ƒ ƒ ƒ ƒ |  i	 i
 | ƒ d S(   s   Updates self.buffer, adding a chunk from the iterator.

		Returns None if we have reached the end of the iterator,
		otherwise return true.

		R   R   R#   R   i   R   N(   R!   t   addfromfileR5   R'   R$   R   t   hasattrR   t   dumpsR7   t
   fromstringR   t   long2strt   longR   (   R   t
   currentobjt   pickle(    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR-   Á   s    
   	 	%c         C   s'  t  i |  i |  i i t i g ƒ } | d j oO d |  _ t i	 |  i
 d ƒ } d i d t i t t | ƒ ƒ ƒ | f ƒ } n” d i | t i t t | ƒ ƒ ƒ | f ƒ } | d j oY t i	 |  i i ƒ  d ƒ } d |  _ | d i d t i t t | ƒ ƒ ƒ | f ƒ 7} n |  i i | ƒ d S(   sç   Read a chunk from the current file and add to array_buf

		prefix_letter and the length will be prepended to the file
		data.  If there is an exception while reading the file, the
		exception will be added to array_buf instead.

		i   R3   R   R   N(   t   robustt   check_common_errort   read_error_handlerR!   R   t   Globalst	   blocksizeR   R   R<   t   last_exceptiont   joinR   R>   R?   R   R#   R7   R=   (   R   t   prefix_letterR   t   excstrt   totalt   cstr(    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR:   Ö   s    		1-	5c         C   s   | |  _  d S(   s    Log error when reading from fileN(   RG   R   (   R   t   excRF   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyRD   í   s    	c         C   sZ   d } x9 t  d ƒ D]+ } t | d ƒ \ } } t | ƒ | } q W| d j p t ‚ | S(   s*   Convert long int to string of 7 charactersR3   i   i   i    (   R	   t   divmodt   chrR   (   R   R   R   R   t	   remainder(    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyt   _l2s_oldò   s     c         C   s   d |  _  d  S(   Ni   (   R*   (   R   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR#   û   s    (
   R   R   R   R   R   R-   R:   RD   RQ   R#   (    (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR4   ¢   s   		
					t   MiscIterFlushc           B   s   e  Z d  Z RS(   s8   Used to signal that a MiscIterToFile should flush buffer(   R   R   R   (    (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyRR   þ   s   t   MiscIterFlushRepeatc           B   s   e  Z d  Z RS(   sµ   Flush, but then cause Misc Iter to yield this same object

	Thus if we put together a pipeline of these, one MiscIterFlushRepeat
	can cause all the segments to flush in sequence.

	(   R   R   R   (    (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyRS     s   t   MiscIterToFilec           B   sV   e  Z d  Z d d d „ Z d d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   s  Take an iter and give it a file-ish interface

	This expands on the FileWrappingIter by understanding how to
	process RORPaths with file objects attached.  It adds a new
	character "r" to mark these.

	This is how we send signatures and diffs across the line.  As
	sending each one separately via a read() call would result in a
	lot of latency, the read()'s are buffered - a read() call with no
	arguments will return a variable length string (possibly empty).

	To flush the MiscIterToFile, have the iterator yield a
	MiscIterFlush class.

	c         C   sL   | p t  i |  _ | p t  i |  _ d |  _ d |  _ t i	 |  | ƒ d S(   s›   MiscIterToFile initializer

		max_buffer_bytes is the maximum size of the buffer in bytes.
		max_buffer_rps is the maximum size of the buffer in rorps.

		i    N(
   RE   t   conn_bufsizet   max_buffer_bytest   pipeline_max_lengtht   max_buffer_rpst   rorps_in_bufferR   t   next_in_lineR4   R   (   R   t   rpiterRV   RX   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR     s
    		c         C   s÷   |  i  p t ‚ | d j om xC t |  i ƒ |  i j  o) |  i |  i j  o |  i ƒ  p Pq" q" W|  i i	 ƒ  } |  i 2d |  _ | Snh | d j p t ‚ |  i
 ƒ  } x( t | ƒ | j  o | |  i
 ƒ  7} q¯ W|  i i | | ƒ | | Sd S(   s(   Return some number of bytes, including 0i    N(   R*   R   R   R   R7   RV   RY   RX   R-   R8   R   R=   (   R   R   R9   t   read_buffer(    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR   (  s$      
	  c         C   s;  |  i  o. |  i d ƒ |  i  p |  i d 7_ q7n |  i o |  i } d |  _ n8 y |  i i ƒ  } Wn! t j
 o |  i ƒ  d Sn Xt	 | d ƒ o* t	 | d ƒ o | |  _  |  i d ƒ no | t
 i j o d SnW | t
 i j o |  i | ƒ d Sn2 t | t i ƒ o |  i | ƒ n |  i | ƒ d S(   s=   Add some number of bytes to the buffer.  Return false if doneR   i   i    R   R#   R   N(   R!   R:   RY   RZ   R5   R'   R$   t   addfinalR   R;   t   iterfileRR   RS   t   add_misct
   isinstancet   rpatht   RORPatht   addrorp(   R   R@   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR-   ;  s0    

 
	 
	 	 c         C   s[   t  i | d ƒ } |  i i d ƒ |  i i t i t t | ƒ ƒ ƒ ƒ |  i i | ƒ d S(   s0   Add an arbitrary pickleable object to the bufferi   R   N(   R   R<   R7   R=   R   R>   R?   R   (   R   t   objRA   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR_   V  s    %c         C   s´   | i  o1 t i | i | i d f d ƒ } | i  |  _ n1 t i | i | i d f d ƒ } |  i d 7_ |  i i d ƒ |  i i t	 i
 t t | ƒ ƒ ƒ ƒ |  i i | ƒ d S(   s   Add a rorp to the bufferi   i    t   rN(   R   R   R<   t   indexR&   RZ   RY   R7   R=   R   R>   R?   R   (   R   t   rorpRA   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyRc   ]  s    
!!%c         C   s-   |  i  i d ƒ |  i  i t i d ƒ ƒ d S(   s/   Signal the end of the iterator to the other endt   zl    N(   R7   R=   R   R>   (   R   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR]   i  s    c         C   s   d |  _  d  S(   Ni   (   R*   (   R   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR#   n  s    N(   R   R   R   R   R   R   R-   R_   Rc   R]   R#   (    (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyRT     s   				t   FileToMiscIterc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s6   Take a MiscIterToFile and turn it back into a iteratorc         C   s   t  i |  | ƒ d |  _ d  S(   NR3   (   R    R   R   (   R   R   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR   s  s    c         C   s   |  S(   N(    (   R   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR"   w  s    c         C   s£   |  i  o |  i  i ƒ  n d } x | p |  i ƒ  \ } } q$ W| d j o
 t ‚ nG | d j o |  i | ƒ Sn) | d j o | Sn t d | f ƒ ‚ d S(   s2   Return next object in iter, or raise StopIterationRh   Re   R   s   Bad file type %sN(   R!   R#   R   R   R$   t   get_rorpR    (   R   R   R&   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR'   y  s    
   
  c         C   sZ   | \ } } } t  i | | ƒ } | o. | d j p
 t d ‚ | i |  i ƒ  ƒ n | S(   s    Return rorp that data representsi   s    Only one file accepted right now(   Ra   Rb   R   t   setfilet   get_file(   R   t   pickled_tupleRf   t	   data_dictt	   num_filesRg   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyRj   „  s    c         C   so   |  i  ƒ  \ } } | d j o t |  | ƒ Sn | d j p t d | f ‚ t | t ƒ p t ‚ t | ƒ S(   s   Read file object from fileR   R   s   Expected type e, got %s(   R   R%   R   R`   t	   Exceptiont	   ErrorFile(   R   R   R&   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyRl     s     c         C   sÙ   |  i  p |  i  |  i i ƒ  7_  n |  i  p d Sn t |  i  ƒ d j p
 t d ‚ |  i  d t i |  i  d d !ƒ } } |  i  d d | !} |  i  d | |  _  | d j o | t i	 | ƒ f Sn | | f Sd S(   sî   Return (type, data or object) pair

		This is like UnwrapFile._get() but reads in variable length
		blocks.  Also type "z" is allowed, which means end of
		iterator.  An empty read() is not considered to mark the end
		of remote iter.

		i   s   Unexpected end of MiscIter filei    i   t   oerhN(   NN(
   R   R   R   R   R   R   R   R   R   R   (   R   R   R   R&   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR   •  s    	
 
  ' (	   R   R   R   R   R"   R'   Rj   Rl   R   (    (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyRi   q  s   						Rq   c           B   s,   e  Z d  Z d „  Z d d „ Z d „  Z RS(   s?   File-like that just raises error (used by FileToMiscIter above)c         C   s   | |  _  d S(   s@   Initialize new ErrorFile.  exc is the exception to raise on readN(   RM   (   R   RM   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR   «  s    iÿÿÿÿc         C   s   |  i  ‚ d  S(   N(   RM   (   R   R   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR   ®  s    c         C   s   d  S(   N(   R   (   R   (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyR#   ¯  s    (   R   R   R   R   R   R#   (    (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pyRq   ©  s   	(    (    (    (    (   R   R   R6   t   typesRE   R   RB   t   logRa   Rp   R    R   R    R%   R4   RR   RS   RT   Ri   Rq   R^   (    (    (    s:   /var/lib/python-support/python2.5/rdiff_backup/iterfile.pys   <module>   s   $<'H\	f8	