
    tc                        d dl Z d dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZmZmZmZmZ d dlmZ ddlmZmZ ddlmZ ddlmZmZmZmZmZmZ dd	lmZm Z   G d
 dee          Z! G d de          Z" G d de          Z# G d dee          Z$dee%e&e
e&         ee&         f         dee	e%e%f         eeef         f         fdZ'dedee	e%e%f         e!f         fdZ(dededee&         dee	e%e%f         ef         fdZ)de%dee	e%e%f         e!f         fdZ*de%dee	e%e%f         e!f         fdZ+dedee	e%e%f         e!f         fdZ,	 	 	 	 	 d"dee         dee         dee         dee         dee&         dee	e%e%f         eeef         f         fd Z-	 	 	 	 d#dee         dee%         dee%         dee         dee	e%e%f         eeef         f         f
d!Z.dS )$    N)dumps)
AnyAsyncIterableAsyncIteratorDictIterableIteratorMappingOptionalTupleUnion)	urlencode   )StreamClosedStreamConsumed)MultipartStream)AsyncByteStreamRequestContentRequestDataRequestFilesResponseContentSyncByteStream)peek_filelike_lengthprimitive_value_to_strc                   N    e Zd ZdeddfdZdee         fdZdee         fdZdS )
ByteStreamstreamreturnNc                     || _         d S N_streamselfr   s     0/usr/lib/python3/dist-packages/httpx/_content.py__init__zByteStream.__init__    s        c              #      K   | j         V  d S r    r!   r$   s    r%   __iter__zByteStream.__iter__#   s      lr'   c                   K   | j         W V  d S r    r!   r)   s    r%   	__aiter__zByteStream.__aiter__&   s      lr'   )	__name__
__module____qualname__bytesr&   r	   r*   r   r,    r'   r%   r   r      su        u     (5/    u!5      r'   r   c                   B    e Zd ZdZdee         fdZdee         fdZdS )IteratorByteStream   r   c                 T    || _         d| _        t          j        |          | _        d S NF)r"   _is_stream_consumedinspectisgenerator_is_generatorr#   s     r%   r&   zIteratorByteStream.__init__-   s*    #( $088r'   r   c              #   *  K   | j         r| j        rt                      d| _         t          | j        d          rJ| j                            | j                  }|r'|V  | j                            | j                  }|%d S d S | j        D ]}|V  d S )NTread)r7   r:   r   hasattrr"   r<   
CHUNK_SIZEr$   chunkparts      r%   r*   zIteratorByteStream.__iter__2   s      # 	#(: 	# """#' 4<(( 		L%%do66E ;))$/::  ; ; ; ; ;
   



 r'   N)	r-   r.   r/   r>   r   r0   r&   r	   r*   r1   r'   r%   r3   r3   *   sW        J9x 9 9 9 9
(5/      r'   r3   c                   B    e Zd ZdZdee         fdZdee         fdZdS )AsyncIteratorByteStreamr4   r   c                 T    || _         d| _        t          j        |          | _        d S r6   )r"   r7   r8   
isasyncgenr:   r#   s     r%   r&   z AsyncIteratorByteStream.__init__F   s*    #( $/77r'   r   c                R  K   | j         r| j        rt                      d| _         t          | j        d          rW| j                            | j                   d {V }|r.|W V  | j                            | j                   d {V }|,d S d S | j        2 3 d {V }|W V  6 d S )NTaread)r7   r:   r   r=   r"   rG   r>   r?   s      r%   r,   z!AsyncIteratorByteStream.__aiter__K   s     # 	#(: 	# """#' 4<)) 		,,,T_========E B"l00AAAAAAAA  B B B B B
 #l       d




 +lls   B&N)	r-   r.   r/   r>   r   r0   r&   r   r,   r1   r'   r%   rC   rC   C   sY        J8}U3 8 8 8 8
u!5      r'   rC   c                   B    e Zd ZdZdee         fdZdee         fdZdS )UnattachedStreamz
    If a request or response is serialized using pickle, then it is no longer
    attached to a stream for I/O purposes. Any stream operations should result
    in `httpx.StreamClosed`.
    r   c                     t                      r    r   r)   s    r%   r*   zUnattachedStream.__iter__c   s    nnr'   c                "   K   t                      r    rK   r)   s    r%   r,   zUnattachedStream.__aiter__f   s      nnr'   N)	r-   r.   r/   __doc__r	   r0   r*   r   r,   r1   r'   r%   rI   rI   \   s]         (5/    u!5      r'   rI   contentr   c                 R   t          | t          t          f          rat          | t                    r|                     d          n| }t	          |          }|rdt          |          ini }|t          |          fS t          | t                    rMt          | t                    s8t          |           }|ddi}ndt          |          i}|t          |           fS t          | t                    rddi}|t          |           fS t          dt          |                     )Nutf-8Content-LengthzTransfer-EncodingchunkedzUnexpected type for 'content', )
isinstancer0   strencodelenr   r   dictr   r3   r   rC   	TypeErrortype)rN   bodycontent_lengthheaderscontent_length_or_nones        r%   encode_contentr^   k   s3    'E3<(( 9*4Wc*B*BOw~~g&&&T=AI#S%8%899r
4((((	GX	&	& 9z'4/H/H 9
 "6g!>!>!)*I6GG'-C)D)DEG*73333	G]	+	+ 9&	2/8888
Gd7mmGG
H
HHr'   datac                    g }|                                  D ]g\  }t          |t          t          f          r"|                    fd|D                        C|                    t          |          f           ht          |d                              d          }t          t          |                    }d}||d}|t          |          fS )Nc                 2    g | ]}t          |          fS r1   )r   ).0itemkeys     r%   
<listcomp>z*encode_urlencoded_data.<locals>.<listcomp>   s'    UUUt%;D%A%ABUUUr'   T)doseqrP   z!application/x-www-form-urlencodedrQ   zContent-Type)itemsrS   listtupleextendappendr   r   rU   rT   rV   r   )r_   
plain_datavaluerZ   r[   content_typer\   rd   s          @r%   encode_urlencoded_datarp      s     Jjjll D D
UedE]++ 	DUUUUuUUUVVVVs$:5$A$ABCCCCZt,,,33G<<DT^^N6L!/NNGJt$$$$r'   filesboundaryc                 V    t          | ||          }|                                }||fS )N)r_   rq   rr   )r   get_headers)r_   rq   rr   	multipartr\   s        r%   encode_multipart_datarv      s4      TJJJI##%%GIr'   textc                     |                      d          }t          t          |                    }d}||d}|t          |          fS )NrP   ztext/plain; charset=utf-8rg   rU   rT   rV   r   )rw   rZ   r[   ro   r\   s        r%   encode_textrz      sI    ;;wDT^^N.L!/NNGJt$$$$r'   htmlc                     |                      d          }t          t          |                    }d}||d}|t          |          fS )NrP   ztext/html; charset=utf-8rg   ry   )r{   rZ   r[   ro   r\   s        r%   encode_htmlr}      sI    ;;wDT^^N-L!/NNGJt$$$$r'   jsonc                     t          |                               d          }t          t          |                    }d}||d}|t	          |          fS )NrP   zapplication/jsonrg   )
json_dumpsrU   rT   rV   r   )r~   rZ   r[   ro   r\   s        r%   encode_jsonr      sS    d""7++DT^^N%L!/NNGJt$$$$r'   c                 8   |@t          |t                    s+d}t          j        |t                     t          |          S | t          |           S |rt          |pi ||          S |rt          |          S |t          |          S i t          d          fS )z
    Handles encoding the given `content`, `data`, `files`, and `json`,
    returning a two-tuple of (<headers>, <stream>).
    Nz5Use 'content=<...>' to upload raw bytes/text content.r'   )
rS   r
   warningswarnDeprecationWarningr^   rv   rp   r   r   )rN   r_   rq   r~   rr   messages         r%   encode_requestr      s     
4 9 9 Jg1222d###g&&&	 !$TZRAAA	 !%d+++		4   z#r'   c                     | t          |           S |t          |          S |t          |          S |t          |          S i t	          d          fS )zc
    Handles encoding the given `content`, returning a two-tuple of
    (<headers>, <stream>).
    Nr'   )r^   rz   r}   r   r   )rN   rw   r{   r~   s       r%   encode_responser      se     g&&&		4   		4   		4   z#r'   )NNNNN)NNNN)/r8   r   r~   r   r   typingr   r   r   r   r   r	   r
   r   r   r   urllib.parser   _exceptionsr   r   
_multipartr   _typesr   r   r   r   r   r   _utilsr   r   r   r3   rC   rI   rT   r0   r^   rp   rv   rz   r}   r   r   r   r1   r'   r%   <module>r      s     $ $ $ $ $ $                        # " " " " " 5 5 5 5 5 5 5 5 ' ' ' ' ' '                A @ @ @ @ @ @ @    .          2    o   2       I3xe0DDEI
4S>5!@AABI I I I<%
%
4S>:%&% % % % 
*6>uo
4S>?*+   %c %eDcNJ$>? % % % %%c %eDcNJ$>? % % % %%c %eDcNJ$>? % % % % )-"&$( $   n% 
;
  L!  3-	 
 uo  4S>5!@AAB       H *.	 o&
3- 3- 3-	
 4S>5!@AAB     r'   