
    3fiK9                       d dl Z d dlZd dlmZ d dlmZ d dlmZmZ d dl	m
Z
mZ d dlmZ d dlmZ dd	lmZ dd
lmZmZmZmZmZmZ  e j2                  e      ZdZdZdZdZdZ h dZ! G d d      Z" G d de      Z# G d dee"      Z$ G d de      Z% G d de      Z& G d de&e"      Z' G d de'      Z( G d d e(      Z) G d! d"e&      Z* G d# d$e      Z+ G d% d&e      Z,y)'    N)Path)sleep)UnionOptional)quoteurlparse)BytesIO)parse   )Contact)NEXT_LINK_KEYWORDApiComponentOneDriveWellKnowFolderNames
PaginationQueryBuilderCompositeFilteri    i  @ i  i   i  P >   .csv.doc.odp.ods.odt.pot.pps.ppt.rtf.xls.docx.potm.potx.ppsx.pptm.pptx.xlsx.ppsxmc                   L    e Zd Z	 	 	 ddedeef   dedeeef   dedee	   f
dZ
y)	DownloadableMixinNto_pathname
chunk_sizeconvert_to_pdfoutputc           	        
 |s|t               }nt        |t               st        |      }|j                         st        dj	                  |            |rCt        |      j
                  s.| j                  r"|t        | j                        j
                  z   }|xs | j                  }|r|t        |      j                  d      z  }n||z  }| j                  | j                  j                  d      j	                  | j                              }	 dnJdk(  r'| j                  r| j                  t        kD  rdnddnt        t              rdnt        d	      i }|r(|s!t        |      j
                  t         v rd
|d<   nd
|d<   | j"                  j                  ||      5 

s8t$        j'                  dj	                  
j(                               	 ddd       y
fd}|r	 ||       n#|j+                  d      5 } ||       ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w# t,        $ rB}	t$        j/                  dj	                  | j                  t1        |	                   Y d}	~	yd}	~	ww xY w)a<   Downloads this file to the local drive. Can download the
        file in chunks with multiple requests to the server.

        :param to_path: a path to store the downloaded file
        :type to_path: str or Path
        :param str name: the name you want the stored file to have.
        :param int chunk_size: number of bytes to retrieve from
         each api call to the server. if auto, files bigger than
         SIZE_THERSHOLD will be chunked (into memory, will be
         however only 1 request)
        :param bool convert_to_pdf: will try to download the converted pdf
         if file extension in ALLOWED_PDF_EXTENSIONS
        :param BytesIO output: (optional) an opened io object to write to.
         if set, the to_path and name will be ignored
        :return: Success / Failure
        :rtype: bool
        Nz{} does not existz.pdfdownloadidFautoTzRArgument chunk_size must be either 'auto' or any integer number representing bytespdfformat)streamparamsz(Downloading driveitem Request failed: {}c                     r,j                        D ]  }|s| j                  |        y | j                  j                         y )N)r)   )iter_contentwritecontent)outchunkr)   responser3   s     H/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/O365/drive.pywrite_outputz0DownloadableMixin.download.<locals>.write_outputp   sK    %-%:%:+5 &; &7 1E$ #		% 01
 		("2"23    wbmodez)Error downloading driveitem {}. Error: {})r   
isinstanceexistsFileNotFoundErrorr2   suffixr(   with_suffix	build_url
_endpointsget	object_idsizeSIZE_THERSHOLDint
ValueErrorALLOWED_PDF_EXTENSIONSconlogdebugreasonopen	Exceptionerrorstr)selfr'   r(   r)   r*   r+   urlr4   r=   er;   r3   s      `      @@r<   r-   zDownloadableMixin.download&   sM   . &!'40"7mG>>#'(;(B(B7(KLLDJ--$))d499o444$499D!DJ$:$:6$BB!D.nnOO
+22dnn2EG0	!v%99^!;!F"F!
J,  "L M M FDz((,BB+0x(',F8$c&@ -HIIHOO ) * 	- -4  ( 40 -F$V,-%-6 - -%-6   	II;BB499CFq6KL 		s[   BI 02H5"I +$H5	H)H5 I )H2	.H55H>:I >I 	J
8JJNNr0   FN)__name__
__module____qualname__r   rW   r   rM   boolr   r	   r-    r>   r<   r&   r&   $   sT    KONS-1_dCo 6 _S _"38__GK_!'*_r>   r&   c                   H     e Zd ZdZddiZdddd fd
Zd Zd
dZd	 Z xZ	S )CopyOperationz: https://github.com/OneDrive/onedrive-api-docs/issues/762 item/items/{id}N)parentrP   targetc                R   |r|rt        d      |r|j                  n|| _        || _        |xs || _        |j	                  dd      xs |rt        |dd      nd}t        |   |r|j                  n|j                  d      |       |j                  dd      | _
        |j                  dd      | _        | j                  | j                  t        d      | j                  | j                  t        d	      | j                  rd
| _        d| _        yd| _        d| _        y)a  

        :param parent: parent for this operation i.e. the source of the copied item
        :type parent: Drive
        :param Connection con: connection to use if no parent specified
        :param target: The target drive for the copy operation
        :type target: Drive
        :param Protocol protocol: protocol to use if no parent specified
         (kwargs)
        :param str main_resource: use this resource instead of parent resource
         (kwargs)
        :param str monitor_url:
        :param str item_id:
        *Need a parent or a connection but not bothmain_resourceNprotocolrj   ri   monitor_urlitem_idz+Must provide a valid monitor_url or item_idz9Must provide a valid monitor_url or item_id, but not both	completedg      Y@
inProgressg        )rN   rP   re   rf   popgetattrsuper__init__rj   rI   rl   rm   statuscompletion_percentage)rX   re   rP   rf   kwargsri   	__class__s         r<   rs   zCopyOperation.__init__   s$    cIJJ!'6::S& 

?D9 H6<GFOT2$ 	 	(.V__FJJz4J' 	 	)
 "::mT:zz)T2#(<JKK'DLL,DKM M <<%DK).D&&DK),D&r>   c                 r   | j                   ry| j                  j                  | j                  d      }|sy|j	                         }|j                  dd      | _        |j                  | j                  d      d      | _        |j                  | j                  d	      d
      | _         | j                   d
uS )z< Checks the api endpoint to check if the async job progress TrI   )methodFrt   ro   percentageCompleter   
resourceIdN)	rm   rP   naive_requestrl   jsonrI   rt   _ccru   )rX   r;   datas      r<   _request_statuszCopyOperation._request_status   s    <<88))$*:*:5)I}}hhx6%)XXdhh7K.L./&1"xx 6=||4''r>   c              #      K   | j                   sT| j                         sC| j                  | j                  f | j                   t	        |       | j                         sByy| j                  | j                  f yw)a    Checks the api endpoint in a loop

        :param delay: number of seconds to wait between api calls.
         Note Connection 'requests_delay' also apply.
        :return: tuple of status and percentage complete
        :rtype: tuple(str, float)
        N)rm   r   rt   ru   r   )rX   delays     r<   check_statuszCopyOperation.check_status   sf      ||**,kk4#=#===<<'%L	 **, ++t9999s   AA>!A>c                 h    | j                   %| j                  j                  | j                         S dS )zY Returns the item copied

        :return: Copied Item
        :rtype: DriveItem
        N)rm   rf   get_itemrX   s    r<   r   zCopyOperation.get_item   s8     "\\5 {{##LL 	@;?	@r>   )r   )
r\   r]   r^   __doc__rH   rs   r   r   r   __classcell__rw   s   @r<   rb   rb      s3    D 	J
 "&4 0-d($:"@r>   rb   c                        e Zd ZdZdddZddd fd
Zd Zd	 Zd
 Z	 	 	 dde	de
ef   de
de	e
ef   dedee   f
 fdZ xZS )DriveItemVersionz A version of a DriveItem z/versions/{id}/contentz/versions/{id}/restoreVersion)r-   restoreNre   rP   c                :   |r|rt        d      |r|j                  n|| _        t        |t              r|nd| _        |r|j
                  n|j                  d      }|j                  dd      xs |rt        |dd      nd}dj                  | j                  j                        }dj                  |xs |r|j                  nd|      }t        | 5  ||	       |j                  | j                  i       }| j                  j                  | _        |j                  d
d      | _
        | j                  | _        |j                  | j#                  d      d      }| j
                  j$                  }	|rt'        |      j)                  |	      nd| _        |j                  dd      | _        |j                  | j#                  d      i       j                  dd      }
|
r4t/        d| j                  | j
                  d| j                  |
i| _        yd| _        y)at   Version of DriveItem

        :param parent: parent for this operation
        :type parent: DriveItem
        :param Connection con: connection to use if no parent specified
        :param Protocol protocol: protocol to use if no parent specified
         (kwargs)
        :param str main_resource: use this resource instead of parent resource
         (kwargs)
        rh   Nrj   ri   z/items/{item_id}rm   {}{} rk   r/   z1.0lastModifiedDateTimerK   r   lastModifiedByuserrP   rj   r`   )rN   rP   rB   	DriveItem_parentrj   rI   rp   rq   r2   rJ   default_resourcerr   rs   _cloud_data_keydriveitem_idr(   r~   timezoner
   
astimezonemodifiedrK   r   modified_by)rX   re   rP   rv   rj   ri   resource_prefix
cloud_datar   local_tzr   rw   s              r<   rs   zDriveItemVersion.__init__   s    cIJJ!'6::S!+FI!>vD&,6??&**Z2H

?D9 H6<GFOT2$ 	 -33LL** 4 ,L8h77 	(-HZZ 4 4b9
 !LL22#e4NN	>>$((+A"BDI==)) " h22'+ 	 NN61-	 nnTXX.>%?DHHIMO 4? # 0txx$-- 0  +L/ 0DH 	r>   c                 "    | j                         S N__repr__r   s    r<   __str__zDriveItemVersion.__str__)      }}r>   c                     dj                  | j                  | j                  | j                  r| j                  j                        S d       S )Nz)Version Id: {} | Modified on: {} | by: {})r2   r(   r   r   display_namer   s    r<   r   zDriveItemVersion.__repr__,  sL    6$))--!-- **779	: 489	:r>   c                     | j                  | j                  j                  d      j                  | j                              }| j
                  j                  |      }t        |      S )z Restores this DriveItem Version.
        You can not restore the current version (last one).

        :return: Success / Failure
        :rtype: bool
        r   r.   )rG   rH   rI   r2   rJ   rP   postr_   rX   rY   r;   s      r<   r   zDriveItemVersion.restore3  sU     nnOO	*11T^^1DF 88==%H~r>   r'   r(   r)   r*   r+   c                 ,    t         |   |||||      S )z Downloads this version.
        You can not download the current version (last one).

        :return: Success / Failure
        :rtype: bool
        )r'   r(   r)   r*   r+   )rr   r-   )rX   r'   r(   r)   r*   r+   rw   s         r<   r-   zDriveItemVersion.downloadA  s)     wdz/=f   N 	Nr>   r[   )r\   r]   r^   r   rH   rs   r   r   r   r   rW   r   rM   r_   r   r	   r-   r   r   s   @r<   r   r      s    $ -2J
 "&4 0Id: LPNS-1
NdCo 6 
NS 
N"38_
NGK
N!'*
N 
Nr>   r   c                   L     e Zd ZdZddiZddd fd
Zd Zd Zdd	Zd
 Z	 xZ
S )DriveItemPermissionz- A Permission representation for a DriveItem 
permissionz&/items/{driveitem_id}/permissions/{id}Nr   c                   |r|rt        d      |r|j                  n|| _        t        |t              r|nd| _        |j                  dd      xs |rt        |dd      nd}|r|j                  n|j                  d      }t        | )  ||       | j                  j                  | _        |j                  | j                  i       }|j                  | j                  d            | _        |j                  | j                  d      d      | _        |j                  | j                  d      d      }d	| _        |rLd| _        |j                  d
d      | _        |j                  dd      | _        |j                  dd      | _        |j                  | j                  d      d      }|rd| _        |j                  dd      | _        |j                  di       }	|	j                  di       j                  | j                  d      d      xs1 |	j                  di       j                  | j                  d      d      | _        |j                  | j                  d      d      | _        |j                  | j                  d      g       | _        |j                  | j                  d      i       }
|
j                  di       j                  | j                  d            xs0 |
j                  di       j                  | j                  d            | _        |j                  | j                  d      d      | _        y)ay   Permissions for DriveItem

        :param parent: parent for this operation
        :type parent: DriveItem
        :param Connection con: connection to use if no parent specified
        :param Protocol protocol: protocol to use if no parent specified
         (kwargs)
        :param str main_resource: use this resource instead of parent resource
         (kwargs)
        rh   Nri   rj   rk   r/   inheritedFromlinkownertypeviewscope	anonymouswebUrl
invitationemailr   	invitedByr   displayNameapplicationsignInRequiredTroles	grantedToshareId)rN   rP   rB   r   r   rp   rq   rj   rI   rr   rs   rJ   r   r   r~   inherited_frompermission_type
share_typeshare_scope
share_linkshare_email
invited_byrequire_sign_inr   
granted_toshare_id)rX   re   rP   rv   ri   rj   r   r   r   r   r   rw   s              r<   rs   zDriveItemPermission.__init__T  s    cIJJ!'6::S!+FI!>vD

?D9 H6<GFOT2$ 	 '-6??&**Z2H(-H !LL22ZZ 4 4b9
#7 )nnTXXo-FM~~dhhv.5&#)D "hhvv6DO#xx=D"hhx6DO^^DHH\$:DA
#/D )~~gr:D#R8J(nnVR8<<'/ /2<..AC3EEHS'F/ O
 $.>>$((;K2L26$8D   ^^DHHW$5r:
^^DHH[$92>
 %..488HH]#% %(2}b(I(M(MHH]#)% 	
 #txx	':DAr>   c                 "    | j                         S r   r   r   s    r<   r   zDriveItemPermission.__str__  r   r>   c                 b    dj                  | j                  j                  | j                        S )NzPermission for {} of type: {})r2   r   r(   r   r   s    r<   r   zDriveItemPermission.__repr__  s,    .55dll6G6G6:6J6JL 	Lr>   c                    | j                   sy| j                  | j                  j                  d      j	                  | j
                  | j                               }|dv rddgi}n$|dv rddgi}nt        d	j	                  |            | j                  j                  ||
      }|sy|j                  dg       | _	        y)zg Updates the roles of this permission

        :return: Success / Failure
        :rtype: bool
        Fr   r   r/   >   readr   r   r   >   editr7   r7   "{}" is not a valid share_typer   T)
rJ   rG   rH   rI   r2   r   rN   rP   patchr   )rX   r   rY   r   r;   s        r<   update_rolesz DriveItemPermission.update_roles  s     ~~nnT__00>EE**t~~ F ? @ $$fX&D''gY'D=DDUKLL88>>#D>1XXgr*
r>   c                    | j                   sy| j                  | j                  j                  d      j	                  | j
                  | j                               }| j                  j                  |      }|syd| _         y)z Deletes this permission. Only permissions that are not
        inherited can be deleted.

        :return: Success / Failure
        :rtype: bool
        Fr   r   NT)rJ   rG   rH   rI   r2   r   rP   deleter   s      r<   r   zDriveItemPermission.delete  sr     ~~nnT__00>EE**t~~ F ? @ 88??3'r>   )r   )r\   r]   r^   r   rH   rs   r   r   r   r   r   r   s   @r<   r   r   N  s7    7>J "&4 EBNL4r>   r   c                        e Zd ZdZdddddddd	d
dddddZddd fd
Zd Zd Zd Ze	d        Z
ed        Zed        Zed        Zed        Zd Zd Zd'dZd Zd Zd  Zd(d!Zd" Zd# Zd)d$Z	 	 d*d%Zd& Z xZS )+r   z6 A DriveItem representation. Groups all functionality z/items/{id}/childrenz/items/{id}/thumbnailsrd   z/items/{id}/copyz/items/{id}/contentz%/items/{id}/search(q='{search_text}')z/items/{id}/versionsz!/items/{id}/versions/{version_id}z /items/{id}:/{filename}:/contentz,/items/{id}:/{filename}:/createUploadSessionz/items/{id}/createLinkz/items/{id}/invitez/items/{id}/permissions)
list_items
thumbnailsrc   copyr-   searchversionsversionsimple_uploadcreate_upload_sessionr   share_invitepermissionsNr   c                f
   |r|rt        d      |r|j                  n|| _        t        |t              r|nd| _        |j                  dd      xs |rt        |dd      nd}|r|j                  n|j                  d      }|rkt        |t              s[|j                  dk(  rdn|j                  xs d}|rdj                  |      nd}d	j                  |xs |r|j                  nd
|      }t        | 5  ||       |j                  | j                  i       }|j                  | j                  d            | _	        |j                  | j                  d      i       }	|	j                  dd      | _        |	j                  | j                  d      d      | _        |	j                  | j                  d      d      | _        |j                  | j                  d      d      }
|
d| _         | j)                  |
      d"d| i| j                  |
i| _        | j*                  j                   | _        | j*                  j"                  | _        | j-                  dj                  | j"                               nVt        |t.              r|n7t        |j&                  t.              r|j&                  n|j                  dd      | _        d| _        |j                  | j                  d      d
      | _        |j                  | j                  d            | _        |j                  | j                  d      i       j                  dd      }|r.t5        d"| j                  | j                  d| j                  |ind| _        |j                  | j                  d      i       j                  dd      }|r.t5        d"| j                  | j                  d| j                  |ind| _        |j                  | j                  d      d      }|j                  | j                  d      d      }| j                  j:                  }|rt=        |      j?                  |      nd| _         |rt=        |      j?                  |      nd| _!        |j                  | j                  d      d
      | _"        |j                  | j                  d      d      | _#        |j                  | j                  d      i       j                  d d      | _$        |j                  | j                  d!      g       | _%        y)#a~   Create a DriveItem

        :param parent: parent for this operation
        :type parent: Drive or drive.Folder
        :param Connection con: connection to use if no parent specified
        :param Protocol protocol: protocol to use if no parent specified
         (kwargs)
        :param str main_resource: use this resource instead of parent resource
         (kwargs)
        rh   Nri   rj   rootz/drives/{drive_id})drive_id/driver   r   rk   r/   parentReferencedriveIdpath
remoteItemre   z	drives/{}driver(   r   	createdByr   r   r   createdDateTimer   descriptionrK   r   sharedr   r   r`   )&rN   rP   rB   r   r   rp   rq   rj   rI   rJ   r2   r   rr   rs   r   r~   	parent_idr   parent_pathr   _classifierremote_itemset_base_urlDriver(   web_urlr   
created_byr   r   r
   r   createdr   r   rK   r   r   )rX   re   rP   rv   ri   rj   r   r   r   parent_referencer   r   r   r   r   r   rw   s                   r<   rs   zDriveItem.__init__  s    cIJJ!'6::S!+FI!>vD 

?D9 H6<GFOT2$ 	 '-6??&**Z2H*VY7 & 0 0F :#--726 
 '/ 399! : #4< "MM- +?-5))2QM 	(-HZZ 4 4b9
 $7%>>$((3D*ErJ)--dD9(,,TXXi-@$G+//0@$G nnTXXl%;TB"DJ  =t//<  4D  4$$kM3  4D!--77DN ,,55DMk00?@#-fe#< *6<< ?VZZTF# J  $D NN488F#3R8	!~~dhhx&89^^DHH[$92>BB64P
 3= " /dhh /  *K. /BF 	 nnTXX.>%?DHHIMO
 4? # 0txx$-- 0  +L/ 0DH 	 ..*;!<dC>>$((+A"BDI==))>EuW~00:4 " h22'+ 	 &>>$((=*A2FNN488F#3Q7	 !nnTXXh%7<@@$O %..,)?Dr>   c                 "    | j                         S r   r   r   s    r<   r   zDriveItem.__str__I  r   r>   c                 b    dj                  | j                  j                  | j                        S )Nz{}: {})r2   rw   r\   r(   r   s    r<   r   zDriveItem.__repr__L  s!    t~~66		BBr>   c                 @    t        |dd       }|| j                  |k(  S y)NrJ   F)rq   rJ   )rX   otherobj_ids      r<   __eq__zDriveItem.__eq__O  s(    T2>>V++r>   c                 J    d| v rt         S d| v rt        S d| v rt        S t        S z$ Subclass to change factory classes folderimagephotoFolderImagePhotoFilerc   s    r<   r   zDriveItem._classifierU  .     tM_L_LKr>   c                 "    t        | t              S )z' Returns if this DriveItem is a Folder )rB   r  r   s    r<   	is_folderzDriveItem.is_foldera  s     $''r>   c                 "    t        | t              S )z% Returns if this DriveItem is a File )rB   r
  r   s    r<   is_filezDriveItem.is_filef  s     $%%r>   c                 "    t        | t              S )z& Returns if this DriveItem is a Image )rB   r  r   s    r<   is_imagezDriveItem.is_imagek       $&&r>   c                 "    t        | t              S )z& Returns if this DriveItem is a Photo )rB   r	  r   s    r<   is_photozDriveItem.is_photop  r  r>   c                     | j                   r/| j                   j                  | j                  k(  r| j                   S | j                  r%| j                  j	                  | j                        S | j                  S )zr the parent of this DriveItem

        :return: Parent of this item
        :rtype: Drive or drive.Folder
        )r   rJ   r   r   r   r   s    r<   
get_parentzDriveItem.get_parentu  sV     <<DLL22dnnD<<~~zz**4>>:: zz!r>   c                     | j                   sy| j                  d      }| j                  j                  |      }|sy|j	                         }t        d| dd| j                  |iS )zk
        Returns this item drive
        :return: Drive of this item
        :rtype: Drive or None
        Nr   )re   ri   r`   )r   rG   rP   rI   r}   r   r   rX   rY   r;   r   s       r<   	get_drivezDriveItem.get_drive  s_     }}nnR 88<<$TDTt7K7KU6STTr>   c                 H   | j                   sg S | j                  | j                  j                  d      j	                  | j                               }i }|||d<   | j
                  j                  ||      }|sg S |j                         }| j                  r||| _        |S )a   Returns this Item Thumbnails. Thumbnails are not supported on
        SharePoint Server 2016.

        :param size: request only the specified size: ej: "small",
         Custom 300x400 px: "c300x400", Crop: "c300x400_Crop"
        :return: Thumbnail Data
        :rtype: dict
        r   r.   selectr4   )rJ   rG   rH   rI   r2   rP   r}   r   )rX   rK   rY   r4   r;   r   s         r<   get_thumbnailszDriveItem.get_thumbnails  s     ~~InnOO-444GI #F888<<F<3I}}$,"DOr>   c                    | j                   sy| j                  | j                  j                  d      j	                  | j                               }|j                         D ci c]  \  }}|dv r| j                  |      | }}}|sy| j                  j                  ||      }|sy|j                         }|D ]=  }|j                  |d      }|st        | | j                  j                  |      |       ? yc c}}w )z Updates this item

        :param kwargs: all the properties to be updated.
         only name and description are allowed at the moment.
        :return: Success / Failure
        :rtype: bool
        Frc   r.   >   r(   r   r   NT)rJ   rG   rH   rI   r2   itemsr~   rP   r   r}   setattrrj   to_api_case)rX   rv   rY   keyvaluer   r;   new_datas           r<   updatezDriveItem.update  s     ~~nnOO'..$...AC 8>||~ (e ' ' u$ ( ( 88>>#D>1==? 	ECLLd+Edmm77<eD	E
 #(s   % C>c                     | j                   sy| j                  | j                  j                  d      j	                  | j                               }| j
                  j                  |      }|syd| _         y)ze Moves this item to the Recycle Bin

        :return: Success / Failure
        :rtype: bool
        Frc   r.   NT)rJ   rG   rH   rI   r2   rP   r   r   s      r<   r   zDriveItem.delete  se     ~~nnOO'..$...AC 88??3'r>   c                    t        |t              r|j                  }nNt        |t              r |j	                         }|sy|j                  }nt        |t
              r|}nt        d      | j                  r|st        d      |dk(  rt        d      | j                  | j                  j                  d      j                  | j                              }dd	|ii}| j                  j                  ||
      }|sy|| _        y)aQ   Moves this DriveItem to another Folder.
        Can't move between different Drives.

        :param target: a Folder, Drive item or Item Id string.
         If it's a drive the item will be moved to the root folder.
        :type target: drive.Folder or DriveItem or str
        :return: Success / Failure
        :rtype: bool
        Fz Target must be a Folder or Drivez2Both self, and target must have a valid object_id.r   z&When moving, target id can't be 'root'rc   r.   r   r/   r   T)rB   r  rJ   r   get_root_folderrW   rN   rG   rH   rI   r2   rP   r   r   )rX   rf   	target_idroot_folderrY   r   r;   s          r<   movezDriveItem.move  s     ff%((I& 002K#--I$I?@@~~YDF F EFFnnOO'..$...AC "D)#4588>>#D>1"r>   c                    ||t        d      t        |t              r%|j                  }|j                  }|j
                  }n\t        |t              r8|j                         }|sy|j                  }|j                  }|j
                  }n|d}d}d}nt        d      | j                  sy|dk(  rt        d      | j                  | j                  j                  d      j                  | j                              }|r
|rd||d	i}ni }|rHt        |      j                  s.| j                  r"|t        | j                        j                  z   }||d
<   | j                  j!                  ||      }	|	sy|	j"                  j                  dd      }
| j
                  xs | j$                  }|	j&                  dk(  rt)        ||
|      S t+        |
      j,                  }|j/                  d      d   }t)        |||      S )a  Asynchronously creates a copy of this DriveItem and all it's
        child elements.

        :param target: target location to move to.
            If it's a drive the item will be moved to the root folder.
            If it's None, the target is the parent of the item being copied i.e. item will be copied
            into the same location.
        :type target: drive.Folder or Drive
        :param name: a new name for the copy.
        :rtype: CopyOperation
        Nz)Must provide a target or a name (or both)z.Target, if provided, must be a Folder or Driver   z'When copying, target id can't be 'root'r   r.   r   )r/   r   r(   r   Location   )re   rl   rf   /)re   rm   rf   )rN   rB   r  rJ   r   r   r   r)  rG   rH   rI   r2   r   rE   r(   rP   r   headersr   status_coderb   r   r   split)rX   rf   r(   r*  r   target_driver+  rY   r   r;   locationre   r   rm   s                 r<   r   zDriveItem.copy  s    >dlHIIff%((IH!<<L& 002K#--I"++H&,,L^IHLMNN~~FGGnnOO'..$...AC %iH'MNDD:$$d499o444DL88==4=0 ##''
D9/t//3& H\ZZ H%**Djjob)G UUr>   c           	      |   | j                   sg S | j                  | j                  j                  d      j	                  | j                               }| j
                  j                  |      }|sg S |j                         }|j                  dg       D cg c]  }t        dd| i| j                  |i c}S c c}w )z Returns a list of available versions for this item

        :return: list of versions
        :rtype: list[DriveItemVersion]
        r   r.   r$  re   r`   	rJ   rG   rH   rI   r2   rP   r}   r   r   rX   rY   r;   r   rc   s        r<   get_versionszDriveItem.get_versions]  s     ~~InnOO
+22dnn2EG 88<<$I}} !HHWb13 !MM1E1Et0LM 3 	3 3s    B9c                 4   | j                   sy| j                  | j                  j                  d      j	                  | j                   |            }| j
                  j                  |      }|sy|j                         }t        dd| i| j                  |iS )z Returns a version for specified id

        :return: a version object of specified id
        :rtype: DriveItemVersion
        Nr   )r/   
version_idre   r`   r8  )rX   r<  rY   r;   r   s        r<   get_versionzDriveItem.get_versions  s     ~~nnOO	*11T^^=G 2 IJ 88<<$}}  LtL0D0Dd/KLLr>   c                 \   | j                   sy| j                  | j                  j                  d      j	                  | j                               }||d}|||d<   |||d<   | j
                  j                  ||      }|sy|j                         }t        d	d| i| j                  |iS )
a   Creates or returns a link you can share with others

        :param str share_type: 'view' to allow only view access,
         'edit' to allow editions, and
         'embed' to allow the DriveItem to be embedded
        :param str share_scope: 'anonymous': anyone with the link can access.
         'organization' Only organization members can access
        :param str share_password: sharing link password that is set by the creator. Optional.
        :param str share_expiration_date: format of yyyy-MM-dd (e.g., 2022-02-14) that indicates the expiration date of the permission. Optional.
        :return: link to share
        :rtype: DriveItemPermission
        Nr   r.   )r   r   passwordexpirationDateTimer   re   r`   )
rJ   rG   rH   rI   r2   rP   r   r}   r   r   )rX   r   r   share_passwordshare_expiration_daterY   r   r;   s           r<   share_with_linkzDriveItem.share_with_link  s     ~~nnOO-444GI  
 %-D ,)>D%&88==4=0}} #O$O43G3G2NOOr>   c                    | j                   syg }|t        d      t        |t        t        f      rd|D ]^  }t        |t
              r|j                  d|i       't        |t              r|j                  d|j                  i       Ut        d       n]t        |t
              r|j                  d|i       n9t        |t              r|j                  d|j                  i       nt        d      | j                  | j                  j                  d      j                  | j                               }d|| j                  d      || j                  d	      |i}	|d
v rdg|	d<   n%|dv rdg|	d<   nt        dj                  |            |r|r||	d<   | j                  j                  ||	      }
|
sy|
j!                         }	t#        dd| i| j$                  |	iS )a   Sends an invitation to access or edit this DriveItem

        :param recipients: a string or Contact or a list of the former
         representing recipients of this invitation
        :type recipients: list[str] or list[Contact] or str or Contact
        :param bool require_sign_in: if True the recipients
         invited will need to log in to view the contents
        :param bool send_email: if True an email will be send to the recipients
        :param str message: the body text of the message emailed
        :param str share_type: 'view': will allow to read the contents.
         'edit' will allow to modify the contents
        :return: link to share
        :rtype: DriveItemPermission
        NzProvide a valid to parameterr   z5All the recipients must be either strings or Contactsr   r.   
recipientsrequireSignInsendInvitation>   r   r   r   r   >   r   r7   r7   r   messager   re   r`   )rJ   rN   rB   listtuplerW   appendr   
main_emailrG   rH   rI   r2   r~   rP   r   r}   r   r   )rX   rE  r   
send_emailrH  r   toxrY   r   r;   s              r<   share_with_invitezDriveItem.share_with_invite  s     ~~;<<
T5M2 Qa%IIwl+7+IIw56$OQ QQ 
C(IIw
+,
G,IIw
 5 567GI I nnOO/66$..6IK "HH_%HH%&


 ))#HDM,,$IDM077
CE E'%DO88==4=0}}"O$O43G3G2NOOr>   c           	      z   | j                   sg S | j                  | j                  j                  d      j	                  | j                               }| j
                  j                  |      }|sy|j                         }|j                  dg       D cg c]  }t        dd| i| j                  |i c}S c c}w )z Returns a list of DriveItemPermissions with the
        permissions granted for this DriveItem.

        :return: List of Permissions
        :rtype: list[DriveItemPermission]
        r   r.   Nr$  re   r`   )	rJ   rG   rH   rI   r2   rP   r}   r   r   r9  s        r<   get_permissionszDriveItem.get_permissions  s     ~~InnOO.555HJ 88<<$}} !HHWb13 $P4PD4H4H$3OP 3 	3 3s    B8r   )NN)r   r   NN)TTNr   )r\   r]   r^   r   rH   rs   r   r   r   staticmethodr   propertyr  r  r  r  r  r  r  r&  r   r,  r   r:  r=  rC  rP  rR  r   r   s   @r<   r   r     s	   @ -.")9*6;!O.,0J" "&4 bEHC 	 	 ( ( & & ' ' ' '"U$<B**XEVN3,M,$PL =ADJ?PB3r>   r   c                   2     e Zd ZdZ fdZed        Z xZS )r
  z A File c                 p   t        |   di | |j                  | j                  i       }|j                  | j	                  d      i       j                  | j	                  d      d       | _        |j                  | j	                  d      i       j                  | j	                  d      d       | _        y )NfilemimeTypehashesr`   )rr   rs   rI   r   r~   	mime_typerY  )rX   rv   r   rw   s      r<   rs   zFile.__init__  s    "6"ZZ 4 4b9
 $(8"=AAHHZ $( !nnTXXf%5r:>>HHX&r>   c                 @    t        | j                        j                  S )zYThe suffix of the file name.

        :getter: get the suffix
        :type: str
        )r   r(   rE   r   s    r<   	extensionzFile.extension  s     DII%%%r>   )r\   r]   r^   r   rs   rT  r\  r   r   s   @r<   r
  r
    s    
& & &r>   r
  c                   2     e Zd ZdZ fdZed        Z xZS )r  z
 An Image c                 6   t        |   di | |j                  | j                  i       }|j                  | j	                  d      i       }|j                  | j	                  d      d      | _        |j                  | j	                  d      d      | _        y )Nr  heightr   widthr`   )rr   rs   rI   r   r~   r_  r`  )rX   rv   r   r  rw   s       r<   rs   zImage.__init__$  sx    "6"ZZ 4 4b9
txx0"5ii 2A6YYtxx0!4
r>   c                 N    dj                  | j                  | j                        S )zU Dimension of the Image

        :return: width x height
        :rtype: str
        z{}x{})r2   r`  r_  r   s    r<   
dimensionszImage.dimensions.  s     ~~djj$++66r>   )r\   r]   r^   r   rs   rT  rb  r   r   s   @r<   r  r  !  s    5 7 7r>   r  c                   "     e Zd ZdZ fdZ xZS )r	  z; Photo Object. Inherits from Image but has more attributes c                 f   t        |   d
i | |j                  | j                  i       }|j                  | j	                  d      i       }|j                  | j	                  d      d       }| j
                  j                  }|rt        |      j                  |      nd | _	        |j                  | j	                  d      d       | _
        |j                  | j	                  d      d       | _        |j                  | j	                  d      d       | _        |j                  | j	                  d      d       | _        |j                  | j	                  d      d       | _        |j                  | j	                  d      d       | _        |j                  | j	                  d	      d       | _        y )Nr  takenDateTime
cameraMakecameraModelexposureDenominatorexposureNumeratorfNumberfocalLengthisor`   )rr   rs   rI   r   r~   rj   r   r
   r   taken_datetimecamera_makecamera_modelexposure_denominatorexposure_numeratorfnumberfocal_lengthrl  )rX   rv   r   r  takenr   rw   s         r<   rs   zPhoto.__init__;  s[   "6"ZZ 4 4b9
txx0"5		$((?3T:==))  $El55$( 	 !99TXXl%;TB!IIdhh}&=tD$)IIdhh7L.M.2%4! #())DHH5H,I4"Pyy)!4d;!IIdhh}&=tD99TXXe_d3r>   )r\   r]   r^   r   rs   r   r   s   @r<   r	  r	  8  s    E4 4r>   r	  c                        e Zd ZdZ fdZddddddZddddddZddZddZdddddd	Z	de
d
dddddfdedefdZ xZS )r  z A Folder inside a Drive c                 R   t        |   |i | |j                  | j                  i       }|j                  | j	                  d      i       j                  | j	                  d      d      | _        |j                  | j	                  d      i       j                  dd       | _        y )Nr  
childCountr   specialFolderr(   )rr   rs   rI   r   r~   child_countspecial_folder)rX   argsrv   r   rw   s       r<   rs   zFolder.__init__Z  s    $)&)ZZ 4 4b9
 &>>$((8*<bAEEHH\"A' )nnTXXo-FKOODr>   Nqueryorder_bybatchc                     j                   j                  j                  d      j                   j                              }|| j
                  j                  kD  r j
                  j                  }d|r|n|i}|r||d<   |r5t        |t              r||d<   n|j                  |j                                 j                  j                  ||      }|st        d      S |j                         } fd	|j                  d
g       D        }	|j                  t        d      }
|r|
rt         |	 j                   |
|      S |	S )a&   Returns generator all the items inside this folder

        :param int limit: max no. of folders to get. Over 999 uses batch.
        :param query: applies a OData filter to the request
        :type query: Query or str
        :param order_by: orders the result set based on this condition
        :type order_by: Query or str
        :param int batch: batch size, retrieves items in
         batches allowing to retrieve more items than the limit.
        :return: items in this folder
        :rtype: generator of DriveItem or Pagination
        r   r.   N$top$orderby$filterr  r`   c              3   h   K   | ])  } j                  |      dd ij                  |i + ywre   Nr`   r   r   .0rc   rX   s     r<   	<genexpr>z#Folder.get_items.<locals>.<genexpr>  >      / #DT"O$O43G3G2NO/   /2r$  re   r   constructor	next_linklimit)rG   rH   rI   r2   rJ   rj   max_top_valuerB   rW   r&  	as_paramsrP   iterr}   r   r   r   )rX   r  r}  r~  r  rY   r4   r;   r   r   r  s   `          r<   	get_itemszFolder.get_itemse  s+    nnOO-444GI =EDMM$?$??MM//E5%e4!)F:%%$)y!eoo/088<<F<38O}}/"-/ HH.5	YT*.*:*:(1@ @ Lr>   c                Z   |rmt        |t              st        |t              r,t        | j                        }||j                  dd      z  }nI|j                  d      j                  d      }n(t        | j                        }|j                  dd      }| j                  ||||      S a%   Returns all the folders inside this folder

        :param int limit: max no. of folders to get. Over 999 uses batch.
        :param query: applies a OData filter to the request
        :type query: Query or str
        :param order_by: orders the result set based on this condition
        :type order_by: Query or str
        :param int batch: batch size, retrieves items in
         batches allowing to retrieve more items than the limit.
        :return: folder items in this folder
        :rtype: generator of DriveItem or Pagination
        )rj   r  Nr  r}  r~  r  rB   rW   r   r   rj   unequalon_attributer  rX   r  r}  r~  r  qs         r<   get_child_folderszFolder.get_child_folders  s     eS)e_5$dmm<A!AIIh$==E!..x8@@FEdmm4AIIh-E~~EQV~WWr>   c                 f   | j                   sy| j                  | j                  j                  d      j	                  | j                               }|i d}|r||d<   | j
                  j                  ||      }|sy|j                         } | j                  |      dd| i| j                  |iS )	z Creates a Child Folder

        :param str name: the name of the new child folder
        :param str description: the description of the new child folder
        :return: newly created folder
        :rtype: drive.Folder
        Nr   r.   )r(   r  r   r   re   r`   )
rJ   rG   rH   rI   r2   rP   r   r}   r   r   )rX   r(   r   rY   r   r;   r  s          r<   create_child_folderzFolder.create_child_folder  s     ~~nnOO-444GI +"-D88==4=0't' Jt J+/+?+?*HJ 	Jr>   c                 b   |	 t               | j                  z  }n-t               |z  }|j                         s|j                          t        |t              s!|j                         s(|j                          nt               | j                  z  }| j                  | j                         j                  dddd            D ]  }|j                  r/|j                  dkD  r |j                  ||j                  z  	       >|j                  r@|j                  dk(  r1||j                  z  }|j                         ry|j                          |j!                  |        y# t        $ rD}t        j	                  dj                  | j                  |             t               }Y d}~`d}~ww xY w)
z This will download each file and folder sequentially.
        Caution when downloading big folder structures
        :param drive.Folder to_folder: folder where to store the contents
        Nz0Could not create folder with name: {}. Error: {}r/   rK   r  r(   )r}  r   )	to_folder)r   r(   rU   rQ   rV   r2   rC   mkdirrB   rW   r  	new_queryr  r  ry  download_contentsr-   )rX   r  rZ   rc   child_folders        r<   r  zFolder.download_contents  sU   
 # FTYY.	
 *I##%!)S)##%!*INN)9)@)@vxY_)`Na 		)D~~$"2"2Q"6&&TYY1F&GD$4$4$9(4994#**, &&(i(		)  #		LSSTXT]T]_`ab F	#s   E! !	F.*9F))F.c                .    t        |t              r|st        d       j                   j                  j                  d      j                   j                  |            }|| j                  j                  kD  r j                  j                  }d|r|n|i}|r||d<   |rft        |t              r||d<   nP|j                  r%t        j                  d       |j                          |j                  |j                                 j                   j                  ||	      }|st#        d
      S |j%                         }	 fd|	j                  dg       D        }
|	j                  t&        d      }|r|rt)         |
 j*                  ||      S |
S )a   Search for DriveItems under this folder
        The search API uses a search service under the covers,
        which requires indexing of content.

        As a result, there will be some time between creation of an item
        and when it will appear in search results.

        :param str search_text: The query text used to search for items.
         Values may be matched across several fields including filename,
         metadata, and file content.
        :param int limit: max no. of folders to get. Over 999 uses batch.
        :param query: applies a OData filter to the request
        :type query: Query or str
        :param order_by: orders the result set based on this condition
        :type order_by: Query or str
        :param int batch: batch size, retrieves items in
         batches allowing to retrieve more items than the limit.
        :return: items in this folder matching search
        :rtype: generator of DriveItem or Pagination
        Provide a valid search_textr   r/   search_textNr  r  r  :Filters are not allowed by the Api Provider in this methodr  r`   c              3   h   K   | ])  } j                  |      dd ij                  |i + ywr  r  r  s     r<   r  z Folder.search.<locals>.<genexpr>$  r  r  r$  r  )rB   rW   rN   rG   rH   rI   r2   rJ   rj   r  has_filterswarningswarnclear_filtersr&  r  rP   r  r}   r   r   r   rX   r  r  r}  r~  r  rY   r4   r;   r   r   r  s   `           r<   r   zFolder.search  ss   , +s+;:;;nnOO)00DNN=H 1 JK =EDMM$?$??MM//E5%e4!)F:%%$)y!$$MM23 '')eoo/088<<F<38O}}/"-/ HH.5	YT*.*:*:(1@ @ Lr>   Ffile_created_date_timefile_last_modified_date_timec
                     |s`|t        d      t        |t              st        |      n|}|j                         st        d      |j	                         st        d      ||n|j                         j                  |st        k  r j                   j                  j                  d      j                   j                  t        ||j                  n|                  }
ddi}|r|j                         }n+|j!                  d	
      5 }|j                         }ddd        j"                  j%                  |
|      }|sy|j'                         }  j)                  |      dd i j*                  |iS  j                   j                  j                  d      j                   j                  t        ||j                  n|                  }
i }|r||j-                  dt/                     d<   |r5||j-                  dt/                     j-                  dt/                     d<   |	r5|	|j-                  dt/                     j-                  dt/                     d<   t0        j3                  d|        j"                  j5                  |
|      }|sy|j'                         }|j                   j7                  d      d      t0        j3                  dj                               |j                   j7                  d      d      }|r$t0        j3                  dj                  |             /t0        j9                  dj                  |j                               y fd}|r ||      S |j!                  d	
      5 } ||      cddd       S # 1 sw Y   xY w# 1 sw Y   yxY w)a   Uploads a file

        :param item: path to the item you want to upload
        :type item: str or Path
        :param item_name: name of the item on the server. None to use original name
        :type item_name: str or Path
        :param chunk_size: Only applies if file is bigger than 4MB or upload_in_chunks is True.
         Chunk size for uploads. Must be a multiple of 327.680 bytes
        :param upload_in_chunks: force the method to upload the file in chunks
        :param io.BufferedIOBase stream: (optional) an opened io object to read into.
         if set, the to_path and name will be ignored
        :param int stream_size: size of stream, required if using stream
        :param conflict_handling: How to handle conflicts.
         NOTE: works for chunk upload only (>4MB or upload_in_chunks is True)
         None to use default (overwrite). Options: fail | replace | rename
        :param file_created_date_time: allow to force file created date time while uploading
        :param file_last_modified_date_time: allow to force file last modified date time while uploading
        :type conflict_handling: str
        :return: uploaded file
        :rtype: DriveItem
        Nz!Item must be a valid path to filezItem must existzItem must be a filer   )r/   filenameContent-typeapplication/octet-streamrbr@   )r2  r   re   r   rc   z!@microsoft.graph.conflictBehaviorfileSystemInfor   r   zUploading file with file_data=r   	uploadUrlzResumable upload on url: {}r@  z*Expiration Date for this upload url is: {}z=Create upload session response without upload_url for file {}c                 ~   d}	 | j                        }|sy t        |      }dt        t        |            dj                  |||z   dz
        d}||z  }j                  j                  	d||      }|sy |j                  dk7  r5|j                         } j                  |      d
d	ij                  |iS )Nr   r  zbytes {}-{}/{}r   )r  zContent-LengthzContent-RangePUT)r   r2  r/  re   r`   )
r   lenrW   r2   rP   r|   r3  r}   r   r   )
rW  current_bytesr   transfer_bytesr2  r;   r)   	file_sizerX   
upload_urls
         r<   write_streamz(Folder.upload_file.<locals>.write_stream  s     !99Z0D%(YN(B*-c$i.*,,2F=3@3A4BDE4F3<->	G "^3M  $xx55j%;?>E  6  GH $#++s2'}}5t//5  9T  9 00$F8  9 97 r>   r`   )rN   rB   r   rC   r  statst_sizeUPLOAD_SIZE_LIMIT_SIMPLErG   rH   rI   r2   rJ   r   r(   r   rT   rP   putr}   r   r   
setdefaultdictrQ   infor   r~   rV   )rX   rc   	item_namer)   upload_in_chunksr3   stream_sizeconflict_handlingr  r  rY   r2  r   rW  r;   	file_dataexpiration_dater  r  r  s   `  `              @@r<   upload_filezFolder.upload_file/  sd   D | !DEE%/d%;4:D;;= !233<<> !677$/$;[ATAT	I1I$I..##O4;;t~~EJXaXi499oxEy < {|C &'ABG{{}YYDY) 'T99;D' xx||Ct|DH==?D)4##D) J J-1-A-A4,HJ J ..##$;<CC~~9CTdiiZc0d D fgC I \m	$$VTV45XY% pF	$$VTV4??@PRVRXYZkl+ uQ	$$VTV4??@PRVRXYZpqHH6I<89xx}}Sy}9H==?D$((;"7>JHH299*EF"hhtxx0D'EtLOELL_]^!		 3396$))3DF9@ #F++YYDY) .T'-. .a' '`. .s   N*N7*N47O r   )r\   r]   r^   r   rs   r  r  r  r  r   DEFAULT_UPLOAD_CHUNK_SIZErW   r  r   r   s   @r<   r  r  W  s    #	/TD /bXTDPT X6J8)@@td@J 0""*./3J. %(J. +.J.r>   r  c                   P    e Zd ZdZi dddddddd	d
dddddddddddddddddddddd d!d"d#d$d%iZd&d&d' fd(
Zd) Zd* Zd+ Zd, Z	d- Z
d;d&d&d&i d.d/Zd;d&d&d&d0d1Zd;d&d&d&d0d2Zd;d&d&d&d0d3Zd<d&d&d&d0d4Zd5 Zd6 Zd7 Zed8        Zd9 Zd;d&d&d&d0d:Z xZS )=r   z` A Drive representation.
    A Drive is a Container of Folders and Files and act as a root item default_driver   r  /drives/{id}get_root_item_defaultz/drive/rootget_root_itemz/drives/{id}/rootlist_items_defaultz/drive/root/childrenr   z/drives/{id}/root/childrenget_item_defaultz/drive/items/{item_id}r   z/drives/{id}/items/{item_id}get_item_by_path_defaultz/drive/root:{item_path}get_item_by_pathz/drives/{id}/root:{item_path}recent_defaultz/drive/recentrecentz/drives/{id}/recentshared_with_me_defaultz/drive/sharedWithMeshared_with_mez/drives/{id}/sharedWithMeget_special_defaultz/drive/special/{name}get_specialz/drives/{id}/special/{name}search_defaultz /drive/search(q='{search_text}')r   z&/drives/{id}/search(q='{search_text}')Nr   c                H   |r|rt        d      |r|j                  n|| _        t        |t              r|nd| _        |j                  dd      }||rt        |dd      nd}t        | !  |r|j                  n|j                  d      |       | j                  |       y)a   Create a drive representation

        :param parent: parent for this operation
        :type parent: Drive or Storage
        :param Connection con: connection to use if no parent specified
        :param Protocol protocol: protocol to use if no parent specified
         (kwargs)
        :param str main_resource: use this resource instead of parent resource
         (kwargs)
        rh   Nri   rj   rk   )rN   rP   rB   r   re   rp   rq   rr   rs   rj   rI   _update_datarX   re   rP   rv   ri   rw   s        r<   rs   zDrive.__init__  s     cIJJ!'6::S *65 9ft 

?D9 FLGFOTBRVM(.V__FJJz4J' 	 	) 	&!r>   c                 2   |j                  | j                  i       }|j                  | j                  d            | _        |j                  | j                  d      |j                  dd            | _        |j                  | j                  d            | _        |j                  | j                  d            | _        |j                  | j                  d            | _        |j                  | j                  d      i       j                  dd       }|r.t        d| j                  | j                  d	| j                  |ind | _        |j                  | j                  d
            | _        |j                  | j                  d      d       }|j                  | j                  d      d       }| j                  j                  }|rt        |      j                  |      nd | _        |r t        |      j                  |      | _        y d | _        y )Nr/   r(   r   r   	driveTyper   r   r   r   quotar   r   r`   )rI   r   r~   rJ   r(   r   
drive_typer   r   rP   rj   r   r  r   r
   r   r   r   )rX   r   r   r   r   r   r   s          r<   r  zDrive._update_data  s   XXd22B7
#7NN488F#3TXXf>@6B C	%>>$((=*AB$..+)>?!~~dhhx&89txx0"599&$GAF  >DMM > $ 4 4e<>LP 	
^^DHHW$56
..*;!<dC>>$((+A"BDI==))>EuW~00:4! h22'+ 	r>   c                 "    | j                         S r   r   r   s    r<   r   zDrive.__str__  r   r>   c                     | j                   rt        | j                         nd}| j                  xs | j                  xs d}|rdj	                  ||      S dj	                  |      S )Nr   Default DrivezDrive: {} (Owned by: {})z	Drive: {})r   rW   r(   rJ   r2   )rX   r   r(   s      r<   r   zDrive.__repr__
  sU    #'::DJJ2yy=DNN=o-44T5AA%%d++r>   c                 4    | j                   |j                   k(  S r   )rJ   )rX   r   s     r<   r   zDrive.__eq__  s    ~~00r>   c                    | j                   rE| j                  | j                  j                  d      j	                  | j                               }n*| j                  | j                  j                  d            }| j
                  j                  |      }|sy|j                         } | j                  |      dd| i| j                  |iS )zg Returns the Root Folder of this drive

        :return: Root Folder
        :rtype: DriveItem
        r  r.   r  Nre   r`   	rJ   rG   rH   rI   r2   rP   r}   r   r   )rX   rY   r;   r   s       r<   r)  zDrive.get_root_folder  s     >>..##O4;;t~~;NPC ..!4!45L!MNC88<<$}} &t% FT F)-)=)=t(DF 	Fr>   )r}  r~  r  r4   c                
    || j                   j                  kD  r j                   j                  }|r|n||d<   |r||d<   |r5t        |t              r||d<   n|j	                  |j                                 j                  j                  ||      }|st        d      S |j                         } fd|j                  dg       D        }	|j                  t        d      }
|r|
rt         |	 j                  |
|	      S |	S )
z% Returns a collection of drive items Nr  r  r  r  r`   c              3   h   K   | ])  } j                  |      dd ij                  |i + ywr  r  r  s     r<   r  z'Drive._base_get_list.<locals>.<genexpr>F  r  r  r$  r  )rj   r  rB   rW   r&  r  rP   rI   r  r}   r   r   r   )rX   rY   r  r}  r~  r  r4   r;   r   r   r  s   `          r<   _base_get_listzDrive._base_get_list-  s     =EDMM$?$??MM//E"'Uv!)F:%%$)y!eoo/088<<F<38O}}/"-/ HH.5	YT*.*:*:(1@ @ Lr>   r|  c                $   | j                   rE| j                  | j                  j                  d      j	                  | j                               }n*| j                  | j                  j                  d            }| j                  |||||      S )a*   Returns a collection of drive items from the root folder

        :param int limit: max no. of items to get. Over 999 uses batch.
        :param query: applies a OData filter to the request
        :type query: Query or str
        :param order_by: orders the result set based on this condition
        :type order_by: Query or str
        :param int batch: batch size, retrieves items in
         batches allowing to retrieve more items than the limit.
        :return: items in this folder
        :rtype: generator of DriveItem or Pagination
        r   r.   r  r  rJ   rG   rH   rI   r2   r  rX   r  r}  r~  r  rY   s         r<   r  zDrive.get_itemsR  s     >>..##L188DNN8KMC ..!4!45I!JKC""3e5,4E # C 	Cr>   c                Z   |rmt        |t              st        |t              r,t        | j                        }||j                  dd      z  }nI|j                  d      j                  d      }n(t        | j                        }|j                  dd      }| j                  ||||      S r  r  r  s         r<   r  zDrive.get_child_foldersk  s     eS)e_5$dmm<A!AIIh$==E!..x8@@FEdmm4AIIh-E~~EQV~WWr>   c                $   | j                   rE| j                  | j                  j                  d      j	                  | j                               }n*| j                  | j                  j                  d            }| j                  |||||      S )a"   Returns a collection of recently used DriveItems

        :param int limit: max no. of items to get. Over 999 uses batch.
        :param query: applies a OData filter to the request
        :type query: Query or str
        :param order_by: orders the result set based on this condition
        :type order_by: Query or str
        :param int batch: batch size, retrieves items in
         batches allowing to retrieve more items than the limit.
        :return: items in this folder
        :rtype: generator of DriveItem or Pagination
        r  r.   r  r  r  r  s         r<   
get_recentzDrive.get_recent  s     >>..##H-444GIC ..!4!45E!FGC""3e5,4E # C 	Cr>   c                .   | j                   rE| j                  | j                  j                  d      j	                  | j                               }n*| j                  | j                  j                  d            }d|i}| j                  ||||||      S )a   Returns a collection of DriveItems shared with me

        :param int limit: max no. of items to get. Over 999 uses batch.
        :param query: applies a OData filter to the request
        :type query: Query or str
        :param order_by: orders the result set based on this condition
        :type order_by: Query or str
        :param int batch: batch size, retrieves items in
         batches allowing to retrieve more items than the limit.
        :param allow_external: includes items shared from external tenants
        :type allow_external: bool
        :return: items in this folder
        :rtype: generator of DriveItem or Pagination
        r  r.   r  allowexternal)r  r}  r~  r  r4   r  )rX   r  allow_externalr}  r~  r  rY   r4   s           r<   get_shared_with_mezDrive.get_shared_with_me  s    " >>..##$45<<<OQC ..!4!45M!NOC ">2""3e5,4E& # R 	Rr>   c                    | j                   rF| j                  | j                  j                  d      j	                  | j                   |            }n:| j                  | j                  j                  d      j	                  |            }| j
                  j                  |      }|sy|j                         } | j                  |      dd| i| j                  |iS )z] Returns a DriveItem by it's Id

        :return: one item
        :rtype: DriveItem
        r   )r/   rm   r  r   Nre   r`   r  )rX   rm   rY   r;   r   s        r<   r   zDrive.get_item  s     >>..##J/66$..?F 7 HIC
 ..##$67>>w>OQC 88<<$}} &t% FT F)-)=)=t(DF 	Fr>   c                    |j                  d      sd|z   }| j                  rF| j                  | j                  j	                  d      j                  | j                  |            }n:| j                  | j                  j	                  d      j                  |            }| j                  j	                  |      }|sy|j                         } | j                  |      dd| i| j                  |iS )	zv Returns a DriveItem by it's absolute path: /path/to/file
        :return: one item
        :rtype: DriveItem
        r0  r  )r/   	item_pathr  )r  Nre   r`   )

startswithrJ   rG   rH   rI   r2   rP   r}   r   r   )rX   r  rY   r;   r   s        r<   r  zDrive.get_item_by_path  s     ##C(iI>>..##$67>>$..IR ? TUC
 ..##$>?FFQZF[]C 88<<$}} &t% FT F)-)=)=t(DF 	Fr>   c                 .   t        |t              r|nt        |j                               }|j                  }| j                  rF| j                  | j                  j                  d      j                  | j                  |            }n:| j                  | j                  j                  d      j                  |            }| j                  j                  |      }|sy|j                         } | j                  |      dd| i| j                  |iS )zn Returns the specified Special Folder

        :return: a special Folder
        :rtype: drive.Folder
        r  )r/   r(   r  )r(   Nre   r`   )rB   r   lowerr$  rJ   rG   rH   rI   r2   rP   r}   r   r   )rX   r(   rY   r;   r   s        r<   get_special_folderzDrive.get_special_folder  s    t89 ,TZZ\: 	 zz>>..##M299T^^?C : EFC
 ..##$9:AAtALNC 88<<$}} &t% FT F)-)=)=t(DF 	Fr>   c                 J    d| v rt         S d| v rt        S d| v rt        S t        S r  r  r  s    r<   r   zDrive._classifier  r  r>   c                    | j                   +| j                  | j                  j                  d            }nD| j                  | j                  j                  d      j	                  | j                               }| j
                  j                  |      }|sy|j                         }| j                  | j                  |i       y)zo Updates this drive with data from the server

        :return: Success / Failure
        :rtype: bool
        r  r  r.   FT)	rJ   rG   rH   rI   r2   rP   r}   r  r   r  s       r<   refreshzDrive.refresh  s     >>!..!4!4_!EFC..##K0774>>7JLC 88<<$4//78r>   c                    t        |t              r|st        d       j                  ; j	                   j
                  j                  d      j                  |            }nE j	                   j
                  j                  d      j                   j                  |            }|| j                  j                  kD  r j                  j                  }d|r|n|i}|r||d<   |rf|j                  r%t        j                  d	       |j                          t        |t              r||d
<   n|j                  |j                                 j                   j                  ||      }|st#        d      S |j%                         }	 fd|	j                  dg       D        }
|	j                  t&        d      }|r|rt)         |
 j*                  ||      S |
S )az   Search for DriveItems under this drive.
        Your app can search more broadly to include items shared with the
        current user.

        To broaden the search scope, use this search instead the Folder Search.

        The search API uses a search service under the covers, which requires
        indexing of content.

        As a result, there will be some time between creation of an
        item and when it will appear in search results.

        :param str search_text: The query text used to search for items.
         Values may be matched across several fields including filename,
         metadata, and file content.
        :param int limit: max no. of items to get. Over 999 uses batch.
        :param query: applies a OData filter to the request
        :type query: Query or str
        :param order_by: orders the result set based on this condition
        :type order_by: Query or str
        :param int batch: batch size, retrieves items in
         batches allowing to retrieve more items than the limit.
        :return: items in this folder matching search
        :rtype: generator of DriveItem or Pagination
        r  Nr  )r  r   r  r  r  r  r  r  r`   c              3   h   K   | ])  } j                  |      dd ij                  |i + ywr  r  r  s     r<   r  zDrive.search.<locals>.<genexpr>u  r  r  r$  r  )rB   rW   rN   rJ   rG   rH   rI   r2   rj   r  r  r  r  r  r&  r  rP   r  r}   r   r   r   r  s   `           r<   r   zDrive.search5  s   6 +s+;:;;>>!..!4!45E!F!M!M' "N ") *C ..##H-44AL 5 NOC =EDMM$?$??MM//E5%e4!)F:  %& ##%%%$)y!eoo/088<<F<38O}}/"-/ HH.5	YT*.*:*:(1@ @ Lr>   r   )NF)r\   r]   r^   r   rH   rs   r  r   r   r   r)  r  r  r  r  r  r   r  r   rS  r   r  r   r   r   s   @r<   r   r     s   K^ 	  	,	
 	4 	2 	4 	2 	#$= 	; 	/ 	' 	!"7 	5 	6  	4!" 	<#$ 	:%J* "&4 "6,.,1F0#td!"#JCTD C2XTDPT X4CdT C0RD[_!%R>F4F:F@ 	 	,ItdI Ir>   r   c                   Z     e Zd ZdZddddZeZddd fd
Zd	 Zd
 Z	ddZ
d Zd Z xZS )Storagez  Parent Class that holds drives r   r  z/drives)r  r  list_drivesNr   c                    |r|rt        d      |r|j                  n|| _        |j                  dd      xs |rt        |dd      nd}t        |   |r|j                  n|j                  d      |       y)a}   Create a storage representation

        :param parent: parent for this operation
        :type parent: Account
        :param Connection con: connection to use if no parent specified
        :param Protocol protocol: protocol to use if no parent specified
         (kwargs)
        :param str main_resource: use this resource instead of parent resource
         (kwargs)
        rh   ri   Nrj   rk   )rN   rP   rp   rq   rr   rs   rj   rI   r  s        r<   rs   zStorage.__init__  sy     cIJJ!'6::S 

?D9 H6<GFOT2$ 	(.V__FJJz4J' 	 	)r>   c                 "    | j                         S r   r   r   s    r<   r   zStorage.__str__  r   r>   c                 8    dj                  | j                        S )NzStorage for resource: {})r2   ri   r   s    r<   r   zStorage.__repr__  s    )001C1CDDr>   c                    |du r-t        | j                  | j                  | j                  d      S | j	                  | j
                  j                  d            }| j                  j                  |      }|sy|j                         } | j                  d| j                  | j                  | j                  d| j                  |iS )z Returns a Drive instance

        :param request_drive: True will make an api call to retrieve the drive
         data
        :return: default One Drive
        :rtype: Drive
        Fr  )rP   rj   ri   r(   r  NrP   rj   ri   r`   )
r   rP   rj   ri   rG   rH   rI   r}   drive_constructorr   )rX   request_driverY   r;   r   s        r<   get_default_drivezStorage.get_default_drive  s     E!TXX'+'9'9Q Q nnT__00AB88<<$ &t%% G$((T]]484F4FG)-)=)=u(EG 	Gr>   c                 X   |sy| j                  | j                  j                  d      j                  |            }| j                  j                  |      }|sy|j                         } | j                  d| j                  | j                  | j                  d| j                  |iS )z Returns a Drive instance

        :param drive_id: the drive_id to be retrieved
        :return: Drive for the id
        :rtype: Drive
        Nr  r.   r  r`   )
rG   rH   rI   r2   rP   r}   r  rj   ri   r   )rX   r   rY   r;   r   s        r<   r  zStorage.get_drive  s     nnOO,33x3@B 88<<$ &t%% G$((T]]484F4FG)-)=)=u(EG 	Gr>   c           	      <   | j                  | j                  j                  d            }| j                  j                  |      }|sg S |j	                         }|j                  dg       D cg c]"  } | j
                  dd| i| j                  |i$ }}|S c c}w )z Returns a collection of drivesr  r$  re   r`   )rG   rH   rI   rP   r}   r  r   )rX   rY   r;   r   r   drivess         r<   
get_driveszStorage.get_drives  s     nnT__00?@88<<$I}}  88GR02 )$((VV9M9Mu8UV 2 2 2s   .'B)F)r\   r]   r^   r   rH   r   r  rs   r   r   r  r  r  r   r   s   @r<   r  r    sF    * "# J
 !%4 ),EG2G0r>   r  )-loggingr  pathlibr   timer   typingr   r   urllib.parser   r   ior	   dateutil.parserr
   address_bookr   utilsr   r   r   r   r   r   	getLoggerr\   rQ   rL   r  UPLOAD_SIZE_LIMIT_SESSIONCHUNK_SIZE_BASEr  rO   r&   rb   r   r   r   r
  r  r	  r  r   r  r`   r>   r<   <module>r!     s       " (  ! !  g! * ,  , 3 a aHd@L d@N\N|%6 \N~@, @Ft3 t3n&9' &27D 7.4E 4>b.Y b.JBL BJgl gr>   