[ @sdZddlZddgZddZddZdd Zd d Zd d ZddgddZdddZ gddZ ddZ ddZ ddZ edkre ndS)z%Mailcap file handling. See RFC 1524.Ngetcaps findmatchcCsi}xtD]}yt|d}Wntk r@wYnX|t|}WdQXxE|jD]7\}}||kr|||s zlookup..)r)r r9r r<Z MIMEtypesr)r rr6s   r6c Csfd}dt|}}xF||kra||}|d}|dkr|dkru|||d}|d}n||}q||}|d}|dkr||}q|dkr||}q|dkr||}q|dkrP|}x*||kr||d kr|d}qW|||} |d}|t| |}q|d|}qW|S) Nrrr(%r2st{})r findparam) r/r9r:r;Zresr-r.r4r3namerrrr7s6              r7cCs[|jd}t|}x8|D]0}|d|j|kr#||dSq#WdS)Nr*r)r"r )rGr;r.prrrrFs   rFc Csddl}t}|jdds6t|dSxtdt|jdD]}|j||d}t|dkrtddS|d}|d}t||d|\}}|stdtqRtd|t j |}|rRtd|qRqRWdS) Nrr(rz"usage: mailcap [MIMEtype file] ...r)zNo viewer found forz Executing:z Exit status:) sysrargvshowrr printrtyperr8) rIr r-argsr9filer>r=stsrrrr5s&   "    r5cCstdxtD]}td|qWt|sEt}ntdtt|}xl|D]d}t|||}xG|D]?}t|}x#|D]}td|||qWtqWqiWdS)NzMailcap files: zMailcap entries:z %-15s)rLrrsorted)r fnZckeysrMr<r=keyskrrrrKs"          rK__main__)__doc__r__all__rrrrr+rr6r7rFr5rK__name__rrrrs     &