
    =h&                     H   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  G d d      Z	 G d d	e	      Z
 G d
 de	      Z G d de	      Z G d de	      Z G d de	      Z G d d      Z G d d      Z G d d      Z G d d      Ze
eeedZeej)                  d       yy)zq
Handlers for Content-Encoding.

See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
    N   )brotli)DecodingErrorc                   (    e Zd ZdedefdZdefdZy)ContentDecoderdatareturnc                     t               NNotImplementedErrorselfr   s     _/var/www/html/phonemate/phone_mate_backend/venv/lib/python3.12/site-packages/httpx/_decoders.pydecodezContentDecoder.decode       !##    c                     t               r   r   r   s    r   flushzContentDecoder.flush   r   r   N)__name__
__module____qualname__bytesr   r    r   r   r   r      s!    $5 $U $$u $r   r   c                   ,    e Zd ZdZdedefdZdefdZy)IdentityDecoderz 
    Handle unencoded data.
    r   r	   c                     |S r   r   r   s     r   r   zIdentityDecoder.decode   s    r   c                      yNr   r   r   s    r   r   zIdentityDecoder.flush   s    r   N)r   r   r   __doc__r   r   r   r   r   r   r   r      s&    5 U u r   r   c                   4    e Zd ZdZddZdedefdZdefdZy)	DeflateDecoderzZ
    Handle 'deflate' decoding.

    See: https://stackoverflow.com/questions/1838699
    r	   Nc                 D    d| _         t        j                         | _        y )NT)first_attemptzlibdecompressobjdecompressorr   s    r   __init__zDeflateDecoder.__init__*   s    ! ..0r   r   c                 B   | j                   }d| _         	 | j                  j                  |      S # t        j                  $ r[}|r?t        j
                  t        j                         | _        | j                  |      cY d }~S t        t        |            |d }~ww xY wNF)
r%   r(   
decompressr&   errorr'   	MAX_WBITSr   r   str)r   r   was_first_attemptexcs       r   r   zDeflateDecoder.decode.   s     .."	3$$//55zz 	3 $($6$6$G!{{4((C)s2		3s!   0 B;B>BBBc                     	 | j                   j                         S # t        j                  $ r}t	        t        |            |d }~ww xY wr   r(   r   r&   r-   r   r/   r   r1   s     r   r   zDeflateDecoder.flush9   A    	3$$**,,zz 	3C)s2	3    A	AA	r	   Nr   r   r   r!   r)   r   r   r   r   r   r   r#   r#   #   s+    1	35 	3U 	33u 3r   r#   c                   4    e Zd ZdZddZdedefdZdefdZy)	GZipDecoderzW
    Handle 'gzip' decoding.

    See: https://stackoverflow.com/questions/1838699
    r	   Nc                 Z    t        j                  t         j                  dz        | _        y )N   )r&   r'   r.   r(   r   s    r   r)   zGZipDecoder.__init__G   s     ..t~~/BCr   r   c                     	 | j                   j                  |      S # t        j                  $ r}t	        t        |            |d }~ww xY wr   )r(   r,   r&   r-   r   r/   r   r   r1   s      r   r   zGZipDecoder.decodeJ   sC    	3$$//55zz 	3C)s2	3s    A
AA
c                     	 | j                   j                         S # t        j                  $ r}t	        t        |            |d }~ww xY wr   r3   r4   s     r   r   zGZipDecoder.flushP   r5   r6   r7   r8   r   r   r   r:   r:   @   s,    D35 3U 33u 3r   r:   c                   4    e Zd ZdZddZdedefdZdefdZy)	BrotliDecoderaT  
    Handle 'brotli' decoding.

    Requires `pip install brotlipy`. See: https://brotlipy.readthedocs.io/
        or   `pip install brotli`. See https://github.com/google/brotli
    Supports both 'brotlipy' and 'Brotli' packages since they share an import
    name. The top branches are for 'brotlipy' and bottom branches for 'Brotli'
    r	   Nc                    t         t        d      d t        j                         | _        d| _        |  t        | j                  d      r| j                  j                  | _        y | j                  j                  | _        y )NzUsing 'BrotliDecoder', but neither of the 'brotlicffi' or 'brotli' packages have been installed. Make sure to install httpx using `pip install httpx[brotli]`.Fr,   )	r   ImportErrorDecompressorr(   	seen_datahasattrr,   _decompressprocessr   s    r   r)   zBrotliDecoder.__init__a   sv    >P 	 #//14$$l3#00;;D  $0088Dr   r   c                     |syd| _         	 | j                  |      S # t        j                  $ r}t	        t        |            |d }~ww xY wNr   T)rE   rG   r   r-   r   r/   r>   s      r   r   zBrotliDecoder.decodes   sJ    	3##D))|| 	3C)s2	3s    A
AA
c                     | j                   sy	 t        | j                  d      r| j                  j                          y# t        j
                  $ r}t        t        |            |d }~ww xY w)Nr   finish)rE   rF   r(   rL   r   r-   r   r/   r4   s     r   r   zBrotliDecoder.flush|   s]    ~~
	3t(((3 !!((*|| 	3C)s2	3s   0A   A-A((A-r7   r8   r   r   r   rA   rA   W   s+    9$35 3U 33u 3r   rA   c                   V    e Zd ZdZdej
                  e   ddfdZdedefdZ	defdZ
y)	MultiDecoderzE
    Handle the case where multiple encodings have been applied.
    childrenr	   Nc                 6    t        t        |            | _        y)zm
        'children' should be a sequence of decoders in the order in which
        each was applied.
        N)listreversedrO   )r   rO   s     r   r)   zMultiDecoder.__init__   s     Xh/0r   r   c                 J    | j                   D ]  }|j                  |      } |S r   )rO   r   r   r   childs      r   r   zMultiDecoder.decode   s#    ]]E<<%D #r   c                 p    d}| j                   D ]$  }|j                  |      |j                         z   }& |S r    )rO   r   r   rT   s      r   r   zMultiDecoder.flush   s3    ]]E<<%5D #r   )r   r   r   r!   typingSequencer   r)   r   r   r   r   r   r   rN   rN      sB    1!@ 1T 15 U 
u r   rN   c                       e Zd ZdZd	dej
                  e   ddfdZdedej                  e   fdZ
dej                  e   fdZy)
ByteChunkerz>
    Handles returning byte content in fixed-size chunks.
    N
chunk_sizer	   c                 D    t        j                         | _        || _        y r   )ioBytesIO_buffer_chunk_sizer   r[   s     r   r)   zByteChunker.__init__   s    zz|%r   contentc                    | j                   |r|gS g S | j                  j                  |       | j                  j                         | j                   k\  r| j                  j	                         }t        dt        |      | j                         D cg c]  }|||| j                   z     }}t        |d         | j                   k(  r7| j                  j                  d       | j                  j                          |S | j                  j                  d       | j                  j                  |d          | j                  j                          |d d S g S c c}w Nr   	r`   r_   writetellgetvaluerangelenseektruncater   rb   valueichunkss        r   r   zByteChunker.decode   s0   # 'G9/R/7#<<$"2"22LL))+E q#e*d.>.>??A a!d.../?   6":$"2"22!!!$%%'!!!$""6":.%%'cr{"Is   Ec                     | j                   j                         }| j                   j                  d       | j                   j                          |r|gS g S Nr   r_   ri   rl   rm   r   ro   s     r   r   zByteChunker.flush   E    %%'!w'R'r   r   )r   r   r   r!   rW   Optionalintr)   r   Listr   r   r   r   r   rZ   rZ      sT    &6??3#7 &4 &e E(: .(v{{5) (r   rZ   c                       e Zd ZdZd	dej
                  e   ddfdZdedej                  e   fdZ
dej                  e   fdZy)
TextChunkerz>
    Handles returning text content in fixed-size chunks.
    Nr[   r	   c                 D    t        j                         | _        || _        y r   )r]   StringIOr_   r`   ra   s     r   r)   zTextChunker.__init__   s    {{}%r   rb   c                    | j                   |gS | j                  j                  |       | j                  j                         | j                   k\  r| j                  j	                         }t        dt        |      | j                         D cg c]  }|||| j                   z     }}t        |d         | j                   k(  r7| j                  j                  d       | j                  j                          |S | j                  j                  d       | j                  j                  |d          | j                  j                          |d d S g S c c}w rd   rf   rn   s        r   r   zTextChunker.decode   s)   #97#<<$"2"22LL))+E q#e*d.>.>??A a!d.../?   6":$"2"22!!!$%%'!!!$""6":.%%'cr{"Is   Ec                     | j                   j                         }| j                   j                  d       | j                   j                          |r|gS g S rs   rt   ru   s     r   r   zTextChunker.flush   rv   r   r   )r   r   r   r!   rW   rw   rx   r)   r/   ry   r   r   r   r   r   r{   r{      sT    &6??3#7 &4 &c fkk#&6 .(v{{3' (r   r{   c                   :    e Zd ZdZd	defdZdedefdZdefdZy)
TextDecoderz8
    Handles incrementally decoding bytes into text
    encodingc                 F     t        j                  |      d      | _        y )Nreplace)errors)codecsgetincrementaldecoderdecoder)r   r   s     r   r)   zTextDecoder.__init__   s    =v33H=YOr   r   r	   c                 8    | j                   j                  |      S r   r   r   r   s     r   r   zTextDecoder.decode   s    ||""4((r   c                 :    | j                   j                  dd      S rJ   r   r   s    r   r   zTextDecoder.flush   s    ||""3--r   N)zutf-8)	r   r   r   r!   r/   r)   r   r   r   r   r   r   r   r      s4    P P)5 )S ).s .r   r   c                   h    e Zd ZdZddZdedej                  e   fdZdej                  e   fdZ	y)	LineDecoderz
    Handles incrementally reading lines from text.

    Has the same behaviour as the stdllib splitlines, but handling the input iteratively.
    r	   Nc                      g | _         d| _        y r+   )buffertrailing_crr   s    r   r)   zLineDecoder.__init__	  s    (*!&r   textc                    d}| j                   rd|z   }d| _         |j                  d      rd| _         |d d }|sg S |d   |v }|j                         }t        |      dk(  r"|s | j                  j                  |d          g S | j                  r/dj                  | j                        |d   z   g|dd  z   }g | _        |s|j                         g| _        |S )	Nu   
  FTre   r   r    )r   endswith
splitlinesrk   r   appendjoinpop)r   r   NEWLINE_CHARStrailing_newlineliness        r   r   zLineDecoder.decode  s    B $;D$D==#D9DI8}4!u:?#3KKuQx(I;; WWT[[)E!H45ab	AEDK !99;-DKr   c                     | j                   s| j                  sg S dj                  | j                         g}g | _         d| _        |S )Nr   F)r   r   r   )r   r   s     r   r   zLineDecoder.flush1  s?    {{4#3#3I%& r   r7   )
r   r   r   r!   r)   r/   rW   ry   r   r   r   r   r   r   r     s>    '"3 "6;;s#3 "Hv{{3' r   r   )identitygzipdeflatebrr   )r!   r   r]   rW   r&   _compatr   _exceptionsr   r   r   r#   r:   rA   rN   rZ   r{   r   r   SUPPORTED_DECODERSr   r   r   r   <module>r      s   
  	    &$ $	n 	3^ 3:3. 3.23N 23j> 2$( $(N$( $(N. .6 6t  
	  
>4  r   