Skip to content

Commit a7897ee

Browse files
committed
typings enhancements & examples update
1 parent 2253066 commit a7897ee

File tree

9 files changed

+132
-63
lines changed

9 files changed

+132
-63
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
Retrieves collection of checked-out files in a document library
3+
"""
4+
import sys
5+
6+
from office365.sharepoint.client_context import ClientContext
7+
from tests import test_client_credentials, test_site_url
8+
9+
ctx = ClientContext(test_site_url).with_credentials(test_client_credentials)
10+
doc_lib = ctx.web.default_document_library()
11+
12+
files = doc_lib.items.top(1).get().execute_query()
13+
if len(files) < 1:
14+
sys.exit("No files were found")
15+
16+
17+
items = doc_lib.get_checked_out_files().execute_query()
18+
if len(items) == 0:
19+
sys.exit("No files were checked out")

generator/import_metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ def export_to_file(path, content):
2121
"--endpoint",
2222
dest="endpoint",
2323
help="Import metadata endpoint",
24-
default="microsoftgraph",
24+
default="sharepoint",
2525
)
2626
parser.add_argument(
2727
"-p",
2828
"--path",
2929
dest="path",
30-
default="./metadata/MicrosoftGraph.xml",
30+
default="./metadata/SharePoint.xml",
3131
help="Import metadata endpoint",
3232
)
3333

generator/metadata/SharePoint.xml

Lines changed: 70 additions & 25 deletions
Large diffs are not rendered by default.

office365/directory/extensions/extended_property.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from office365.entity import Entity
24
from office365.runtime.types.collections import StringCollection
35

@@ -7,10 +9,8 @@ class SingleValueLegacyExtendedProperty(Entity):
79

810
@property
911
def value(self):
10-
"""
11-
A property value.
12-
:rtype: str
13-
"""
12+
# type: () -> Optional[str]
13+
"""A property value."""
1414
return self.properties.get("value", None)
1515

1616

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from office365.entity import Entity
24

35

@@ -7,11 +9,11 @@ class IdentityProviderBase(Entity):
79
an Azure AD B2C tenant.
810
"""
911

12+
def __str__(self):
13+
return self.display_name or self.entity_type_name
14+
1015
@property
1116
def display_name(self):
12-
"""
13-
The display name for the identity provider.
14-
15-
:rtype: str or None
16-
"""
17+
# type: () -> Optional[str]
18+
"""The display name for the identity provider."""
1719
return self.properties.get("displayName", None)

office365/directory/identities/providers/social_identity.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from office365.directory.identities.providers.base import IdentityProviderBase
24

35

@@ -9,27 +11,27 @@ class SocialIdentityProvider(IdentityProviderBase):
911

1012
@property
1113
def client_id(self):
14+
# type: () -> Optional[str]
1215
"""
1316
The client identifier for the application obtained when registering the application with the identity provider.
14-
:rtype: str or None
1517
"""
1618
return self.properties.get("clientId", None)
1719

1820
@property
1921
def client_secret(self):
22+
# type: () -> Optional[str]
2023
"""
2124
The client secret for the application that is obtained when the application is registered
2225
with the identity provider. This is write-only. A read operation returns ****.
23-
:rtype: str or None
2426
"""
2527
return self.properties.get("clientSecret", None)
2628

2729
@property
2830
def identity_provider_type(self):
31+
# type: () -> Optional[str]
2932
"""
3033
For a B2B scenario, possible values: Google, Facebook.
3134
For a B2C scenario, possible values: Microsoft, Google, Amazon, LinkedIn, Facebook, GitHub, Twitter, Weibo,
3235
QQ, WeChat.
33-
:rtype: str or None
3436
"""
3537
return self.properties.get("identityProviderType", None)

office365/runtime/client_runtime_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import abc
22
from time import sleep
3-
from typing import TYPE_CHECKING, Any, AnyStr, Callable, List, Optional
3+
from typing import TYPE_CHECKING, Any, AnyStr, Callable, List
44

55
import requests
66
from typing_extensions import Self

office365/sharepoint/client_context.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def with_client_certificate(
8181
thumbprint,
8282
cert_path=None,
8383
private_key=None,
84-
scopes=None
84+
scopes=None,
8585
):
8686
# type: (str, str, str, Optional[str], Optional[str], Optional[List[str]]) -> Self
8787
"""
@@ -136,7 +136,12 @@ def with_access_token(self, token_func):
136136
return self
137137

138138
def with_user_credentials(
139-
self, username, password, allow_ntlm=False, browser_mode=False, environment='commercial'
139+
self,
140+
username,
141+
password,
142+
allow_ntlm=False,
143+
browser_mode=False,
144+
environment="commercial",
140145
):
141146
# type: (str, str, bool, bool, Optional[str]) -> Self
142147
"""
@@ -152,11 +157,13 @@ def with_user_credentials(
152157
UserCredential(username, password),
153158
allow_ntlm=allow_ntlm,
154159
browser_mode=browser_mode,
155-
environment=environment
160+
environment=environment,
156161
)
157162
return self
158163

159-
def with_client_credentials(self, client_id, client_secret, environment='commercial'):
164+
def with_client_credentials(
165+
self, client_id, client_secret, environment="commercial"
166+
):
160167
# type: (str, str, Optional[str]) -> Self
161168
"""
162169
Initializes a client to acquire a token via client credentials (SharePoint App-Only)
@@ -170,20 +177,21 @@ def with_client_credentials(self, client_id, client_secret, environment='commerc
170177
defaults to 'commercial'.
171178
"""
172179
self.authentication_context.with_credentials(
173-
ClientCredential(client_id, client_secret),
174-
environment=environment
180+
ClientCredential(client_id, client_secret), environment=environment
175181
)
176182
return self
177183

178-
def with_credentials(self, credentials, environment='commercial'):
184+
def with_credentials(self, credentials, environment="commercial"):
179185
# type: (UserCredential|ClientCredential, Optional[str]) -> Self
180186
"""
181187
Initializes a client to acquire a token via user or client credentials
182188
:type credentials: UserCredential or ClientCredential
183189
:param str environment: The Office 365 Cloud Environment endpoint used for authentication
184190
defaults to 'commercial'.
185191
"""
186-
self.authentication_context.with_credentials(credentials, environment=environment)
192+
self.authentication_context.with_credentials(
193+
credentials, environment=environment
194+
)
187195
return self
188196

189197
def execute_batch(self, items_per_batch=100, success_callback=None):
@@ -204,9 +212,7 @@ def execute_batch(self, items_per_batch=100, success_callback=None):
204212
return self
205213

206214
def pending_request(self):
207-
"""
208-
Provides access to underlying request instance
209-
"""
215+
"""Provides access to underlying request instance"""
210216
if self._pending_request is None:
211217
self._pending_request = ODataRequest(JsonLightFormat())
212218
self._pending_request.beforeExecute += self._authenticate_request
@@ -220,9 +226,7 @@ def _ensure_form_digest(self, request):
220226
request.set_header("X-RequestDigest", self._ctx_web_info.FormDigestValue)
221227

222228
def _get_context_web_information(self):
223-
"""
224-
Returns an ContextWebInformation object that specifies metadata about the site
225-
"""
229+
"""Returns an ContextWebInformation object that specifies metadata about the site"""
226230
client = ODataRequest(JsonLightFormat())
227231
client.beforeExecute += self._authenticate_request
228232
for e in self.pending_request().beforeExecute:
@@ -278,9 +282,7 @@ def _authenticate_request(self, request):
278282

279283
def _build_modification_query(self, request):
280284
# type: (RequestOptions) -> None
281-
"""
282-
Constructs SharePoint specific modification OData request
283-
"""
285+
"""Constructs SharePoint specific modification OData request"""
284286
if request.method == HttpMethod.Post:
285287
self._ensure_form_digest(request)
286288
# set custom SharePoint control headers
@@ -366,9 +368,7 @@ def _after_site_created(result):
366368

367369
@property
368370
def context_info(self):
369-
"""
370-
Returns an ContextWebInformation object that specifies metadata about the site
371-
"""
371+
"""Returns an ContextWebInformation object that specifies metadata about the site"""
372372
if self._ctx_web_info is None:
373373
self._ctx_web_info = ContextWebInformation()
374374
return self._ctx_web_info

office365/sharepoint/files/checked_out_file.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from office365.runtime.paths.resource_path import ResourcePath
24
from office365.runtime.paths.v3.entity import EntityPath
35
from office365.runtime.queries.service_operation import ServiceOperationQuery
@@ -16,9 +18,8 @@ def takeover_checkout(self):
1618

1719
@property
1820
def checked_out_by_id(self):
19-
"""Returns the user ID of the account used to check out the file.
20-
:rtype: int or None
21-
"""
21+
# type: () -> Optional[int]
22+
"""Returns the user ID of the account used to check out the file."""
2223
return self.properties.get("CheckedOutById", None)
2324

2425
@property

0 commit comments

Comments
 (0)