o
    —¨Êhx%  ã                   @  sü   d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	m
Z
mZ ddlmZ ddlmZ dd	lmZ dd
lmZmZ erDddlmZ dZeedƒZedd�dd„ ƒZG dd„ deƒZe	jG dd„ dƒƒZG dd„ dƒZeefdd„ƒZ G dd„ dƒZ!dS )z&Base async HTTP client implementation.é    )ÚannotationsN)Ú	responses)ÚTYPE_CHECKING)ÚThenableÚmaybe_promiseÚpromise)Ú	HttpError)Úcoro)Úbytes_to_str)Ú
maybe_listÚmemoize)ÚTracebackType)ÚHeadersÚResponseÚRequestÚpypy_version_infoiè  )Úmaxsizec                 C  s   d  dd„ |  d¡D ƒ¡S )Nú-c                 s  s   � | ]}|  ¡ V  qd S ©N)Ú
capitalize)Ú.0Úp© r   úN/var/www/html/env/lib/python3.10/site-packages/kombu/asynchronous/http/base.pyÚ	<genexpr>   s   € z#normalize_header.<locals>.<genexpr>)ÚjoinÚsplit)Úkeyr   r   r   Únormalize_header   s   r   c                   @  s   e Zd ZdZdZdZdS )r   z%Represents a mapping of HTTP headers.FN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚcompleteÚ	_prev_keyr   r   r   r   r      s    r   c                   @  s†   e Zd ZdZd Z Z Z Z Z Z	 Z
 Z Z Z Z ZZdZdZdZdZdZdZes0dZ			ddd	„Zdd
d„Zdd„ ZdS )r   a?  A HTTP Request.

    Arguments:
    ---------
        url (str): The URL to request.
        method (str): The HTTP method to use (defaults to ``GET``).

    Keyword Arguments:
    -----------------
        headers (Dict, ~kombu.asynchronous.http.Headers): Optional headers for
            this request
        body (str): Optional body for this request.
        connect_timeout (float): Connection timeout in float seconds
            Default is 30.0.
        timeout (float): Time in float seconds before the request times out
            Default is 30.0.
        follow_redirects (bool): Specify if the client should follow redirects
            Enabled by default.
        max_redirects (int): Maximum number of redirects (default 6).
        use_gzip (bool): Allow the server to use gzip compression.
            Enabled by default.
        validate_cert (bool): Set to true if the server certificate should be
            verified when performing ``https://`` requests.
            Enabled by default.
        auth_username (str): Username for HTTP authentication.
        auth_password (str): Password for HTTP authentication.
        auth_mode (str): Type of HTTP authentication (``basic`` or ``digest``).
        user_agent (str): Custom user agent for this request.
        network_interface (str): Network interface to use for this request.
        on_ready (Callable): Callback to be called when the response has been
            received. Must accept single ``response`` argument.
        on_stream (Callable): Optional callback to be called every time body
            content has been read from the socket.  If specified then the
            response body and buffer attributes will not be available.
        on_timeout (callable): Optional callback to be called if the request
            times out.
        on_header (Callable): Optional callback to be called for every header
            line received from the server.  The signature
            is ``(headers, line)`` and note that if you want
            ``response.headers`` to be populated then your callback needs to
            also call ``client.on_header(headers, line)``.
        on_prepare (Callable): Optional callback that is implementation
            specific (e.g. curl client will pass the ``curl`` instance to
            this callback).
        proxy_host (str): Optional proxy host.  Note that a ``proxy_port`` must
            also be provided or a :exc:`ValueError` will be raised.
        proxy_username (str): Optional username to use when logging in
            to the proxy.
        proxy_password (str): Optional password to use when authenticating
            with the proxy server.
        ca_certs (str): Custom CA certificates file to use.
        client_key (str): Optional filename for client SSL key.
        client_cert (str): Optional filename for client SSL certificate.
    Ng      >@Té   )
ÚurlÚmethodÚon_readyÚ
on_timeoutÚ	on_streamÚ
on_prepareÚ	on_headerÚheadersÚ__weakref__Ú__dict__ÚGETc	                 K  sŒ   || _ |p| j| _t|ƒptƒ | _t|ƒ| _t|ƒ| _t|ƒ| _t|ƒ| _|	r6|	 	¡ D ]
\}
}t
| |
|ƒ q+t|tƒsAt|p?i ƒ}|| _d S r   )r&   r'   r   r   r(   r)   r*   r+   r,   ÚitemsÚsetattrÚ
isinstancer   r-   )Úselfr&   r'   r(   r)   r*   r+   r,   r-   ÚkwargsÚkÚvr   r   r   Ú__init__t   s   





zRequest.__init__c                 C  s   | j  ||¡ d S r   )r(   Úthen)r4   ÚcallbackÚerrbackr   r   r   r9   …   s   zRequest.thenc                 C  s
   d  | ¡S )Nz&<Request: {0.method} {0.url} {0.body}>)Úformat©r4   r   r   r   Ú__repr__ˆ   s   
zRequest.__repr__)r0   NNNNNNr   )r   r    r!   r"   ÚbodyÚ
user_agentÚnetwork_interfaceÚauth_usernameÚauth_passwordÚ	auth_modeÚ
proxy_hostÚ
proxy_portÚproxy_usernameÚproxy_passwordÚca_certsÚ
client_keyÚclient_certÚconnect_timeoutÚrequest_timeoutÚfollow_redirectsÚmax_redirectsÚuse_gzipÚvalidate_certÚPYPYÚ	__slots__r8   r9   r>   r   r   r   r   r   *   sF    :ýÿÿÿþþþþý
þ
r   c                   @  sR   e Zd ZdZes
dZ		ddd„Zdd„ Zedd	„ ƒZ	ed
d„ ƒZ
edd„ ƒZdS )r   a	  HTTP Response.

    Arguments
    ---------
        request (~kombu.asynchronous.http.Request): See :attr:`request`.
        code (int): See :attr:`code`.
        headers (~kombu.asynchronous.http.Headers): See :attr:`headers`.
        buffer (bytes): See :attr:`buffer`
        effective_url (str): See :attr:`effective_url`.
        status (str): See :attr:`status`.

    Attributes
    ----------
        request (~kombu.asynchronous.http.Request): object used to
            get this response.
        code (int): HTTP response code (e.g. 200, 404, or 500).
        headers (~kombu.asynchronous.http.Headers): HTTP headers
            for this response.
        buffer (bytes): Socket read buffer.
        effective_url (str): The destination url for this request after
            following redirects.
        error (Exception): Error instance if the request resulted in
            a HTTP error code.
        status (str): Human equivalent of :attr:`code`,
            e.g. ``OK``, `Not found`, or 'Internal Server Error'.
    )	ÚrequestÚcoder-   ÚbufferÚeffective_urlÚerrorÚstatusÚ_bodyr.   Nc                 C  sŽ   || _ || _|d ur|ntƒ | _|| _|p|j| _d | _|p$t 	| jd¡| _
|| _| jd u rC| jdk s8| jdkrEt| j| j
| ƒ| _d S d S d S )NÚUnknownéÈ   i+  )rT   rU   r   r-   rV   r&   rW   rZ   r   ÚgetrY   rX   r   )r4   rT   rU   r-   rV   rW   rX   rY   r   r   r   r8   ¬   s   ÿzResponse.__init__c                 C  s   | j r| j ‚dS )z�Raise if the request resulted in an HTTP error code.

        Raises
        ------
            :class:`~kombu.exceptions.HttpError`
        N)rX   r=   r   r   r   Úraise_for_errorº   s   ÿzResponse.raise_for_errorc                 C  s&   | j du r| jdur| j ¡ | _ | j S )z½The full contents of the response body.

        Note:
        ----
            Accessing this property will evaluate the buffer
            and subsequent accesses will be cached.
        N)rZ   rV   Úgetvaluer=   r   r   r   r?   Ä   s   
	
zResponse.bodyc                 C  ó   | j S r   )rU   r=   r   r   r   Ústatus_codeÓ   ó   zResponse.status_codec                 C  r`   r   )r?   r=   r   r   r   Úcontent×   rb   zResponse.content)NNNNN)r   r    r!   r"   rR   rS   r8   r^   Úpropertyr?   ra   rc   r   r   r   r   r   Œ   s    
ÿ


r   c                 c  s†   � 	 d V \}}|  d¡rq|sd|_q|d  ¡ r-|j}d | |¡p$d| ¡ g¡||< n| dd¡\}}| |ƒ }|_| ¡ ||< q)Né   zHTTP/Tr   ú Ú ú:)	Ú
startswithr#   Úisspacer$   r   r]   Úlstripr   Ústrip)ÚkeytÚliner-   Úpkeyr   Úvaluer   r   r   Úheader_parserÜ   s   €

"órq   c                   @  sR   e Zd ZeZeZeZdd„ Zdd„ Zdd„ Zdd„ Z	d	d
„ Z
dd„ Zddd„ZdS )Ú
BaseClientc                 K  s   || _ tƒ | _d S r   )Úhubrq   Ú_header_parser)r4   rs   r5   r   r   r   r8   ó   s   zBaseClient.__init__c                 K  s>   t |ƒpg D ]}t|| jƒs| j|fi |¤Ž}|  |¡ qd S r   )r   r3   r   Úadd_request)r4   rT   r5   Úreqr   r   r   Úperform÷   s
   ýzBaseClient.performc                 C  s   t dƒ‚)Nzmust implement add_request)ÚNotImplementedError)r4   rT   r   r   r   ru   ý   s   zBaseClient.add_requestc                 C  s   d S r   r   r=   r   r   r   Úclose   ó   zBaseClient.closec                 C  s8   z| j  t|ƒ|f¡ W d S  ty   tƒ | _ Y d S w r   )rt   Úsendr
   ÚStopIterationrq   )r4   r-   rn   r   r   r   r,     s
   ÿzBaseClient.on_headerc                 C  s   | S r   r   r=   r   r   r   Ú	__enter__	  rz   zBaseClient.__enter__Úexc_typeútype[BaseException] | NoneÚexc_valúBaseException | NoneÚexc_tbúTracebackType | NoneÚreturnÚNonec                 C  s   |   ¡  d S r   )ry   )r4   r~   r€   r‚   r   r   r   Ú__exit__  s   zBaseClient.__exit__N)r~   r   r€   r�   r‚   rƒ   r„   r…   )r   r    r!   r   r   r   r8   rw   ru   ry   r,   r}   r†   r   r   r   r   rr   î   s    rr   )"r"   Ú
__future__r   ÚsysÚhttp.clientr   Útypingr   Úviner   r   r   Úkombu.exceptionsr   Úkombu.utils.compatr	   Úkombu.utils.encodingr
   Úkombu.utils.functionalr   r   Útypesr   Ú__all__ÚhasattrrR   r   Údictr   Úregisterr   r   rq   rr   r   r   r   r   Ú<module>   s.    

aP