-
H ?c       s     d  Z    d k Z  d d g 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.Ns   getcapss	   findmatchc     s   	   h  }  x t   D ] }   y  t |  d  } Wn  t j
 o  q n X t |  }  | i    xY | i	   D ]H }  | 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".

    s   rN(   s   capss   listmailcapfiless   mailcaps   opens   fps   IOErrors   readmailcapfiles   morecapss   closes   keyss   keys   has_key(   s   mailcaps   fps   morecapss   keys   caps(    (    s$   /mit/python/lib/python2.2/mailcap.pys   getcaps	 s    		 	 	!c     s   " # % t  i i d  o& & t  i d } ' | 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   splits   mailcapss   home(   s   homes   mailcapss   str(    (    s$   /mit/python/lib/python2.2/mailcap.pys   listmailcapfiles" s   	c    s  5 = > h  } ? x? d o@ |  i   } A | o A Pn C | d d j p | i   d j o
 D q n E | } G xQ 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 | i	 d  } Q x4 t t |   DQ ] } R | | i   | | <q+WS d i |  i   } 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    is   \
s   
s   /N(   s   capss   fps   readlines   lines   strips   nextlines	   parselines   keys   fieldss   splits   typess   ranges   lens   js   joins   lowers   has_keys   append(   s   fps   nextlines   keys   fieldss   js   capss   lines   types(    (    s$   /mit/python/lib/python2.2/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 ] } l | i d  } m | d j  o n | } o d } n+ q | |  i   } r | | d i   } 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   finds   fkeys   fvalues   strips   has_key(
   s   lines   is   fieldss   rests   ns   fields   keys   fkeys   fvalues   view(    (    s$   /mit/python/lib/python2.2/mailcap.pys	   parseline[ s0   	 '
 		c    s   z { | | } } xh } | | j  oW ~ |  | }  | d j o  Pn/  | d j o  | d } n  | d } q W |  | | !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   strip(   s   lines   is   ns   starts   c(    (    s$   /mit/python/lib/python2.2/mailcap.pys
   parsefieldz s   	 s   views	   /dev/nullc 	   s      t  |  | |  }  x | D ] }  | 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.

    s   testi    N(   s   lookups   capss   MIMEtypes   keys   entriess   es   has_keys   substs   filenames   plists   tests   oss   systems   commands   None(	   s   capss   MIMEtypes   keys   filenames   plists   es   entriess   tests   command(    (    s$   /mit/python/lib/python2.2/mailcap.pys	   findmatch s   
 	 c    s     g  }  |  i |  o  | |  | } n  | 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   key(    (    s$   /mit/python/lib/python2.2/mailcap.pys   <lambda> s    (	   s   entriess   capss   has_keys   MIMEtypes   splits	   MIMEtypess   keys   Nones   filter(   s   capss   MIMEtypes   keys	   MIMEtypess   entries(    (    s$   /mit/python/lib/python2.2/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   cs   names   starts   is   ress   n(    (    s$   /mit/python/lib/python2.2/mailcap.pys   subst s4   	 "	 !c    sp     |  i   d }   t |   }  x: | D ]/ }  | |  i   |  j o  | | Sn q/ W d Sd  S(   Ns   =s    (   s   names   lowers   lens   ns   plists   p(   s   names   plists   ps   n(    (    s$   /mit/python/lib/python2.2/mailcap.pys	   findparam s   
 	c  	   s@    d  k  }  t   }  | i d o  t |   d  Sn  x t d t | i  d  D ] }  | 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 qd Wd  S(	   Ni   i   s"   usage: mailcap [MIMEtype file] ...i    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   MIMEtypes   es   is   argss   capss   syss   commands   files   sts(    (    s$   /mit/python/lib/python2.2/mailcap.pys   test s(    	
c    s
    d GH x  t    D ] }  d | GHq W H |  o  t   }  n  d GH H |  i   }  | i    x | D ]} }  | GH |  | }  x\ | D ]Q }  | i   }  | i    x% | D ] }  d | G| | GHq W Hq Wq Wd  S(   Ns   Mailcap files:s   	s   Mailcap entries:s     %-15s(   s   listmailcapfiless   fns   capss   getcapss   keyss   ckeyss   sorts   types   entriess   es   k(   s   capss   es   ckeyss   entriess   keyss   types   ks   fn(    (    s$   /mit/python/lib/python2.2/mailcap.pys   show s.    	  
 	
 	
 	s   __main__(   s   __doc__s   oss   __all__s   getcapss   listmailcapfiless   readmailcapfiles	   parselines
   parsefields	   findmatchs   Nones   lookups   substs	   findparams   tests   shows   __name__(   s
   parsefields   __all__s	   findparams   listmailcapfiless   shows   substs	   findmatchs   getcapss   readmailcapfiles   lookups	   parselines   tests   os(    (    s$   /mit/python/lib/python2.2/mailcap.pys   ? s   & 