ó
Ú"wTc           @   s!  d  Z  d d d d d d d d d	 d
 d d d d g Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Td d l Td d l	 Z
 d d l m Z m Z d d' d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d  „  ƒ  YZ d e f d! „  ƒ  YZ d e f d" „  ƒ  YZ e j d# k  rd$ „  d% „ Z e j  d& ƒ n  d S((   s-   Base classes used elsewhere in the package.

t   ConfigurableBaset   ForkingBaset   ConfInstancet
   ConfStringt   ConfBoolt   ConfIntt   ConfTupleOfStringst   ConfTupleOfUnicodet   ConfTupleOfTupleOfStringst   ConfPasswordt   ConfDirectoryt   ConfFilet   ConfMaildirPatht   ConfMboxPathiÿÿÿÿN(   t   *(   t	   eval_boolt   expand_user_varst   ConfItemc           B   s)   e  Z e Z d e d  „ Z d d „ Z RS(   c         C   s:   t  j j ƒ  |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   t   getmailcoret   loggingt   Loggert   logt   namet   dtypet   defaultt   required(   t   selfR   R   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyt   __init__)   s
    			c         C   sH  | d  k r$ | j |  j d  ƒ } n  | d  k rV |  j rO t d |  j ƒ ‚ n  |  j St | ƒ |  j k	 rD| |  j k rD|  j r¦ |  j	 j
 d |  j |  j f ƒ n# |  j	 j
 d |  j | |  j f ƒ y7 |  j t k rê t | ƒ } n |  j t | ƒ ƒ } WqDt t t f k
 r@} t d |  j | |  j | f ƒ ‚ qDXn  | S(   Ns,   %s: missing required configuration parameters   converting %s to type %s
s   converting %s (%s) to type %s
s9   %s: configuration value (%s) not of required type %s (%s)(   t   Nonet   getR   R   t   getmailConfigurationErrorR   t   typeR   t   securevalueR   t   debugt   boolR   t   evalt
   ValueErrort   SyntaxErrort	   TypeError(   R   t   configurationt   valt   o(    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyt   validate0   s,    	$	#N(   t   __name__t
   __module__t   FalseR    R   t   TrueR   R*   (    (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   '   s   c           B   s   e  Z d e d  „ Z RS(   c         C   s&   t  j |  | t j d | d | ƒd  S(   NR   R   (   R   R   t   typest   InstanceType(   R   R   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   R   s    N(   R+   R,   R   R.   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   Q   s   c           B   s   e  Z d e d  „ Z RS(   c         C   s#   t  j |  | t d | d | ƒd  S(   NR   R   (   R   R   t   str(   R   R   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   W   s    N(   R+   R,   R   R.   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   V   s   c           B   s   e  Z d e d  „ Z RS(   c         C   s#   t  j |  | t d | d | ƒd  S(   NR   R   (   R   R   R"   (   R   R   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   [   s    N(   R+   R,   R   R.   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   Z   s   c           B   s   e  Z d e d  „ Z RS(   c         C   s#   t  j |  | t d | d | ƒd  S(   NR   R   (   R   R   t   int(   R   R   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   _   s    N(   R+   R,   R   R.   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   ^   s   c           B   s    e  Z d e d  „ Z d „  Z RS(   c         C   s    t  j |  | d | d | ƒd  S(   NR   R   (   R   R   (   R   R   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   c   s    c         C   s¶   t  j |  | ƒ } yF | s$ d } n  t | ƒ } t | ƒ t k rQ t d ƒ ‚ n  | } Wn2 t t f k
 rŒ } t d |  j | f ƒ ‚ n Xg  | D] } t	 | ƒ ^ q” } t | ƒ S(   Ns   ()s   not a tuples   %s: incorrect format (%s)(
   R   R*   R#   R   t   tupleR$   R%   R   R   R1   (   R   R'   R(   t   tupR)   t   itemt   result(    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR*   f   s    	
N(   R+   R,   R   R.   R   R*   (    (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   b   s   c           B   s#   e  Z d e d d  „ Z d „  Z RS(   c         C   s)   t  j |  | d | d | ƒ| |  _ d  S(   NR   R   (   R   R   t   specials(   R   R   R   R   t   allow_specials(    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   w   s    c   	      C   ss  t  g  |  j D] } | | f ^ q ƒ } t j |  | ƒ } yú | sL d } n  t | i  | ƒ } | |  j k ry | g } nº t | ƒ t k rš t d ƒ ‚ n  g  } xŠ | D]‚ } t | ƒ } y | j	 | j
 d ƒ ƒ Wq§ t k
 r(} y | j	 | j
 d ƒ ƒ Wq)t k
 r$} t d | ƒ ‚ q)Xq§ Xq§ W| } Wn2 t t f k
 rh} t d |  j | f ƒ ‚ n Xt | ƒ S(   Ns   ()s   not a tuplet   asciis   utf-8s   not ascii or utf-8: %ss   %s: incorrect format (%s)(   t   dictR7   R   R*   R#   R   R3   R$   R1   t   appendt   decodet   UnicodeErrorR%   R   R   (	   R   R'   t   vt   _localsR(   R4   t   valsR5   R)   (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR*   {   s2    (	
N(    (   R+   R,   R   R.   R   R*   (    (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   v   s   c           B   s    e  Z d e d  „ Z d „  Z RS(   c         C   s    t  j |  | d | d | ƒd  S(   NR   R   (   R   R   (   R   R   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   ™   s    c         C   s(  t  j |  | ƒ } yF | s$ d } n  t | ƒ } t | ƒ t k rQ t d ƒ ‚ n  | } Wn2 t t f k
 rŒ } t d |  j | f ƒ ‚ n Xx” | D]Œ } t | ƒ t k r¿ t d | ƒ ‚ n  t	 | ƒ d k rä t d | ƒ ‚ n  x9 | D]1 } t | ƒ t
 k rë t d | | f ƒ ‚ që që Wq” W| S(   Ns   ()s   not a tuples   %s: incorrect format (%s)s    contained value "%s" not a tuplei   s!   contained value "%s" not length 2s-   contained value "%s" has non-string part "%s"(   R   R*   R#   R   R3   R$   R%   R   R   t   lenR1   (   R   R'   R(   R4   R)   t   part(    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR*   œ   s*    	
N(   R+   R,   R   R.   R   R*   (    (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   ˜   s   c           B   s   e  Z e Z RS(    (   R+   R,   R.   R    (    (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR	   µ   s   c           B   s    e  Z d e d  „ Z d „  Z RS(   c         C   s    t  j |  | d | d | ƒd  S(   NR   R   (   R   R   (   R   R   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   ¹   s    c         C   s`   t  j |  | ƒ } | d  k r" d  St | ƒ } t j j | ƒ s\ t d |  j | f ƒ ‚ n  | S(   Ns+   %s: specified directory "%s" does not exist(	   R   R*   R   R   t   ost   patht   isdirR   R   (   R   R'   R(   (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR*   ¼   s    N(   R+   R,   R   R.   R   R*   (    (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR
   ¸   s   c           B   s    e  Z d e d  „ Z d „  Z RS(   c         C   s    t  j |  | d | d | ƒd  S(   NR   R   (   R   R   (   R   R   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   È   s    c         C   s`   t  j |  | ƒ } | d  k r" d  St | ƒ } t j j | ƒ s\ t d |  j | f ƒ ‚ n  | S(   Ns&   %s: specified file "%s" does not exist(	   R   R*   R   R   RC   RD   t   isfileR   R   (   R   R'   R(   (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR*   Ë   s    N(   R+   R,   R   R.   R   R*   (    (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   Ç   s   c           B   s   e  Z d  „  Z RS(   c         C   sŸ   t  j |  | ƒ } | d  k r" d  S| j d ƒ sG t d |  j ƒ ‚ n  xQ d D]I } t j j | | ƒ } t j j	 | ƒ sN t d |  j | f ƒ ‚ qN qN W| S(   Nt   /s   %s: maildir must end with "/"t   curt   newt   tmps,   %s: maildir subdirectory "%s" does not exist(   RH   s   newRJ   (
   R
   R*   R   t   endswithR   R   RC   RD   t   joinRE   (   R   R'   R(   t   subdirt
   subdirpath(    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR*   ×   s    (   R+   R,   R*   (    (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   Ö   s   c           B   s    e  Z d e d  „ Z d „  Z RS(   c         C   s    t  j |  | d | d | ƒd  S(   NR   R   (   R   R   (   R   R   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   é   s    c         C   s  t  j |  | ƒ } | d  k r" d  St | ƒ } t j j | ƒ s\ t d |  j | f ƒ ‚ n  t j	 | t j
 ƒ } t j | ƒ } t j | d ƒ } | j d d ƒ | j ƒ  } | r× | d  d k r× t d | ƒ ‚ n  y  t j | | j | j f ƒ Wn t k
 r} n X| S(   Ns+   %s: specified mbox file "%s" does not exists   r+bi    i   s   From s   %s: not an mboxrd file(   R   R*   R   R   RC   RD   RF   R   R   t   opent   O_RDWRt   fstatt   fdopent   seekt   readlinet   utimet   st_atimet   st_mtimet   OSError(   R   R'   R(   t   fdt
   status_oldt   ft
   first_lineR)   (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR*   ì   s&     N(   R+   R,   R   R.   R   R*   (    (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   è   s   c           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sb  Base class for user-configurable classes.

    Sub-classes must provide the following data attributes and methods:

      _confitems - a tuple of dictionaries representing the parameters the class
                   takes.  Each dictionary should contain the following key,
                   value pairs:
                     - name - parameter name
                     - type - a type function to compare the parameter value
                       against (i.e. str, int, bool)
                     - default - optional default value.  If not preseent, the
                       parameter is required.
    c         K   s  t  j j ƒ  |  _ |  j j ƒ  i  |  _ t g  |  j D] } | j ^ q5 ƒ } x« | j	 ƒ  D] \ } } | | k r’ |  j j
 d | | f ƒ qZ n  | j ƒ  d k rÇ |  j j d | t | ƒ f ƒ n# |  j j d | | t | ƒ f ƒ | |  j | <qZ Wt |  _ |  j ƒ  d  S(   Ns5   Warning: ignoring unknown parameter "%s" (value: %s)
t   passwords   setting %s to * (%s)
s   setting %s to "%s" (%s)
(   R   R   R   R   t   tracet   conft   sett
   _confitemsR   t   itemst   warningt   lowerR   R-   t   _ConfigurableBase__confcheckedt	   checkconf(   R   t   argsR5   t   allowed_paramsR   t   value(    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR     s     	%#	c         C   s  |  j  j ƒ  |  j r d  SxD |  j D]9 } |  j  j d | j ƒ | j |  j ƒ |  j | j <q$ Wt |  j j ƒ  ƒ j	 t g  |  j D] } | j ^ qƒ ƒ ƒ } xD t
 t | ƒ d t j ƒD]' } |  j  j d | |  j | f ƒ qº Wt |  _ |  j  j d ƒ d  S(   Ns   checking %s
t   keys5   Warning: ignoring unknown parameter "%s" (value: %s)
s   done
(   R   R^   Re   Ra   R   R*   R_   t	   frozensett   keyst
   differencet   sortedt   listR1   Rd   Rc   R.   (   R   R5   t   unknown_paramst   param(    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyRf   .  s    	 ("	c         C   sª   |  j  j ƒ  d } |  j j ƒ  } | j ƒ  xw | D]o } | j ƒ  d k rQ q3 n  | rd | d 7} n  | j ƒ  d k r‡ | d | 7} q3 | d | |  j | f 7} q3 W| S(   Nt    t   configparsers   , R]   s   %s="*"s   %s="%s"(   R   R^   R_   Rl   t   sortRd   (   R   t
   confstringt   namesR   (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyt   _confstring?  s    
(   R+   R,   t   __doc__R   Rf   Rw   (    (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR      s   		c           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sÒ   Base class for classes which fork children and wait for them to exit.

    Sub-classes must provide the following data attributes and methods:

        log - an object of type getmailcore.logging.Logger()

    c         C   s¤   |  j  j d | ƒ y t j ƒ  \ } } Wn( t k
 rT } |  j  j d | ƒ d  SXt j t j |  j ƒ | |  _	 | |  _
 |  j  j d | | f ƒ t |  _ d  S(   Ns   handler called for signal %ss$   handler called, but no children (%s)s&   handler reaped child %s with status %s(   R   R^   RC   t   waitRX   Rc   t   signalt   SIGCHLDt   _ForkingBase__orig_handlert   _ForkingBase__child_pidt   _ForkingBase__child_statusR.   t   _ForkingBase__child_exited(   R   t   sigt
   stackframet   pidt   rR)   (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyt   _child_handlerX  s    		c         C   sJ   |  j  j d ƒ t |  _ d  |  _ d  |  _ t j t j |  j	 ƒ |  _
 d  S(   NRr   (   R   R^   R-   R   R   R}   R~   Rz   R{   R„   R|   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyt   _prepare_childf  s
    			c         C   s  x. |  j  s0 |  j j d | ƒ t j d ƒ q W|  j | k r\ t d |  j | f ƒ ‚ n  t j |  j	 ƒ r– t d |  j t j
 |  j	 ƒ f ƒ ‚ n  t j |  j	 ƒ rÐ t d |  j t j |  j	 ƒ f ƒ ‚ n  t j |  j	 ƒ sø t d |  j ƒ ‚ n  t j |  j	 ƒ } | S(   Ns   waiting for child %dg      ð?s   got child pid %d, not %ds!   child pid %d stopped by signal %ds    child pid %d killed by signal %ds   child pid %d failed to exit(   R   R   R^   t   timet   sleepR}   t   getmailOperationErrorRC   t
   WIFSTOPPEDR~   t   WSTOPSIGt   WIFSIGNALEDt   WTERMSIGt	   WIFEXITEDt   WEXITSTATUS(   R   t   childpidt   exitcode(    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyt   _wait_for_childm  s(    ""(   R+   R,   Rx   R„   R…   R‘   (    (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyR   P  s   		i  c         C   s   |  S(   N(    (   t   x(    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyt   <lambda>Ž  s    c         C   sL   g  |  D] } | | ƒ | f ^ q } | j  ƒ  g  | D] \ } } | ^ q6 S(   N(   Rt   (   t   lRj   R5   t   lstt   unusedR(   (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyRn   Ž  s    %
Rn   (    (!   Rx   t   __all__t   sysRC   R†   Rz   R/   t   getmailcore.exceptionst   getmailcore.compatibilityt   getmailcore.loggingR   t   getmailcore.utilitiesR   R   R   R   R   R   R   R   R   R   R	   R
   R   R   R   t   objectR    R   t
   hexversionRn   R;   (    (    (    s;   /usr/lib/python2.7/dist-packages/getmailcore/baseclasses.pyt   <module>   sR   	

*"$D=