
    ޛ7i                         d dl Z d dlZd dlZd dlZd dlZ G d dej
                        Z G d dej                  j                        Z	y)    Nc                   \     e Zd ZdZdZd fd	ZddZddZd ZddZ	ddZ
d	 Zdd
Z xZS )JupyterFileSystemz?View of the files as seen by a Jupyter server (notebook or lab))jupyterjlabc                 h   d|v r1|	 t        j                  d|      d   }|j	                  dd      d   }|j                  d      dz   | _        t        j                         | _	        |rd	| | j                  j                  d
<   t        | 0  di | y# t        $ r}t        d      |d}~ww xY w)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__s        [/home/rose/Desktop/poly/venv/lib/python3.12/site-packages/fsspec/implementations/jupyter.pyr   zJupyterFileSystem.__init__   s     #:{I**%8#>qAC ))C#A&C::c?_4'')6<SENDLL  1"6" " I$%@AqHIs   B 	B1 B,,B1c                    | j                  |      }| j                  j                  | j                   d|       }|j                  dk(  rt        |      |j                          |j                         }|d   dk(  r|d   }n|g}|D ]5  }|j                  d      |d<   |j                  d       |d   dk(  s1d	|d<   7 |r|S |D cg c]  }|d   	 c}S c c}w )
Nr
     type	directorycontentpathnamenotebookfile)	_strip_protocolr   getr   status_codeFileNotFoundErrorraise_for_statusjsonpop)r   r%   detailr   routos          r   lszJupyterFileSystem.ls)   s    ##D)LLz4&12==C#D))	ffhv;+%i.C%CAfAfIEE)yJ&"&		 
 J#&'3a&	3'''s   	Cc                 ^   | j                  |      }| j                  j                  | j                   d|       }|j                  dk(  rt        |      |j                          |j                         }|d   dk(  r|d   j                         }nt        j                  |d         }||| S )Nr
   r!   formattextr$   )r)   r   r*   r   r+   r,   r-   r.   encodebase64	b64decode)r   r%   startendr   r1   r2   bs           r   cat_filezJupyterFileSystem.cat_file>   s    ##D)LLz4&12==C#D))	ffhx=F"I%%'A  Y0As|    c                 
   | j                  |      }|j                  dd      d   |t        |      t        j                  |      j                         ddd}| j                  j                  | j                   d| |       y )Nr
   r	   r9   r(   )r&   r%   sizer$   r6   r"   r.   )	r)   rsplitlenr9   	b64encodedecoder   putr   )r   r%   value_r.   s        r   	pipe_filezJupyterFileSystem.pipe_fileL   s{    ##D)KKQ'+J''.557
 	DHH:Qtf-D9r?   c                 
   | j                  |      }|r)d|v r%| j                  |j                  dd      d   d       |j                  dd      d   |d d dd}| j                  j	                  | j
                   d| |       y )	Nr
   r	   r   TrA   r#   )r&   r%   rB   r$   r"   rC   )r)   mkdirrD   r   rH   r   )r   r%   create_parentsr   r.   s        r   rM   zJupyterFileSystem.mkdirX   s    ##D)cTkJJt{{3*1-t4KKQ'+
 	DHH:Qtf-D9r?   c                 l    ||k(  ry | j                   j                  | j                   d| d|i       y )Nr
   r%   rC   )r   patchr   )r   path1path2	recursivemaxdepthr   s         r   mvzJupyterFileSystem.mve   s6    E>dhhZq0Gr?   c                 z    | j                  |      }| j                  j                  | j                   d|        y )Nr
   )r)   r   deleter   )r   r%   s     r   _rmzJupyterFileSystem._rmj   s3    ##D)txxj$01r?   c                     | j                  |      }|dk(  r&| j                  |      }t        j                  |      S t	        | |d      S )Nrbwb)mode)r)   r>   ioBytesIOSimpleFileWriter)r   r%   r\   r   datas        r   _openzJupyterFileSystem._openn   sE    ##D)4<==&D::d###D$T::r?   )N)T)NN)FN)rZ   )__name__
__module____qualname____doc__protocolr   r4   r>   rK   rM   rU   rX   ra   __classcell__)r   s   @r   r   r   
   s4    I"H#4(*
::H
2;r?   r   c                       e Zd ZddZy)r_   c                     |du ry| j                   j                  d       | j                   j                         }| j                  j	                  | j
                  |       y)zWNever uploads a chunk until file is done

        Not suitable for large files
        Fr   N)bufferseekreadfsrK   r%   )r   finalr`   s      r   _upload_chunkzSimpleFileWriter._upload_chunkx   sJ    
 E>{{!$))T*r?   N)F)rb   rc   rd   ro   r   r?   r   r_   r_   w   s    	+r?   r_   )
r9   r]   r   r   fsspecAbstractFileSystemr   specAbstractBufferedFiler_   r   r?   r   <module>rt      s?     	 	  j;11 j;Z
+v{{77 
+r?   