
    kjn              	       \    d dl Z d dlZdedeeeeeef   f   dz  fdZd Zd	dededefdZy)
    Ncreturnc                    | j                  dd      }|d   j                  dd      }t        |      dk7  ryt        j                         }t        |      dk(  ra|d   j                  d      D ]J  }|j                  dd      }t        |      dk(  s$|d   j	                         ||d   j	                         <   L |d   j                         |d   j                         |fS )aU  
    A simple parser for content-type values. Returns a (type, subtype,
    parameters) tuple, where type and subtype are strings, and parameters
    is a dict. If the string could not be parsed, return None.

    E.g. the following string:

        text/html; charset=UTF-8

    Returns:

        ("text", "html", {"charset": "UTF-8"})
    ;   r   /   N=)splitlencollectionsOrderedDictstriplower)r   partstsdiclauses         c/home/ubuntu/.cache/pipx/cdb5059130eadca/lib/python3.12/site-packages/mitmproxy/net/http/headers.pyparse_content_typer      s     GGCOE	qQ	B
2w!|!A
5zQq$ 	9AWWS!_F6{a'-ay'8&)//#$	9 a5;;="Q%++-**    c                 t    |s|  d| S dj                  d |j                         D              }|  d| d| S )Nr   z; c              3   0   K   | ]  \  }}| d |   yw)r
   N ).0kvs      r   	<genexpr>z(assemble_content_type.<locals>.<genexpr>#   s     Ada!AaSzAs   )joinitems)typesubtype
parametersparamss       r   assemble_content_typer&       sJ    q	""YYAj.>.>.@AAFV1WIRx((r   content_typecontentc                 R   d}|j                  d      rd}nq|j                  d      rd}n]|j                  d      rd}nI|j                  d      rd	}n5|j                  d
      rd}n!t        |       x}r|d   j                  d      }|sd| v rd}|sOd| v rKt        j                  d|t        j
                        }|r"|j                  d      j                  dd      }nd}|sOd| v rKt        j                  d|t        j
                        x}r"|j                  d      j                  dd      }nd}|s
d| v sd| v rd}|sOd| v rKt        j                  d|t        j
                        }|r"|j                  d      j                  dd      }nd}|sd}|j                         dv rd}|S )zE
    Infer the encoding of content from the content-type header.
    Ns     zutf-32bes     zutf-32les   zutf-16bes   zutf-16les   ﻿z	utf-8-sigr	   charsetjsonutf8htmls    <meta[^>]+charset=['"]?([^'">]+)r   asciiignorexmls%   <\?xml[^\?>]+encoding=['"]([^'"\?>]+)
javascript
ecmascriptztext/csss   @charset "([^"]+)";zlatin-1)gb2312gbkgb18030)

startswithr   getresearch
IGNORECASEgroupdecodematchr   )r'   r(   encparsed_content_typemeta_charsetxml_encodingcss_charsets          r   infer_content_encodingrC   '   s    C -.			/	0			K	(			K	(			O	, 2< @	@		@!!$((3 6\)6\)yy4gr}}
 $$Q'..wAC
 C5L(9997BMM
 
< 
 $$Q'..wAC
 CLL0LL4P :-hh:GR]]S##A&--gx@C
 C  yy{''Jr   )r   )	r   r8   strtupledictr   r&   bytesrC   r   r   r   <module>rH      sZ     	+# +%S$sCx.(@"AD"H +6)J Ju Js Jr   