
[c           @   s|  d  Z  d d l m Z e d d d [ d Z d Z d Z d	 Z d d
 l Z d d
 l Z d d
 l	 Z	 d d
 l
 Z
 d d
 l Z d d
 l Z d d l m Z d d d d g Z d e f d     YZ d f  d     YZ e	 j d  Z d   Z d f  d     YZ d e
 j f d     YZ d e f d     YZ d f  d     YZ d d  Z d d  Z d   Z e d k rxe   n  d
 S(   s	  MH interface -- purely object-oriented (well, almost)

Executive summary:

import mhlib

mh = mhlib.MH()         # use default mailbox directory and profile
mh = mhlib.MH(mailbox)  # override mailbox location (default from profile)
mh = mhlib.MH(mailbox, profile) # override mailbox and profile

mh.error(format, ...)   # print error message -- can be overridden
s = mh.getprofile(key)  # profile entry (None if not set)
path = mh.getpath()     # mailbox pathname
name = mh.getcontext()  # name of current folder
mh.setcontext(name)     # set name of current folder

list = mh.listfolders() # names of top-level folders
list = mh.listallfolders() # names of all folders, including subfolders
list = mh.listsubfolders(name) # direct subfolders of given folder
list = mh.listallsubfolders(name) # all subfolders of given folder

mh.makefolder(name)     # create new folder
mh.deletefolder(name)   # delete folder -- must have no subfolders

f = mh.openfolder(name) # new open folder object

f.error(format, ...)    # same as mh.error(format, ...)
path = f.getfullname()  # folder's full pathname
path = f.getsequencesfilename() # full pathname of folder's sequences file
path = f.getmessagefilename(n)  # full pathname of message n in folder

list = f.listmessages() # list of messages in folder (as numbers)
n = f.getcurrent()      # get current message
f.setcurrent(n)         # set current message
list = f.parsesequence(seq)     # parse msgs syntax into list of messages
n = f.getlast()         # get last message (0 if no messagse)
f.setlast(n)            # set last message (internal use only)

dict = f.getsequences() # dictionary of sequences in folder {name: list}
f.putsequences(dict)    # write sequences back to folder

f.createmessage(n, fp)  # add message from file f as number n
f.removemessages(list)  # remove messages in list from folder
f.refilemessages(list, tofolder) # move messages in list to other folder
f.movemessage(n, tofolder, ton)  # move one message to a given destination
f.copymessage(n, tofolder, ton)  # copy one message to a given destination

m = f.openmessage(n)    # new open message object (costs a file descriptor)
m is a derived class of mimetools.Message(rfc822.Message), with:
s = m.getheadertext()   # text of message's headers
s = m.getheadertext(pred) # text of message's headers, filtered by pred
s = m.getbodytext()     # text of message's body, decoded
s = m.getbodytext(0)    # text of message's body, not decoded
i(   t   warnpy3ksO   the mhlib module has been removed in Python 3.0; use the mailbox module insteadt
   stackleveli   s   ~/.mh_profiles   ~/Mails   .mh_sequencesi  N(   t   bisectt   MHt   Errort   Foldert   Messagec           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s   /usr/lib/python2.7/mhlib.pyR   [   s   c           B   s   e  Z d  Z d d d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z RS(   s<  Class representing a particular collection of folders.
    Optional constructor arguments are the pathname for the directory
    containing the collection, and the MH profile to use.
    If either is omitted or empty a default is used; the default
    directory is taken from the MH profile if it is specified there.c         C   s   | d k r t } n  t j j |  |  _ | d k rH |  j d  } n  | sW t } n  t j j |  r | d d k r t j j	 d |  } n  t j j |  } t j j
 |  s t d  n  | |  _ d S(   s   Constructor.t   Pathi    t   ~s   MH() path not foundN(   t   Nonet
   MH_PROFILEt   ost   patht
   expandusert   profilet
   getprofilet   PATHt   isabst   joint   isdirR   (   t   selfR   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   __init__f   s     	  	# c         C   s   d |  j  |  j f S(   s   String representation.s
   MH(%r, %r)(   R   R   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   __repr__r   s    c         G   s   t  j j d | |  d S(   sA   Routine to print an error.  May be overridden by a derived class.s   MH error: %s
N(   t   syst   stderrt   write(   R   t   msgt   args(    (    s   /usr/lib/python2.7/mhlib.pyt   errorv   s    c         C   s   t  |  j |  S(   s*   Return a profile entry, None if not found.(   t   picklineR   (   R   t   key(    (    s   /usr/lib/python2.7/mhlib.pyR   z   s    c         C   s   |  j  S(   s9   Return the path (the name of the collection's directory).(   R   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   getpath~   s    c         C   s7   t  t j j |  j   d  d  } | s3 d } n  | S(   s&   Return the name of the current folder.t   contexts   Current-Foldert   inbox(   R   R   R   R   R!   (   R   R"   (    (    s   /usr/lib/python2.7/mhlib.pyt
   getcontext   s
    	 	c         C   sI   t  j j |  j   d  } t | d  } | j d |  | j   d S(   s#   Set the name of the current folder.R"   t   ws   Current-Folder: %s
N(   R   R   R   R!   t   openR   t   close(   R   R"   t   fnt   f(    (    s   /usr/lib/python2.7/mhlib.pyt
   setcontext   s    c         C   sq   g  } |  j    } xN t j |  D]= } t j j | |  } t j j |  r" | j |  q" q" W| j   | S(   s*   Return the names of the top-level folders.(   R!   R   t   listdirR   R   R   t   appendt   sort(   R   t   foldersR   t   namet   fullname(    (    s   /usr/lib/python2.7/mhlib.pyt   listfolders   s    
c   	      C   s   t  j j |  j |  } t  j |  j } | d k r: g  Sg  } t  j |  } xt | D]l } t  j j | |  } t  j j |  rV t  j j | |  } | j |  | d } | d k r Pq qV qV W| j   | S(   sc   Return the names of the subfolders in a given folder
        (prefixed with the given folder name).i   i   (	   R   R   R   t   statt   st_nlinkR+   R   R,   R-   (	   R   R/   R0   t   nlinkst
   subfolderst   subnamest   subnamet   fullsubnamet   name_subname(    (    s   /usr/lib/python2.7/mhlib.pyt   listsubfolders   s     

c         C   s   |  j  d  S(   s<   Return the names of all folders and subfolders, recursively.t    (   t   listallsubfolders(   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   listallfolders   s    c   
      C   s$  t  j j |  j |  } t  j |  j } | d k r: g  Sg  } t  j |  } x | D] } | d d k sV t |  r~ qV n  t  j j | |  } t  j j |  rV t  j j | |  } | j |  t  j j	 |  s |  j
 |  }	 | |	 } n  | d } | d k rPqqV qV W| j   | S(   s>   Return the names of subfolders in a given folder, recursively.i   i    t   ,i   (   R   R   R   R2   R3   R+   t	   isnumericR   R,   t   islinkR<   R-   (
   R   R/   R0   R4   R5   R6   R7   R8   R9   t   subsubfolders(    (    s   /usr/lib/python2.7/mhlib.pyR<      s,     	

c         C   s   t  |  |  S(   s0   Return a new Folder object for the named folder.(   R   (   R   R/   (    (    s   /usr/lib/python2.7/mhlib.pyt
   openfolder   s    c         C   se   t  |  j d  } | r6 t |  r6 t | d  } n t } t j t j j |  j	   |  |  d S(   s@   Create a new folder (or raise os.error if it cannot be created).s   Folder-Protecti   N(
   R   R   R?   t   intt   FOLDER_PROTECTR   t   mkdirR   R   R!   (   R   R/   t   protectt   mode(    (    s   /usr/lib/python2.7/mhlib.pyt
   makefolder   s
    c         C   s   t  j j |  j   |  } xe t  j |  D]T } t  j j | |  } y t  j |  Wq+ t  j k
 r~ |  j d |  q+ Xq+ Wt  j |  d S(   s   Delete a folder.  This removes files in the folder but not
        subdirectories.  Raise os.error if deleting the folder itself fails.s   %s not deleted, continuing...N(   R   R   R   R!   R+   t   unlinkR   t   rmdir(   R   R/   R0   R7   R8   (    (    s   /usr/lib/python2.7/mhlib.pyt   deletefolder   s    	N(   R   R   t   __doc__R   R   R   R   R   R!   R$   R*   R1   R:   R=   R<   RB   RH   RK   (    (    (    s   /usr/lib/python2.7/mhlib.pyR   _   s   													s   ^[1-9][0-9]*$c         C   s   t  j |   d  k	 S(   N(   t   numericprogt   matchR   (   t   str(    (    s   /usr/lib/python2.7/mhlib.pyR?      s    c           B   s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s'   Class representing a particular folder.c         C   s>   | |  _  | |  _ t j j |  j    s: t d |  n  d S(   s   Constructor.s   no folder %sN(   t   mhR/   R   R   R   t   getfullnameR   (   R   RP   R/   (    (    s   /usr/lib/python2.7/mhlib.pyR      s    		c         C   s   d |  j  |  j f S(   s   String representation.s   Folder(%r, %r)(   RP   R/   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyR      s    c         G   s   |  j  j |   d S(   s   Error message handler.N(   RP   R   (   R   R   (    (    s   /usr/lib/python2.7/mhlib.pyR      s    c         C   s   t  j j |  j j |  j  S(   s'   Return the full pathname of the folder.(   R   R   R   RP   R/   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyRQ     s    c         C   s   t  j j |  j   t  S(   s8   Return the full pathname of the folder's sequences file.(   R   R   R   RQ   t   MH_SEQUENCES(   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   getsequencesfilename  s    c         C   s   t  j j |  j   t |   S(   s4   Return the full pathname of a message in the folder.(   R   R   R   RQ   RO   (   R   t   n(    (    s   /usr/lib/python2.7/mhlib.pyt   getmessagefilename  s    c         C   s   |  j  j |  j  S(   s!   Return list of direct subfolders.(   RP   R:   R/   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyR:     s    c         C   s   |  j  j |  j  S(   s   Return list of all subfolders.(   RP   R<   R/   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyR<     s    c         C   s   g  } t  j } | j } x6 t j |  j    D] } | |  r. | |  q. q. Wt t |  } | j   | r | d |  _	 n	 d |  _	 | S(   s   Return the list of messages currently present in the folder.
        As a side effect, set self.last to the last message (or 0).ii    (
   RM   RN   R,   R   R+   RQ   t   mapRC   R-   t   last(   R   t   messagesRN   R,   R/   (    (    s   /usr/lib/python2.7/mhlib.pyt   listmessages  s    		
	c         C   s   i  } |  j    } y t | d  } Wn t k
 r9 | SXx | j   } | sS Pn  | j d  } t |  d k r |  j d | | j   f  n  | d j   } t | d j   d  j	   } | | | <q= | S(   s+   Return the set of sequences for the folder.t   rt   :i   s   bad sequence in %s: %si    i   t    (
   RS   R&   t   IOErrort   readlinet   splitt   lenR   t   stript   IntSett   tolist(   R   t	   sequencesR0   R)   t   linet   fieldsR    t   value(    (    s   /usr/lib/python2.7/mhlib.pyt   getsequences)  s$     	c         C   s   |  j    } d } xk | j   D]] \ } } t d d  } | j |  | s_ t | d  } n  | j d | | j   f  q W| s y t j	 |  Wq t j
 k
 r q Xn
 | j   d S(   s.   Write the set of sequences back to the folder.R;   R\   R%   s   %s: %s
N(   RS   R   t	   iteritemsRb   t   fromlistR&   R   t   tostringR   RI   R   R'   (   R   Rd   R0   R)   R    t   seqt   s(    (    s   /usr/lib/python2.7/mhlib.pyt   putsequences=  s     !c         C   sE   |  j    } y t | d  SWn  t t f k
 r@ t d  n Xd S(   s<   Return the current message.  Raise Error when there is none.t   curs   no cur messageN(   Rh   t   maxt
   ValueErrort   KeyErrorR   (   R   t   seqs(    (    s   /usr/lib/python2.7/mhlib.pyt
   getcurrentN  s
    c         C   s#   t  |  j   d t |  d  d S(   s   Set the current message.Ro   i    N(   t
   updatelineRS   RO   (   R   RT   (    (    s   /usr/lib/python2.7/mhlib.pyt
   setcurrentV  s    c         C   sL  |  j    } | s% t d |  j  n  | d k r5 | S| j d  } | d k r| |  d | | d } } } | d  d k r | d  | d } } n  t |  s t d |  n  y t |  } Wn# t t f k
 r t |  } n Xy |  j	 | |  } Wn t k
 r}	 |  j
   }
 | |
 k rV|	 s=d | }	 n  t |	 t j   d	  n  |
 | } | svt d
 |  n  | d k r| | S| |  SqX| s| d k rd } qn  | d k rt | |  } | t d | |  | !St | | d  } | | | | !Sn  | j d  } | d k r|  j	 | |  |  } |  j	 | | d |  } t | | d  } t | |  } | | | !} | st d |  n  | Sy |  j	 | |  } WnO t k
 r}	 |  j
   }
 | |
 k r |	 sd | }	 n  t |	  n  |
 | SX| | k rAt |  r1t d |  qHt d |  n | g Sd S(   s   Parse an MH sequence specification into a message list.
        Attempt to mimic mh-sequence(5) as close as possible.
        Also attempt to mimic observed behavior regarding which
        conditions cause which error messages.s   no messages in %st   allR[   i    R;   i   s   -+s   bad message list %si   s   sequence %s emptyt   -t   prevRW   s   message %d doesn't exists   no %s messageN(   Ry   s   last(   RY   R   R/   t   findR?   RC   Rq   t   OverflowErrorR`   t   _parseindexRh   R   t   exc_infoR   Rp   (   R   Rl   Rw   t   it   headt   dirt   tailt   countt   anchorR   Rs   t   msgst   begint   endt   jRZ   RT   (    (    s   /usr/lib/python2.7/mhlib.pyt   parsesequenceZ  s|    	 
		c         C   sL  t  |  r; y t |  SWq; t t f k
 r7 t j SXn  | d k rQ |  j   S| d k re | d S| d k ry | d S| d k r |  j   } t | |  } y | | SWq t k
 r t	 d  q Xn  | d	 k r?|  j   } t | | d
  } | d k rt	 d  n  y | | d
 SWq?t k
 r;t	 d  q?Xn  t	 d  d S(   s7   Internal: parse a message number (or cur, first, etc.).Ro   t   .t   firsti    RW   it   nexts   no next messageRy   i   s   no prev messageN(   s   curR   (   R?   RC   R{   Rq   R   t   maxintRt   R   t
   IndexErrorR   R   (   R   Rl   Rw   RT   R~   (    (    s   /usr/lib/python2.7/mhlib.pyR|     s8    
c         C   s   t  |  |  S(   s+   Open a message -- returns a Message object.(   R   (   R   RT   (    (    s   /usr/lib/python2.7/mhlib.pyt   openmessage  s    c         C   s  g  } g  } x | D] } |  j  |  } |  j  d t |   } y t j |  Wn t j k
 rh n Xy t j | |  Wn# t j k
 r } | j |  q X| j |  q W| r |  j |  n  | r
t |  d k r t j | d  q
t j d | f  n  d S(   s2   Remove one or more messages -- may raise os.error.R>   i   i    s   multiple errors:N(	   RU   RO   R   RI   R   t   renameR,   t   removefromallsequencesR`   (   R   t   listt   errorst   deletedRT   R   t	   commapathR   (    (    s   /usr/lib/python2.7/mhlib.pyt   removemessages  s(    i    c         C   s  g  } i  } x | D] } | j    d } |  j |  } | j |  }	 y t j | |	  Wn t j k
 r y! t j | |	  t j |  Wq t t j f k
 r }
 | j	 |
  y t j |	  Wq t j k
 r q Xq q Xn X| j
 |  | | | <q W| r@| r*| j |  | j    n  |  j | j    n  | rt |  d k rkt j | d  qt j d | f  n  d S(   s_   Refile one or more messages -- may raise os.error.
        'tofolder' is an open folder object.i   i    s   multiple errors:N(   t   getlastRU   R   R   R   t   shutilt   copy2RI   R]   R,   t   setlastt   _copysequencest   itemsR   t   keysR`   (   R   R   t   tofoldert   keepsequencesR   t   refiledRT   t   tonR   t   topathR   (    (    s   /usr/lib/python2.7/mhlib.pyt   refilemessages  s:    c         C   s   | j    } |  j    } d } x | j   D] \ } } y | | } d }	 Wn t k
 rj g  } d }	 n Xx6 | D]. \ }
 } |
 | k rr | j |  d } qr qr W|	 r+ | r+ | | | <q+ q+ W| r |  j |  n  d S(   s.   Helper for refilemessages() to copy sequences.i    i   N(   Rh   R   Rr   R,   Rn   (   R   t
   fromfoldert   refileditemst   fromsequencest   tosequencest   changedR/   Rl   t   toseqt   newt   fromnR   (    (    s   /usr/lib/python2.7/mhlib.pyR     s$    


c   	      C   s#  |  j  |  } t |  } | j   ~ | j  |  } | j  d |  } y t j | |  Wn t j k
 rt n Xy t j | |  Wn t j k
 rd } z' | j d  t j	 | |  d } Wd | s y t j
 |  Wq t j k
 r q Xn  Xt j
 |  n X|  j | g  d S(   sa   Move one message over a specific destination message,
        which may or may not already exist.s   ,%di    i   N(   RU   R&   R'   R   R   R   R   R   R   R   RI   R   (	   R   RT   R   R   R   R)   R   t   backuptopatht   ok(    (    s   /usr/lib/python2.7/mhlib.pyt   movemessage"  s2    

c   	      C   s   |  j  |  } t |  } | j   ~ | j  |  } | j  d |  } y t j | |  Wn t j k
 rt n Xd } z' | j d  t j	 | |  d } Wd | s y t j
 |  Wq t j k
 r q Xn  Xd S(   sa   Copy one message over a specific destination message,
        which may or may not already exist.s   ,%di    i   N(   RU   R&   R'   R   R   R   R   R   R   R   RI   (	   R   RT   R   R   R   R)   R   R   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   copymessageB  s(    

c   	      C   s   |  j  |  } |  j  d |  } y t j | |  Wn t j k
 rL n Xd } d } zO t | d  } x) | j |  } | s Pn  | j |  qn | j   d } Wd | s y t j |  Wq t j k
 r q Xn  Xd S(	   s3   Create a message, with text from the open file txt.s   ,%di    i   i   R%   i   Ni @  (	   RU   R   R   R   R&   t   readR   R'   RI   (	   R   RT   t   txtR   t
   backuppathR   t   BUFSIZER)   t   buf(    (    s   /usr/lib/python2.7/mhlib.pyt   createmessage\  s,    

c         C   s   t  |  d  r' |  j | k r' |  ` n  |  j   } d } xo | j   D]a \ } } | d k rd qF n  x@ | D]8 } | | k rk | j |  d } | s | | =q qk qk WqF W| r |  j |  n  d S(   s`   Remove one or more messages from all sequences (including last)
        -- but not from 'cur'!!!RW   i    Ro   i   N(   t   hasattrRW   Rh   R   t   removeRn   (   R   R   Rd   R   R/   Rl   RT   (    (    s   /usr/lib/python2.7/mhlib.pyR   v  s    	c         C   s#   t  |  d  s |  j   n  |  j S(   s   Return the last message number.RW   (   R   RY   RW   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyR     s    c         C   s4   | d k r' t |  d  r0 |  ` q0 n	 | |  _ d S(   s   Set the last message number.RW   N(   R   R   RW   (   R   RW   (    (    s   /usr/lib/python2.7/mhlib.pyR     s    (   R   R   RL   R   R   R   RQ   RS   RU   R:   R<   RY   Rh   Rn   Rt   Rv   R   R|   R   R   R   R   R   R   R   R   R   R   (    (    (    s   /usr/lib/python2.7/mhlib.pyR      s4   														T			#		 				c           B   sG   e  Z d d   Z d   Z d d  Z d d  Z d   Z d   Z RS(   c         C   sV   | |  _  | |  _ | d k r? | j |  } t | d  } n  t j j |  |  d S(   s   Constructor.RZ   N(   t   foldert   numberR   RU   R&   t	   mimetoolsR   R   (   R   R)   RT   t   fpR   (    (    s   /usr/lib/python2.7/mhlib.pyR     s    		c         C   s   d t  |  j  |  j f S(   s   String representation.s   Message(%s, %s)(   t   reprR   R   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyR     s    c         C   s   | d k r d j |  j  Sg  } d } xn |  j D]c } | d j   s | j d  } | d k r | | |  j    } q n  | r2 | j |  q2 q2 Wd j |  S(   s   Return the message's header text as a string.  If an
        argument is specified, it is used as a filter predicate to
        decide which headers to return (its argument is the header
        name converted to lower case).R;   i    R[   N(   R   R   t   headerst   isspaceRz   t   lowerR,   (   R   t   predR   t   hitRe   R~   (    (    s   /usr/lib/python2.7/mhlib.pyt   getheadertext  s     i   c         C   s   |  j  j |  j  |  j   } | s2 | d k r? |  j  j   Sy d d l m } Wn! t k
 rv d d l m } n X|   } t j	 |  j  | |  | j
   S(   s   Return the message's body text as string.  This undoes a
        Content-Transfer-Encoding, but does not interpret other MIME
        features (e.g. multipart messages).  To suppress decoding,
        pass 0 as an argument.R;   t   7bitt   8bitt   binaryi(   t   StringIO(   R;   R   R   R   (   R   t   seekt   startofbodyt   getencodingR   t	   cStringIOR   t   ImportErrorR   t   decodet   getvalue(   R   R   t   encodingR   t   output(    (    s   /usr/lib/python2.7/mhlib.pyt   getbodytext  s    	c         C   s   |  j    d k r t d  n  |  j d  } | s? t d  n  |  j j |  j  t j |  j  } | j |  g  } xO | j	   r d |  j
 d t |  f } t |  j | |  } | j |  qz W| j   | S(   s   Only for multipart messages: return the message's body as a
        list of SubMessage objects.  Each submessage object behaves
        (almost) as a Message object.t	   multiparts   Content-Type is not multipart/*t   boundarys"   multipart/* without boundary params   %s.%ri   (   t   getmaintypeR   t   getparamR   R   R   t	   multifilet	   MultiFilet   pushR   R   R`   t
   SubMessageR   R,   t   pop(   R   t   bdryt   mft   partsRT   t   part(    (    s   /usr/lib/python2.7/mhlib.pyt   getbodyparts  s    
c         C   s*   |  j    d k r |  j   S|  j   Sd S(   s3   Return body, either a string or a list of messages.R   N(   R   R   R   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   getbody  s    
N(	   R   R   R   R   R   R   R   R   R   (    (    (    s   /usr/lib/python2.7/mhlib.pyR     s   			R   c           B   s8   e  Z d    Z d   Z d d  Z d   Z d   Z RS(   c         C   sk   t  j |  | | |  |  j   d k r= t  j |   |  _ n t  j |   |  _ t  j |  d d |  _ d S(   s   Constructor.R   R   i    N(   R   R   R   R   t   bodyR   t   bodyencoded(   R   R)   RT   R   (    (    s   /usr/lib/python2.7/mhlib.pyR     s
    c         C   s.   |  j  |  j |  j } } } d | | | f S(   s   String representation.s   SubMessage(%s, %s, %s)(   R   R   R   (   R   R)   RT   R   (    (    s   /usr/lib/python2.7/mhlib.pyR     s    i   c         C   s3   | s |  j  St |  j  t d  k r/ |  j Sd  S(   NR;   (   R   t   typeR   (   R   R   (    (    s   /usr/lib/python2.7/mhlib.pyR     s    c         C   s&   t  |  j  t  g   k r" |  j Sd  S(   N(   R   R   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyR     s    c         C   s   |  j  S(   N(   R   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyR     s    (   R   R   R   R   R   R   R   (    (    (    s   /usr/lib/python2.7/mhlib.pyR     s
   	
		Rb   c           B   s   e  Z d  Z d d d d  Z d   Z d   Z d   Z d   Z d   Z	 d	   Z
 d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s  Class implementing sets of integers.

    This is an efficient representation for sets consisting of several
    continuous ranges, e.g. 1-100,200-400,402-1000 is represented
    internally as a list of three pairs: [(1,100), (200,400),
    (402,1000)].  The internal representation is always kept normalized.

    The constructor has up to three arguments:
    - the string used to initialize the set (default ''),
    - the separator between ranges (default ',')
    - the separator between begin and end of a range (default '-')
    The separators must be strings (not regexprs) and should be different.

    The tostring() function yields a string that can be passed to another
    IntSet constructor; __repr__() is a valid IntSet constructor itself.
    R>   Rx   c         C   s5   g  |  _  | |  _ | |  _ | r1 |  j |  n  d  S(   N(   t   pairst   sept   rngt
   fromstring(   R   t   dataR   R   (    (    s   /usr/lib/python2.7/mhlib.pyR     s
    			 c         C   s   g  |  _  d  S(   N(   R   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   reset   s    c         C   s   t  |  j | j  S(   N(   t   cmpR   (   R   t   other(    (    s   /usr/lib/python2.7/mhlib.pyt   __cmp__#  s    c         C   s   t  |  j  S(   N(   t   hashR   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   __hash__&  s    c         C   s   d |  j    |  j |  j f S(   Ns   IntSet(%r, %r, %r)(   Rk   R   R   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyR   )  s    c         C   s   |  j  j   d } x | t |  j   k  r |  j  | d \ } } |  j  | \ } } | | d k r | t | |  f g |  j  | d | d +q | d } q Wd  S(   Ni   (   R   R-   R`   Rp   (   R   R~   t   alot   ahit   blot   bhi(    (    s   /usr/lib/python2.7/mhlib.pyt	   normalize,  s    -c         C   s|   d } xo |  j  D]d \ } } | | k r7 t |  } n t |  |  j t |  } | rn | |  j | } q | } q W| S(   NR;   (   R   R   R   R   (   R   Rm   t   lot   hit   t(    (    s   /usr/lib/python2.7/mhlib.pyRk   7  s      
c         C   sA   g  } x4 |  j  D]) \ } } t | | d  } | | } q W| S(   Ni   (   R   t   range(   R   t   lR   R   t   m(    (    s   /usr/lib/python2.7/mhlib.pyRc   @  s
    c         C   s"   x | D] } |  j  |  q Wd  S(   N(   R,   (   R   R   R~   (    (    s   /usr/lib/python2.7/mhlib.pyRj   G  s    c         C   s   t    } |  j | _ | S(   N(   Rb   R   (   R   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   cloneK  s    	c         C   s   |  j  d d S(   Ni    (   R   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   minP  s    c         C   s   |  j  d d S(   Ni(   R   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyRp   S  s    c         C   s>   x7 |  j  D], \ } } | | k o- | k n r
 t Sq
 Wt S(   N(   R   t   Truet   False(   R   t   xR   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   containsV  s     c         C   sq  x t  t |  j   D] } |  j | \ } } | | k  r | d | k ra | | f |  j | <n |  j j | | | f  | d k r | d |  j | d d k r |  j | d d |  j | d f g |  j | d | d +n  d  S| | k r d  Sq Wt |  j  d } | d k rW|  j | \ } } | d | k rW| | f |  j | <d  Sn  |  j j | | f  d  S(   Ni   i    (   R   R`   R   t   insertR,   (   R   R   R~   R   R   (    (    s   /usr/lib/python2.7/mhlib.pyR,   [  s&    +,c         C   s4   | | k r d  S|  j  j | | f  |  j   d  S(   N(   R   R,   R   (   R   t   xlot   xhi(    (    s   /usr/lib/python2.7/mhlib.pyt   addpairt  s     c         C   s   g  } x | j  |  j  D] } g  } x9 | j  |  j  D]% } | j   } | j t |   q8 Wt |  d k r | j | d | d f  q t |  d k r | d | d k r | j | d | d f  q t d  q W|  j | |  _ |  j	   d  S(   Ni   i    i   s   bad data passed to IntSet(
   R_   R   R   Ra   R,   RC   R`   Rq   R   R   (   R   R   R   R   R   t   subpRm   (    (    s   /usr/lib/python2.7/mhlib.pyR   y  s    &N(   R   R   RL   R   R   R   R   R   R   R   Rk   Rc   Rj   R   R   Rp   R   R,   R  R   (    (    (    s   /usr/lib/python2.7/mhlib.pyRb     s"   															i   c         C   s   y t  |  d  } Wn t k
 r' d  SXt j |  d } t j | | oP t j  } x~ | j   } | so Pn  | j |  rY | t	 |  d } x5 | j   } | s | d j
   r Pn  | | } q | j   SqY d  S(   NRZ   R[   i   i    (   R&   R]   R   t   ret   escapet   compilet
   IGNORECASER^   RN   R`   R   Ra   (   t   fileR    t   casefoldR)   t   patt   progRe   t   text(    (    s   /usr/lib/python2.7/mhlib.pyR     s&     c         C   sa  y) t  |  d  } | j   } | j   Wn t k
 rB g  } n Xt j |  d } t j | | ok t j  } | d  k r d  } n d | | f } xs t	 t
 |   D]C }	 | |	 }
 | j |
  r | d  k r | |	 =n
 | | |	 <Pq q W| d  k	 r| j |  n  |  d } t  | d  } x | D] }
 | j |
  q,W| j   t j | |   d  S(   NRZ   s   :(.*)
s   %s: %s
R
   R%   (   R&   t	   readlinesR'   R]   R  R  R  R  R   R   R`   RN   R,   R   R   R   (   R  R    Rg   R  R)   t   linesR	  R
  t   newlineR~   Re   t   tempfile(    (    s   /usr/lib/python2.7/mhlib.pyRu     s4    
	




c    	      C   s  t  j d  t   a d   }  |  d  |  d  d d d d d	 d
 g } x | D] } |  d | f  qR W|  d  |  d  t j d  a |  d  |  d  |  d  t j   } t d d  j   | d <| GHt j	 |  |  d  x% t
 |  D] } |  d | f  q W|  d  t j   } t j |  a |  d  x| d/ D]t } y |  d* | f  Wn t k
 r} d+ G| GHn Xt  j d, | f  j   } t t | j    } | Gd- GHqMW|  d.  d  S(0   Ns   rm -rf $HOME/Mail/@testc         S   s   |  GHt  |   GHd  S(   N(   t   eval(   Rm   (    (    s   /usr/lib/python2.7/mhlib.pyt   do  s    s   mh.listfolders()s   mh.listallfolders()s   @tests   @test/test1s   @test/test2s   @test/test1/test11s   @test/test1/test12s   @test/test1/test11/test111s   mh.makefolder(%r)s   mh.listsubfolders('@test')s   mh.listallsubfolders('@test')s   f.listsubfolders()s   f.listallsubfolders()s   f.getsequences()s
   1-10 12-20R\   t   foos   mh.deletefolder(%r)s   mh.getcontext()s   f.getcurrent()R   RW   Ro   R   Ry   R   s   first:3s   last:3s   cur:3s   cur:-3s   prev:3s   next:3s   1:3s   1:-3s   100:3s   100:-3s   10000:3s   10000:-3Rw   s   f.parsesequence(%r)s   Error:s   pick %r 2>/dev/nulls   <-- picks   f.listmessages()(   s   firsts   lasts   curR   s   prevs   nexts   first:3s   last:3s   cur:3s   cur:-3s   prev:3s   next:3s   1:3s   1:-3s   100:3s   100:-3s   10000:3s   10000:-3s   all(   R   t   systemR   RP   RB   R)   Rh   Rb   Rc   Rn   t   reversedR$   R   t   popenR   RV   RC   R_   (	   R  t   testfoldersR   Rs   R"   Rl   R   t   stuffR   (    (    s   /usr/lib/python2.7/mhlib.pyt   test  sP    		

		 





 

   
t   __main__(   RL   t   warningsR    R   R   RR   RD   R   R   R  R   R   R   R   t   __all__t	   ExceptionR   R   R  RM   R?   R   R   R   Rb   R   Ru   R  R   (    (    (    s   /usr/lib/python2.7/mhlib.pyt   <module>6   s<   		 M"	*