%PDF- %PDF-
Mini Shell

Mini Shell

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

�

�2e�@����ddlZddlZddlZddlZddlZddlmZddlZ	ddl	m
Z
ddl	mZddlm
Z
Gd�de	jj�Ze	jj#de�y)	�N)�DEFAULT_BUFFER_SIZE)�config)�log)�BackendExceptionc��eZdZdZej
j
d�ZdZdZ	dZ
ddgZdZd	Z
d
Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�	ADBackendz�
    Backend for Amazon Drive. It communicates directly with Amazon Drive using
    their RESTful API and does not rely on externally setup software (like
    acd_cli).
    z~/.duplicity_ad_oauthtoken.jsonzhttps://www.amazon.com/ap/oaz$https://api.amazon.com/auth/o2/tokenz'https://breunig.xyz/duplicity/copy.htmlzclouddrive:read_otherzclouddrive:writez=amzn1.application-oa2-client.791c9c2d78444e85a32eb66f92eb6bcc�@5b322c6a37b25f16d848a6a556eddcc30314fc46ae65c87068ff1bc4588d715b�CDuplicityFormBoundaryd66364f7f8924f7e9d478e19cf4b871d114a1e00262542c��tjjj||�d|_d|_i|_d|_|jjd�|_
tjdkDrtjd�	ddladdlma|j)�|j+�y#t$$rt'd��wxYw)	Nz%https://drive.amazonaws.com/drive/v1/z/https://content-na.drive.amazonaws.com/cdproxy/�/l
zxYour --volsize is bigger than 10 GiB, which is the maximum file size on Amazon Drive that does not require work arounds.r)�
OAuth2Sessiona
Amazon Drive backend requires python-requests and python-requests-oauthlib to be installed.

For Debian and derivates use:
  apt-get install python-requests python-requests-oauthlib
For Fedora and derivates use:
  yum install python-requests python-requests-oauthlib)�	duplicity�backend�Backend�__init__�metadata_url�content_url�names_to_ids�backup_target_id�path�lstrip�
backup_targetr�volsizer�
FatalError�requests�requests_oauthlibr
�ImportErrorr�initialize_oauth2_session�resolve_backup_target)�self�
parsed_urls  �>/usr/lib/python3/dist-packages/duplicity/backends/adbackend.pyrzADBackend.__init__:s������!�!�*�*�4��<�C���L������ $���'�_�_�3�3�C�8����>�>�4�5�
�N�N�P�
�

	�
�7�	
�&�&�(��"�"�$���	�"�I��
�	�s�
B;�;Cc	����fd�}d}	t�j�5}tj|�}ddd�t�j�j�j|�j�jd��j|���_
|�%�jj�j��jj�j dz�}|j"t$j&j(k7rd}|��Ot*j,j/�rt*j0j/�s#tj2d�j�d	���jj5�j6�\}}t9d
�t9d�t9|�t9d
�t;d�j=d
dd�j?�}�jjA�j�j|��}�jj�j dz�}|jC�||�|j�}	d|	vsd|	vrtj2d�|	d�_|	d�_"y#1swY��lxYw#t$r$}tjd|�d��Yd}~���d}~wwxYw)z1Setup or refresh oauth2 session with Amazon Drivec���	t�jd�5}tj||�ddd�y#1swYyxYw#t$r/}tjd�j�d|���Yd}~yd}~wwxYw)zStores oauth2 token on disk�wNz#Could not save the OAuth2 token to z]. This means you may need to do the OAuth2 authorization process again soon. Original error: )�open�OAUTH_TOKEN_PATH�json�dump�	Exceptionr�Error)�token�f�errr s   �r"�
token_updaterz:ADBackend.initialize_oauth2_session.<locals>.token_updateras{���
��$�/�/��5�(���I�I�e�Q�'�(�(�(���
��	�	�9�$�:O�:O�9P�Q'�'*�e�-����
�s0�A�9�A�A�A�A�	A=�%A8�8A=NzJCould not load OAuth2 token. Trying to create a new one. (original error: �))�	client_id�
client_secret)�scope�redirect_urir,�auto_refresh_kwargs�auto_refresh_urlr/zaccount/endpointz*The OAuth2 token could not be loaded from zc and you are not running duplicity interactively, so duplicity cannot possibly access Amazon Drive.�z�In order to allow duplicity to access Amazon Drive, please open the following URL in a browser and copy the URL of the page you see after authorization here:zURL of the resulting page: zhttp://zhttps://�)r2�authorization_response�metadataUrl�
contentUrlz1Could not retrieve endpoint URLs for this account)#r&r'r(�load�IOErrorr�Noticer
�	CLIENT_ID�OAUTH_SCOPE�OAUTH_REDIRECT_URL�
CLIENT_SECRET�OAUTH_TOKEN_URL�http_client�
refresh_token�getr�status_coder�codes�ok�sys�stdout�isatty�stdinr�authorization_url�OAUTH_AUTHORIZE_URL�print�input�replace�strip�fetch_token�raise_for_statusr)
r r/r,r-r.�endpoints_responserN�_�
redirected_to�urlss
`         r"rz#ADBackend.initialize_oauth2_session^s����
	���	l��d�+�+�,�
%���	�	�!���
%�
)��N�N��"�"��0�0��!�^�^�!%�!3�!3�!�"�1�1�'�
��������*�*�4�+?�+?�@�!�-�-�1�1�$�2C�2C�FX�2X�Y���)�)�X�^�^�->�->�>��E��=��:�:�$�$�&�c�i�i�.>�.>�.@����@��AV�AV�@W�X;�<��
$(�#3�#3�#E�#E�d�F^�F^�#_� ��q��"�I��9�
�

�#�$��"�I�"�#@�A�I�I�)�U_�ab�c�j�j�l�M��$�$�0�0��$�$�"�0�0�'4�1��E�"&�!1�!1�!5�!5�d�6G�6G�J\�6\�!]���/�/�1��%� �!�&�&�(����$��D�(@��N�N�N�O� ��/�����-���w
%�
%���	l��J�J�c�dg�ch�hi�j�k�k��	l�s-�J,�J�J,�J)�$J,�,	K�5K�Kc��|jj|jdz�}|j�ddd}|jjd�D�cgc]}|s�|��	c}D]�}t
jd|�jd�}||k7r|dz}|j|jd|�d	|��z�}|D�cgc]}|jd
�|k(s�|��}}t|�dk\rtjd|�d
|�����t|�dk(r	|dd}��tjd|�d��|j||�}��tjd|���||_ycc}wcc}w)z/Resolve node id for remote backup target folderz)nodes?filters=kind:FOLDER AND isRoot:true�datar�idrz^[A-Za-z0-9_-]*�*z#nodes?filters=kind:FOLDER AND name:z
 AND parents:�name�zJThere are multiple folders with the same name below one parent.
ParentID: z
FolderName: r8zFolder z does not exist yet. Creating.zBackup target folder has id: N)rDrFrr(r�split�re�search�group�read_all_pages�lenrr�Debug�mkdirr)	r �response�parent_node_id�x�	component�query�matchesr-�
candidatess	         r"rzADBackend.resolve_backup_target�s����#�#�'�'��(9�(9�<g�(g�h��!�����0��3�D�9��%)�%7�%7�%=�%=�c�%B�H��a�!�H�	G�I��I�I�/��;�A�A�!�D�E��E�!������)�)��!�!�&I�%��P]�^l�]m�$n�n��G�&-�K�����f�
��0J�!�K�J�K��:��!�#����!�!/� 0��y�k�K���Z��A�%�!+�A��t�!4���	�	�G�I�;�.L�M�N�!%���N�I�!F��+	G�.	�	�	�1�.�1A�B�C� .����1I��Ls�E6�'E6�E;�"E;c�t�||jvr|j�|jj|�S)z.Find id of remote file in backup target folder)r�_listrF�r �remote_filenames  r"�get_file_idzADBackend.get_file_id�s2���$�"3�"3�3��J�J�L�� � �$�$�_�5�5�c���||gdd�}|jj|jdztj|���}|j�|j�dS)z/Create a new folder as a child of a parent node�FOLDER)r^�parents�kind�nodes)r[r\)rD�postrr(�dumpsrU)r ri�folder_namer[rhs     r"rgzADBackend.mkdir�s`��$��0@�(�S���#�#�(�(��):�):�W�)D�4�:�:�VZ�K[�(�\���!�!�#��}�}��t�$�$rtc#�vK�|j}tjd|�d�tj|��d�zd|�d�z���d��d��|j�5}	|j
t�}|r|��nn�	ddd�tjd|�d�d	|��z���y#1swY�+xYw�w)
z>Generator for multipart/form-data file upload from source filez--z5
Content-Disposition: form-data; name="metadata"

z
sKContent-Disposition: form-data; name="content"; filename="i_love_backups"
s*Content-Type: application/octet-stream

Nz
--z--
�multipart/form-data; boundary=)�MULTIPART_BOUNDARY�str�encoder(r{r&�readr)r �metadata�source_path�boundary�streamr-s      r"�multipart_streamzADBackend.multipart_stream�s������*�*���j�j���
�U�V����H�%�&�d�+�
,��8�*�D�!�
"�
�	
�
_�^�?�?�
�
�
�
�	�6���K�K� 3�4����G���
�
	��j�j�6�(��6�2�7U�V^�U_�5`�`�a�a�	�	�s�A B9�" B-�*B9�-B6�2B9c�r�g}d}d|vrdnd}	||z|z}|jj|�}|jdk7rtd|j�d|����|j	�}d|vr&t|d�d	kDr|j
|d�n	|St|�|d
k\r	|Sd|vr	|S|d}��)z5Iterates over nodes API URL until all pages were readr7�?z&startToken=z?startToken=��zPagination failed with status=z on URL=r[r�count�	nextToken)rDrFrGrr(re�extend)r �url�result�
next_token�token_param�
paginated_urlrh�parseds        r"rdzADBackend.read_all_pages�s������
�(+�s�
�n�����+�-�
�:�M��'�'�+�+�M�:�H��#�#�s�*�&�)G��H\�H\�G]�]e�fi�ej�'k�l�l��]�]�_�F����C��v��$7�!�$;��
�
�f�V�n�-���
��6�{�f�W�o�-���
�	�&�(���
� ��,�J�%rtc�B�|j|�td|�d���)z@Report error when file already existed in location and delete itz>Upload failed, because there was a file with the same name as zt already present. The file was deleted, and duplicity will retry the upload unless the retry limit has been reached.)�_deleterrqs  r"�raise_for_existing_filez!ADBackend.raise_for_existing_files0��	
���_�%��L�_�L]�^7�
8�
�	
rtc
�$�|jj|jdz�}|j�|j	�d}t
jj|j�}||kDr1td|j�dt|��dt|��d���||jvr*tjd|�d��|j|�|d	|jgd
�}dd|j ��i}|j#||�}|jj%|j&d
z||��}	|	j(dk(r|j+|��nt|	j(dk(rtj|�d���nK|	j(dk(s|	j(dk(r�tj,|�dt|	j(��dtt.j0��d��t.j0dz}
|
dk\r�|
dz}
t3j4d�|j7|�d}||k(rtjd�y|dk(r&tjdt|
dz��d���y|j+|�|
dk\r��t|�d ���tj|�d!|	j(���|	j�|	j	�}d"|vrt|�d#|����|d"|j|d$<y)%z#Upload a local file to Amazon Drivez
account/quota�	availablezOut of space: trying to store "z" (z bytes), but only z! bytes available on Amazon Drive.zFile zW seems to already exist on Amazon Drive. Deleting before attempting to upload it again.�FILE)r^rxrwzContent-Typer~znodes?suppress=deduplication)r[�headersi���z uploaded successfullyi�i�z( upload failed with timeout status code=z. Speculatively waiting for z: seconds to see if Amazon Drive finished the upload anyway�rr8�sizez-Upload turned out to be successful after all.N���z Uploaded file is not yet there, z tries left.z: upload failed and file did not show up within time limit.z, upload returned an undesirable status code r\zR was uploaded but returned JSON does not contain ID of new file. Retrying.
JSON:

r^)rDrFrrUr(�osr�getsizer^r�intrrrfr�rrr�rzrrGr��Infor�timeout�time�sleep�_query)
r r�rr�quotar��source_sizer�r�r[rh�tries�remote_sizer�s
             r"�_putzADBackend._puts#��� � �$�$�T�%6�%6��%H�I��
��� ��J�J�L��-�	��g�g�o�o�k�&6�&6�7����"�"�1�+�2B�2B�1C�3�s�;�GW�FX�Y��	�N�+�+L�N��
��d�/�/�/��I�I���(�)A�B�
�
�L�L��)�$���-�-�.�
��
"�%C�D�D[�D[�C\�#]�^���$�$�X�{�;���#�#�(�(����=�=���)�
�����3�&��(�(��9�
�
!�
!�S�
(��I�I��)�)?�@�A�
�
!�
!�S�
(�H�,@�,@�C�,G��H�H�"�#�#K�C�PX�Pd�Pd�Le�Kf�g-�-0����-@�,A�B-�.�
�
�N�N�R�'�E��1�*���
���
�
�2��"�k�k�/�:�6�B���+�-��I�I�M�N�� �B�&��I�I� @��U�Q�Y��@P�P\�]�^���0�0��A��1�*�#�o�%6�6p�#q�r�r��I�I��)�)U�V^�Vj�Vj�Uk�l�m��%�%�'�������v��"�"�#�$'�'-�h�0��
�-3�4�L����&��.�)rtc��|jd�5}|j|�}|�td|�d���|jj	|j
dz|zdzd��}|j
�|jt�	�D]}|s�|j|��|j�ddd�y#1swYyxYw)
zDownload file from Amazon Drive�wbN�File "z)" cannot be downloaded: it does not existz/nodes/z/contentT)r�)�
chunk_size)r&rsrrDrFrrU�iter_contentr�write�flush)r rr�
local_path�
local_file�file_idrh�chunks       r"�_getzADBackend._getis����_�_�T�
"�
	�j��&�&��7�G���&���/@�@i�'j�k�k��'�'�+�+�D�,<�,<�y�,H�7�,R�U_�,_�hl�+�m�H��%�%�'�!�.�.�:M�.�N�
,����$�$�U�+�
,�
����
	�
	�
	�s�A>B=�#B=�=Cc���|j|�}|�ddiS|jj|jdz|z�}|j	�d|j�ddiS)z)Retrieve file size info from Amazon Driver�r��nodes/�contentProperties)rsrDrFrrUr(�r rrr�rhs    r"r�zADBackend._queryxsq���"�"�?�3���?��B�<���#�#�'�'��(9�(9�H�(D�w�(N�O���!�!�#���
�
��(;�<�V�D�E�Ertc���|j|jdz|jzdz�}|D�cic]}|d|d��
c}|_t	|jj��Scc}w)z(List files in Amazon Drive backup folderr�z/children?filters=kind:FILEr^r\)rdrrr�list�keys)r �filesr-s   r"rpzADBackend._list�su���#�#�����(�4�+@�+@�@�C`�`�
��:?�?�A�Q�v�Y��$��/�?����D�%�%�*�*�,�-�-��@s�A.c���|j|�}|�td|�d���|jj|jdz|z�}|j�|j|=y)zDelete file from Amazon DriveNr�z&" cannot be deleted: it does not existztrash/)rsrrD�putrrUrr�s    r"r�zADBackend._delete�so���"�"�?�3���?�"�V�O�+<�<b�#c�d�d��#�#�'�'��(9�(9�H�(D�w�(N�O���!�!�#����o�.rtN)�__name__�
__module__�__qualname__�__doc__r�r�
expanduserr'rOrCrAr@r?rBrrrrrsrgr�rdr�r�r�r�rpr��rtr"rr$s�����w�w�)�)�*K�L��8��<�O�C��*�,>�?�K�O�I�V�M�^��"%�HL.�\/�@6�%�b�.�:
�M9�^
�	F�	.�/rtr�ad)r(�os.pathr�rarJr��ior�duplicity.backendrrr�duplicity.errorsrrrr�register_backendr�rtr"�<module>r�sX��.��	�
��"����-�r/�	�!�!�)�)�r/�j
���"�"�4��3rt

Zerion Mini Shell 1.0