HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/duplicity/backends/__pycache__/megav3backend.cpython-310.pyc
o

��Hal(�@s�ddlmZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZe��Gdd�dej
j�Zej
�de�ej
j�dg�dS)	�)�print_functionN)�util)�BackendException)�standard_libraryc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
d dd�Zdd�Zdd�Zdd�ZdS)!�
Megav3BackendaxBackend for MEGA.nz cloud storage, only one that works for accounts created since Nov. 2018
    See https://github.com/megous/megatools/issues/411 for more details

    This MEGA backend resorts to official tools (MEGAcmd) as available at https://mega.nz/cmd
    MEGAcmd works through a single binary called "mega-cmd", which keeps state (for example,
    persisting a session). Multiple "mega-*" shell wrappers (ie. "mega-ls") exist as the user
    interface to "mega-cmd" and MEGA API
    The full MEGAcmd User Guide can be found in the software's GitHub page below :
    https://github.com/meganz/MEGAcmd/blob/master/UserGuide.mdc

Cs�tjj�||�|�d�|�d�|�d�|�d�|�d�|�d�|�d�|�d�|�d	�|�d
�|�d�|j|_|jdur�t�	d�d
|_
zt|j
d�}Wntyl}zt
d|j
f��d}~wwi}|D]}|�d�ddd�\}}t|���||��<qq|��|d|_|d|_n|j|_|j|_|j�dg�}t|�dko�|d��dv|_|��d|jdd�|_|��d|jg}	z|�|	�WdSty�}z
|�|j�WYd}~dSd}~ww)Nzmega-cmd�	mega-exec�	mega-help�mega-get�
mega-login�mega-logout�mega-ls�
mega-mkdir�mega-put�mega-rm�mega-whoami�HOMEz
/.megav3rc�rz\No password provided in URL and MEGA configuration file for duplicity does not exist as '%s'�=��Username�Password�	no_logoutr)�1�yes�true�/�) �	duplicity�backend�Backend�__init__�_check_binary_exists�hostname�	_hostname�username�os�getenv�_megarc�open�	Exceptionr�	partition�str�strip�close�	_username�	_password�password�
query_args�get�len�lower�
_no_logout�ensure_mega_cmd_running�path�_folder�
mega_login�subprocess_popen�_makedir)
�self�
parsed_url�	conf_file�e�myvars�line�name�var�no_logout_option�cmd�rF�B/usr/lib/python3/dist-packages/duplicity/backends/megav3backend.pyr .s`











����
�
��zMegav3Backend.__init__c
Cs<z
t�d|g�WdSty}ztd|f��d}~ww)zGChecks that a specified command exists in the running user command path�whichz�Command '%s' not found, make sure 'MEGAcmd' tools (https://mega.nz/cmd) is properly installed and in the running user command pathN)�
subprocess�check_outputr)r)r<rEr?rFrFrGr!js����z"Megav3Backend._check_binary_existscCs6ztjdtjtjd���WdStytd��w)z=Trigger any mega command to ensure mega-cmd server is runningr)�stdout�stderrzCannot execute mega commandN)rI�run�DEVNULL�check_returncoder)r�r<rFrFrGr6ws��z%Megav3Backend.ensure_mega_cmd_runningc
Csj|��dd|g}z|�|�WdSty4}zt|�}d|vr(td|f��td||f��d}~ww)z5Creates a remote directory (recursively if necessary)r
z-pzFolder already existszzFolder '%s' could not be created on MEGA because it already exists. Use another path or remove the folder in MEGA manuallyz/Folder '%s' could not be created, reason : '%s'N)r9r:r)r+r)r<r7rEr?�	error_strrFrFrGr;�s&
������zMegav3Backend._makedircCsDz	|�|���Wn	tyYnw|j|����|��d�dS)zwUploads file to the specified remote folder (tries to delete it first to make
        sure the new one can be uploaded))�
local_file�remote_fileN)�delete�decoder)�upload�
get_canonical)r<�source_path�remote_filenamerFrFrG�_put�s�

�zMegav3Backend._putcCs|j|��|j��d�dS)z-Downloads file from the specified remote path)rSrRN)�downloadrUrB)r<rY�
local_pathrFrFrG�_get�s
�zMegav3Backend._getcCs|jdd�S)z(Lists files in the specified remote pathT)�
files_only)�folder_contentsrPrFrFrG�_list�szMegav3Backend._listcCs|j|��d�dS)z+Deletes file from the specified remote path)rSN)rTrU)r<�filenamerFrFrG�_delete�szMegav3Backend._deletecCs,|jsdg}|�|�ddg}|�|�dS)z/Function called when backend is done being usedrr�exitN)r5r:)r<rErFrFrG�_close�s

zMegav3Backend._closec
Cs�z$tjdddd�}|��|j���d�d��}||jkr"td��Wd	Stj	y4|�
�td��ty{}z<|jd	urE|�
�|_d
|j|jg}ztj|tjd���Wntyo}z|�
�td|f��d	}~wwWYd	}~d	Sd	}~ww)
z0Helper function to check existing session existsr�T)�timeout�capture_output�:���zUsername is not matchz<Timed out while trying to determine if a MEGA session existsNr
)rLz&Could not log in to MEGA, error : '%s')rIrMrOrKrU�splitr,r.r)�TimeoutExpiredrdrr/�get_passwordrN)r<�result�current_usernamer?rErFrFrGr9�sH�
��

�
������zMegav3Backend.mega_loginFcCsBdd|jg}|��t�|�}|���d�}|rdd�|D�}|S)zHLists contents of a remote MEGA path, optionally ignoring subdirectoriesrz-l�
cSs$g|]}t�d|�r|��d�qS)z^-�)�re�searchrj)�.0�frFrFrG�
<listcomp>�s$z1Megav3Backend.folder_contents.<locals>.<listcomp>)r8r9rIrJrUrj)r<r^rE�filesrFrFrGr_�s
zMegav3Backend.folder_contentscCs*d|jd||g}|��|�|�dS)z(Downloads a file from a remote MEGA pathr	rN�r8r9r:)r<rSrRrErFrFrGr[��zMegav3Backend.downloadc
Cstd||jd|g}|��z|�|�WdSty9}zt|�}d|vr-td|f��td||f��d}~ww)z$Uploads a file to a remote MEGA pathrrzReached storage quotazwMEGA account over quota, could not write file : '%s' . Upgrade your storage at https://mega.nz/pro or remove some data.z/Failed writing file '%s' to MEGA, reason : '%s'N)r8r9r:r)r+r)r<rRrSrEr?rQrFrFrGrV�s&������zMegav3Backend.uploadcCs*dd|jd|g}|��|�|�dS)z&Deletes a file from a remote MEGA pathrz-frNrw)r<rSrErFrFrGrTrxzMegav3Backend.deleteN)F)�__name__�
__module__�__qualname__�__doc__r r!r6r;rZr]r`rbrdr9r_r[rVrTrFrFrFrGr#s 
<



$r�megav3)�
__future__rr%rqrI�duplicity.backendrr�duplicity.errorsr�futurer�install_aliasesrrr�register_backend�uses_netloc�extendrFrFrFrG�<module>su