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

��`V4�@s�ddlmZddlmZddlZddlmZddlmZddlmZddl	ZGdd�dej
j�Zej
�
d	e�	ej
�
d
e�	ej
�
de�ej
j�gd��dS)
�)�next)�strN)�log)�util)�BackendExceptionc@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�PyDriveBackendz)Connect to remote store using PyDrive APIc
stjj�||�zddl}ddlm}Wnty(}ztdt	|���d}~wwi|_
d|_d|jvrE|jdd|_d|jddd�|_
zddl
m}dd	lm}dd
lm}m}Wn=ty�}z1zddlm}dd	lm}dd
lm}m}Wnty�}ztdt	|���d}~wwWYd}~nd}~wwzddlm}	d|_Wndd
lm}
ddlm}d|_Ydtjvr�tjd}|jr�|	|j d|j!|dd�}
n|j"�#|�}|
|j d|j!|dd�}
|
�$|�%��|dd�}|
|_&nZdtjv�r
|tjddd�}|�'�nFdtjv�rLdtjv�rL|dd�}|�(tjd�|�)tjd�|j&du�r6|�'�n
|j*�r?|�+�n|�,�|�-tjd�ntd��||�|_.|j�r]|j}n0|j.�/ddi��0�}|�ru|dddd}n|j.�1dd i�}|�2�|ddd}|�3�|j4�5d!�}|D]c���s��q�dd"|d#i}|�6|j
�|j.�/|��0�}t7�fd$d%�|D�d�}|du�r�d&d|igd'�}|dd�6|j
�|�6|j
�|j.�1|�}|j�r�|j2d(did)�n|�2�|d}�q�||_8i|_9dS)*Nr)�buildz}PyDrive backend requires PyDrive and Google API client installation.
Please read the manpage for setup details.
Exception: %s�driveID�	teamDriveT)�corpora�teamDriveId�includeTeamDriveItems�supportsTeamDrives)�
GoogleAuth)�GoogleDrive��ApiRequestError�FileNotUploadedErrorzhPyDrive backend requires PyDrive installation.  Please read the manpage for setup details.
Exception: %s)�SignedJwtAssertionCredentials)�ServiceAccountCredentials)�cryptF�GOOGLE_DRIVE_ACCOUNT_KEY�@z%https://www.googleapis.com/auth/drive)�scopes�<)�http_timeout�GOOGLE_DRIVE_SETTINGS)�
settings_filer�GOOGLE_SECRETS_FILE�GOOGLE_CREDENTIALS_FILEzoGOOGLE_DRIVE_ACCOUNT_KEY or GOOGLE_DRIVE_SETTINGS environment variable not set. Please read the manpage to fix.�qz#'Root' in parents and trashed=false�parents�id�title�i_am_in_root�/�'�' in parents and trashed=falsec3s,�|]}|d�kr|ddkr|VqdS)r#�mimeType�"application/vnd.google-apps.folderN���.0�item��folder_namer*�C/usr/lib/python3/dist-packages/duplicity/backends/pydrivebackend.py�	<genexpr>�s���z*PyDriveBackend.__init__.<locals>.<genexpr>r))r#r(r!r��param):�	duplicity�backend�Backend�__init__�httplib2�apiclient.discoveryr�ImportErrorrr�
api_params�shared_drive_id�
query_args�
pydrive2.authr�pydrive2.driver�pydrive2.filesrr�pydrive.auth�
pydrive.drive�
pydrive.files�oauth2client.clientr�	oldClient�oauth2client.service_accountr�oauth2clientr�os�environ�username�hostname�Signer�from_string�	authorize�Http�credentials�CommandLineAuth�LoadClientConfigFile�LoadCredentialsFile�access_token_expired�Refresh�	Authorize�SaveCredentialsFile�drive�ListFile�GetList�
CreateFile�Upload�Delete�path�split�updater�folder�id_cache)�self�
parsed_urlr8r�errrrrrr�account_keyrP�signer�gauth�parent_folder_id�	file_list�file_in_root�folder_names�list_file_argsra�create_file_argsr*r.r0r7!s����
�������


����




�
��
�
zPyDriveBackend.__init__c
Cs�zddlm}Wntyddlm}Ynwt�|�}||jvr�|j|}|j�d|i�}z*|d|krX|ddsX|dD]}|d|j	krWt
�d||f�|WSq@Wn|yu}z|jdj
jd	krk�WYd}~nd}~wwt
�d
||f�|j|=d||j	f}d}||d
�}	|	�|j�|j�|	���}
t|
�dkr�t
�td�|f�n|
r�|
dd}|
dd|j|<t
�d||f�|
dSt
�d|f�dS)Nr)rr"r#�labels�trashedr!z7PyDrive backend: found file '%s' with id %s in ID cachei�zCPyDrive backend: invalidating '%s' (previously ID %s) from ID cachez0title='%s' and '%s' in parents and trashed=falsez>items(title,id,fileSize,downloadUrl,exportLinks),nextPageToken�r �fields�z,PyDrive backend: multiple files called '%s'.zFPyDrive backend: found file '%s' with id %s on server, adding to cachez:PyDrive backend: file '%s' not found in cache or on server)r@rr:rCr�fsdecoderbrXr[rar�Info�args�resp�statusr`r;rYrZ�len�
FatalError�_)rc�filenamer�file_id�
drive_file�parent�errorr rrrm�flistr*r*r0�file_by_name�s^�


�
������
��zPyDriveBackend.file_by_namecCs|�|�}|durdS|dS)N�r")r�)rcr|r~r*r*r0�
id_by_name�s
zPyDriveBackend.id_by_namecCs�t�|�}|�|�}|dur1|d|jd�gd�}|dd�|j�|j�|�}t�	d|f�nt�	d||df�|�
t�|j��|jrQ|j
d	d
id�n|�
�|d|j|<dS)Nzdrive#fileLink)�kindr")r#r!r!rz'PyDrive backend: creating new file '%s'z:PyDrive backend: replacing existing file '%s' with id '%s'r"rTr2)rrtr�rar`r;rXr[rru�SetContentFile�namer<r\rb)rc�source_path�remote_filenamer~rnr*r*r0�_put�s&

���zPyDriveBackend._putcCs |�|�}|�t�|j��dS)N)r��GetContentFilerrtr�)rcr��
local_pathr~r*r*r0�_get�s
zPyDriveBackend._getcCs~d|jddd�}|�|j�|j�|���}tdd�|D��}t|j�	��D]}||vr:|�
|�dur:|�|�q(t|�S)Nr&r'zitems(title,id),nextPageTokenrqcss�|]}|dVqdS)r#Nr*r+r*r*r0r1�s�z'PyDriveBackend._list.<locals>.<genexpr>)rar`r;rXrYrZ�set�listrb�keysr��add)rcrm�drive_files�	filenamesr|r*r*r0�_list�s�
�zPyDriveBackend._listcCst|�|�}|dkrt�dt�|�f�dS|jr+|jjj�	�j
|ddid���dS|jjj�	�j
|d���dS)Nr�z2File '%s' does not exist while trying to delete itrT)�fileIdr3)r�)r�r�Warnrrtr<rX�auth�service�files�delete�execute)rcr|r}r*r*r0�_delete�s
$zPyDriveBackend._deletecCs2|�|�}|durd}d|iSt|d�}d|iS)N����fileSize�size)r��int)rcr|r~r�r*r*r0�_querys
�zPyDriveBackend._querycCsdz
ddlm}m}Wntyddlm}m}Ynwt||�r%tjjSt||�r.tjj	Stjj
S)Nrr)r@rrr:rC�
isinstancer�	ErrorCode�backend_not_found�backend_permission_denied�
backend_error)rc�	operationr�rrr*r*r0�_error_codes�

zPyDriveBackend._error_codeN)
�__name__�
__module__�__qualname__�__doc__r7r�r�r�r�r�r�r�r�r*r*r*r0rsv0	r�pydrive�
pydrive+gdocs�gdocs)r�r�r�)�builtinsrrrHr4rr�duplicity.errorsr�duplicity.backendr5r6r�register_backend�uses_netloc�extendr*r*r*r0�<module>sw