Qfu$dZddlZddlZddlZddgZdZej eeddZejd jZ Gd d e Z d Zd ZdZdZdZdZddgfdZddZgfdZdZdZdZedk(reyy)z%Mailcap file handling. See RFC 1524.Ngetcaps findmatchztThe {name} module is deprecated and will be removed in Python {remove}. See the mimetypes module for an alternative.) )removecd|vrd|dfSy)Nlinenor)r)entrys ./opt/alt/python312/lib64/python3.12/mailcap.pylineno_sort_keyrs5%/!!z[^\xa1-\U0010FFFF\w@+=:,./-]ceZdZdZy)UnsafeMailcapInputz)Warning raised when refusing unsafe inputN)__name__ __module__ __qualname____doc__r rr rrs3rrc i}d}tD]V} t|d}|5t||\}}dddj D]\}}||vr|||<|||z||<X|S#t$rYfwxYw#1swYIxYw)aReturn 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". rrN)listmailcapfilesopenOSError_readmailcapfileitems)capsr mailcapfpmorecapskeyvalues r rrs D F#% gs#B/F; Hf"..*JC$;!S  I-S +& K    Rs A*A9* A65A69B cdtjvr4tjd}|jtj}|Sdtjvrtjd}nd}|dzdddg}|S)z7Return a list of all mailcap files found on the system.MAILCAPSHOME.z /.mailcapz /etc/mailcapz/usr/etc/mailcapz/usr/local/etc/mailcap)osenvironsplitpathsep)pathstrmailcapshomes r rr9svRZZ**Z(==, O RZZ ::f%DD;&"$<> OrcZtjdtdt|d\}}|S)z?Read a mailcap file and return a dictionary keyed by MIME type.z2readmailcapfile is deprecated, use getcaps insteadN)warningswarnDeprecationWarningr)rr_s r readmailcapfiler4Ks+ MMF$a)r4(GD! Krc(i}|jx}r|ddk(s|jdk(r.|}|dddk(r%|j}|sd}|dd|z}|dddk(r%t|\}}|r|sp| ||d<|d z }|jd }t t |D]}||j||<d j |j}||vr||j|n|g||<|jx}r||fS) aRead 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". r#Nz\  r r /) readlinestrip parseliner)rangelenjoinlowerappend) rr rlinenextliner!fieldstypesjs r rrSs7 D++- $  7c>TZZ\R/ rsmv%{{}HX9x'Drsmv%  o V   %F8  aKF #s5z"AQx~~'E!H#hhuo##% $; I  V $DI5++- $ 6 <rcxg}dt|}}||kr,t|||\}}|j||dz}||kr,t|dkry|d|d|dd}}}d|i}|D]P}|jd}|dkr|}d} n)|d|j }||dzdj } ||vrL| ||<R||fS) zParse 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. rr r/NNNview=r7)r? parsefieldrBfindr<) rCrEinfieldr!rJrestfkeyfvalues r r=r=zs F c$iqA a%dAq)q e aC a% 6{QQiF12JtCd^F JJsO q5DF!9??$D1Q34[&&(F 6> !F4L ;rc||}||kr!||}|dk(rn|dk(r|dz}n|dz}||kr!|||j|fS)z/Separate one key-value pair in a mailcap entry.;\r/r )r<)rCrNrOstartcs r rLrLs_ E a% G 8  $Y!A!A a% a=   ! ##rrJz /dev/nullct|r!d|d}tj|tyt |||}|D]M}d|vr.t |d||}||rt j|dk7r5t |||||} | I| |fcSy)aFind 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. z&Refusing to use mailcap with filename z . Use a safe temporary filename.rItestr) _find_unsafer0r1rlookupsubstr'system) rMIMEtyper!filenameplistmsgentrieserZcommands r rrsH\df c-.T8S)G  Q;6He4D| $1,#(E:  A:  rcg}||vr|||z}|jd}|ddz}||vr|||z}||Dcgc] }||vs| }}t|t}|Scc}w)Nr:rz/*)r!)r)sortedr)rr_r!rc MIMEtypesrds r r\r\sG4DN*s#I|d"H4DN* %2g1g2W/2G N3s AAc*d}dt|}}||kr||}|dz}|dk7r|dk(r |||dz}|dz}||z}n||}|dz}|dk(r||z}n|dk(r||z}n|dk(r2t|r!d|d }tj|ty||z}nz|d k(rm|} ||kr||d k7r|dz}||kr ||d k7r|| |} |dz}t | |} t| r$d | d | d}tj|ty|| z}n|dz|z}||kr|S)Nr7rr %rVstz!Refusing to substitute MIME type z into a shell command.{}z!Refusing to substitute parameter z (z) into a shell command)r?r[r0r1r findparam) rPr_r`raresrNrOrXrbrWnameparams r r]r]se C c%jqA a% !H!A#a 8Dy!AaCLac!'CaAac!CxAgcHnc)YacCMM#'9:Hnc!eaC!A!eaCU1~aC!$.&]bdhiCMM#'9:Ek Ci!mE a%F Jrc|jdz}t|}|D]}|d|j|k(s||dcSy)NrKr7)rAr?)rqrarOps r rorosI ::<# D D A  Ra5;;=D QR5L rcddl}t}|jdds t|yt dt |jdD]}|j||dz}t |dkr t dy|d}|d}t||d|\}}|st dt^t d|tj|}tj|}|st d|y) Nrr r/z"usage: mailcap [MIMEtype file] ...rJzNo viewer found forz Executing:z Exit status:) sysrargvshowr>r?printrtyper'r^waitstatus_to_exitcode) rvrrNargsr_filererdstss r rZrZs 9D 88AB< T  1c#((mQ 'xx!A# t9q= 6 7 7AwtXvt<  ' . , ())G$C++C0Cnc*(rcXtdtD]}td|zt|s t}tdtt|}|D]G}t|||}|D]0}t|}|D]}td|z||t2Iy)NzMailcap files: zMailcap entries:z %-15s)ryrrrg)rfnckeysrzrcrdkeysks r rxrxs  %r "2  G    G 4LE d t*A!9Di!mQqT* G r__main__)N)rr'r0re__all___DEPRECATION_MSG _deprecatedrrcompilesearchr[Warningrrrr4rr=rLrr\r]rorZrxr rr rs+  [ !#X/@rzz9:AA 44 4$%N> $ #);b6 ,.'R+." zFr