Skip to content

Commit 4ba6349

Browse files
committed
Updates for the Ruff linter and several refactorings
1 parent 34eef16 commit 4ba6349

File tree

14 files changed

+83
-33
lines changed

14 files changed

+83
-33
lines changed

examples/onedrive/files/copy_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# source_path = "archive/Sample.rtf"
1515
local_path = "../../data/Financial Sample.xlsx"
1616
source_file = client.me.drive.root.upload_file(local_path).execute_query()
17-
# new_name = "Sample (copy).rtf"
17+
1818
# source_file = client.me.drive.root.get_by_path(source_path) # source file item
1919
target_path = "archive/2018"
2020
target_folder = client.me.drive.root.get_by_path(target_path)

examples/sharepoint/files/download_large.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
Demonstrates how to download large files.
3+
"""
4+
15
import os
26
import tempfile
37

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
"""
2+
Create a new Document Set
3+
4+
https://support.microsoft.com/en-us/office/introduction-to-document-sets-3dbcd93e-0bed-46b7-b1ba-b31de2bcd234
5+
"""
6+
17
from office365.sharepoint.client_context import ClientContext
28
from office365.sharepoint.documentmanagement.document_set import DocumentSet
39
from tests import test_client_credentials, test_team_site_url
410

511
client = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
612
lib = client.web.default_document_library()
7-
doc_set = DocumentSet.create(client, lib.root_folder, "07").execute_query()
13+
doc_set = DocumentSet.create(client, lib.root_folder, "09").execute_query()
814
print("DocSet created: {0}".format(doc_set.name))
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""
2+
Returns a SharePoint site status
3+
"""
4+
from office365.sharepoint.client_context import ClientContext
5+
from tests import test_team_site_url, test_admin_site_url, test_admin_credentials
6+
7+
admin_client = ClientContext(test_admin_site_url).with_credentials(test_admin_credentials)
8+
result = admin_client.site_manager.get_status(test_team_site_url).execute_query()
9+
print(result.value)

generator/metadata/SharePoint.xml

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,11 @@
398398
<Property Name="FieldValues" Type="Collection(SP.CAFieldValue)"/>
399399
<Property Name="ServerRedirectedEmbedUrl" Type="Edm.String"/>
400400
</ComplexType>
401+
<ComplexType Name="GridInitInfoType">
402+
<Property Name="ControllerId" Type="Edm.String"/>
403+
<Property Name="GridSerializer" Type="Edm.String"/>
404+
<Property Name="JsInitObj" Type="Edm.String"/>
405+
</ComplexType>
401406
<ComplexType Name="HTMLFieldSecuritySetting">
402407
<Property Name="allowedDomains" Type="Collection(Edm.String)"/>
403408
<Property Name="allowEmbedding" Type="Edm.Int16" Nullable="false"/>
@@ -1971,6 +1976,7 @@
19711976
<Key>
19721977
<PropertyRef Name="Id"/>
19731978
</Key>
1979+
<Property Name="AutofillInfo" Type="Edm.String"/>
19741980
<Property Name="AutoIndexed" Type="Edm.Boolean" Nullable="false"/>
19751981
<Property Name="CanBeDeleted" Type="Edm.Boolean" Nullable="false"/>
19761982
<Property Name="ClientSideComponentId" Type="Edm.Guid" Nullable="false"/>
@@ -2329,6 +2335,7 @@
23292335
<Property Name="DefaultViewForContentType" Type="Edm.Boolean" Nullable="false"/>
23302336
<Property Name="EditorModified" Type="Edm.Boolean" Nullable="false"/>
23312337
<Property Name="Formats" Type="Edm.String"/>
2338+
<Property Name="GridInitInfo" Type="SP.GridInitInfoType"/>
23322339
<Property Name="GridLayout" Type="Edm.String"/>
23332340
<Property Name="Hidden" Type="Edm.Boolean" Nullable="false"/>
23342341
<Property Name="HtmlSchemaXml" Type="Edm.String"/>
@@ -10394,8 +10401,9 @@
1039410401
<FunctionImport Name="GetSiteMoveState" ReturnType="Edm.Int32" IsBindable="true">
1039510402
<Parameter Name="this" Type="Microsoft.SharePoint.Administration.SiteMove.Service.SiteMoveService"/>
1039610403
</FunctionImport>
10397-
<FunctionImport Name="GetSiteSize" ReturnType="Edm.Int64" IsBindable="true">
10404+
<FunctionImport Name="GetSiteProperties" ReturnType="Edm.String" IsBindable="true">
1039810405
<Parameter Name="this" Type="Microsoft.SharePoint.Administration.SiteMove.Service.SiteMoveService"/>
10406+
<Parameter Name="isDeleted" Type="Edm.Boolean" Nullable="false"/>
1039910407
</FunctionImport>
1040010408
<FunctionImport Name="IsDbReadOnly" ReturnType="Edm.Boolean" IsBindable="true">
1040110409
<Parameter Name="this" Type="Microsoft.SharePoint.Administration.SiteMove.Service.SiteMoveService"/>
@@ -12068,6 +12076,10 @@
1206812076
<Parameter Name="folderPath" Type="Edm.String"/>
1206912077
<Parameter Name="extension" Type="Edm.String"/>
1207012078
</FunctionImport>
12079+
<FunctionImport Name="CreateHVCSItemApprovalRequest" ReturnType="Edm.String" IsBindable="true">
12080+
<Parameter Name="this" Type="SP.List"/>
12081+
<Parameter Name="createItemRequestPayload" Type="SP.ApprovalsCreateRequestParameters"/>
12082+
</FunctionImport>
1207112083
<FunctionImport Name="CreateMappedView" ReturnType="SP.View" IsBindable="true" EntitySet="Views">
1207212084
<Parameter Name="this" Type="SP.List"/>
1207312085
<Parameter Name="appViewCreationInfo" Type="SP.AppViewCreationInfo"/>
@@ -13793,10 +13805,12 @@
1379313805
<FunctionImport Name="SP_SharedWithMeItemCollection_RemoveFromSharedWithMe" ReturnType="Edm.String">
1379413806
<Parameter Name="spoIds" Type="Edm.String"/>
1379513807
<Parameter Name="itemIds" Type="Collection(Edm.String)"/>
13808+
<Parameter Name="workingSetIds" Type="Collection(Edm.String)"/>
1379613809
</FunctionImport>
1379713810
<FunctionImport Name="SP_SharedWithMeItemCollection_RestoreToSharedWithMe" ReturnType="Edm.String">
1379813811
<Parameter Name="spoIds" Type="Edm.String"/>
1379913812
<Parameter Name="itemIds" Type="Collection(Edm.String)"/>
13813+
<Parameter Name="workingSetIds" Type="Collection(Edm.String)"/>
1380013814
</FunctionImport>
1380113815
<FunctionImport Name="SP_SmartCache_Update">
1380213816
<Parameter Name="smartCacheJson" Type="Edm.String"/>
@@ -14526,6 +14540,9 @@
1452614540
<Parameter Name="this" Type="SP.File"/>
1452714541
<Parameter Name="comment" Type="Edm.String"/>
1452814542
</FunctionImport>
14543+
<FunctionImport Name="Archive" IsBindable="true">
14544+
<Parameter Name="this" Type="SP.File"/>
14545+
</FunctionImport>
1452914546
<FunctionImport Name="CancelUpload" IsBindable="true">
1453014547
<Parameter Name="this" Type="SP.File"/>
1453114548
<Parameter Name="uploadId" Type="Edm.Guid" Nullable="false"/>
@@ -14692,6 +14709,9 @@
1469214709
<Parameter Name="uploadId" Type="Edm.Guid" Nullable="false"/>
1469314710
<Parameter Name="stream" Type="Edm.Stream"/>
1469414711
</FunctionImport>
14712+
<FunctionImport Name="Unarchive" IsBindable="true">
14713+
<Parameter Name="this" Type="SP.File"/>
14714+
</FunctionImport>
1469514715
<FunctionImport Name="UndoCheckOut" IsBindable="true">
1469614716
<Parameter Name="this" Type="SP.File"/>
1469714717
</FunctionImport>
@@ -21491,6 +21511,9 @@
2149121511
<Annotations Target="SP.CurrencyInformation">
2149221512
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
2149321513
</Annotations>
21514+
<Annotations Target="SP.GridInitInfoType">
21515+
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
21516+
</Annotations>
2149421517
<Annotations Target="SP.ItemOrderUpdateValue">
2149521518
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
2149621519
</Annotations>
@@ -23162,6 +23185,9 @@
2316223185
<Annotations Target="SP.ContentType/EditFormTarget">
2316323186
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
2316423187
</Annotations>
23188+
<Annotations Target="SP.Field/AutofillInfo">
23189+
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
23190+
</Annotations>
2316523191
<Annotations Target="SP.Field/ClientSideComponentId">
2316623192
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
2316723193
</Annotations>
@@ -27474,10 +27500,10 @@
2747427500
<Annotations Target="SP.ApiData/SP_SharedWithMeItemCollection_GetSharedWithMeItems(Edm.Int32, Edm.String, Edm.Boolean)">
2747527501
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
2747627502
</Annotations>
27477-
<Annotations Target="SP.ApiData/SP_SharedWithMeItemCollection_RemoveFromSharedWithMe(Edm.String, Collection(Edm.String))">
27503+
<Annotations Target="SP.ApiData/SP_SharedWithMeItemCollection_RemoveFromSharedWithMe(Edm.String, Collection(Edm.String), Collection(Edm.String))">
2747827504
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
2747927505
</Annotations>
27480-
<Annotations Target="SP.ApiData/SP_SharedWithMeItemCollection_RestoreToSharedWithMe(Edm.String, Collection(Edm.String))">
27506+
<Annotations Target="SP.ApiData/SP_SharedWithMeItemCollection_RestoreToSharedWithMe(Edm.String, Collection(Edm.String), Collection(Edm.String))">
2748127507
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
2748227508
</Annotations>
2748327509
<Annotations Target="SP.ApiData/SP_SmartCache_Update(Edm.String)">
@@ -35342,6 +35368,7 @@
3534235368
<Property Name="Audiences" Type="Collection(Edm.String)"/>
3534335369
<Property Name="Icon" Type="Edm.String"/>
3534435370
<Property Name="Id" Type="Edm.Int32" Nullable="false"/>
35371+
<Property Name="ThumbnailOption" Type="Edm.String"/>
3534535372
<Property Name="Title" Type="Edm.String"/>
3534635373
<Property Name="Url" Type="Edm.String"/>
3534735374
</ComplexType>
@@ -37548,6 +37575,10 @@
3754837575
<Property Name="ResourceGroup" Type="Edm.String"/>
3754937576
<Property Name="SPContainerTypeBillingClassification" Type="Edm.Int32" Nullable="false"/>
3755037577
</ComplexType>
37578+
<ComplexType Name="SPContentEventsCustomEmailProperty">
37579+
<Property Name="Category" Type="Edm.Int32" Nullable="false"/>
37580+
<Property Name="EmailAddresses" Type="Collection(Edm.String)"/>
37581+
</ComplexType>
3755137582
<ComplexType Name="SPDataGovernanceInsightMetadata">
3755237583
<Property Name="ReportId" Type="Edm.Guid" Nullable="false"/>
3755337584
<Property Name="Status" Type="Edm.String"/>
@@ -37875,8 +37906,6 @@
3787537906
<Property Name="LockState" Type="Edm.String"/>
3787637907
<Property Name="LoopDefaultSharingLinkRole" Type="Edm.Int32" Nullable="false"/>
3787737908
<Property Name="LoopDefaultSharingLinkScope" Type="Edm.Int32" Nullable="false"/>
37878-
<Property Name="LoopOverrideSharingCapability" Type="Edm.Boolean" Nullable="false"/>
37879-
<Property Name="LoopSharingCapability" Type="Edm.Int32" Nullable="false"/>
3788037909
<Property Name="MajorVersionLimit" Type="Edm.Int32" Nullable="false"/>
3788137910
<Property Name="MajorWithMinorVersionsLimit" Type="Edm.Int32" Nullable="false"/>
3788237911
<Property Name="MediaTranscription" Type="Edm.Int32" Nullable="false"/>
@@ -38133,6 +38162,7 @@
3813338162
<Property Name="EnableDirectToCustomerBilling" Type="Edm.Boolean" Nullable="false"/>
3813438163
<Property Name="EnableDiscoverableByOrganizationForVideos" Type="Edm.Boolean" Nullable="false"/>
3813538164
<Property Name="EnableGuestSignInAcceleration" Type="Edm.Boolean" Nullable="false"/>
38165+
<Property Name="EnableMediaReactions" Type="Edm.Boolean" Nullable="false"/>
3813638166
<Property Name="EnableMinimumVersionRequirement" Type="Edm.Boolean" Nullable="false"/>
3813738167
<Property Name="EnableMipSiteLabel" Type="Edm.Boolean" Nullable="false"/>
3813838168
<Property Name="EnablePromotedFileHandlers" Type="Edm.Boolean" Nullable="false"/>
@@ -38261,6 +38291,7 @@
3826138291
<Property Name="RequireAnonymousLinksExpireInDays" Type="Edm.Int32" Nullable="false"/>
3826238292
<Property Name="ResourceQuota" Type="Edm.Double" Nullable="false"/>
3826338293
<Property Name="ResourceQuotaAllocated" Type="Edm.Double" Nullable="false"/>
38294+
<Property Name="RestrictedAccessControlforSitesErrorHelpLink" Type="Edm.String"/>
3826438295
<Property Name="RestrictedOneDriveLicense" Type="Edm.Boolean" Nullable="false"/>
3826538296
<Property Name="RestrictedSharePointLicense" Type="Edm.Boolean" Nullable="false"/>
3826638297
<Property Name="RootSiteUrl" Type="Edm.String"/>
@@ -40204,7 +40235,6 @@
4020440235
<Property Name="CoreDefaultShareLinkScope" Type="Edm.Int32" Nullable="false"/>
4020540236
<Property Name="CoreLoopDefaultSharingLinkRole" Type="Edm.Int32" Nullable="false"/>
4020640237
<Property Name="CoreLoopDefaultSharingLinkScope" Type="Edm.Int32" Nullable="false"/>
40207-
<Property Name="CoreLoopSharingCapability" Type="Edm.Int32" Nullable="false"/>
4020840238
<Property Name="CoreRequestFilesLinkEnabled" Type="Edm.Boolean" Nullable="false"/>
4020940239
<Property Name="CoreRequestFilesLinkExpirationInDays" Type="Edm.Int32" Nullable="false"/>
4021040240
<Property Name="CoreSharingCapability" Type="Edm.Int32" Nullable="false"/>
@@ -40282,7 +40312,6 @@
4028240312
<Property Name="MySitesPublicEnabled" Type="Edm.Boolean" Nullable="false"/>
4028340313
<Property Name="NotificationsInOneDriveForBusinessEnabled" Type="Edm.Boolean" Nullable="false"/>
4028440314
<Property Name="NotificationsInSharePointEnabled" Type="Edm.Boolean" Nullable="false"/>
40285-
<Property Name="NotifyOwnersWhenInvitationsAccepted" Type="Edm.Boolean" Nullable="false"/>
4028640315
<Property Name="NotifyOwnersWhenItemsReshared" Type="Edm.Boolean" Nullable="false"/>
4028740316
<Property Name="ODBAccessRequests" Type="Edm.Int32" Nullable="false"/>
4028840317
<Property Name="ODBMembersCanShare" Type="Edm.Int32" Nullable="false"/>
@@ -40296,7 +40325,6 @@
4029640325
<Property Name="OneDriveForGuestsEnabled" Type="Edm.Boolean" Nullable="false"/>
4029740326
<Property Name="OneDriveLoopDefaultSharingLinkRole" Type="Edm.Int32" Nullable="false"/>
4029840327
<Property Name="OneDriveLoopDefaultSharingLinkScope" Type="Edm.Int32" Nullable="false"/>
40299-
<Property Name="OneDriveLoopSharingCapability" Type="Edm.Int32" Nullable="false"/>
4030040328
<Property Name="OneDriveRequestFilesLinkEnabled" Type="Edm.Boolean" Nullable="false"/>
4030140329
<Property Name="OneDriveRequestFilesLinkExpirationInDays" Type="Edm.Int32" Nullable="false"/>
4030240330
<Property Name="OwnerAnonymousNotification" Type="Edm.Boolean" Nullable="false"/>
@@ -40308,8 +40336,8 @@
4030840336
<Property Name="RecycleBinRetentionPeriod" Type="Edm.Int32" Nullable="false"/>
4030940337
<Property Name="ReduceTempTokenLifetimeEnabled" Type="Edm.Boolean" Nullable="false"/>
4031040338
<Property Name="ReduceTempTokenLifetimeValue" Type="Edm.Int32" Nullable="false"/>
40311-
<Property Name="RequireAcceptingAccountMatchInvitedAccount" Type="Edm.Boolean" Nullable="false"/>
4031240339
<Property Name="RequireAnonymousLinksExpireInDays" Type="Edm.Int32" Nullable="false"/>
40340+
<Property Name="RestrictedAccessControlforSitesErrorHelpLink" Type="Edm.String"/>
4031340341
<Property Name="SearchResolveExactEmailOrUPN" Type="Edm.Boolean" Nullable="false"/>
4031440342
<Property Name="SharingAllowedDomainList" Type="Edm.String"/>
4031540343
<Property Name="SharingBlockedDomainList" Type="Edm.String"/>

office365/directory/users/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def _construct_request(request):
349349
start_dt.isoformat(), end_dt.isoformat()
350350
)
351351

352-
self.context.add_query(qry).before_execute(_construct_request)
352+
self.context.add_query(qry).before_query_execute(_construct_request)
353353
return return_type
354354

355355
def get_reminder_view(self, start_dt, end_dt):

office365/onedrive/driveitems/driveItem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ def _process_response(resp):
502502

503503
payload = {"name": name, "parentReference": parent_reference}
504504
qry = ServiceOperationQuery(self, "copy", None, payload, None, return_type)
505-
self.context.add_query(qry).before_execute(_create_request).after_execute(
505+
self.context.add_query(qry).before_query_execute(_create_request).after_execute(
506506
_process_response
507507
)
508508

office365/onedrive/workbooks/workbook.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing_extensions import Self
2+
13
from office365.entity import Entity
24
from office365.entity_collection import EntityCollection
35
from office365.onedrive.workbooks.applications.application import WorkbookApplication
@@ -50,6 +52,7 @@ def create_session(self, persist_changes=None):
5052
return return_type
5153

5254
def refresh_session(self, session_id):
55+
# type: (str) -> Self
5356
"""Use this API to refresh an existing workbook session.
5457
:param str session_id: Identifier of the workbook session
5558
"""
@@ -59,10 +62,11 @@ def _construct_request(request):
5962
request.set_header("workbook-session-id", session_id)
6063

6164
qry = ServiceOperationQuery(self, "refreshSession")
62-
self.context.add_query(qry).before_execute(_construct_request)
65+
self.context.add_query(qry).before_query_execute(_construct_request)
6366
return self
6467

6568
def close_session(self, session_id):
69+
# type: (str) -> Self
6670
"""Use this API to close an existing workbook session.
6771
:param str session_id: Identifier of the workbook session
6872
"""
@@ -72,7 +76,7 @@ def _construct_request(request):
7276
# type: (RequestOptions) -> None
7377
request.set_header("workbook-session-id", session_id)
7478

75-
self.context.add_query(qry).before_execute(_construct_request)
79+
self.context.add_query(qry).before_query_execute(_construct_request)
7680
return self
7781

7882
@property

office365/onenote/internal/multipart_page_query.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from office365.runtime.compat import get_mime_type, message_as_bytes_or_string
55
from office365.runtime.http.http_method import HttpMethod
6+
from office365.runtime.http.request_options import RequestOptions
67
from office365.runtime.queries.batch import create_boundary
78
from office365.runtime.queries.client_query import ClientQuery
89

@@ -32,9 +33,7 @@ def __init__(self, pages, presentation_file, attachment_files=None):
3233
self._files = attachment_files
3334

3435
def _construct_multipart_request(self, request):
35-
"""
36-
:type request: office365.runtime.http.request_options.RequestOptions
37-
"""
36+
# type: (RequestOptions) -> None
3837
request.method = HttpMethod.Post
3938
boundary = create_boundary("PageBoundary", True)
4039
request.set_header(

office365/sharepoint/documentmanagement/document_set.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,9 @@ def create(context, parent_folder, name, ct_id="0x0120D520"):
2121

2222
return_type = DocumentSet(context)
2323

24-
def _parent_folder_loaded():
25-
custom_props = parent_folder.get_property("Properties")
26-
list_id = custom_props.get("vti_x005f_listname")
27-
target_list = context.web.lists.get_by_id(list_id)
28-
target_list.ensure_property("Title", _create, target_list=target_list)
29-
3024
def _create(target_list):
3125
# type: (List) -> None
3226
qry = ClientQuery(context, return_type=return_type)
33-
context.add_query(qry)
3427
folder_url = parent_folder.serverRelativeUrl + "/" + name
3528
return_type.set_property("ServerRelativeUrl", folder_url)
3629

@@ -43,7 +36,13 @@ def _construct_request(request):
4336
request.set_header("Slug", "{0}|{1}".format(folder_url, ct_id))
4437
request.method = HttpMethod.Post
4538

46-
context.before_execute(_construct_request)
39+
context.add_query(qry).before_query_execute(_construct_request)
40+
41+
def _parent_folder_loaded():
42+
custom_props = parent_folder.get_property("Properties")
43+
list_id = custom_props.get("vti_x005f_listname")
44+
target_list = context.web.lists.get_by_id(list_id)
45+
target_list.ensure_property("Title", _create, target_list=target_list)
4746

4847
parent_folder.ensure_properties(
4948
["UniqueId", "Properties", "ServerRelativeUrl"], _parent_folder_loaded

0 commit comments

Comments
 (0)