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__/onedrivebackend.cpython-310.pyc
o

K�a<�@s�ddlmZddlmZddlmZddlmZddlmZddlZddl	Z	ddl
Z
ddlZddlZ
ddlmZddl
mZdd	l
mZGd
d�de
jj�ZGdd
�d
e�ZGdd�de�ZGdd�de�Ze
j�de�dS)�)�print_function)�division)�old_div)�input)�strN)�BackendException)�config)�logc@sXeZdZdZdZdZdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dS)�OneDriveBackendz8Uses Microsoft OneDrive (formerly SkyDrive) for backups.z!https://graph.microsoft.com/v1.0/icCsltjj�||�|j�d�|_tj�	dd�}d||jf|_
|jdkr'td��tj
dkr0td��|��dS)	N�/�
ONEDRIVE_ROOTz
me/drive/rootz%s:/%s/�zTYou did not specify a path. Please specify a path, e.g. onedrive://duplicity_backupsl
zQYour --volsize is bigger than 10 GiB, which is the maximum file size on OneDrive.)�	duplicity�backend�Backend�__init__�path�lstrip�	directory�os�environ�get�directory_onedrive_pathrr�volsize�initialize_oauth2_session)�self�
parsed_url�
onedrive_root�r�D/usr/lib/python3/dist-packages/duplicity/backends/onedrivebackend.pyr7s
�
�zOneDriveBackend.__init__cCs@tj�d�}tj�d�}|r|rt||�|_dSt|j�|_dS)N�OAUTH2_CLIENT_ID�OAUTH2_REFRESH_TOKEN)rrr�ExternalOAuth2Session�http_client�DefaultOAuth2Session�API_URI)r�	client_id�
refresh_tokenrrrrIs
z)OneDriveBackend.initialize_oauth2_sessioncCs�g}|j|j�d�d}	|j�|�}|jdkrn#|��|��}d|vr,td|��||d7}d|vr;|d}nnqdd	�|D�S)
Nrz
:/childrenT��valuez-Malformed JSON: expected "value" member in %sz@odata.nextLinkcSsg|]}|d�qS)�namer)�.0�xrrr�
<listcomp>fsz)OneDriveBackend._list.<locals>.<listcomp>)	r%r�rstripr#r�status_code�raise_for_status�jsonr)r�accum�next_url�response�responseJsonrrr�_listQs(
��
�zOneDriveBackend._listcCs�|�d�}|�d��1}|jj|j|j|ddd�}|��|jdd�D]	}|r.|�|�q%|�	�Wd�dS1s>wYdS)N�UTF-8�wbz	:/contentT)�streami)�
chunk_size)
�decode�openr#rr%rr0�iter_content�write�flush)r�remote_filename�
local_path�fr4�chunkrrr�_geths
�
�
"�zOneDriveBackend._getcCs�|�d�}tj�|j�}t��}|j�|jd�}|�	�d|�
�vrD|�
�d�dd�}|rDt�d|�||krDt
d|j||f��t�dt��|�|����}t��}|j|j|d}|j�|�}|�	�t
�|j�d��}	d	|	vr�t
d
||jf��|	d	}
d}td|j�}	|�||j�}
t|
�dkr�n3dt|
�d||t|
�d|fd�}t�d||df�|jj|
||
d�}|�	�|t|
�7}q�t�dt��|�Wd�dS1s�wYdS)Nr7zme/drive?$select=quota�quota�	remainingzBytes available: %dzWOut of space: trying to store "%s" (%d bytes), but only %d bytes available on OneDrive.zChecked quota in %fsz:/createUploadSession�	uploadUrlzAFile "%s" cannot be uploaded: could not create upload session: %sri�Tz%dzbytes %d-%d/%d�)zContent-Length�
Content-Rangez	PUT %s %srI)�headers�datazPUT file in %fs)r;rr�getsizer*�timer#rr%r0r1r	�Debugrr<r�post�loads�contentr�REQUIRED_FRAGMENT_SIZE_MULTIPLE�read�len�put)r�source_pathr@�source_size�startr4�	available�source_file�url�
response_jsonrG�offset�desired_num_fragmentsrCrJrrr�_putssf
���
��
���"�zOneDriveBackend._putcCsD|�d�}|j�|j|j|�}|jdkrtd|��|��dS)Nr7r(z.File "%s" cannot be deleted: it does not exist)r;r#�deleter%rr/rr0�rr@r4rrr�_delete�s

��zOneDriveBackend._deletecCs`|�d�}|j�|j|j|�}|jdkrddiSd|��vr(td|����d|��diS)Nr7���size���z,Malformed JSON: expected "size" member in %s)r;r#rr%rr/r1rrarrr�_query�s

��zOneDriveBackend._querycCs|��dS�N)r)rrrr�_retry_cleanup�szOneDriveBackend._retry_cleanupN)�__name__�
__module__�__qualname__�__doc__r%rRrrr6rDr_rbrfrhrrrrr
0s9	r
c@s<eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�OneDriveOAuth2SessionzDA tiny wrapper for OAuth2Session that handles some OneDrive details.z(https://login.live.com/oauth20_token.srfc
CsTdtjd<zddlm}||_Wnty$}ztdt|���d}~wwd|_dS)N�TRUE�OAUTHLIB_RELAX_TOKEN_SCOPEr)�
OAuth2SessionzeOneDrive backend requires python-requests-oauthlib to be installed. Please install it and try again.
)	rr�requests_oauthlibrp�
session_class�ImportErrorrr�session)rrp�errrr�s

����
zOneDriveOAuth2Session.__init__cO�|jj|i|��Srg)rtr�r�args�kwargsrrrr��zOneDriveOAuth2Session.getcOrvrg)rtrUrwrrrrU�rzzOneDriveOAuth2Session.putcOrvrg)rtrOrwrrrrO�rzzOneDriveOAuth2Session.postcOrvrg)rtr`rwrrrr`�rzzOneDriveOAuth2Session.deleteN)
rirjrkrl�OAUTH_TOKEN_URIrrrUrOr`rrrrrm�srmcsHeZdZdZej�d�ZdZdZ	dZ
gd�Z�fdd�Zd	d
�Z
�ZS)r$z?A possibly-interactive console session using a built-in API keyz%~/.duplicity_onedrive_oauthtoken.json�000000004C12E85Dz,https://login.live.com/oauth20_authorize.srfz*https://login.live.com/oauth20_desktop.srf)z
Files.ReadzFiles.ReadWritez	User.Read�offline_accessc	
s�tt|���d}zt|j��
}t�|�}Wd�n1swYWnty>}z
t�	d|�WYd}~nd}~ww|j
|j|j|j
|d|ji|j|jd�|_|dur_|j�|j�|j�|d�}|jdkrnd}|dur�tj��r|tj��s�t�d|j�|jj|jdd�\}}t�td	|�t�td
���}|jj|j|d�}|j�|d�}|��z!t|jd��}t� ||�Wd�WdS1s�wYWdSt!y�}zt�	d
|j|f�WYd}~dSd}~wwdS)NzMCould not load OAuth2 token. Trying to create a new one. (original error: %s)r&)�scope�redirect_uri�token�auto_refresh_kwargs�auto_refresh_url�
token_updater�mercz�The OAuth2 token could not be loaded from %s and you are not running duplicity interactively, so duplicity cannot possibly access OneDrive.�touch)�displayz�In order to authorize duplicity to access your OneDrive, please open %s in a browser and copy the URL of the blank page the dialog leads to.zURL of the blank page: )�authorization_response�wz�Could not save the OAuth2 token to %s. This means you need to do the OAuth2 authorization process on every start of duplicity. Original error: %s)"�superr$rr<�OAUTH_TOKEN_PATHr1�load�IOErrorr	�Errorrr�	CLIENT_ID�OAUTH_SCOPE�OAUTH_REDIRECT_URIr{r�rtr'rr/�sys�stdout�isatty�stdin�
FatalError�authorization_url�OAUTH_AUTHORIZE_URI�printr�strip�fetch_tokenr0�dump�	Exception)	r�api_urir�rBru�user_info_responser��state�
redirected_to��	__class__rrr�sx�������
�
���&������zDefaultOAuth2Session.__init__c
Cs~z!t|jd��}t�||�Wd�WdS1swYWdSty>}zt�d|j|f�WYd}~dSd}~ww)Nr�z�Could not save the OAuth2 token to %s. This means you may need to do the OAuth2 authorization process again soon. Original error: %s)r<r�r1r�r�r	r�)rr�rBrurrrr�As&�����z"DefaultOAuth2Session.token_updater)rirjrkrlrr�
expanduserr�r�r�r�r�rr��
__classcell__rrr�rr$�s�Dr$cs eZdZdZ�fdd�Z�ZS)r"z?Caller is managing tokens and provides an active refresh token.csBtt|���d|i}|j||d|i|jd�|_|j�|j�dS)Nr'r&)r�r�r�)r�r"rrrr{rtr')rr&r'r�r�rrrOs���
zExternalOAuth2Session.__init__)rirjrkrlrr�rrr�rr"Msr"�onedrive)�
__future__rr�
past.utilsr�builtinsrrrMr1rr��duplicity.backendr�duplicity.errorsrrr	rrr
�objectrmr$r"�register_backendrrrr�<module>s&
*_