;ò
îŒü?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          C   s¯   h  } xž t ƒ  D]“ }  y t |  d ƒ } Wn t j
 o
 q n Xt | ƒ } | i ƒ  xH | i	 ƒ  D]: \ } } | | j o | | | <qe | | | | | <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	   iteritemss   keys   value(   s   mailcaps   fps   morecapss   values   capss   key(    (    s$   /mit/python/lib/python2.3/mailcap.pys   getcaps	   s     	 
 
 c          C   su   d t  i j o  t  i d } | i d ƒ } n> d t  i j 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   strs   splits   mailcapss   home(   s   homes   mailcapss   str(    (    s$   /mit/python/lib/python2.3/mailcap.pys   listmailcapfiles"   s     c         C   sX  h  } xGn o?|  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 ƒ  } | | j o | | i | ƒ q	 | 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   append(   s   fps   nextlines   fieldss   js   capss   keys   lines   types(    (    s$   /mit/python/lib/python2.3/mailcap.pys   readmailcapfile5   s8       $  
 c   
      C   s@  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 |	 <} xy | D]q } | i d ƒ } | d j  o | } d } n% | |  i ƒ  } | | d i ƒ  } | | j o q½ | | | <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   strip(
   s   lines   is   fieldss   ns   fields   rests   keys   fkeys   fvalues   view(    (    s$   /mit/python/lib/python2.3/mailcap.pys	   parseline[   s0      $ 
c         C   sw   | } xS | | j  oE |  | } | d j o Pq	 | d j o | d } q	 | 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.3/mailcap.pys
   parsefieldz   s      
s   views	   /dev/nullc   	      C   sŸ   t  |  | | ƒ } x| | D]t } d | j o> t | d | | ƒ } | o t
 i | ƒ d j o q qj 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   substs   filenames   plists   tests   oss   systems   commands   None(	   s   capss   MIMEtypes   keys   filenames   plists   es   entriess   tests   command(    (    s$   /mit/python/lib/python2.3/mailcap.pys	   findmatchŠ   s      c         C   s   g  } | |  j o | |  | } n | i d ƒ } | d d } | |  j o | |  | } n | t j	 o t | d „ | ƒ } n | Sd  S(   Ns   /i    s   /*c         C   s
   | |  j S(   N(   s   keys   e(   s   es   key(    (    s$   /mit/python/lib/python2.3/mailcap.pys   <lambda>§   s    (   s   entriess   MIMEtypes   capss   splits	   MIMEtypess   keys   Nones   filter(   s   capss   MIMEtypes   keys	   MIMEtypess   entries(    (    s$   /mit/python/lib/python2.3/mailcap.pys   lookupž   s    c   
      C   sz  d } d t |  ƒ f \ } }	 xQ| |	 j  oC|  | } | d } | d j o: | d j o |  | | d !} | d } n | | } q! |  | } | d } | d j o | | } q! | d j o | | } q! | d j o | | } q! | d j od | } x- | |	 j  o |  | d	 j o | d } qW|  | | !} | d } | t
 | | ƒ } q! | 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.3/mailcap.pys   substª   s4      
c         C   sX   |  i ƒ  d }  t |  ƒ } x1 | D]) } | |  i ƒ  |  j o | | Sq# q# Wd Sd  S(   Ns   =s    (   s   names   lowers   lens   ns   plists   p(   s   names   plists   ps   n(    (    s$   /mit/python/lib/python2.3/mailcap.pys	   findparamÊ   s     c    	      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 GHqO d G| GHt i | ƒ } | o d G| GHqO 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   argss   capss   syss   is   commands   files   sts(    (    s$   /mit/python/lib/python2.3/mailcap.pys   testÕ   s(    		
 

	c         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   keyss   entriess   types   ks   fn(    (    s$   /mit/python/lib/python2.3/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   getcapss   shows	   findmatchs   listmailcapfiless   readmailcapfiles   lookups	   parselines   tests   substs   os(    (    s$   /mit/python/lib/python2.3/mailcap.pys   ?   s   				&		 			