o
    Ikc2                     @   s   d Z ddlZddl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 ddl	m
Z
mZmZ ddlmZmZ ddlmZ ddlmZ G dd	 d	eZdS )
aF  
Copyright 2015 Red Hat, Inc.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
    N)BytesIO)unquoteurljoinurlparse)Responsecodes)BaseAdapter)is_win32c                   @   s   e Zd Zdd Zdd ZdS )FileAdapterc              
   K   s  |j dvrtd|j  t|j}tr(|jdr(|jd|j |j dd}|jr4|jdvr4td|jd	v r[t	j
|jt	jdd }trNd| }|jt||jdd
}t }|j|_z|jdkr~tjj|_dt	j
dt	jd d |_ndd |jdD }|r|d s|d |r|d rtdd |D rttjt	tj|r|d ds|d dr|d}|dr|dd  d}|r|d s|d |r|d rnd}|t	j t	jj|  }|rt	j|st	jt	jj|g|R   }t|d|_|jj|j_ W nL ty` }	 z?|	jtj!kr)t"j#|_$n|	jtjkr5t"j%|_$nt"j&|_$t'|	(t)*d}
t+|
|_t,|
|j-d< |jj|j_ W Y d}	~	|S d}	~	ww t"j.|_$t	/|j0 }t12|j3rz|j4|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 :/ )pathnetloc)	localhost...-z5file: URLs with hostname components are not permitted)r   r   )r   r   zfile://r   c                 S   s   g | ]}t |qS  )r   .0pr   r   C/usr/lib/python3/dist-packages/streamlink/packages/requests_file.py
<listcomp>O   s    z$FileAdapter.send.<locals>.<listcomp>r   c                 s   s    | ]}t j|v V  qd S N)ossepr   r   r   r   	<genexpr>W   s    z#FileAdapter.send.<locals>.<genexpr>|NrbFzContent-Length)5method
ValueErrorr   urlr	   r   endswith_replacer   r   abspathreplacer   r   lstripr   sysstdinbufferrawsplitpopanyIOErrorerrnoENOENTstrerrorjoin
splitdriveioopencloserelease_connEACCESr   	forbiddenstatus_code	not_foundbad_requeststrencodelocalegetpreferredencodingr   lenheadersokfstatfilenostatS_ISREGst_modest_size)selfrequestkwargs	url_partspwdresp
path_parts
path_driver   eresp_str	resp_statr   r   r   send"   sr   





"
 





	zFileAdapter.sendc                 C   s   d S r   r   )rN   r   r   r   r:      s   zFileAdapter.closeN)__name__
__module____qualname__rY   r:   r   r   r   r   r
   !   s    qr
   )__doc__r3   r8   rC   r   os.pathrJ   r+   r   urllib.parser   r   r   requestsr   r   requests.adaptersr   streamlink.compatr	   r
   r   r   r   r   <module>   s    