
    hg                        d Z ddlZddlZddlZddlZddlmZ ddlmZm	Z	m
Z
mZ ddlZddlZ ej        dd          Z edddd          aed"ddd	ed
eddfd            Zed"ded	ed
edefd            Zed"ded	ed
ede
eef         fd            Zd"de
deef         d	ed
ede
deef         fdZed"ddd	ed
eddfd            Zed"ded	ed
ede
eef         fd            Zed"ded	ed
edefd            Zd"de
deef         de
deef         fdZd ZdedefdZdedefdZdedefdZdedefdZdedefdZdedefdZdedefdZdedefdZeeeeeeedZeeeeeeedZ d d!gZ!dS )#z1
Utility functions for decoding response bodies.
    N)BytesIO)AnyStrOptionalUnionoverloadCachedDecodezencoded encoding errors decodedstrictencodedencodingerrorsreturnc                     d S N r
   r   r   s      l/var/www/fb-scrape/myenv/lib/python3.11/site-packages/seleniumwire/thirdparty/mitmproxy/net/http/encoding.pydecoder          C    c                     d S r   r   r   s      r   r   r      r   r   c                     d S r   r   r   s      r   r   r   !   r   r   c                 `   | dS t          | t                    o/t          j        | k    ot          j        |k    ot          j        |k    }|rt          j        S 	 	 t          |         |           }n&# t          $ r t          j
        | ||          }Y nw xY w|dv rt          | |||          a|S # t          $ r  t          $ rk}t          d                    t!          |          j        t%          |           dd         t%          |          t%          |                              d}~ww xY w)z
    Decode the given input object

    Returns:
        The decoded value

    Raises:
        ValueError, if decoding fails.
    Ngzipdeflatebrzstdz{} when decoding {} with {}: {}
   )
isinstancebytes_cacher
   r   r   decodedcustom_decodeKeyErrorcodecsr   r   	TypeError	Exception
ValueErrorformattype__name__repr)r
   r   r   cachedr"   es         r   r   r   &   `    t 	7E"" 	$Ng%	$Ox'	$ MV#	   ~
	?#H-g66GG 	? 	? 	?mGXv>>GGG	?888!'8VWEEF    
 
 
-44Q Wcrc"XQ	 
 
 	

7   A0 /B. 0 BB. BB. .D-A&D((D-r"   c                     d S r   r   r"   r   r   s      r   encoder3   Q   r   r   c                     d S r   r   r2   s      r   r3   r3   V   r   r   c                     d S r   r   r2   s      r   r3   r3   [   r   r   c                 `   | dS t          | t                    o/t          j        | k    ot          j        |k    ot          j        |k    }|rt          j        S 	 	 t          |         |           }n&# t          $ r t          j
        | ||          }Y nw xY w|dv rt          ||||           a|S # t          $ r  t          $ rk}t          d                    t!          |          j        t%          |           dd         t%          |          t%          |                              d}~ww xY w)z
    Encode the given input object

    Returns:
        The encoded value

    Raises:
        ValueError, if encoding fails.
    Nr   z{} when encoding {} with {}: {}r   )r   r    r!   r"   r   r   r
   custom_encoder$   r%   r3   r   r&   r'   r(   r)   r*   r+   r,   )r"   r   r   r-   r
   r.   s         r   r3   r3   `   r/   r0   c                     | S )zb
    Returns content unchanged. Identity is the default value of
    Accept-Encoding headers.
    r   contents    r   identityr;      s	    
 Nr   r:   c                 v    | sdS t          j        t          |                     }|                                S )Nr   )fileobj)r   GzipFiler   read)r:   gfiles     r   decode_gziprA      s7     sM''"2"2333E::<<r   c                     t                      }t          j        |d          }|                    |            |                                 |                                S )Nwb)r=   mode)r   r   r>   writeclosegetvalue)r:   sgfs      r   encode_gziprJ      sL    		A	qt	,	,	,BHHWHHJJJ::<<r   c                 2    | sdS t          j        |           S )Nr   )brotli
decompressr9   s    r   decode_brotlirN      s      sW%%%r   c                 *    t          j        |           S r   )rL   compressr9   s    r   encode_brotlirQ      s    ?7###r   c                     | sdS t          j                    }	 |                    |           S # t           j        $ r |                    | d          cY S w xY w)Nr   i   )max_output_size)r   ZstdDecompressorrM   	ZstdErrorr:   zstd_ctxs     r   decode_zstdrX      sy     s$&&HJ""7+++> J J J ""7L"IIIIIJs   . &AAc                 R    t          j                    }|                    |           S r   )r   ZstdCompressorrP   rV   s     r   encode_zstdr[      s$    "$$HW%%%r   c                     | sdS 	 t          j        |           S # t           j        $ r t          j        | d          cY S w xY w)a  
    Returns decompressed data for DEFLATE. Some servers may respond with
    compressed data without a zlib header or checksum. An undocumented
    feature of zlib permits the lenient decompression of data missing both
    values.

    http://bugs.python.org/issue5784
    r   i)zlibrM   errorr9   s    r   decode_deflater_      s[      s-w''': - - -w,,,,,-s    $A Ac                 *    t          j        |           S )zP
    Returns compressed content, always including zlib header and checksum.
    )r]   rP   r9   s    r   encode_deflatera      s     =!!!r   )noner;   r   r   
deflateRawr   r   r3   r   )r	   )"__doc__r%   collectionsr   r]   ior   typingr   r   r   r   rL   	zstandardr   
namedtupler   r!   strr   r    r3   r;   rA   rJ   rN   rQ   rX   r[   r_   ra   r#   r7   __all__r   r   r   <module>rl      sX                 4 4 4 4 4 4 4 4 4 4 4 4      &{%n6WXX	dD$	-	- 
 D C  D    
 
 C 3  3    
 
 E S # U3PU:EV    
(
 (
E$U*+ (
s (
C (
W\]acfhm]mWn (
 (
 (
 (
V 
 D C  D    
 
 C 3  5eCT    
 
 E S # U    
(
 (
E$U*+ (
5QUWZ\aQaKb (
 (
 (
 (
V   5     5    &5 &U & & & &$5 $U $ $ $ $	J 	J5 	J 	J 	J 	J& &5 & & & &
-E -e - - - -""E "e " " " "  
   
  X
r   