o
    iw
                     @   s<   d dl mZ d dlmZ d dlZd dlZG dd deZdS )    )FileContentsManager)webNc                       s*   e Zd ZdZd fdd	Zdd Z  ZS )LargeFileManagerzHandle large file upload. c              
      sj  | dd}|dur|d}d|vrtdd|d dkr+tdd|d  d	d
|vr;|d dkr;tdd| |}z.|dkra| jd| | j||d t 	||d
 | d n| 
||d
 | d W n+ tjyw     ty } z| jjd||dd tdd| d| |d}~ww | j |dd}|dkr| j||d |S t ||S )z9Save the file model and return the model with no content.chunkN/type  zNo file type providedfilezFile type "z*" is not supported for large file transfercontent	directoryzNo file content provided   z	Saving %s)modelpathformatzError while saving file: %s %sT)exc_infoi  z$Unexpected error while saving file:  F)r   )r   os_path)getstripr   	HTTPError_get_os_pathlogdebugrun_pre_save_hooksuper
_save_file_save_large_file	Exceptionerrorrun_post_save_hooksave)selfr   r   r   r   e	__class__ f/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/notebook/services/contents/largefilemanager.pyr"   	   s:   

zLargeFileManager.savec              
   C   s  |dvr
t ddz|dkr|d}n
|d}t|}W n ty9 } zt dd| d| |d	}~ww | |? tj	|rTtj
tj|t|}t|d
}|| W d	   n1 siw   Y  W d	   d	S W d	   d	S 1 sw   Y  d	S )zSave content of a generic file.>   textbase64r	   z:Must specify format of file contents as 'text' or 'base64'r)   utf8asciizEncoding error saving z: Nab)r   r   encoder*   	b64decoder   perm_to_403osr   islinkjoindirnamereadlinkopenwrite)r#   r   r   r   bcontent	b64_bytesr$   fr'   r'   r(   r   .   s8   

"z!LargeFileManager._save_large_file)r   )__name__
__module____qualname____doc__r"   r   __classcell__r'   r'   r%   r(   r      s    %r   )&notebook.services.contents.filemanagerr   tornador   r*   r1   r   r'   r'   r'   r(   <module>   s
    