³ò
OÉcIc           @   s  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 d k	 Z	 d d k
 Z
 d d k Z g  d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z d
 e f d „  ƒ  YZ d d d „  ƒ  YZ e i e ƒ d S(   s*   Catch various exceptions given system calliÿÿÿÿNc         C   sè   y | | Œ  SWnÓ t  t t f j
 o¾ } t i | g t | ƒ ƒ t | ƒ oT t i i	 ƒ  t
 i } | d j	 o | i i ƒ  n |  o |  | | Œ Sq¥ d Sn t | ƒ o t i i	 d d ƒ n t i i	 d d ƒ ‚  n Xd S(   s®   Apply function to args, if error, run error_handler on exception

	This uses the catch_error predicate below to only catch
	certain exceptions which seems innocent enough.

	i   i   i   N(   t	   Exceptiont   KeyboardInterruptt
   SystemExitt   TracebackArchivet   addt   listt   catch_errort   logt   Logt	   exceptiont   Globalst   backup_writert   Nonet
   statisticst   record_errort   is_routine_fatal(   t   error_handlert   functiont   argst   exct   conn(    (    s8   /var/lib/python-support/python2.5/rdiff_backup/robust.pyt   check_common_error   s      	   c         C   s   x> t  i t  i t i t i f D] } t |  | ƒ o d Sq q Wt |  t ƒ oH |  d d j p/ t	 i
 i |  d ƒ o  t	 i
 |  d d j o d Sn d S(   s-   Return true if exception exc should be caughti   i    s   invalid mode: rbs   Not a gzipped filet   EPERMt   ENOENTt   EACCESt   EBUSYt   EEXISTt   ENOTDIRt   EILSEQt   ENAMETOOLONGt   EINTRt   ESTALEt	   ENOTEMPTYt   EIOt   ETXTBSYt   ESRCHt   EINVALt	   EDEADLOCKt   EDEADLKt
   EOPNOTSUPPt	   ETIMEDOUT(   s   invalid mode: rbs   Not a gzipped file(   R   s   ENOENTR   R   s   EEXISTs   ENOTDIRR   R   R   R   R    R!   R"   R#   R$   R%   R&   R'   R(   (   t   rpatht   SkipFileExceptiont   RPathExceptiont   librsynct   librsyncErrort   Ct   UnknownFileTypeErrort
   isinstancet   EnvironmentErrort   errnot	   errorcodet   has_key(   R   t   exception_class(    (    s8   /var/lib/python-support/python2.5/rdiff_backup/robust.pyR   -   s           
c         C   sˆ   t  |  t i ƒ o d Snj t  |  t i ƒ o d SnO t  |  t ƒ o d |  f Sn0 t  |  t ƒ o |  i t i j o d |  Sn d S(   sÛ   Return string if exception is non-error unrecoverable, None otherwise

	Used to suppress a stack trace for exceptions like keyboard
	interrupts or connection drops.  Return value is string to use as
	an exit message.

	s
   User aborts$   Lost connection to the remote systems   Killed with signal %ss)   Filesystem reports connection failure:
%sN(
   R0   t
   exceptionsR   t
   connectiont   ConnectionErrort   SignalExceptionR1   R2   t   ENOTCONNR   (   R   (    (    s8   /var/lib/python-support/python2.5/rdiff_backup/robust.pyR   ?   s    #c            s   ‡  f d †  } | S(   sæ   Return error handler function that can be used above

	Function will just log error to the error_log and then return
	None.  First two arguments must be the exception and then an rp
	(from which the filename will be extracted).

	c            s   t  i i ˆ  | |  ƒ d S(   Ni    (   R   t   ErrorLogt   write_if_open(   R   t   rpR   (   t
   error_type(    s8   /var/lib/python-support/python2.5/rdiff_backup/robust.pyR   Y   s    (    (   R>   R   (    (   R>   s8   /var/lib/python-support/python2.5/rdiff_backup/robust.pyt   get_error_handlerQ   s    c            s/   ‡  f d †  } t  | ˆ  i ƒ } | i ƒ  | S(   s:   Like rp.listdir() but return [] if error, and sort resultsc            s   t  i d ˆ  i d ƒ g  S(   Ns   Error listing directory %si   (   R   R   t   path(   R   (   R=   (    s8   /var/lib/python-support/python2.5/rdiff_backup/robust.pyR   `   s    (   R   t   listdirt   sort(   R=   R   t   dir_listing(    (   R=   s8   /var/lib/python-support/python2.5/rdiff_backup/robust.pyt   listrp^   s    
c         C   s   t  |  ƒ ‚ d S(   s+   This is called when signal signum is caughtN(   R9   (   t   signumt   frame(    (    s8   /var/lib/python-support/python2.5/rdiff_backup/robust.pyt   signal_handlerg   s    c          C   sj   t  i t  i g }  y |  i t  i t  i g ƒ Wn t j
 o n Xx |  D] } t  i  | t ƒ qL Wd S(   s-   Install signal handlers on current connectionN(   t   signalt   SIGTERMt   SIGINTt   extendt   SIGHUPt   SIGQUITt   AttributeErrorRG   (   t   signalsRE   (    (    s8   /var/lib/python-support/python2.5/rdiff_backup/robust.pyt   install_signal_handlersk   s     R9   c           B   s   e  Z d  Z RS(   s=   SignalException(signum) means signal signum has been received(   t   __name__t
   __module__t   __doc__(    (    (    s8   /var/lib/python-support/python2.5/rdiff_backup/robust.pyR9   v   s   R   c           B   s)   e  Z d  Z g  Z g  d „ Z d „  Z RS(   s?   Save last 10 caught exceptions, so they can be printed if fatalc         C   sJ   |  i  i t i i | ƒ ƒ t |  i  ƒ d j o |  i  d  |  _  n d S(   sž   Add most recent exception to archived list

		If extra_args are present, convert to strings and add them as
		extra information to same traceback archive.

		i
   N(   t   _traceback_stringst   appendR   R   t   exception_to_stringt   len(   t   clst
   extra_args(    (    s8   /var/lib/python-support/python2.5/rdiff_backup/robust.pyR   ~   s    c         C   s5   |  i  o' t i d d i |  i  ƒ f d ƒ n d S(   s+   Print all exception information to log filesZ   ------------ Old traceback info -----------
%s
-------------------------------------------s   
i   N(   RT   R   R   t   join(   RX   (    (    s8   /var/lib/python-support/python2.5/rdiff_backup/robust.pyR   ‰   s    
	(   RQ   RR   RS   RT   R   R   (    (    (    s8   /var/lib/python-support/python2.5/rdiff_backup/robust.pyR   {   s   (    (   RS   R2   RH   R6   R,   R.   t   staticR)   R
   R   R   R7   R   R   R   R?   RD   RG   RP   R    R9   R   t	   MakeClass(    (    (    s8   /var/lib/python-support/python2.5/rdiff_backup/robust.pys   <module>   s   $`							