
    d$                        d Z ddlZddlZddlZddgZdZ ej        eed           d Z ej	        d	          j
        Z G d
 de          Zd Zd Zd Zd Zd Zd Zddg fdZddZg fdZd Zd Zd Zedk    r e             dS dS )z%Mailcap file handling.  See RFC 1524.    Ngetcaps	findmatchztThe {name} module is deprecated and will be removed in Python {remove}. See the mimetypes module for an alternative.)      )removec                 "    d| v r
d| d         fS dS )Nlinenor   )   r    )entrys      /croot/python-split_1694437901252/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib/python3.11/mailcap.pylineno_sort_keyr      s!    5%/!!t    z[^\xa1-\U0010FFFF\w@+=:,./-]c                       e Zd ZdZdS )UnsafeMailcapInputz)Warning raised when refusing unsafe inputN)__name__
__module____qualname____doc__r   r   r   r   r      s        3333r   r   c                  2   i } d}t                      D ]}	 t          |d          }n# t          $ r Y  w xY w|5  t          ||          \  }}ddd           n# 1 swxY w Y   |                                D ]\  }}|| vr|| |<   | |         |z   | |<   | 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)capsr	   mailcapfpmorecapskeyvalues          r   r   r      s    DF#%% . .	gs##BB 	 	 	H	 	< 	</F;;Hf	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<"..** 	. 	.JC$;;!S		 I-S				.
 Ks   '
44AA	 A	c                      dt           j        v r2t           j        d         } |                     t           j                  }n,dt           j        v rt           j        d         }nd}|dz   dddg}|S )z7Return a list of all mailcap files found on the system.MAILCAPSHOME.z	/.mailcapz/etc/mailcapz/usr/etc/mailcapz/usr/local/etc/mailcap)osenvironsplitpathsep)pathstrmailcapshomes      r   r   r   9   sp     RZ*Z(==,,RZ:f%DD D;&"$<>Or   c                 b    t          j        dt          d           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   )r   r   _s      r   readmailcapfiler4   K   s6    MF$a) ) )r4((GD!Kr   c                    i }	 |                                  }|sn+|d         dk    s|                                dk    r>|}|dd         dk    r3|                                  }|sd}|dd         |z   }|dd         dk    3t          |          \  }}|r|s|
||d	<   |dz  }|                    d
          }t	          t          |                    D ]}||                                         ||<    d
                    |                                          }||v r||                             |           n|g||<   C||fS )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".
    r
   r   # Nz\

r	   /)	readlinestrip	parseliner)   rangelenjoinlowerappend)	r   r	   r   linenextliner!   fieldstypesjs	            r   r   r   S   sw    D!{{}}U7c>>TZZ\\R//rssmv%%{{}}H,X9x'D rssmv%%
  ooV 	 	%F8aKF		#s5zz"" 	( 	(AQx~~''E!HHhhuoo##%%$;;IV$$$$DI9!: <r   c                    g }dt          |           }}||k     r4t          | ||          \  }}|                    |           |dz   }||k     4t          |          dk     rdS |d         |d         |dd         }}}d|i}|D ]g}|                    d          }|dk     r|}d}	n;|d|                                         }||dz   d                                         }	||v rb|	||<   h||fS )	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.
    r   r
   r/   NNNview=r7   )r?   
parsefieldrB   findr<   )
rC   rE   infieldr!   rJ   restfkeyfvalues
             r   r=   r=   |   s     Fc$iiqA
a%%dAq))qeaC a%% 6{{QzQiF122JtCd^F " "JJsOOq55DFF!9??$$D1Q344[&&((F6>>!F4LL;r   c                     |}||k     r&| |         }|dk    rn|dk    r|dz   }n|dz   }||k     &| ||                                          |fS )z/Separate one key-value pair in a mailcap entry.;\r/   r
   )r<   )rC   rN   rO   startcs        r   rL   rL      sn    E
a%%G88$YY!AA!A a%% a=  !##r   rJ   z	/dev/nullc                 F   t          |          r"d|d}t          j        |t                     dS t	          | ||          }|D ][}d|v r5t          |d         ||          }| |rt          j        |          dk    r;t          ||         |||          }	|	|	|fc S \dS )a  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.

    z&Refusing to use mailcap with filename z . Use a safe temporary filename.rI   testNr   )_find_unsafer0   r1   r   lookupsubstr'   system)
r   MIMEtyper!   filenameplistmsgentrieserZ   commands
             r   r   r      s     H  \d\d\dfc-...zT8S))G 	 	Q;;6He44D| 	$1,,#(E::A: :r   c                     g }|| v r|| |         z   }|                     d          }|d         dz   }|| v r|| |         z   }fd|D             }t          |t                    }|S )Nr:   r   z/*c                     g | ]}|v |	S r   r   ).0rd   r!   s     r   
<listcomp>zlookup.<locals>.<listcomp>   s    2221r   )r!   )r)   sortedr   )r   r_   r!   rc   	MIMEtypess     `  r   r\   r\      s    G4DN*s##I|d"H4DN*
2222g222W/222GNr   c                    d}dt          |           }}||k     r,| |         }|dz   }|dk    r|dk    r| ||dz            }|dz   }||z   }n| |         }|dz   }|dk    r||z   }n|dk    r||z   }n|dk    r7t          |          r"d|d	}t          j        |t                     d S ||z   }n|d
k    r|}	||k     r#| |         dk    r|dz   }||k     r| |         dk    | |	|         }
|dz   }t          |
|          }t          |          r%d|d|
d}t          j        |t                     d S ||z   }n|dz   |z   }||k     ,|S )Nr7   r   r
   %rV   stz!Refusing to substitute MIME type z into a shell command.{}z!Refusing to substitute parameter z (z) into a shell command)r?   r[   r0   r1   r   	findparam)rP   r_   r`   ra   resrN   rO   rX   rb   rW   nameparams               r   r]   r]      s   
Cc%jjqA
a%%!H!A#a88Dyy!AaC%Lac!'CCaAac!CxxAgcHnc))    YaYaYacCM#'9:::4Hnc!eeaC!A !eeaCU1W~aC!$..&&    ]b]b]bdhdhdhiCM#'9:::4Ek
 Ci!mE a%%F Jr   c                     |                                  dz   } t          |           }|D ].}|d |                                          | k    r||d          c S /dS )NrK   r7   )rA   r?   )rt   ra   rO   ps       r   rr   rr      sd    ::<<#DD		A  RaR5;;==D  QRR5LLL !2r   c                  2   dd l } t                      }| j        dd          st          |           d S t	          dt          | j                  d          D ]}| j        ||dz            }t          |          dk     rt          d            d S |d         }|d         }t          ||d|          \  }}|st          dt                     vt          d|           t          j
        |          }t          j        |          }|rt          d|           d S )	Nr   r
   r/   z"usage: mailcap [MIMEtype file] ...rJ   zNo viewer found forz
Executing:zExit status:)sysr   argvshowr>   r?   printr   typer'   r^   waitstatus_to_exitcode)	ry   r   rN   argsr_   filere   rd   stss	            r   rZ   rZ     s(   JJJ99D8ABB< T


1c#(mmQ'' + +x!A#t99q==6777FF7AwtXvt<<
 	+'....,((()G$$C+C00C +nc***+ +r   c                    t          d           t                      D ]}t          d|z              t                       | st                      } t          d           t                       t          |           }|D ]Y}t          |           | |         }|D ]=}t          |          }|D ]}t          d|z  ||                    t                       >Zd S )NzMailcap files:	zMailcap entries:z  %-15s)r|   r   r   rj   )r   fnckeysr}   rc   rd   keysks           r   r{   r{     s    	
  22%r	"2"2"2"2	GGG!			
	GGG4LLE  dt* 	 	A!99D + +i!mQqT****GGGG		 r   __main__)N)r   r'   r0   re__all___DEPRECATION_MSG_deprecatedr   r   compilesearchr[   Warningr   r   r   r4   r   r=   rL   r   r\   r]   rr   rZ   r{   r   r   r   <module>r      s   + + 				  				[
!#   X/ @ @ @ @   rz9::A4 4 4 4 4 4 4 4  4  $  ' ' 'R  >$ $ $  #);b    6    ,. ' ' ' 'R  + + +.  " zDFFFFF r   