
M9c       s     d  Z    d k Z  d k Z 	 d   Z " d   Z 5 d   Z [ d   Z z d   Z  d d	 g  d  Z  e	 d
  Z
  g  d  Z  d   Z  d   Z  d   Z  e d j o  e   n d S(   s%   Mailcap file handling.  See RFC 1524.Nc     s   	   h  }   x t   d  r }  y  t | d  } Wn   q n X t |  }  | i    x[ | i   d  rH }  |  i
 |  o  | | |  | <n  |  | | | |  | <q Wq W  |  Sd S(   s  Return a dictionary containing the mailcap database.
    
    The dictionary maps a MIME type (in all lowercase, e.g. 'text/plain')
    to a list of dictionaries corresponding to mailcap entries.  The list
    collects all the entries for that MIME type from all available mailcap
    files.  Each dictionary contains key-value pairs for that MIME type,
    where the viewing command is stored with the key "view".

    i    s   rN(   s   capss   listmailcapfiless   mailcaps   opens   fps   readmailcapfiles   morecapss   closes   keyss   keys   has_key(   s   capss   mailcaps   fps   morecapss   keys$   /mit/python/lib/python2.0/mailcap.pys   getcaps	 s    		 	
 	!c     s   " # % t  i i d  o) & t  i d }  ' t i |  d  } nM ) t  i i d  o * t  i d } n
 - d } . | d d d d g } 0 | Sd	 S(
   s7   Return a list of all mailcap files found on the system.s   MAILCAPSs   :s   HOMEs   .s	   /.mailcaps   /etc/mailcaps   /usr/etc/mailcaps   /usr/local/etc/mailcapN(   s   oss   environs   has_keys   strs   strings   splitfieldss   mailcapss   home(   s   strs   mailcapss   homes$   /mit/python/lib/python2.0/mailcap.pys   listmailcapfiles" s   	c    s  5 = > h  } ? x? d o@ |  i   } A | o A Pn C | d d j p t i |  d j o
 D q n E | } G xS G | d d j o= H |  i   } I | o I d } n J | d  | } q WL t |  \ } } M | o | o
 N q n P t i
 | d  } Q x9 t t |   d Q r  } R t i | |  | | <q5WS t i t i | d   } U | i |  o V | | i |  n X | g | | <q WY | Sd	 S(
   s  Read a mailcap file and return a dictionary keyed by MIME type.

    Each MIME type is mapped to an entry consisting of a list of
    dictionaries; the list will contain more than one such dictionary
    if a given MIME type appears more than once in the mailcap file.
    Each dictionary contains key-value pairs for that MIME type, where
    the viewing command is stored with the key "view".
    i   i    s   #s    i   s   \
s   
s   /N(   s   capss   fps   readlines   lines   strings   strips   nextlines	   parselines   keys   fieldss   splitfieldss   typess   ranges   lens   js   lowers
   joinfieldss   has_keys   append(   s   fps   capss   lines   nextlines   keys   fieldss   typess   js$   /mit/python/lib/python2.0/mailcap.pys   readmailcapfile5 s8   	 
 *
	  
 	c 
   s  [ ` a g  } b d t |   f \ } } c xM c | | j  o< d t |  | |  \ } } e | i |  f | d } q0 Wg t |  d j  o h t t f Sn i | d | d | d f \ } } } j h  | d <} k x | d k r } l t i | d  } m | d j  o n | } o d }	 n1 q t i | |   } r t i | | d  }	 s | i |  o u n w |	 | | <q Wx | | f Sd S(   s   Parse one entry in a mailcap file and return a dictionary.

    The viewing command is stored as the value with the key "view",
    and the rest of the fields produce key-value pairs in the dict.
    i    i   i   s   views   =s    N(   s   fieldss   lens   lines   is   ns
   parsefields   fields   appends   Nones   keys   views   rests   strings   finds   fkeys   fvalues   strips   has_key(
   s   lines   fieldss   is   ns   fields   keys   views   rests   fkeys   fvalues$   /mit/python/lib/python2.0/mailcap.pys	   parseline[ s0   	 ' 		c    s   z { | | } } xh } | | j  oW ~ |  | }  | d j o  Pn/  | d j o  | d } n  | d } q W t i |  | | ! | f Sd S(   s/   Separate one key-value pair in a mailcap entry.s   ;s   \i   i   N(   s   is   starts   ns   lines   cs   strings   strip(   s   lines   is   ns   starts   cs$   /mit/python/lib/python2.0/mailcap.pys
   parsefieldz s   	 c 	   s      t  |  | |  }  x | d  r }  | i d  oG  t | d | |  }  | o t i |  d j o
  q' n n  t | | | | |  }  | | f Sq' W t t f Sd S(   s  Find a match for a mailcap entry.
    
    Return a tuple containing the command line, and the mailcap entry
    used; (None, None) if no match is found.  This may invoke the
    'test' command of several matching entries before deciding which
    entry to use.

    i    s   testN(   s   lookups   capss   MIMEtypes   keys   entriess   es   has_keys   substs   filenames   plists   tests   oss   systems   commands   None(	   s   capss   MIMEtypes   keys   filenames   plists   entriess   es   tests   commands$   /mit/python/lib/python2.0/mailcap.pys	   findmatch s    	 s   views	   /dev/nullc    s     g  }  |  i |  o  | |  | } n  t i | d  }  | d d }  |  i |  o  | |  | } n  | t j	 o  t	 | d  |  } n  | Sd  S(   Ns   /i    s   /*c    s    |  i |  S(   N(   s   es   has_keys   key(   s   es   keys$   /mit/python/lib/python2.0/mailcap.pys   <lambda> s    (
   s   entriess   capss   has_keys   MIMEtypes   strings   splitfieldss	   MIMEtypess   keys   Nones   filter(   s   capss   MIMEtypes   keys   entriess	   MIMEtypess$   /mit/python/lib/python2.0/mailcap.pys   lookup s   	c 
   s    d }  d t |   f \ } }  x | | j  o |  | } | d }  | d j oC  | d j o"  |  | | d !} | d } n  | | } n |  | } | d }  | d j o  | | } n  | d j o  | | } n  | d j o  | | } n  | d j oy  | }  x3  | | j  o |  | d	 j o  | d } q@W |  | | !}	  | d }  | t
 |	 |  } n  | d | } q- W | Sd  S(
   Ns    i    i   s   %s   \s   ss   ts   {s   }(   s   ress   lens   fields   is   ns   cs   filenames   MIMEtypes   starts   names	   findparams   plist(
   s   fields   MIMEtypes   filenames   plists   ress   is   ns   cs   starts   names$   /mit/python/lib/python2.0/mailcap.pys   subst s4   	 "	 !c    sx     t  i |   d }   t |   }  x? | d  r2 }  t  i | |   |  j o  | | Sn q4 W d Sd  S(   Ns   =i    s    (   s   strings   lowers   names   lens   ns   plists   p(   s   names   plists   ns   ps$   /mit/python/lib/python2.0/mailcap.pys	   findparam s    	c  	   sB    d  k  }   t   }  |  i d o  t |   d  Sn  x t d t |  i  d  d  r }  |  i | | d !}  t |  d j  o  d GH d  Sn  | d }  | d }  t | | d |  \ } }  | o  d Gt GHn9  d G| GH t i |  }  | o  d G| GHn qf Wd  S(	   Ni   i   i    s"   usage: mailcap [MIMEtype file] ...s   views   No viewer found fors
   Executing:s   Exit status:(   s   syss   getcapss   capss   argvs   shows   ranges   lens   is   argss   MIMEtypes   files	   findmatchs   commands   es   types   oss   systems   sts(	   s   syss   capss   is   argss   MIMEtypes   files   commands   es   stss$   /mit/python/lib/python2.0/mailcap.pys   test s(   ! 	
c    s    d GH x" t    d  r }  d | GHq W H |  o  t   }  n  d GH H |  i   }  | i    x | d  r }  | GH |  | }  x` | d  rS }  | i   }  | i    x' | d  r }  d | G| | GHq W Hq Wq Wd  S(   Ns   Mailcap files:i    s   	s   Mailcap entries:s     %-15s(   s   listmailcapfiless   fns   capss   getcapss   keyss   ckeyss   sorts   types   entriess   es   k(   s   capss   fns   ckeyss   types   entriess   es   keyss   ks$   /mit/python/lib/python2.0/mailcap.pys   show s.    	   	 	 	s   __main__(   s   __doc__s   oss   strings   getcapss   listmailcapfiless   readmailcapfiles	   parselines
   parsefields	   findmatchs   Nones   lookups   substs	   findparams   tests   shows   __name__(    s$   /mit/python/lib/python2.0/mailcap.pys   ? s   & 