o
    oĎi                     @   s   d dl Z d dlZd dl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 d dlZddlmZmZmZ er@ddlmZmZ ed	G d
d deZedG dd deZdS )    N)PathPurePosixPath)TemporaryDirectory)AnyTupleTYPE_CHECKINGUnionOptional   )	CloudPathNoStatErrorregister_path_class   )
HttpClientHttpsClienthttpc                	       s  e Zd ZU dZded< dddeed f deded ddf fd	d
Ze	de
fddZdedef fddZe	dejjfddZe	defddZe	defddZe	defddZd<dedefddZd<dedefddZ	d=ded ed!ee ddfd"d#Zd>d ed!ee ddfd$d%Zd<dedejfd&d'Zd?d)ed*edefd+d,Ze	defd-d.Ze	de d/ f fd0d1Z!de e"j#j$e%f fd2d3Z&de e"j#j$e%f fd4d5Z'de e"j#j$e%f fd6d7Z(de e"j#j$e%f fd8d9Z)de e"j#j$e%f fd:d;Z*  Z+S )@HttpPathzhttp://r   clientN)r   
cloud_pathpartsreturnc                   sR   t  j|g|R d|i | jjdrt| jj| _d S td| jj | _d S )Nr   /)super__init___urlpath
startswithr   _path)selfr   r   r   	__class__ V/home/jeff/fluffinator/venv/lib/python3.10/site-packages/cloudpathlib/http/httppath.pyr      s   zHttpPath.__init__c                 C   s   | j j| jjd S )z!Cached local version of the file.r   )r   _local_cache_dirr   r   lstripr   r!   r!   r"   _local#   s   zHttpPath._localfuncc                    sJ   t  j|g|R i |}|dkr#t|d dr#| t|d S |S )N__truediv__r   r   )r   _dispatch_to_pathstrendswith_new_cloudpath)r   r'   argskwargssupr   r!   r"   r)   )   s   zHttpPath._dispatch_to_pathc                 C   s   | j S N)r   r%   r!   r!   r"   
parsed_url4   s   zHttpPath.parsed_urlc                 C      | j jS r0   )r   netlocr%   r!   r!   r"   drive8   s   zHttpPath.drivec                 C   s   | j j d| j j dS )Nz://r   )r   schemer3   r%   r!   r!   r"   anchor=   s   zHttpPath.anchorc                 C   s   | j t| jd d  S )Nr   )_strlenr6   r%   r!   r!   r"   _no_prefix_no_driveA   s   zHttpPath._no_prefix_no_driveTfollow_symlinksc                 C   s   |   sdS | jt| S NFexistsr   dir_matcherr*   r   r:   r!   r!   r"   is_dirF   s   zHttpPath.is_dirc                 C   s   |   sdS | jt|  S r;   r<   r?   r!   r!   r"   is_fileM   s   zHttpPath.is_fileFparentsexist_okmodec                 C   s   d S r0   r!   )r   rB   rC   rD   r!   r!   r"   mkdirS   s   zHttpPath.mkdirc                 C   s^   |   r|std|  tdtt jd }|jjddd |d | j	
||  d S )NzFile already exists: zTouch not implemented for existing HTTP files since we can't update the modified time; use `put()` or write to the file instead.zempty_file.txtT)rB   rC    )r=   FileExistsErrorNotImplementedErrorr   r   nameparentrE   
write_textr   _upload_file)r   rC   rD   
empty_filer!   r!   r"   touchX   s   
zHttpPath.touchc                 C   sb   z| j | }W n
   td|  td d | jd d d |ddd |dtjd	 d f
S )NzCould not get metadata for sizer   last_modified)
r   _get_metadatar   osstat_resultcloud_prefixgetdatetimefromtimestamp	timestamp)r   r:   metar!   r!   r"   statg   s(   
zHttpPath.stat  presignexpire_secondsc                 C   s   |rt d| j S )Nz'Presigning not supported for HTTP paths)rH   r   geturl)r   r\   r]   r!   r!   r"   as_url~   s   zHttpPath.as_urlc                 C   r2   r0   )r   rI   r%   r!   r!   r"   rI      s   zHttpPath.name)r   .c                    s   t  j| df S )NrF   )r   rB   r,   r%   r   r!   r"   rB      s   zHttpPath.parentsc                 K      | j j| dfi |S )z1Issue a get request with `urllib.request.Request`GETr   requestr   r.   r!   r!   r"   rU         zHttpPath.getc                 K   r`   )z1Issue a put request with `urllib.request.Request`PUTrb   rd   r!   r!   r"   put   re   zHttpPath.putc                 K   r`   )z2Issue a post request with `urllib.request.Request`POSTrb   rd   r!   r!   r"   post   re   zHttpPath.postc                 K   r`   )z4Issue a delete request with `urllib.request.Request`DELETErb   rd   r!   r!   r"   delete   re   zHttpPath.deletec                 K   r`   )z2Issue a head request with `urllib.request.Request`HEADrb   rd   r!   r!   r"   head   re   zHttpPath.head)T)FFN)TN)Fr[   ),__name__
__module____qualname__rT   __annotations__r   r*   r	   r   propertyr   r&   r   r)   urllibparseParseResultr1   r4   r6   r9   boolr@   rA   rE   rN   rR   rS   rZ   intr_   rI   r   rB   r   r   HTTPResponsebytesrU   rg   ri   rk   rm   __classcell__r!   r!   r   r"   r      s`   
 

"r   httpsc                   @   s"   e Zd ZU dZeed< ded< dS )	HttpsPathzhttps://rT   r   r   N)rn   ro   rp   rT   r*   rq   r!   r!   r!   r"   r|      s   
 r|   )rV   r   rR   pathlibr   r   tempfiler   typingr   r   r   r   r	   rs   	cloudpathr   r   r   
httpclientr   r   r   r|   r!   r!   r!   r"   <module>   s     