4
4
from office365 .runtime .queries .service_operation_query import ServiceOperationQuery
5
5
from office365 .runtime .resource_path import ResourcePath
6
6
from 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
7
9
from office365 .sharepoint .internal .download_file import create_download_file_query
8
10
from office365 .sharepoint .base_entity import BaseEntity
9
11
from office365 .sharepoint .directory .user import User
10
12
from office365 .sharepoint .files .file_version_collection import FileVersionCollection
11
13
from office365 .sharepoint .listitems .listitem import ListItem
14
+ from office365 .sharepoint .permissions .information_rights_management_settings import InformationRightsManagementSettings
12
15
from office365 .sharepoint .webparts .limited_webpart_manager import LimitedWebPartManager
13
16
from office365 .sharepoint .types .resource_path import ResourcePath as SPResPath
14
17
@@ -48,6 +51,38 @@ def from_url(abs_url):
48
51
file = ctx .web .get_file_by_server_relative_url (file_relative_url )
49
52
return file
50
53
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
+
51
86
def recycle (self ):
52
87
"""Moves the file to the Recycle Bin and returns the identifier of the new Recycle Bin item."""
53
88
@@ -201,6 +236,51 @@ def get_limited_webpart_manager(self, scope):
201
236
self .resource_path
202
237
))
203
238
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
+
204
284
def start_upload (self , upload_id , content ):
205
285
"""Starts a new chunk upload session and uploads the first fragment.
206
286
@@ -324,6 +404,7 @@ def _construct_download_request(request):
324
404
"""
325
405
request .stream = True
326
406
request .method = HttpMethod .Get
407
+
327
408
self .context .before_execute (_construct_download_request )
328
409
329
410
def _process_download_response (response ):
@@ -337,13 +418,35 @@ def _process_download_response(response):
337
418
if callable (chunk_downloaded ):
338
419
chunk_downloaded (bytes_read )
339
420
file_object .write (chunk )
421
+
340
422
self .context .after_execute (_process_download_response )
341
423
342
424
self .context .add_query (qry )
343
425
344
426
self .ensure_property ("ServerRelativeUrl" , _download_as_stream )
345
427
return self
346
428
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
+
347
450
@property
348
451
def listItemAllFields (self ):
349
452
"""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):
387
490
"""Gets the server-relative Path of the list folder.
388
491
:rtype: SPResPath or None
389
492
"""
390
- return self .properties .get ("ServerRelativePath" , SPResPath (None ))
493
+ return self .properties .get ("ServerRelativePath" , SPResPath ())
391
494
392
495
@property
393
496
def length (self ):
@@ -482,6 +585,9 @@ def unique_id(self):
482
585
def get_property (self , name , default_value = None ):
483
586
if default_value is None :
484
587
property_mapping = {
588
+ "CheckedOutByUser" : self .checked_out_by_user ,
589
+ "VersionEvents" : self .version_events ,
590
+ "InformationRightsManagementSettings" : self .information_rights_management_settings ,
485
591
"LockedByUser" : self .locked_by_user ,
486
592
"ModifiedBy" : self .modified_by
487
593
}
0 commit comments