o
    i                     @   sR   d dl Z d dlZd dlZd dlZd dlZG dd dejZG dd dejjZ	dS )    Nc                       sh   e Zd ZdZdZd fdd	ZdddZdd	d
Zdd ZdddZ	dddZ
dd ZdddZ  ZS )JupyterFileSystemz?View of the files as seen by a Jupyter server (notebook or lab))jupyterZjlabNc              
      s   d|v r,|du r$z
t d|d }W n ty# } ztd|d}~ww |ddd }|dd | _t | _	|rDd	| | j	j
d
< t jdi | dS )aD  

        Parameters
        ----------
        url : str
            Base URL of the server, like "http://127.0.0.1:8888". May include
            token in the string, which is given by the process when starting up
        tok : str
            If the token is obtained separately, can be given here
        kwargs
        ?Nztoken=([a-z0-9]+)r   zCould not determine token   /z/api/contentsztoken Authorization )refindall
IndexError
ValueErrorsplitrstripurlrequestsSessionsessionheaderssuper__init__)selfr   tokkwargse	__class__r   m/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/fsspec/implementations/jupyter.pyr      s   

zJupyterFileSystem.__init__Tc                 K   s   |  |}| j| j d| }|jdkrt||  | }|d dkr-|d }n|g}|D ]}|d|d< |d |d dkrJd	|d< q2|rO|S d
d |D S )Nr     type	directorycontentpathnamenotebookfilec                 S   s   g | ]}|d  qS )r"   r   ).0or   r   r   
<listcomp><   s    z(JupyterFileSystem.ls.<locals>.<listcomp>)	_strip_protocolr   getr   status_codeFileNotFoundErrorraise_for_statusjsonpop)r   r!   detailr   routr&   r   r   r   ls)   s$   



zJupyterFileSystem.lsc                 K   sx   |  |}| j| j d| }|jdkrt||  | }|d dkr/|d  }nt	
|d }||| S )Nr   r   formattextr    )r(   r   r)   r   r*   r+   r,   r-   encodebase64	b64decode)r   r!   startendr   r0   r1   br   r   r   cat_file>   s   

zJupyterFileSystem.cat_filec                 K   sV   |  |}|ddd |t|t| ddd}| jj| j d| |d d S )Nr   r   r6   r$   )r"   r!   sizer    r3   r   r-   )	r(   rsplitlenr6   	b64encodedecoder   putr   )r   r!   value_r-   r   r   r   	pipe_fileL   s   
 zJupyterFileSystem.pipe_filec                 K   sj   |  |}|rd|v r| |ddd d |ddd |d d dd}| jj| j d| |d d S )	Nr   r   r   Tr<   r   )r"   r!   r=   r    r   r>   )r(   mkdirr?   r   rC   r   )r   r!   Zcreate_parentsr   r-   r   r   r   rG   X   s   
 zJupyterFileSystem.mkdirFc                 K   s0   ||krd S | j j| j d| d|id d S )Nr   r!   r>   )r   patchr   )r   Zpath1Zpath2	recursiveZmaxdepthr   r   r   r   mve   s   $zJupyterFileSystem.mvc                 C   s&   |  |}| j| j d|  d S )Nr   )r(   r   deleter   )r   r!   r   r   r   _rmj   s   
zJupyterFileSystem._rmrbc                 K   s4   |  |}|dkr| |}t|S t| |ddS )NrM   wb)mode)r(   r;   ioBytesIOSimpleFileWriter)r   r!   rO   r   datar   r   r   _openn   s
   


zJupyterFileSystem._open)N)T)NN)FN)rM   )__name__
__module____qualname____doc__protocolr   r2   r;   rF   rG   rJ   rL   rT   __classcell__r   r   r   r   r   
   s    



r   c                   @   s   e Zd ZdddZdS )rR   Fc                 C   s6   |du rdS | j d | j  }| j| j| dS )zWNever uploads a chunk until file is done

        Not suitable for large files
        Fr   N)bufferseekreadfsrF   r!   )r   finalrS   r   r   r   _upload_chunkx   s
   
zSimpleFileWriter._upload_chunkN)F)rU   rV   rW   r`   r   r   r   r   rR   w   s    rR   )
r6   rP   r	   r   ZfsspecZAbstractFileSystemr   specZAbstractBufferedFilerR   r   r   r   r   <module>   s    m