-í
ç¶<c       s©   d  Z  d k Z d d g Z d „  Z d „  Z d „  Z d „  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 Xt | ƒ } | i ƒ  xM | i	 ƒ  D]? } | i | ƒ o | | | | <n | | | | | | <qe 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   /usr/lib/python2.2/mailcap.pys   getcaps	 s     	 
 
 c     s{   t  i i d ƒ o  t  i d } | i d ƒ } nA t  i i d ƒ o t  i d }  n d }  |  d d d d g } | 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   /usr/lib/python2.2/mailcap.pys   listmailcapfiles" s     c    s[  h  } xJd oB|  i ƒ  } | o Pn | d d j p | i ƒ  d j o q	 n | } xB | d d j o0 |  i ƒ  } | o
 d } n | d  | } q] Wt | ƒ \ } } | o | o q	 n | i	 d ƒ } x. t t | ƒ ƒ D] } | | i ƒ  | | <qé Wd i | ƒ i ƒ  } | i | ƒ o | | i | ƒ n | g | | <q	 W| 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   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   /usr/lib/python2.2/mailcap.pys   readmailcapfile5 s8       $  
 c 
   sC  g  } d t |  ƒ f \ } } xA | | j  o3 t |  | | ƒ \ } } | i | ƒ | d } q! Wt | ƒ d j  o t t f Sn | d | d | d f \ } }	 } h  |	 d <} x| | D]t } | i d ƒ } | d j  o | } d } n% | |  i ƒ  } | | d i ƒ  } | i | ƒ o n | | | <q½ W| | 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   /usr/lib/python2.2/mailcap.pys	   parseline[ s0      $ 
c    sw   | } xS | | j  oE |  | } | 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   /usr/lib/python2.2/mailcap.pys
   parsefieldz s      
s   views	   /dev/nullc 	   s¢   t  |  | | ƒ } x | D]w } | i d ƒ o> t | d | | ƒ } | o t i | ƒ d j o q n n t | | | | | ƒ } | | f Sq Wt 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   /usr/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   /usr/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   /usr/lib/python2.2/mailcap.pys   lookupž s    c 
   sz  d } d t |  ƒ f \ } }	 xQ| |	 j  oC|  | } | d } | d j o: | d j o |  | | d !} | d } n | | } nå |  | } | d } | d j o | | } n¶ | d j o | | } n› | d j o | | } n€ | d j od | } x- | |	 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   /usr/lib/python2.2/mailcap.pys   substª s4      
c    sX   |  i ƒ  d }  t |  ƒ } x1 | D]) } | |  i ƒ  |  j o | | Sn q# Wd Sd  S(   Ns   =s    (   s   names   lowers   lens   ns   plists   p(   s   names   plists   ps   n(    (    s   /usr/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 GHd  Sn | d }  | d } t | |  d | ƒ \ } } | o d Gt GHn- d G| GHt i | ƒ } | o d G| GHn qO 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   /usr/lib/python2.2/mailcap.pys   testÕ s(    		
 

	c    sÂ   d GHx t  ƒ  D] } d | GHq WH|  o t ƒ  }  n d GHH|  i ƒ  } | i ƒ  xg | D]_ } | GH|  | } xG | D]? } | i ƒ  } | i ƒ  x | D] } d | G| | GHqš WHqw 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   /usr/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   /usr/lib/python2.2/mailcap.pys   ? s   				&		 			