o
    Uh                     @   s`   d Z ddlmZ ddlmZ ddlmZmZmZm	Z	 ddl
mZmZ G dd deZd	d
 ZdS )a  Requests HTTP client support for Dulwich.

To use this implementation as the HTTP implementation in Dulwich, override
the dulwich.client.HttpGitClient attribute:

  >>> from dulwich import client as _mod_client
  >>> from dulwich.contrib.requests_vendor import RequestsHttpGitClient
  >>> _mod_client.HttpGitClient = RequestsHttpGitClient

This implementation is experimental and does not have any tests.
    )BytesIO)Session   )AbstractHttpGitClientHTTPProxyUnauthorizedHTTPUnauthorizeddefault_user_agent_string)GitProtocolErrorNotGitRepositoryc                       s.   e Zd Z	d	d	 fddZd
ddZ  ZS )RequestsHttpGitClientNreturnc                    sF   || _ || _t|| _|d ur||f| j_t jd||d| d S )N)base_urldumb )	_username	_passwordget_sessionsessionauthsuper__init__)selfr   r   configusernamepasswordkwargs	__class__r   s/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/dulwich/contrib/requests_vendor.pyr   0   s   
zRequestsHttpGitClient.__init__Fc                 C   s   | j j }|d ur|| |rd|d< nd|d< |r&| j j|||d}n| j j||d}|jdkr5t|jdkrCt|jd||jd	krQt	|jd
||jdkrat
d|j d| |jd|_d|_|jrr|j|_t|jj}||fS )NgzipzAccept-Encodingidentity)headersdata)r!   i  i  zWWW-Authenticatei  zProxy-Authenticate   zunexpected http resp z for zContent-Type )r   r!   copyupdatepostgetstatus_coder
   r   r   r	   content_typeredirect_locationhistoryurlr   contentread)r   r-   r!   r"   allow_compressionreq_headersrespr/   r   r   r   _http_request=   s.   





z#RequestsHttpGitClient._http_request)NNNN)r   N)NNF)__name__
__module____qualname__r   r3   __classcell__r   r   r   r   r   /   s    r   c                 C   sN  t  }|jddi d  } } }}| d ur~z| dd}t|tr'| }W n	 ty1   Y nw z| dd}t|trB| }W n	 tyL   Y nw z| dd}W n ty`   d}Y nw z| dd}t|trq| }W n ty}   d }Y nw |d u rt	 }|jd	|i |r||_
n|d
u r||_
|r|j||d |S )NPragmazno-caches   https   proxys	   useragents	   sslVerifyTs	   sslCAInfoz
User-agentF)httphttps)r   r!   r&   r(   
isinstancebytesdecodeKeyErrorget_booleanr   verifyproxies)r   r   proxy_server
user_agentca_certs
ssl_verifyr   r   r   r   `   sV   


r   N)__doc__ior   requestsr   clientr   r   r   r   errorsr	   r
   r   r   r   r   r   r   <module>   s   1