
\Kc           @   s[  d  Z  d Z d Z d Z 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 l Z d d	 d
 d g Z d	 e f d     YZ d f  d     YZ e i d  Z d   Z d
 f  d     YZ d e i f d     YZ d e f d     YZ d f  d     YZ d d  Z d d  Z d   Z e d j o 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
s   ~/.mh_profiles   ~/Mails   .mh_sequencesi  iN(   t   bisectt   MHt   Errort   Foldert   Messagec           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s   /usr/lib/python2.5/mhlib.pyR   W   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 j o
 t } n t i i |  |  _ | d j o |  i d  } n | p
 t } n t i i |  o* | d d j o t i i	 d |  } n t i i |  } t i i
 |  p 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.5/mhlib.pyt   __init__b   s     
  
% c         C   s   d |  i  |  i f S(   s   String representation.s
   MH(%r, %r)(   R   R   (   R   (    (    s   /usr/lib/python2.5/mhlib.pyt   __repr__n   s    c         G   s   t  i i 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.5/mhlib.pyt   errorr   s    c         C   s   t  |  i |  S(   s*   Return a profile entry, None if not found.(   t   picklineR   (   R   t   key(    (    s   /usr/lib/python2.5/mhlib.pyR   v   s    c         C   s   |  i  S(   s9   Return the path (the name of the collection's directory).(   R   (   R   (    (    s   /usr/lib/python2.5/mhlib.pyt   getpathz   s    c         C   s9   t  t i i |  i   d  d  } | p
 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.5/mhlib.pyt
   getcontext~   s
    	 
c         C   sI   t  i i |  i   d  } t | d  } | i d |  | i   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.5/mhlib.pyt
   setcontext   s    c         C   ss   g  } |  i    } xP t i |  D]? } t i i | |  } t i i |  o | i |  q" q" W| i   | 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.5/mhlib.pyt   listfolders   s     
c   	      C   s   t  i i |  i |  } t  i |  i } | d j o g  Sn g  } t  i |  } xx | D]p } t  i i | |  } t  i i |  oB t  i i | |  } | i |  | d } | d j o Pq q[ q[ W| i   | 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-   R.   t   nlinkst
   subfolderst   subnamest   subnamet   fullsubnamet   name_subname(    (    s   /usr/lib/python2.5/mhlib.pyt   listsubfolders   s"     

c         C   s   |  i  d  S(   s<   Return the names of all folders and subfolders, recursively.t    (   t   listallsubfolders(   R   (    (    s   /usr/lib/python2.5/mhlib.pyt   listallfolders   s    c   
      C   s2  t  i i |  i |  } t  i |  i } | d j o g  Sn g  } t  i |  } x | D] } | d d j p t |  o q[ n t  i i | |  } t  i i |  or t  i i | |  } | i |  t  i i	 |  p |  i
 |  }	 | |	 } n | d } | d j o Pq q[ q[ W| i   | S(   s>   Return the names of subfolders in a given folder, recursively.i   i    t   ,i   (   R   R   R   R0   R1   R)   t	   isnumericR   R*   t   islinkR:   R+   (
   R   R-   R.   R2   R3   R4   R5   R6   R7   t   subsubfolders(    (    s   /usr/lib/python2.5/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.5/mhlib.pyt
   openfolder   s    c         C   sh   t  |  i d  } | o  t |  o t | d  } n t } t i t i i |  i	   |  |  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.5/mhlib.pyt
   makefolder   s
    c         C   s   t  i i |  i   |  } xg t  i |  D]V } t  i i | |  } y t  i |  Wq+ t  i j
 o |  i d |  q+ Xq+ Wt  i |  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-   R.   R5   R6   (    (    s   /usr/lib/python2.5/mhlib.pyt   deletefolder   s     	N(   R   R   t   __doc__R	   R   R   R   R   R   R"   R(   R/   R8   R;   R:   R@   RF   RI   (    (    (    s   /usr/lib/python2.5/mhlib.pyR   [   s   													s   ^[1-9][0-9]*$c         C   s   t  i |   d  j	 S(   N(   t   numericprogt   matchR	   (   t   str(    (    s   /usr/lib/python2.5/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 i i |  i    p t d |  n d S(   s   Constructor.s   no folder %sN(   t   mhR-   R   R   R   t   getfullnameR   (   R   RN   R-   (    (    s   /usr/lib/python2.5/mhlib.pyR      s    		c         C   s   d |  i  |  i f S(   s   String representation.s   Folder(%r, %r)(   RN   R-   (   R   (    (    s   /usr/lib/python2.5/mhlib.pyR      s    c         G   s   |  i  i |   d S(   s   Error message handler.N(   RN   R   (   R   R   (    (    s   /usr/lib/python2.5/mhlib.pyR      s    c         C   s   t  i i |  i i |  i  S(   s'   Return the full pathname of the folder.(   R   R   R   RN   R-   (   R   (    (    s   /usr/lib/python2.5/mhlib.pyRO      s    c         C   s   t  i i |  i   t  S(   s8   Return the full pathname of the folder's sequences file.(   R   R   R   RO   t   MH_SEQUENCES(   R   (    (    s   /usr/lib/python2.5/mhlib.pyt   getsequencesfilename  s    c         C   s   t  i i |  i   t |   S(   s4   Return the full pathname of a message in the folder.(   R   R   R   RO   RM   (   R   t   n(    (    s   /usr/lib/python2.5/mhlib.pyt   getmessagefilename  s    c         C   s   |  i  i |  i  S(   s!   Return list of direct subfolders.(   RN   R8   R-   (   R   (    (    s   /usr/lib/python2.5/mhlib.pyR8     s    c         C   s   |  i  i |  i  S(   s   Return list of all subfolders.(   RN   R:   R-   (   R   (    (    s   /usr/lib/python2.5/mhlib.pyR:     s    c         C   s   g  } t  i } | i } x8 t i |  i    D]! } | |  o | |  q. q. Wt t |  } | i   | o | 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    (
   RK   RL   R*   R   R)   RO   t   mapRA   R+   t   last(   R   t   messagesRL   R*   R-   (    (    s   /usr/lib/python2.5/mhlib.pyt   listmessages  s    		 
	c         C   s   h  } |  i    } y t | d  } Wn t j
 o | Sn Xx | i   } | p Pn | i d  } t |  d j o! |  i d | | i   f  n | d i   } t | d i   d  i	   } | | | <qB | S(   s+   Return the set of sequences for the folder.t   rt   :i   s   bad sequence in %s: %si    i   t    (
   RQ   R$   t   IOErrort   readlinet   splitt   lenR   t   stript   IntSett   tolist(   R   t	   sequencesR.   R'   t   linet   fieldsR   t   value(    (    s   /usr/lib/python2.5/mhlib.pyt   getsequences%  s$    	 	c         C   s   |  i    } d } xm | i   D]_ \ } } t d d  } | i |  | p t | d  } n | i d | | i   f  q W| p. y t i	 |  Wq t i
 j
 o q Xn | i   d S(   s.   Write the set of sequences back to the folder.R9   RZ   R#   s   %s: %s
N(   RQ   R	   t	   iteritemsR`   t   fromlistR$   R   t   tostringR   RG   R   R%   (   R   Rb   R.   R'   R   t   seqt   s(    (    s   /usr/lib/python2.5/mhlib.pyt   putsequences9  s      !	c         C   sG   |  i    } y t | d  SWn" t t f j
 o t d  n Xd S(   s<   Return the current message.  Raise Error when there is none.t   curs   no cur messageN(   Rf   t   maxt
   ValueErrort   KeyErrorR   (   R   t   seqs(    (    s   /usr/lib/python2.5/mhlib.pyt
   getcurrentJ  s
    c         C   s#   t  |  i   d t |  d  d S(   s   Set the current message.Rm   i    N(   t
   updatelineRQ   RM   (   R   RR   (    (    s   /usr/lib/python2.5/mhlib.pyt
   setcurrentR  s    c         C   s  |  i    } | p t d |  i  n | d j o | Sn | i d  } | d j o| |  d | | d } } } | d  d j o | d  | d } } n t |  p t d |  n y t |  } Wn% t t f j
 o t |  } n Xy |  i	 | |  } Wn t j
 o }	 |  i
   }
 | |
 j o/ |	 p d | }	 n t |	 t i   d	  n |
 | } | p t d
 |  n | d j o | | Sq.| |  Sq2X| p | d j o
 d } qn | d j o+ t | |  } | t d | |  | !Sq2t | | d  } | | | | !Sn | i d  } | d j o |  i	 | |  |  } |  i	 | | d |  } t | | d  } t | |  } | | | !} | p t d |  n | Sn y |  i	 | |  } WnX t j
 oL }	 |  i
   }
 | |
 j o" |	 p d | }	 n t |	  n |
 | SnE X| | j o/ t |  o t d |  q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   allRY   i    R9   i   s   -+s   bad message list %si   s   sequence %s emptyt   -t   prevRU   s   message %d doesn't exists   no %s messageN(   Rw   s   last(   RW   R   R-   t   findR=   RA   Ro   t   OverflowErrorR^   t   _parseindexRf   R   t   exc_infoR    Rn   (   R   Rj   Ru   t   it   headt   dirt   tailt   countt   anchorR   Rq   t   msgst   begint   endt   jRX   RR   (    (    s   /usr/lib/python2.5/mhlib.pyt   parsesequenceV  s|    	 
c         C   sl  t  |  o5 y t |  SWqB t t f j
 o t i SqB Xn | d j o |  i   Sn | d j o | d Sn | d j o | d Sn | d j oJ |  i   } t | |  } y | | SWq t j
 o t	 d  q Xn | d	 j ol |  i   } t | | d
  } | d j o t	 d  n y | | d
 SWq_t j
 o t	 d  q_Xn t	 d  d S(   s7   Internal: parse a message number (or cur, first, etc.).Rm   t   .t   firsti    RU   it   nexts   no next messageRw   i   s   no prev messageN(   s   curR   (   R=   RA   Ry   Ro   R   t   maxintRr   R    t
   IndexErrorR   R	   (   R   Rj   Ru   RR   R|   (    (    s   /usr/lib/python2.5/mhlib.pyRz     s8    c         C   s   t  |  |  S(   s+   Open a message -- returns a Message object.(   R   (   R   RR   (    (    s   /usr/lib/python2.5/mhlib.pyt   openmessage  s    c      
   C   s  g  } g  } x | D] } |  i  |  } |  i  d t |   } y t i |  Wn t i j
 o n Xy t i | |  Wn% t i j
 o } | i |  q X| i |  q W| o |  i |  n | o= t |  d j o t i | d  qt i d | f  n d S(   s2   Remove one or more messages -- may raise os.error.R<   i   i    s   multiple errors:N(	   RS   RM   R   RG   R   t   renameR*   t   removefromallsequencesR^   (   R   t   listt   errorst   deletedRR   R   t	   commapathR   (    (    s   /usr/lib/python2.5/mhlib.pyt   removemessages  s*     i    c         C   s  g  } h  } x | D] } | i    d } |  i |  } | i |  }	 y t i | |	  Wn t i j
 o y! t i | |	  t i |  Wq t t i f j
 oC }
 | i	 |
  y t i |	  Wq t i j
 o q Xq q Xn X| i
 |  | | | <q W| o8 | o | i |  | i    n |  i | i    n | o= t |  d j o t i | d  qt i 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   getlastRS   R   R   R   t   shutilt   copy2RG   R[   R*   t   setlastt   _copysequencest   itemsR   t   keysR^   (   R   R   t   tofoldert   keepsequencesR   t   refiledRR   t   tonR   t   topathR   (    (    s   /usr/lib/python2.5/mhlib.pyt   refilemessages  s<     c      	   C   s   | i    } |  i    } d } x | i   D] \ } } y | | } d }	 Wn t j
 o g  } d }	 n Xx8 | D]0 \ }
 } |
 | j o | i |  d } qt qt W|	 o | o | | | <q+ q+ W| o |  i |  n d S(   s.   Helper for refilemessages() to copy sequences.i    i   N(   Rf   R   Rp   R*   Rl   (   R   t
   fromfoldert   refileditemst   fromsequencest   tosequencest   changedR-   Rj   t   toseqt   newt   fromnR   (    (    s   /usr/lib/python2.5/mhlib.pyR   	  s(     

 c   	      C   s+  |  i  |  } t |  } | i   ~ | i  |  } | i  d |  } y t i | |  Wn t i j
 o n Xy t i | |  Wn t i j
 oz d } z' | i d  t i	 | |  d } Wd | p. y t i
 |  Wqt i j
 o qXn Xt i
 |  n X|  i | g  d S(   sa   Move one message over a specific destination message,
        which may or may not already exist.s   ,%di    i   N(   RS   R$   R%   R   R   R   R   R	   R   R   RG   R   (	   R   RR   R   R   R   R'   R   t   backuptopatht   ok(    (    s   /usr/lib/python2.5/mhlib.pyt   movemessage  s2    


c   	      C   s   |  i  |  } t |  } | i   ~ | i  |  } | i  d |  } y t i | |  Wn t i j
 o n Xd } z' | i d  t i	 | |  d } Wd | p. y t i
 |  Wq t i j
 o q Xn Xd S(   sa   Copy one message over a specific destination message,
        which may or may not already exist.s   ,%di    i   N(   RS   R$   R%   R   R   R   R   R	   R   R   RG   (	   R   RR   R   R   R   R'   R   R   R   (    (    s   /usr/lib/python2.5/mhlib.pyt   copymessage>  s(    

c   	      C   s   |  i  |  } |  i  d |  } y t i | |  Wn t i j
 o n Xd } d } zQ t | d  } x+ | i |  } | p Pn | i |  qp | i   d } Wd | p. y t i |  Wq t i j
 o q Xn Xd S(	   s3   Create a message, with text from the open file txt.s   ,%di    i   i   R#   i   Ni @  (	   RS   R   R   R   R$   t   readR   R%   RG   (	   R   RR   t   txtR   t
   backuppathR   t   BUFSIZER'   t   buf(    (    s   /usr/lib/python2.5/mhlib.pyt   createmessageX  s,    

c         C   s   t  |  d  o |  i | j o
 |  ` n |  i   } d } xu | i   D]g \ } } | d j o qI n xD | D]< } | | j o) | i |  d } | p | | =q qp qp WqI W| o |  i |  n d S(   s`   Remove one or more messages from all sequences (including last)
        -- but not from 'cur'!!!RU   i    Rm   i   N(   t   hasattrRU   Rf   R   t   removeRl   (   R   R   Rb   R   R-   Rj   RR   (    (    s   /usr/lib/python2.5/mhlib.pyR   r  s"     
  c         C   s%   t  |  d  p |  i   n |  i S(   s   Return the last message number.RU   (   R   RW   RU   (   R   (    (    s   /usr/lib/python2.5/mhlib.pyR     s    c         C   s8   | d j o t |  d  o
 |  ` q4 n
 | |  _ d S(   s   Set the last message number.RU   N(   R	   R   RU   (   R   RU   (    (    s   /usr/lib/python2.5/mhlib.pyR     s    (   R   R   RJ   R   R   R   RO   RQ   RS   R8   R:   RW   Rf   Rl   Rr   Rt   R   Rz   R   R   R   R   R   R   R   R   R   R   (    (    (    s   /usr/lib/python2.5/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   sX   | |  _  | |  _ | d j o" | i |  } t | d  } n t i i |  |  d S(   s   Constructor.RX   N(   t   foldert   numberR	   RS   R$   t	   mimetoolsR   R   (   R   R'   RR   t   fpR   (    (    s   /usr/lib/python2.5/mhlib.pyR     s    		c         C   s   d t  |  i  |  i f S(   s   String representation.s   Message(%s, %s)(   t   reprR   R   (   R   (    (    s   /usr/lib/python2.5/mhlib.pyR     s    c         C   s   | d j o d i |  i  Sn g  } d } xt |  i D]i } | d i   p: | i d  } | d j o | | |  i    } q n | o | i |  q7 q7 Wd i |  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).R9   i    RY   N(   R	   R   t   headerst   isspaceRx   t   lowerR*   (   R   t   predR   t   hitRc   R|   (    (    s   /usr/lib/python2.5/mhlib.pyt   getheadertext  s    
  i   c         C   s   |  i  i |  i  |  i   } | p | d j o |  i  i   Sn y d d k l } Wn# t j
 o d d k l } n X|   } t i	 |  i  | |  | i
   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.R9   t   7bitt   8bitt   binaryi(   t   StringIO(   R9   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.5/mhlib.pyt   getbodytext  s    	c         C   s   |  i    d j o t d  n |  i d  } | p t d  n |  i i |  i  t i |  i  } | i |  g  } xQ | i	   oC d |  i
 d t |  f } t |  i | |  } | i |  q~ W| i   | 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   partsRR   t   part(    (    s   /usr/lib/python2.5/mhlib.pyt   getbodyparts  s      
c         C   s/   |  i    d j o |  i   Sn |  i   Sd S(   s3   Return body, either a string or a list of messages.R   N(   R   R   R   (   R   (    (    s   /usr/lib/python2.5/mhlib.pyt   getbody  s    N(	   R   R   R	   R   R   R   R   R   R   (    (    (    s   /usr/lib/python2.5/mhlib.pyR     s   			R   c           B   s8   e  Z d    Z d   Z d d  Z d   Z d   Z RS(   c         C   sm   t  i |  | | |  |  i   d j o t  i |   |  _ n t  i |   |  _ t  i |  d d |  _ d S(   s   Constructor.R   R   i    N(   R   R   R   R   t   bodyR   t   bodyencoded(   R   R'   RR   R   (    (    s   /usr/lib/python2.5/mhlib.pyR     s
    c         C   s.   |  i  |  i |  i } } } d | | | f S(   s   String representation.s   SubMessage(%s, %s, %s)(   R   R   R   (   R   R'   RR   R   (    (    s   /usr/lib/python2.5/mhlib.pyR     s    i   c         C   s=   | p |  i  Sn t |  i  t d  j o |  i Sn d  S(   NR9   (   R   t   typeR   (   R   R   (    (    s   /usr/lib/python2.5/mhlib.pyR     s    c         C   s+   t  |  i  t  g   j o |  i Sn d  S(   N(   R   R   (   R   (    (    s   /usr/lib/python2.5/mhlib.pyR     s    c         C   s   |  i  S(   N(   R   (   R   (    (    s   /usr/lib/python2.5/mhlib.pyR     s    (   R   R   R   R   R   R   R   (    (    (    s   /usr/lib/python2.5/mhlib.pyR     s
   	
		R`   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<   Rv   c         C   s7   g  |  _  | |  _ | |  _ | o |  i |  n d  S(   N(   t   pairst   sept   rngt
   fromstring(   R   t   dataR   R   (    (    s   /usr/lib/python2.5/mhlib.pyR     s
    			 c         C   s   g  |  _  d  S(   N(   R   (   R   (    (    s   /usr/lib/python2.5/mhlib.pyt   reset  s    c         C   s   t  |  i | i  S(   N(   t   cmpR   (   R   t   other(    (    s   /usr/lib/python2.5/mhlib.pyt   __cmp__  s    c         C   s   t  |  i  S(   N(   t   hashR   (   R   (    (    s   /usr/lib/python2.5/mhlib.pyt   __hash__"  s    c         C   s   d |  i    |  i |  i f S(   Ns   IntSet(%r, %r, %r)(   Ri   R   R   (   R   (    (    s   /usr/lib/python2.5/mhlib.pyR   %  s    c         C   s   |  i  i   d } x | t |  i   j  ow |  i  | d \ } } |  i  | \ } } | | d j o. | t | |  f g |  i  | d | d +q | d } q Wd  S(   Ni   (   R   R+   R^   Rn   (   R   R|   t   alot   ahit   blot   bhi(    (    s   /usr/lib/python2.5/mhlib.pyt	   normalize(  s     .c         C   s   d } xs |  i  D]h \ } } | | j o t |  } n t |  |  i t |  } | o | |  i | } q | } q W| S(   NR9   (   R   R   R   R   (   R   Rk   t   lot   hit   t(    (    s   /usr/lib/python2.5/mhlib.pyRi   3  s    
   
c         C   sA   g  } x4 |  i  D]) \ } } t | | d  } | | } q W| S(   Ni   (   R   t   range(   R   t   lR   R   t   m(    (    s   /usr/lib/python2.5/mhlib.pyRa   <  s    
 c         C   s"   x | D] } |  i  |  q Wd  S(   N(   R*   (   R   R   R|   (    (    s   /usr/lib/python2.5/mhlib.pyRh   C  s     c         C   s   t    } |  i | _ | S(   N(   R`   R   (   R   R   (    (    s   /usr/lib/python2.5/mhlib.pyt   cloneG  s    	c         C   s   |  i  d d S(   Ni    (   R   (   R   (    (    s   /usr/lib/python2.5/mhlib.pyt   minL  s    c         C   s   |  i  d d S(   Ni(   R   (   R   (    (    s   /usr/lib/python2.5/mhlib.pyRn   O  s    c         C   sD   x= |  i  D]2 \ } } | | j o
 | j n o t Sq
 q
 Wt S(   N(   R   t   Truet   False(   R   t   xR   R   (    (    s   /usr/lib/python2.5/mhlib.pyt   containsR  s
    
  c         C   s  xt  t |  i   D] } |  i | \ } } | | j  o | d | j o | | f |  i | <n |  i i | | | f  | d j o_ | d |  i | d d j o? |  i | d d |  i | d f g |  i | d | d +n d  Sn | | j o d  Sq q Wt |  i  d } | d j oC |  i | \ } } | d | j o | | f |  i | <d  Sqmn |  i i | | f  d  S(   Ni   i    (   R   R^   R   t   insertR*   (   R   R   R|   R   R   (    (    s   /usr/lib/python2.5/mhlib.pyR*   W  s(     --c         C   s9   | | j o d  Sn |  i  i | | f  |  i   d  S(   N(   R   R*   R   (   R   t   xlot   xhi(    (    s   /usr/lib/python2.5/mhlib.pyt   addpairp  s     c         C   s  g  } x | i  |  i  D] } g  } x9 | i  |  i  D]% } | i   } | i t |   q8 Wt |  d j o | i | d | d f  q t |  d j o4 | d | d j o | i | d | d f  q t d  q W|  i | |  _ |  i	   d  S(   Ni   i    i   s   bad data passed to IntSet(
   R]   R   R   R_   R*   RA   R^   Ro   R   R   (   R   R   R   R   R   t   subpRk   (    (    s   /usr/lib/python2.5/mhlib.pyR   u  s      (N(   R   R   RJ   R	   R   R   R   R   R   R   Ri   Ra   Rh   R   R   Rn   R   R*   R   R   (    (    (    s   /usr/lib/python2.5/mhlib.pyR`     s"   															i   c         C   s   y t  |  d  } Wn t j
 o d  Sn Xt i |  d } t i | | o t i  } x | i   } | p Pn | i |  o] | t	 |  d } x8 | i   } | p | d i
   o Pn | | } q | i   Sq_ q_ d  S(   NRX   RY   i   i    (   R$   R[   R	   t   ret   escapet   compilet
   IGNORECASER\   RL   R^   R   R_   (   t   fileR   t   casefoldR'   t   patt   progRc   t   text(    (    s   /usr/lib/python2.5/mhlib.pyR     s&    	 c      
   C   sl  y) t  |  d  } | i   } | i   Wn t j
 o g  } n Xt i |  d } t i | | o t i  } | d  j o
 d  } n d | | f } xy t	 t
 |   D]G }	 | |	 }
 | i |
  o' | d  j o | |	 =n | | |	 <Pq q W| d  j	 o | i |  n |  d } t  | d  } x | D] }
 | i |
  q7W| i   t i | |   d  S(   NRX   s   :(.*)
s   %s: %s
R   R#   (   R$   t	   readlinesR%   R[   R  R  R  R  R	   R   R^   RL   R*   R   R   R   (   R  R   Re   R  R'   t   linesR  R  t   newlineR|   Rc   t   tempfile(    (    s   /usr/lib/python2.5/mhlib.pyRs     s8    
 

	
 
c    	      C   s  t  i d  t   a d   }  |  d  |  d  d d d d d	 d
 g } x | D] } |  d | f  qR W|  d  |  d  t i d  a |  d  |  d  |  d  t i   } t d d  i   | d <| GHt i	 |  |  d  x% t
 |  D] } |  d | f  q W|  d  t i   } t i |  a |  d  x~ d/ D]v } y |  d* | f  Wn t j
 o } d+ G| GHn Xt  i d, | f  i   } t t | i    } | Gd- GHqMW|  d.  d  S(0   Ns   rm -rf $HOME/Mail/@testc         S   s   |  GHt  |   GHd  S(   N(   t   eval(   Rk   (    (    s   /usr/lib/python2.5/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-20RZ   t   foos   mh.deletefolder(%r)s   mh.getcontext()s   f.getcurrent()R   RU   Rm   R   Rw   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:-3Ru   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   RN   R@   R'   Rf   R`   Ra   Rl   t   reversedR"   R   t   popenR   RT   RA   R]   (	   R  t   testfoldersR   Rq   R    Rj   R   t   stuffR   (    (    s   /usr/lib/python2.5/mhlib.pyt   test  sV    		

		  





  

    t   __main__(   RJ   R
   R   RP   RB   R   R   R  R   R   R   R    t   __all__t	   ExceptionR   R   R  RK   R=   R   R   R   R`   R   Rs   R  R   (    (    (    s   /usr/lib/python2.5/mhlib.pys   <module>6   s4   	 M"	*