mò %U²Ic@s©dZdkZddgZd„Zd„Zd„Zd„Zd„Zd d gd „Zdd „Z gd „Z d„Z d„Z d„Zedjo e ƒndS(s%Mailcap file handling. See RFC 1524.Ntgetcapst findmatchcCsªh}xtƒD]’}yt|dƒ}Wntj o qnXt|ƒ}|iƒxG|i ƒD]9\}}||jo|||dtijotid}nd}|ddddg}|S( s7Return a list of all mailcap files found on the system.tMAILCAPSt:tHOMEt.s /.mailcaps /etc/mailcaps/usr/etc/mailcaps/usr/local/etc/mailcapN(tostenvirontstrtsplittmailcapsthome(RRR((RR"s cCsJh}x=|iƒ}|pPn|ddjp|iƒdjoq n|}xA|ddjo/|iƒ}|p d}n|d |}qUWt|ƒ\}}|o|pq n|i dƒ}x.t t |ƒƒD]}||iƒ||t|d||ƒ}|ot i |ƒdjoqqjnt|||||ƒ}||fSqWdS(sFind 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. ttestiN(NN(tlookupRtMIMEtypeR tentriestetsubsttfilenametplistR8RtsystemtcommandR0( RR:R R>R?R<R;R8RA((RRŠs  cCs‹g}||jo|||}n|idƒ}|dd}||jo|||}n|dj ot|d„|ƒ}n|S(NRis/*cCs ||jS(N(R R<(R<R ((Rt§s(R;R:RRt MIMEtypesR R0tfilter(RR:R RCR;((RR9žs   c Csqd}dt|ƒ}} xQ|| joC||}|d}|djo:|djo|||d!}|d}n||}q||}|d}|djo||}q|djo||}q|djo||}q|djod|}x-|| jo||d jo|d}qÿW|||!}|d}|t ||ƒ}q|d|}qW|S( NRiit%s\tsttt{t}( tresR%R/R,R-R7R>R:R6tnamet findparamR?( R/R:R>R?R7RKR6R,RJR-((RR=ªs4         cCsT|iƒd}t|ƒ}x1|D])}|| iƒ|jo ||Sq#q#WdS(NR+R(RKR(R%R-R?tp(RKR?RMR-((RRLÊs c Csÿdk}tƒ}|idpt|ƒdSnxÆtdt|iƒdƒD]©}|i||d!}t|ƒdjo dGHdSn|d}|d}t ||d|ƒ\}}|p dGtGHqNdG|GHti|ƒ}|o dG|GHqNqNWdS( Niis"usage: mailcap [MIMEtype file] ...iR*sNo viewer found fors Executing:s Exit status:(tsysRRtargvtshowR$R%R,targsR:tfileRRAR<ttypeRR@tsts( R:R<RQRRNR,RARRRT((RR8Õs(       cCsÁdGHxtƒD]}d|GHqWH|p tƒ}ndGHH|iƒ}|iƒxg|D]_}|GH||}xG|D]?}|iƒ}|iƒx|D]}d|G||GHq™WHqvWqZWdS(NsMailcap files:s sMailcap entries:s %-15s( RtfnRRtkeystckeystsortRSR;R<tk(RR<RWRVR;RSRYRU((RRPës.        t__main__(t__doc__Rt__all__RRR R!R.RR0R9R=RLR8RPt__name__( R.R\RLRRPRRR R9R!R8R=R((Rt?s     &