grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026o ®û|jœ#ã@sÌdZddlZddlZddlZddgZdd„Ze d¡jZGdd „d e ƒZ d d„Z d d „Z d d„Z dd„Zdd„Zdd„Zddgfdd„Zd#dd„Zgfdd„Zdd„Zdd„Zd d!„Zed"krdeƒdSdS)$z%Mailcap file handling. See RFC 1524.éNÚgetcapsÚ findmatchcCsd|vr d|dfSdS)NÚlinenor)ér©)Úentryrrú./opt/alt/python310/lib64/python3.10/mailcap.pyÚlineno_sort_key s r z[^\xa1-\U0010FFFF\w@+=:,./-]c@seZdZdZdS)ÚUnsafeMailcapInputz)Warning raised when refusing unsafe inputN)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrr sr c Cs i}d}tƒD]F}zt|dƒ}Wn tyYqw|�t||ƒ\}}Wdƒn1s.wY| ¡D]\}}||vrD|||<q7|||||<q7q|S)a 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". rÚrN)ÚlistmailcapfilesÚopenÚOSErrorÚ_readmailcapfileÚitems)ÚcapsrZmailcapÚfpZmorecapsÚkeyÚvaluerrrrs"   ÿÿ ücCsRdtjvrtjd}| tj¡}|Sdtjvrtjd}nd}|ddddg}|S)z7Return a list of all mailcap files found on the system.ZMAILCAPSÚHOMEÚ.z /.mailcapz /etc/mailcapz/usr/etc/mailcapz/usr/local/etc/mailcap)ÚosÚenvironÚsplitÚpathsep)ZpathstrZmailcapsÚhomerrrr3s    ù ÿrcCs t dtd¡t|dƒ\}}|S)z?Read a mailcap file and return a dictionary keyed by MIME type.z2readmailcapfile is deprecated, use getcaps insteadéN)ÚwarningsÚwarnÚDeprecationWarningr)rrÚ_rrrÚreadmailcapfileEs ÿr%c Csi} | ¡}|s ||fS|ddks| ¡dkrq|}|dd…dkr<| ¡}|s,d}|dd…|}|dd…dks$t|ƒ\}}|rF|sGq|durS||d <|d7}| d ¡}tt|ƒƒD] }|| ¡||<q^d  |¡ ¡}||vr||| |¡n|g||<q) a�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". rrú#ÚéþÿÿÿNz\ Ú rú/) ÚreadlineÚstripÚ parselinerÚrangeÚlenÚjoinÚlowerÚappend) rrrÚlineZnextlinerÚfieldsÚtypesÚjrrrrMs6 çý   ärc Csàg}dt|ƒ}}||kr"t|||ƒ\}}| |¡|d}||ks t|ƒdkr*dS|d|d|dd…}}}d|i}|D]+}| d¡}|dkrP|}d} n|d|… ¡}||dd… ¡} ||vrgq@| ||<q@||fS) zÈ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. rrr ©NNNÚviewú=r')r/Ú parsefieldr2Úfindr,) r3r4ÚiÚnÚfieldrr8ÚrestZfkeyZfvaluerrrr-vs, ý    r-cCsT|}||kr ||}|dkrn|dkr|d}n|d}||ks|||… ¡|fS)z/Separate one key-value pair in a mailcap entry.ú;ú\r r)r,)r3r<r=ÚstartÚcrrrr:•s ùr:r8z /dev/nullc Cs˜t|ƒrd|f}t |t¡dSt|||ƒ}|D]0}d|vr6t|d||ƒ}|dur,q|r6t |¡dkr6qt|||||ƒ} | durI| |fSqdS)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. zHRefusing to use mailcap with filename %r. Use a safe temporary filename.r7ÚtestNr)Ú _find_unsafer!r"r ÚlookupÚsubstrÚsystem) rÚMIMEtyperÚfilenameÚplistÚmsgÚentriesÚerDÚcommandrrrr¥s"    ÿcslg}||vr |||}| d¡}|dd}||vr!|||}ˆdur.‡fdd„|Dƒ}t|td�}|S)Nr*rz/*csg|]}ˆ|vr|‘qSrr)Ú.0rN©rrrÚ Észlookup..rQ)rÚsortedr )rrIrrMZ MIMEtypesrrQrrFÀs     rFc Csdd}dt|ƒ}}||kr°||}|d}|dkr.|dkr)|||d…}|d}||}n~||}|d}|dkr?||}nm|dkrH||}nd|dkrbt|ƒr]d|f}t |t¡dS||}nJ|d kr¦|} ||kr€||d kr€|d}||kr€||d ksr|| |…} |d}t| |ƒ} t| ƒr¡d | | f}t |t¡dS|| }n|d|}||ks |S) Nr'rrú%rAÚsÚtz9Refusing to substitute MIME type %r into a shell command.Ú{Ú}z=Refusing to substitute parameter %r (%s) into a shell command)r/rEr!r"r Ú findparam) r>rIrJrKÚresr<r=rCrLrBÚnameZparamrrrrGÍsF      ÿ      Þ#rGcCsF| ¡d}t|ƒ}|D]}|d|… ¡|kr ||d…Sq dS)Nr9r')r1r/)r[rKr=ÚprrrrYös ÿrYc CsÎddl}tƒ}|jdd…st|ƒdStdt|jƒdƒD]G}|j||d…}t|ƒdkr5tdƒdS|d}|d}t||d|ƒ\}}|sNtdtƒqtd|ƒt   |¡}t   |¡}|rdtd|ƒqdS) Nrrr z"usage: mailcap [MIMEtype file] ...r8zNo viewer found forz Executing:z Exit status:) ÚsysrÚargvÚshowr.r/ÚprintrÚtyperrHÚwaitstatus_to_exitcode) r]rr<ÚargsrIÚfilerOrNÚstsrrrrDs,      €ñrDcCs˜tdƒtƒD]}td|ƒqtƒ|stƒ}tdƒtƒt|ƒ}|D]$}t|ƒ||}|D]}t|ƒ}|D] }td|||ƒq9tƒq1q%dS)NzMailcap files:ú zMailcap entries:z %-15s)r`rrrS)rÚfnZckeysrarMrNÚkeysÚkrrrr_s" üýr_Ú__main__)N)rrr!ÚreÚ__all__r ÚcompileÚsearchrEÚWarningr rrr%rr-r:rrFrGrYrDr_r rrrrÚs. )  )  ÿ