o
    tBhy                     @   st   d dl mZ d dlmZmZ d dlmZmZ d dlZd dl	Z	d dl
Z
d dlZd dlZd dlmZ G dd deZdS )    )BaseAdapter)urlparseunquote)ResponsecodesN)BytesIOc                       s.   e Zd Zd fdd	Zdd Zdd Z  ZS )	FileAdapterTc                    s   t t|   || _d S N)superr   __init___set_content_length)selfset_content_length	__class__ d/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/requests_file.pyr      s   
zFileAdapter.__init__c              
   K   sJ  |j dvrtd|j  t|j}|jr|jdkrtdt }zdd |jdD }|r=|d s=|d |r=|d r2t	d	d
 |D rPt
tjttj|r|d ds`|d dr|d}|drr|dd d }|r|d s|d |r|d rxnd}|tj tjj|  }|rtj|stjtjj|g|R   }t|d|_|jj|j_W nM t
y } z@|jtjkrtj|_n|jtjkrtj|_ntj|_t|t !d}	t"|	|_| j#rt$|	|j%d< |jj|j_W Y d}~|S d}~ww tj&|_|j|_t'|j( }
t)*|
j+r#| j#r#|
j,|j%d< |S )z Wraps a file, described in request, in a Response object.

            :param request: The PreparedRequest` being "sent".
            :returns: a Response object containing the file
        )GETHEADzInvalid request method %s	localhostz5file: URLs with hostname components are not permittedc                 S   s   g | ]}t |qS r   )r   .0pr   r   r   
<listcomp>,   s    z$FileAdapter.send.<locals>.<listcomp>/r   c                 s   s    | ]}t j|v V  qd S r	   )ossepr   r   r   r   	<genexpr>4   s    z#FileAdapter.send.<locals>.<genexpr>|:N rbFzContent-Length)-method
ValueErrorr   urlnetlocr   pathsplitpopanyIOErrorerrnoENOENTr   strerrorendswithr   join
splitdriveioopenrawcloserelease_connEACCESr   	forbiddenstatus_code	not_foundbad_requeststrencodelocalegetpreferredencodingr   r   lenheadersokfstatfilenostatS_ISREGst_modest_size)r   requestkwargs	url_partsresp
path_parts
path_driver'   eresp_str	resp_statr   r   r   send   sf   









zFileAdapter.sendc                 C   s   d S r	   r   )r   r   r   r   r5   t   s   zFileAdapter.close)T)__name__
__module____qualname__r   rR   r5   __classcell__r   r   r   r   r      s    br   )requests.adaptersr   requests.compatr   r   requestsr   r   r,   r   rE   r>   r2   sixr   r   r   r   r   r   <module>   s    