%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/duplicity/backends/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/duplicity/backends/__pycache__/onedrivebackend.cpython-312.pyc

�

�2e�?���ddlZddlZddlZddlZddlZddlmZddlmZddlmZddl	m
Z
Gd�dejj�Z
Gd�d	e�ZGd
�de�ZGd�d
e�Zejj%de
�y)�N)�config)�log)�util)�BackendExceptionc�H�eZdZdZdZdZd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
y)
�OneDriveBackendz8Uses Microsoft OneDrive (formerly SkyDrive) for backups.z!https://graph.microsoft.com/v1.0/ic��tjjj||�|jjd�|_tjjdd�|_
|jdz�d|j�d�|_|jdk(rtd��tjdkDrtd	��|j�y)
N�/�DUPLICITY_ONEDRIVE_ROOTzme/drivez/rootz:/�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�
drive_root�directory_onedrive_pathrr�volsize�initialize_oauth2_session)�self�
parsed_urls  �D/usr/lib/python3/dist-packages/duplicity/backends/onedrivebackend.pyrzOneDriveBackend.__init__5s������!�!�*�*�4��<�#���/�/��4���
�*�*�.�.�)B�J�O���*.�/�/�G�*C�)D�B�t�~�~�FV�VW�'X��$��>�>�R��"�j��
��>�>�4�5�"�g��
�	
�&�&�(�c
�\�tjjd�}tjjd�}tdtj
dz�D]5}	|r|rt
||�|_yt|j�|_yy#t$r�}|tj
k\r|�tjtd�||jjt!j"|�fz�t%j&tj(�Yd}~��d}~wwxYw)N�OAUTH2_CLIENT_ID�OAUTH2_REFRESH_TOKEN�z:Attempt of initialize_oauth2_session Nr. %s failed. %s: %s)rrr�ranger�num_retries�ExternalOAuth2Session�http_client�DefaultOAuth2Session�API_URI�	Exceptionr�Warn�_�	__class__�__name__r�uexc�time�sleep�backend_retry_delay)r�	client_id�
refresh_token�n�es     rrz)OneDriveBackend.initialize_oauth2_sessionLs����J�J�N�N�#5�6�	��
�
���'=�>�
��q�&�,�,�q�0�1�	7�A�

7���'<�Y�
�'V�D�$��(<�D�L�L�'I�D�$��
	7���
7���*�*�*��G�����R�S��!�+�+�.�.��	�	�!��=�>���
�
�6�5�5�6�6��
7�s� B�7B�	D+�BD&�&D+c��g}|j|jjd�zdz}	|jj	|t
j��}|jdk(rnF|j�|j�}d|vrtd|����||dz
}d|vr|d}nn��|D�cgc]}|d��	c}Scc}w)	Nr
z
:/children��timeout��valuez+Malformed JSON: expected "value" member in z@odata.nextLink�name)r(r�rstripr&rrr8�status_code�raise_for_status�jsonr)r�accum�next_url�response�responseJson�xs      r�_listzOneDriveBackend._list_s������<�<�$�">�">�"E�"E�c�"J�J�\�Y����'�'�+�+�H�f�n�n�+�M�H��#�#�s�*���%�%�'�#�=�=�?�L��l�*�&�*U�Vb�Uc�(d�f�f��\�'�*�*�E� �L�0�'�(9�:����$)�)�a��&�	�)�)��)s�4Cc��|jd�}|jd�5}|jj|j|j
z|zdzdtj��}|j�|jd��D]}|s�|j|��|j�ddd�y#1swYyxYw)N�UTF-8�wbz	:/contentT)�streamr8i)�
chunk_size)�decode�openr&rr(rrr8r>�iter_content�write�flush)r�remote_filename�
local_path�frB�chunks      r�_getzOneDriveBackend._getts���)�0�0��9��
�_�_�T�
"�
	�a��'�'�+�+����t�;�;�;�o�M�P[�[�����,��H�

�%�%�'�!�.�.�$�.�?�
#����G�G�E�N�
#�
�G�G�I�
	�
	�
	�s�A1C�#C�C
c���|jd�}tjj|j�}tj
�}|jj|j|jzdztj��}|j�d|j�vr||j�djdd�}|rWtjdt!|����||kDr1t#d|j�dt!|��d	t!|��d
���tjdtj
�|z
d�d
��|j%�5}tj
�}|j|j&z|zdz}|jj)|tj��}|j�tj*|j,jd��}	d|	vrt#d|�d|j,����|	d}
d}d|j.z}	|j1||j.z�}
t3|
�dk(rn�t3|
��dt!|��dt!|t3|
�zdz
��dt!|���d�}tjd|�d|d���|jj5|
||
tj��}|j�|t3|
�z
}��tjdtj
�|z
d�d
��ddd�y#1swYyxYw)NrGz?$select=quotar7�quota�	remainingzBytes available: zOut of space: trying to store "z" (z bytes), but only z bytes available on OneDrive.zChecked quota in rR�sz:/createUploadSession�	uploadUrl�File "z7" cannot be uploaded: could not create upload session: ri�zbytes �-r"r
)zContent-Length�
Content-RangezPUT � r\)�headers�datar8zPUT file in )rKrr�getsizer;r/r&rr(rrr8r>r?r�Debug�intrrLr�post�loads�content�REQUIRED_FRAGMENT_SIZE_MULTIPLE�read�len�put)r�source_pathrP�source_size�startrB�	available�source_file�url�
response_jsonrY�offset�desired_num_fragmentsrSr^s               r�_putzOneDriveBackend._put�s!��
*�0�0��9���g�g�o�o�k�&6�&6�7���	�	����#�#�'�'����t���(F�IY�(Y�ci�cq�cq�'�r���!�!�#��h�m�m�o�%� �
�
���0�4�4�[�$�G�I���	�	�-�c�)�n�-=�>�?���*�*�=�k�>N�>N�=O�s�SV�Wb�Sc�Rd�e(�(+�I��'7�7T�V���	�	�	�%�d�i�i�k�E�&9�!�%<�A�>�?�
�
�
�
�!	?�;��I�I�K�E��,�,��!=�!=�=��O�Ri�i�C��'�'�,�,�S�&�.�.�,�I�H��%�%�'� �J�J�x�'7�'7�'>�'>�w�'G�H�M��-�/�&� �� 1�2<�<D�<L�<L�;M�O���&�k�2�I��F�$4��8\�8\�$\�!��#�(�(�)>��Ae�Ae�)e�f���u�:��?��),�U���'-�c�&�k�]�!�C���U��@S�VW�@W�<X�;Y�YZ�[^�_j�[k�Zl�%m����	�	�D�� 1��7�?�3K�2L�M�N��+�+�/�/�	�7�QV�`f�`n�`n�/�o���)�)�+��#�e�*�$���
�I�I��T�Y�Y�[�5�%8��$;�1�=�>�C!	?�!	?�!	?�s
�1GM�Mc��|jd�}|jj|j|jz|zt
j��}|jdk(rtd|�d���|j�y)NrGr7r9rZz&" cannot be deleted: it does not exist)
rKr&�deleter(rrr8r=rr>�rrPrBs   r�_deletezOneDriveBackend._delete�s}��)�0�0��9���#�#�*�*��L�L�4�7�7�7�/�I��N�N�+�
�����3�&�"�f�_�,=�=c�$d�f�f��!�!�#rc�Z�|jd�}|jj|j|jz|zt
j��}|jdk7rddiSd|j�vrtd|j�����d|j�diS)NrGr7���size���z*Malformed JSON: expected "size" member in )
rKr&rr(rrr8r=r?rrvs   r�_queryzOneDriveBackend._query�s���)�0�0��9���#�#�'�'��L�L�4�7�7�7�/�I��N�N�(�
�����3�&��B�<�������(�"�&P�QY�Q^�Q^�Q`�Pa�$b�d�d���
�
���/�0�0rc�$�|j�y�N)r)rs r�_retry_cleanupzOneDriveBackend._retry_cleanup�s���&�&�(rN)r-�
__module__�__qualname__�__doc__r(rfrrrErTrsrwr|r�rrrr.s9��B�1�G�&,�#�)�.7�&*�*�8?�t$�
1�)rrc�2�eZdZdZdZd�Zd�Zd�Zd�Zd�Z	y)	�OneDriveOAuth2SessionzDA tiny wrapper for OAuth2Session that handles some OneDrive details.z:https://login.microsoftonline.com/common/oauth2/v2.0/tokenc��dtjd<	ddlm}||_d|_y#t
$r}t
dt|�����d}~wwxYw)N�TRUE�OAUTHLIB_RELAX_TOKEN_SCOPEr)�
OAuth2SessionzeOneDrive backend requires python-requests-oauthlib to be installed. Please install it and try again.
)	rr�requests_oauthlibr��
session_class�ImportErrorr�str�session)rr�r5s   rrzOneDriveOAuth2Session.__init__�sb��4:��
�
�/�0�	�

8�!.�D�������	�"�@�@C�A��x�I��
��	�s�
*�	A�A
�
Ac�:�|jj|i|��Sr~)r�r�r�args�kwargss   rrzOneDriveOAuth2Session.get�����t�|�|����0��0�0rc�:�|jj|i|��Sr~)r�rir�s   rrizOneDriveOAuth2Session.put�r�rc�:�|jj|i|��Sr~)r�rcr�s   rrczOneDriveOAuth2Session.post�s�� �t�|�|� � �$�1�&�1�1rc�:�|jj|i|��Sr~)r�rur�s   rruzOneDriveOAuth2Session.delete�s��"�t�|�|�"�"�D�3�F�3�3rN)
r-r�r�r��OAUTH_TOKEN_URIrrrircrur�rrr�r��s#��N�R�O��41�1�2�4rr�c����eZdZdZej
j
ejjdd��Z	ejdd�ZdZdZ
gd�Z�fd	�Zd
�Z�xZS)r'z?A possibly-interactive console session using a built-in API key�DUPLICITY_ONEDRIVE_TOKENz%~/.duplicity_onedrive_oauthtoken.json�DUPLICITY_ONEDRIVE_CLIENT_IDz$1612f841-ae01-46ab-9535-43ba6ec04029z>https://login.microsoftonline.com/common/oauth2/v2.0/authorizez<https://login.microsoftonline.com/common/oauth2/nativeclient)z
Files.ReadzFiles.ReadWritezFiles.Read.AllzFiles.ReadWrite.Allz	User.Read�offline_accessc	���t�	|��d}	t|j�5}t	j
|�}ddd�|j|j|j|j|d|ji|j|j��|_|�5|jj!|jt"j$��|jj'|dzt"j$��}|j(dk7rd}|��]t*j,j/�rt*j0j/�s#tj2d|j�d	��|jj5|j6d
��\}}t9d|�d
��t;d�j=�}|jj?|j|dt"j$��}|jj'|dzt"j$��}|jA�	t|jd�5}t	jB||�ddd�yy#1swY��<xYw#t$r$}tjd|�d��Yd}~��gd}~wwxYw#1swYyxYw#tD$r/}tjd|j�d|���Yd}~yd}~wwxYw)NzJCould not load OAuth2 token. Trying to create a new one. (original error: �)r2)�scope�redirect_uri�token�auto_refresh_kwargs�auto_refresh_url�
token_updaterr7�meryz*The OAuth2 token could not be loaded from z_ and you are not running duplicity interactively, so duplicity cannot possibly access OneDrive.�touch)�displayzF
In order to authorize duplicity to access your OneDrive, please open zF in a browser and copy the URL of the blank page the dialog leads to.
zURL of the blank page: T)�authorization_response�include_client_idr8�w�#Could not save the OAuth2 token to zj. This means you need to do the OAuth2 authorization process on every start of duplicity. Original error: )#�superrrL�OAUTH_TOKEN_PATHr?�load�IOErrorr�Errorr��	CLIENT_ID�OAUTH_SCOPE�OAUTH_REDIRECT_URIr�r�r�r3rr8rr=�sys�stdout�isatty�stdin�
FatalError�authorization_url�OAUTH_AUTHORIZE_URI�print�input�strip�fetch_tokenr>�dumpr))
r�api_urir�rRr5�user_info_responser��state�
redirected_tor,s
         �rrzDefaultOAuth2Session.__init__s����
������	i��d�+�+�,�
%���	�	�!���
%�
�)�)��N�N��"�"��0�0���T�^�^�!�"�1�1��,�,�*�

������L�L�&�&�t�';�';�V�^�^�&�T�"�\�\�-�-�g��n�f�n�n�-�U���)�)�S�0��E��=��:�:�$�$�&�c�i�i�.>�.>�.@����@��AV�AV�@W�Xe�f��(,�|�|�'E�'E�d�F^�F^�ho�'E�'p�$��u��Y�Zk�Yl�mY�Z�
�
"�";�<�B�B�D�M��L�L�,�,��$�$�'4�"&����	-��E�"&���!1�!1�'�D�.�&�.�.�!1�!Y���/�/�1�
��$�/�/��5�(���I�I�e�Q�'�(�(�5�;
%�
%���	i��I�I�b�cd�be�ef�g�h�h��	i��j(�(���
��	�	�9�$�:O�:O�9P�Qa�ab�`c�e����
�sc�J�I8�J�K�J5�.K�8J�=J�	J2�J-�-J2�5J>�:K�>K�	K9�
%K4�4K9c��	t|jd�5}tj||�ddd�y#1swYyxYw#t$r/}tjd|j�d|���Yd}~yd}~wwxYw)Nr�r�z]. This means you may need to do the OAuth2 authorization process again soon. Original error: )rLr�r?r�r)rr�)rr�rRr5s    rr�z"DefaultOAuth2Session.token_updater_s|��	��d�+�+�S�1�
$�Q��	�	�%��#�
$�
$�
$���	��I�I�5�d�6K�6K�5L�ML�LM�3�P�
�
��	�s0�A�8�A�A�A�A�	A<�
%A7�7A<)r-r�r�r�rr�
expanduserrrr��getenvr�r�r�r�rr��
__classcell__�r,s@rr'r'sd���I��w�w�)�)�
�
�
���1�3Z�[�����	�	�8�:`�a�I�Z��W���K�B�Hrr'c�"��eZdZdZ�fd�Z�xZS)r%z?Caller is managing tokens and provides an active refresh token.c����t�|��d|i}|j||d|i|j��|_|jj|jtj��y)Nr3r2)r�r�r�r7)r�rr�r�r�r3rr8)rr2r3r�r,s    �rrzExternalOAuth2Session.__init__mss���
����
�]�
���)�)����Y�!�"�1�1�
*�
���	
���"�"�4�#7�#7����"�Pr)r-r�r�r�rr�r�s@rr%r%js���I�Q�Qrr%�onedrive)r?rr�r/�duplicity.backendr
rrr�duplicity.errorsrrrr�objectr�r'r%�register_backendr�rr�<module>r�s���4�	�
������-�e)�i�'�'�/�/�e)�P)4�F�)4�Xe�0�e�PQ�1�Q�0
���"�"�:��?r

Zerion Mini Shell 1.0