
    hg              
           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dS )    N)DictOptionalTuple)	multidict)strutilsc                 .    |                      dd          S Nzutf-8surrogateescape)decodexs    k/var/www/fb-scrape/myenv/lib/python3.11/site-packages/seleniumwire/thirdparty/mitmproxy/net/http/headers.py_nativer      s    88G.///    c                 .    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                 <   t                                          |           | j        D ]>\  }}t          |t                    rt          |t                    st          d          ?d |                                D             }|                     |           dS )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.c                 v    i | ]6\  }}t          |                              d d          t          |          7S )   _   -)r   replace).0namevalues      r   
<dictcomp>z$Headers.__init__.<locals>.<dictcomp>V   sN     
 
 
e $''d33]55I5I
 
 
r   N)super__init__fields
isinstancebytes	TypeErroritemsupdate)selfr"   headerskeyr   	__class__s        r   r!   zHeaders.__init__D   s     	   + 	@ 	@JCc5)) @E51I1I @ >???@
 
&}}
 
 
 	Gr   c                 ,    d                     |           S )Nz, join)valuess    r   _reduce_valueszHeaders._reduce_values\   s     yy   r   c                 *    |                                  S N)lower)r*   s    r   _kconvzHeaders._kconva   s     yy{{r   c                 b    | j         r'd                    d | j         D                       dz   S dS )Ns   
c              3   @   K   | ]}d                      |          V  dS )s   : Nr-   )r   fields     r   	<genexpr>z$Headers.__bytes__.<locals>.<genexpr>h   s.      KKe

5 1 1KKKKKKr   r   )r"   r.   )r(   s    r   	__bytes__zHeaders.__bytes__f   s9    ; 	<<KKt{KKKKKgUU3r   c                 h    t          |          }t                                          |           d S r2   )r   r    __delitem__)r(   r*   r+   s     r   r;   zHeaders.__delitem__l   s.    C  C     r   c              #   t   K   t                                                      D ]}t          |          V  d S r2   )r    __iter__r   )r(   r   r+   s     r   r=   zHeaders.__iter__p   sE      !!## 	 	A!**	 	r   c                 x    t          |          }d t                                          |          D             S )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
        c                 ,    g | ]}t          |          S r   r   r   r   s     r   
<listcomp>z#Headers.get_all.<locals>.<listcomp>{   s+     
 
 
GAJJ
 
 
r   )r   r    get_all)r(   r   r+   s     r   rC   zHeaders.get_allt   sC     T""
 
GGOOD!!
 
 
 	
r   c                 ~    t          |          }d |D             }t                                          ||          S )zd
        Explicitly set multiple headers for the given key.
        See: :py:meth:`get_all`
        c                 ,    g | ]}t          |          S r   )r   rA   s     r   rB   z#Headers.set_all.<locals>.<listcomp>   s     333q-""333r   )r   r    set_all)r(   r   r/   r+   s      r   rF   zHeaders.set_all   s=    
 T""33F333wwtV,,,r   c                     t          |          }t          |          }t                                          |||           d S r2   )r   r    insert)r(   indexr*   r   r+   s       r   rH   zHeaders.insert   s=    C  e$$uc5)))))r   Fc                 j    |rd | j         D             S t                                                      S )Nc              3   X   K   | ]%\  }}t          |          t          |          fV  &d S r2   r@   r   kvs      r   r8   z Headers.items.<locals>.<genexpr>   sK        Aq WQZZ(     r   )r"   r    r&   )r(   multir+   s     r   r&   zHeaders.items   sB     	#  K   
 77==??"r   )r   )F)__name__
__module____qualname____doc__r!   staticmethodr0   r4   r9   r;   r=   rC   rF   rH   r&   __classcell__)r+   s   @r   r   r      s(       - -^     0 ! ! \!   \  ! ! ! ! !    

 

 

 

 

- - - - -* * * * *
# # # # # # # # # #r   r   creturnc                 >   |                      dd          }|d                              dd          }t          |          dk    rdS t          j                    }t          |          dk    r||d                              d          D ]`}|                     dd          }t          |          dk    r5|d                                         ||d                                         <   a|d                                         |d                                         |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stripr3   )rV   partstsdiclauses         r   parse_content_typerh      s     GGCOOE	qQ		B
2ww!||t!!A
5zzQq$$ 	9 	9AWWS!__F6{{a'-ay'8'8&)//##$a5;;=="Q%++--**r   c                     |sd                     | |          S d                    d |                                D                       }d                     | ||          S )Nz{}/{}z; c              3   H   K   | ]\  }}d                      ||          V  dS )z{}={}N)formatrL   s      r   r8   z(assemble_content_type.<locals>.<genexpr>   sH        Aq 	q!     r   z	{}/{}; {})rk   r.   r&   )typesubtype
parametersparamss       r   assemble_content_typerp      sz     -~~dG,,,YY  $$&&    F gv  r   )r`   typingr   r   r   +seleniumwire.thirdparty.mitmproxy.coretypesr   'seleniumwire.thirdparty.mitmproxy.utilsr   r   r   	MultiDictr   strrh   rp   r   r   r   <module>rv      s        ( ( ( ( ( ( ( ( ( ( A A A A A A < < < < < <0 0 0@ @ @A# A# A# A# A#i! A# A# A#H+# +(5c4S>1I+J"K + + + +6	 	 	 	 	r   