44from office365 .runtime .queries .service_operation_query import ServiceOperationQuery
55from office365 .runtime .resource_path import ResourcePath
66from office365 .runtime .resource_path_service_operation import ResourcePathServiceOperation
7+ from office365 .sharepoint .base_entity_collection import BaseEntityCollection
8+ from office365 .sharepoint .files .file_version_event import FileVersionEvent
79from office365 .sharepoint .internal .download_file import create_download_file_query
810from office365 .sharepoint .base_entity import BaseEntity
911from office365 .sharepoint .directory .user import User
1012from office365 .sharepoint .files .file_version_collection import FileVersionCollection
1113from office365 .sharepoint .listitems .listitem import ListItem
14+ from office365 .sharepoint .permissions .information_rights_management_settings import InformationRightsManagementSettings
1215from office365 .sharepoint .webparts .limited_webpart_manager import LimitedWebPartManager
1316from office365 .sharepoint .types .resource_path import ResourcePath as SPResPath
1417
@@ -48,6 +51,38 @@ def from_url(abs_url):
4851 file = ctx .web .get_file_by_server_relative_url (file_relative_url )
4952 return file
5053
54+ def get_image_preview_uri (self , width , height , client_type = None ):
55+ """
56+ :param int width:
57+ :param int height:
58+ :param str client_type:
59+ """
60+ result = ClientResult (self .context )
61+ payload = {
62+ "width" : width ,
63+ "height" : height ,
64+ "clientType" : client_type
65+ }
66+ qry = ServiceOperationQuery (self , "GetImagePreviewUri" , None , payload , None , result )
67+ self .context .add_query (qry )
68+ return result
69+
70+ def get_image_preview_url (self , width , height , client_type = None ):
71+ """
72+ :param int width:
73+ :param int height:
74+ :param str client_type:
75+ """
76+ result = ClientResult (self .context )
77+ payload = {
78+ "width" : width ,
79+ "height" : height ,
80+ "clientType" : client_type
81+ }
82+ qry = ServiceOperationQuery (self , "GetImagePreviewUrl" , None , payload , None , result )
83+ self .context .add_query (qry )
84+ return result
85+
5186 def recycle (self ):
5287 """Moves the file to the Recycle Bin and returns the identifier of the new Recycle Bin item."""
5388
@@ -201,6 +236,51 @@ def get_limited_webpart_manager(self, scope):
201236 self .resource_path
202237 ))
203238
239+ def open_binary_stream (self ):
240+ """Opens the file as a stream."""
241+ return_stream = ClientResult (self .context )
242+ qry = ServiceOperationQuery (self , "OpenBinaryStream" , None , None , None , return_stream )
243+ self .context .add_query (qry )
244+ return return_stream
245+
246+ def save_binary_stream (self , stream ):
247+ """Saves the file."""
248+ qry = ServiceOperationQuery (self , "SaveBinaryStream" , None , {"file" : stream })
249+ self .context .add_query (qry )
250+ return self
251+
252+ def get_upload_status (self , upload_id ):
253+ payload = {
254+ "uploadId" : upload_id ,
255+ }
256+ qry = ServiceOperationQuery (self , "GetUploadStatus" , None , payload )
257+ self .context .add_query (qry )
258+ return self
259+
260+ def upload_with_checksum (self , upload_id , checksum , stream ):
261+ """
262+ :param str upload_id:
263+ :param str checksum:
264+ :param bytes stream:
265+ """
266+ return_type = File (self .context )
267+ payload = {
268+ "uploadId" : upload_id ,
269+ "checksum" : checksum ,
270+ "stream" : stream
271+ }
272+ qry = ServiceOperationQuery (self , "UploadWithChecksum" , None , payload , None , return_type )
273+ self .context .add_query (qry )
274+ return return_type
275+
276+ def cancel_upload (self , upload_id ):
277+ payload = {
278+ "uploadId" : upload_id ,
279+ }
280+ qry = ServiceOperationQuery (self , "CancelUpload" , None , payload )
281+ self .context .add_query (qry )
282+ return self
283+
204284 def start_upload (self , upload_id , content ):
205285 """Starts a new chunk upload session and uploads the first fragment.
206286
@@ -324,6 +404,7 @@ def _construct_download_request(request):
324404 """
325405 request .stream = True
326406 request .method = HttpMethod .Get
407+
327408 self .context .before_execute (_construct_download_request )
328409
329410 def _process_download_response (response ):
@@ -337,13 +418,35 @@ def _process_download_response(response):
337418 if callable (chunk_downloaded ):
338419 chunk_downloaded (bytes_read )
339420 file_object .write (chunk )
421+
340422 self .context .after_execute (_process_download_response )
341423
342424 self .context .add_query (qry )
343425
344426 self .ensure_property ("ServerRelativeUrl" , _download_as_stream )
345427 return self
346428
429+ @property
430+ def checked_out_by_user (self ):
431+ """Gets an object that represents the user who has checked out the file."""
432+ return self .properties .get ('CheckedOutByUser' ,
433+ User (self .context , ResourcePath ("CheckedOutByUser" , self .resource_path )))
434+
435+ @property
436+ def version_events (self ):
437+ return self .properties .get ("VersionEvents" ,
438+ BaseEntityCollection (self .context ,
439+ FileVersionEvent ,
440+ ResourcePath ("VersionEvents" , self .resource_path )))
441+
442+ @property
443+ def information_rights_management_settings (self ):
444+ return self .properties .get ('InformationRightsManagementSettings' ,
445+ InformationRightsManagementSettings (self .context ,
446+ ResourcePath (
447+ "InformationRightsManagementSettings" ,
448+ self .resource_path )))
449+
347450 @property
348451 def listItemAllFields (self ):
349452 """Gets a value that specifies the list item fields values for the list item corresponding to the file."""
@@ -387,7 +490,7 @@ def server_relative_path(self):
387490 """Gets the server-relative Path of the list folder.
388491 :rtype: SPResPath or None
389492 """
390- return self .properties .get ("ServerRelativePath" , SPResPath (None ))
493+ return self .properties .get ("ServerRelativePath" , SPResPath ())
391494
392495 @property
393496 def length (self ):
@@ -482,6 +585,9 @@ def unique_id(self):
482585 def get_property (self , name , default_value = None ):
483586 if default_value is None :
484587 property_mapping = {
588+ "CheckedOutByUser" : self .checked_out_by_user ,
589+ "VersionEvents" : self .version_events ,
590+ "InformationRightsManagementSettings" : self .information_rights_management_settings ,
485591 "LockedByUser" : self .locked_by_user ,
486592 "ModifiedBy" : self .modified_by
487593 }
0 commit comments