
    <g              
           d dl Z d dlmZmZmZ d dlmZ d dlmZ d Z	d Z
 G d dej                        Zd	ed
eeeeeeef   f      fdZd Zy)    N)DictOptionalTuple)	multidict)strutilsc                 &    | j                  dd      S Nzutf-8surrogateescape)decodexs    f/var/www/html/myenv/lib/python3.12/site-packages/seleniumwire/thirdparty/mitmproxy/net/http/headers.py_nativer      s    88G.//    c                 0    t        j                  | dd      S r	   )r   always_bytesr   s    r   _always_bytesr      s      G->??r   c                        e Zd ZdZd fd	Zed        Zed        Zd Z fdZ	 fdZ
 fdZ fd	Z fd
Zd fd	Z xZS )Headersax  
    Header class which allows both convenient access to individual headers as well as
    direct access to the underlying raw data. Provides a full dictionary interface.

    Example:

    .. code-block:: python

        # Create headers with keyword arguments
        >>> h = Headers(host="example.com", content_type="application/xml")

        # Headers mostly behave like a normal dict.
        >>> h["Host"]
        "example.com"

        # HTTP Headers are case insensitive
        >>> h["host"]
        "example.com"

        # Headers can also be created from a list of raw (header_name, header_value) byte tuples
        >>> h = Headers([
            (b"Host",b"example.com"),
            (b"Accept",b"text/html"),
            (b"accept",b"application/xml")
        ])

        # Multiple headers are folded into a single header as per RFC7230
        >>> h["Accept"]
        "text/html, application/xml"

        # Setting a header removes all existing headers with the same name.
        >>> h["Accept"] = "application/text"
        >>> h["Accept"]
        "application/text"

        # bytes(h) returns a HTTP1 header block.
        >>> print(bytes(h))
        Host: example.com
        Accept: application/text

        # For full control, the raw header fields can be accessed
        >>> h.fields

    Caveats:
        For use with the "Set-Cookie" header, see :py:meth:`get_all`.
    c                 Z   t         |   |       | j                  D ]0  \  }}t        |t              rt        |t              r't        d       |j                         D ci c]*  \  }}t        |      j                  dd      t        |      , }}}| j                  |       yc c}}w )a?  
        Args:
            fields: (optional) list of ``(name, value)`` header byte tuples,
                e.g. ``[(b"Host", b"example.com")]``. All names and values must be bytes.
            **headers: Additional headers to set. Will overwrite existing values from `fields`.
                For convenience, underscores in header names will be transformed to dashes -
                this behaviour does not extend to other methods.
                If ``**headers`` contains multiple keys that have equal ``.lower()`` s,
                the behavior is undefined.
        zHeader fields must be bytes.   _   -N)
super__init__fields
isinstancebytes	TypeErroritemsr   replaceupdate)selfr   headerskeyvaluename	__class__s         r   r   zHeaders.__init__D   s     	 ++ 	@JCc5)E51I >??	@  '}}
e $''d3]55II
 
 	G	
s   #/B'c                 $    dj                  |       S )Nz, join)valuess    r   _reduce_valueszHeaders._reduce_values\   s     yy  r   c                 "    | j                         S N)lower)r$   s    r   _kconvzHeaders._kconva   s     yy{r   c                 f    | j                   r%dj                  d | j                   D              dz   S y)Ns   
c              3   >   K   | ]  }d j                  |        yw)s   : Nr)   ).0fields     r   	<genexpr>z$Headers.__bytes__.<locals>.<genexpr>h   s     Ke

5 1Ks   r   )r   r*   )r"   s    r   	__bytes__zHeaders.__bytes__f   s*    ;;<<Kt{{KKgUUr   c                 :    t        |      }t        | 	  |       y r.   )r   r   __delitem__)r"   r$   r'   s     r   r8   zHeaders.__delitem__l   s    C C r   c              #   N   K   t         |          D ]  }t        |        y wr.   )r   __iter__r   )r"   r   r'   s     r   r:   zHeaders.__iter__p   s(     !# 	A!*	s   "%c                 p    t        |      }t        | 	  |      D cg c]  }t        |       c}S c c}w )z
        Like :py:meth:`get`, but does not fold multiple headers into a single one.
        This is useful for Set-Cookie headers, which do not support folding.
        See also: https://tools.ietf.org/html/rfc7230#section-3.2.2
        )r   r   get_allr   )r"   r&   r   r'   s      r   r<   zHeaders.get_allt   s;     T" GOD!
GAJ
 	
 
s   3c                 t    t        |      }|D cg c]  }t        |       }}t        | 	  ||      S c c}w )zd
        Explicitly set multiple headers for the given key.
        See: :py:meth:`get_all`
        )r   r   set_all)r"   r&   r+   r   r'   s       r   r>   zHeaders.set_all   s=    
 T",23q-"33wtV,, 4s   5c                 T    t        |      }t        |      }t        | 	  |||       y r.   )r   r   insert)r"   indexr$   r%   r'   s       r   r@   zHeaders.insert   s'    C e$uc5)r   c                 J    |rd | j                   D        S t        | 	         S )Nc              3   N   K   | ]  \  }}t        |      t        |      f  y wr.   )r   r3   kvs      r   r5   z Headers.items.<locals>.<genexpr>   s)      Aq WQZ(s   #%)r   r   r   )r"   multir'   s     r   r   zHeaders.items   s*     KK 
 7=?"r   ) )F)__name__
__module____qualname____doc__r   staticmethodr,   r0   r6   r8   r:   r<   r>   r@   r   __classcell__)r'   s   @r   r   r      s^    -^0 ! !  !

-*
# #r   r   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 )aq  
        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stripr/   )rO   partstsdiclauses         r   parse_content_typera      s     GGCOE	qQ	B
2w!|!A
5zQq$ 	9AWWS!_F6{a'-ay'8&)//#$	9 a5;;="Q%++-**r   c                     |sdj                  | |      S dj                  d |j                         D              }dj                  | ||      S )Nz{}/{}z; c              3   F   K   | ]  \  }}d j                  ||        yw)z{}={}N)formatrD   s      r   r5   z(assemble_content_type.<locals>.<genexpr>   s'      Aq 	q!s   !z	{}/{}; {})rd   r*   r   )typesubtype
parametersparamss       r   assemble_content_typeri      sV    ~~dG,,YY $$& F gv r   )rY   typingr   r   r   +seleniumwire.thirdparty.mitmproxy.coretypesr   'seleniumwire.thirdparty.mitmproxy.utilsr   r   r   	MultiDictr   strra   ri   rH   r   r   <module>ro      se     ( ( A <0@A#i!! A#H+# +(5c4S>1I+J"K +6	r   