Skip to content

Commit ce822da

Browse files
committed
Introduce black & fix flake8
1 parent 54634ee commit ce822da

File tree

1,243 files changed

+13324
-6726
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,243 files changed

+13324
-6726
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 23.9.1
4+
hooks:
5+
- id: black
6+
args:
7+
- --quiet

examples/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,3 @@ def upload_sample_files(drive):
66
for local_path in local_paths:
77
file = drive.root.resumable_upload(local_path).get().execute_query()
88
print(f"File {file.web_url} has been uploaded")
9-
10-

examples/auth/interactive.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
def acquire_token():
1919
app = msal.PublicClientApplication(
2020
test_client_id,
21-
authority='https://login.microsoftonline.com/{0}'.format(test_tenant),
22-
client_credential=None
21+
authority="https://login.microsoftonline.com/{0}".format(test_tenant),
22+
client_credential=None,
2323
)
2424
scopes = ["https://graph.microsoft.com/.default"]
2525
result = app.acquire_token_interactive(scopes=scopes)

examples/auth/interactive_sharepoint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
def acquire_token():
1919
app = msal.PublicClientApplication(
2020
test_client_id,
21-
authority='https://login.microsoftonline.com/{0}'.format(test_tenant),
22-
client_credential=None
21+
authority="https://login.microsoftonline.com/{0}".format(test_tenant),
22+
client_credential=None,
2323
)
2424
scopes = ["https://{0}.sharepoint.com/.default".format(test_tenant_name)]
2525
result = app.acquire_token_interactive(scopes=scopes)

examples/auth/with_adal.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,21 @@
1010

1111
def acquire_token():
1212
import adal
13+
1314
settings = load_settings()
14-
authority_url = 'https://login.microsoftonline.com/{0}'.format(settings['default']['tenant'])
15+
authority_url = "https://login.microsoftonline.com/{0}".format(
16+
settings["default"]["tenant"]
17+
)
1518
auth_ctx = adal.AuthenticationContext(authority_url)
1619
token = auth_ctx.acquire_token_with_username_password(
17-
'https://graph.microsoft.com',
18-
settings['user_credentials']['username'],
19-
settings['user_credentials']['password'],
20-
settings['client_credentials']['client_id'])
20+
"https://graph.microsoft.com",
21+
settings["user_credentials"]["username"],
22+
settings["user_credentials"]["password"],
23+
settings["client_credentials"]["client_id"],
24+
)
2125
return token
2226

2327

2428
client = GraphClient(acquire_token)
2529
me = client.me.get().execute_query()
26-
print(me.properties('displayName'))
30+
print(me.properties("displayName"))

examples/auth/with_client_cert.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@
99

1010

1111
def acquire_token():
12-
with open(test_cert_path, 'r') as f:
12+
with open(test_cert_path, "r") as f:
1313
private_key = open(test_cert_path).read()
1414

15-
authority_url = 'https://login.microsoftonline.com/{0}'.format(test_tenant_name)
15+
authority_url = "https://login.microsoftonline.com/{0}".format(test_tenant_name)
1616
credentials = {"thumbprint": test_cert_thumbprint, "private_key": private_key}
1717
import msal
18+
1819
app = msal.ConfidentialClientApplication(
1920
test_client_id,
2021
authority=authority_url,
2122
client_credential=credentials,
2223
)
23-
result = app.acquire_token_for_client(scopes=["https://graph.microsoft.com/.default"])
24+
result = app.acquire_token_for_client(
25+
scopes=["https://graph.microsoft.com/.default"]
26+
)
2427
return result
2528

2629

examples/auth/with_user_creds.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010

1111

1212
def acquire_token():
13-
authority_url = 'https://login.microsoftonline.com/{0}'.format(test_tenant)
13+
authority_url = "https://login.microsoftonline.com/{0}".format(test_tenant)
1414
app = msal.PublicClientApplication(
15-
authority=authority_url,
16-
client_id=test_client_id
15+
authority=authority_url, client_id=test_client_id
1716
)
1817

19-
result = app.acquire_token_by_username_password(username=test_user_credentials.userName,
20-
password=test_user_credentials.password,
21-
scopes=["https://graph.microsoft.com/.default"])
18+
result = app.acquire_token_by_username_password(
19+
username=test_user_credentials.userName,
20+
password=test_user_credentials.password,
21+
scopes=["https://graph.microsoft.com/.default"],
22+
)
2223
return result
2324

2425

examples/communications/create_call.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
from tests.graph_case import acquire_token_by_client_credentials
66

77
client = GraphClient(acquire_token_by_client_credentials)
8-
call = client.communications.calls.create("https://mediadev8.com/teamsapp/api/calling").execute_query()
8+
call = client.communications.calls.create(
9+
"https://mediadev8.com/teamsapp/api/calling"
10+
).execute_query()

examples/directory/applications/add_cert.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,35 @@ def verify_connect():
1616
"""Test the app-only authentication"""
1717

1818
cert_thumbprint = "12FC1BB6796D114AF4FEBBE95FCA8084CF47D81F"
19-
cert_key_path = '../../selfsignkey.pem'
19+
cert_key_path = "../../selfsignkey.pem"
2020

2121
def _acquire_token():
22-
with open(cert_key_path, 'r') as fh:
22+
with open(cert_key_path, "r") as fh:
2323
private_key = fh.read()
2424

25-
authority_url = 'https://login.microsoftonline.com/{0}'.format(test_tenant)
25+
authority_url = "https://login.microsoftonline.com/{0}".format(test_tenant)
2626
credentials = {"thumbprint": cert_thumbprint, "private_key": private_key}
2727
import msal
28+
2829
app = msal.ConfidentialClientApplication(
2930
test_client_id,
3031
authority=authority_url,
3132
client_credential=credentials,
3233
)
33-
return app.acquire_token_for_client(scopes=["https://graph.microsoft.com/.default"])
34+
return app.acquire_token_for_client(
35+
scopes=["https://graph.microsoft.com/.default"]
36+
)
3437

3538
ctx = GraphClient(_acquire_token)
3639
site = ctx.sites.root.get().execute_query()
3740
print(site.web_url)
3841

3942

40-
cert_path = '../../selfsigncert.pem'
43+
cert_path = "../../selfsigncert.pem"
4144

4245
client = GraphClient(acquire_token_by_username_password)
4346
target_app = client.applications.get_by_app_id(test_client_id)
44-
with open(cert_path, 'rb') as f:
47+
with open(cert_path, "rb") as f:
4548
cert_data = f.read()
4649
target_app.add_certificate(cert_data, "Internet Widgits Pty Ltd").execute_query()
4750

examples/directory/applications/get_by_app_id.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,9 @@
1111
from tests.graph_case import acquire_token_by_client_credentials
1212

1313
client = GraphClient(acquire_token_by_client_credentials)
14-
app = client.applications.get_by_app_id(test_client_credentials.clientId).get().execute_query()
14+
app = (
15+
client.applications.get_by_app_id(test_client_credentials.clientId)
16+
.get()
17+
.execute_query()
18+
)
1519
print(app.display_name)

examples/directory/applications/grant_or_revoke_perms.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
client = GraphClient(acquire_token_by_username_password)
1212

1313
# Step 1: Get the appRoles of the resource service principal
14-
service_principal = client.service_principals.single("displayName eq 'Microsoft Graph'").get().execute_query()
14+
service_principal = (
15+
client.service_principals.single("displayName eq 'Microsoft Graph'")
16+
.get()
17+
.execute_query()
18+
)
1519
print(json.dumps(service_principal.app_roles.to_json(), indent=4))
1620

1721
# Step 2: Grant an app role to a client service principal

examples/directory/groups/create_with_team.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ def print_failure(retry_number, ex):
1818

1919
client = GraphClient(acquire_token_by_username_password)
2020
group_name = create_unique_name("Flight")
21-
group = client.groups.create_with_team(group_name).execute_query_retry(max_retry=10, failure_callback=print_failure)
21+
group = client.groups.create_with_team(group_name).execute_query_retry(
22+
max_retry=10, failure_callback=print_failure
23+
)
2224
print("Team has been created: {0}".format(group.team.web_url))
2325

2426
# clean up resources

examples/directory/groups/delete_batch.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@
2020

2121
result = client.groups.get_all().execute_query()
2222
print("Total groups count (after): {0}".format(len(result)))
23-

examples/directory/groups/delete_groups.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
while len(groups) > 0:
1919
cur_grp = groups[0]
2020
print(
21-
"({0} of {1}) Deleting {2} group ...".format(deletedCount + 1, groups_count, cur_grp.properties['displayName']))
21+
"({0} of {1}) Deleting {2} group ...".format(
22+
deletedCount + 1, groups_count, cur_grp.properties["displayName"]
23+
)
24+
)
2225
cur_grp.delete_object(permanent_delete=True).execute_query()
2326
print("Group deleted permanently.")
2427
deletedCount += 1

examples/directory/users/import.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ def generate_user_profile():
99
fake = Faker()
1010

1111
user_json = {
12-
'given_name': fake.name(),
13-
'company_name': fake.company(),
14-
'business_phones': [fake.phone_number()],
15-
'office_location': fake.street_address(),
16-
'city': fake.city(),
17-
'country': fake.country(),
18-
'principal_name': "{0}@{1}".format(fake.user_name(), test_tenant),
19-
'password': create_unique_name("P@ssw0rd"),
20-
'account_enabled': True
12+
"given_name": fake.name(),
13+
"company_name": fake.company(),
14+
"business_phones": [fake.phone_number()],
15+
"office_location": fake.street_address(),
16+
"city": fake.city(),
17+
"country": fake.country(),
18+
"principal_name": "{0}@{1}".format(fake.user_name(), test_tenant),
19+
"password": create_unique_name("P@ssw0rd"),
20+
"account_enabled": True,
2121
}
2222
return UserProfile(**user_json)
2323

examples/informationprotection/create_mail_assessment.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77

88
client = GraphClient(acquire_token_by_username_password)
99
messages = client.me.messages.get().filter("isDraft eq false").top(1).execute_query()
10-
result = client.information_protection.create_mail_assessment(messages[0]).execute_query()
10+
result = client.information_protection.create_mail_assessment(
11+
messages[0]
12+
).execute_query()
1113
print(result)

examples/insights/list_used.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@
1111
client = GraphClient(acquire_token_by_username_password)
1212
result = client.me.insights.used.get().execute_query()
1313
print(json.dumps(result.to_json(), indent=4))
14-

examples/onedrive/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ def ensure_workbook_sample(graph_client):
1414
:type graph_client: office365.graph_client.GraphClient
1515
"""
1616
try:
17-
return graph_client.me.drive.root.get_by_path("Financial Sample.xlsx").workbook.get().execute_query()
17+
return (
18+
graph_client.me.drive.root.get_by_path("Financial Sample.xlsx")
19+
.workbook.get()
20+
.execute_query()
21+
)
1822
except ClientRequestException as e:
1923
if e.response.status_code == 404:
2024
local_path = "../../data/Financial Sample.xlsx"

examples/onedrive/bundles/create.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88

99
client = GraphClient(acquire_token_by_username_password)
1010
file_item = client.me.drive.root.get_by_path("Sample.html").get().execute_query()
11-
bundle = client.me.drive.create_bundle("Just some files", [file_item.id]).execute_query()
11+
bundle = client.me.drive.create_bundle(
12+
"Just some files", [file_item.id]
13+
).execute_query()
1214
print(bundle.web_url)

examples/onedrive/excel/read_table.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
client = GraphClient(acquire_token_by_username_password)
1313
drive_item = upload_excel_sample(client)
14-
table = drive_item.workbook.worksheets["Sheet1"].tables["financials"].get().execute_query()
14+
table = (
15+
drive_item.workbook.worksheets["Sheet1"].tables["financials"].get().execute_query()
16+
)
1517
print(table.name)
1618

1719
# read table content

examples/onedrive/files/copy_file.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@
1414
source_file_item = client.me.drive.root.get_by_path(source_path) # source file item
1515
target_folder_item = client.me.drive.root.get_by_path(target_path) # target folder item
1616
# result = source_file_item.copy(name=new_name).execute_query() # copy to the same folder with a different name
17-
result = source_file_item.copy(parent=target_folder_item).execute_query() # copy to another folder
17+
result = source_file_item.copy(
18+
parent=target_folder_item
19+
).execute_query() # copy to another folder
1820
print(result.value)

examples/onedrive/files/create_sharing_link.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@
1515
client = GraphClient(acquire_token_by_username_password)
1616
file_path = "Financial Sample.xlsx"
1717
drive_item = client.me.drive.root.get_by_path(file_path)
18-
permission = drive_item.create_link("view", "anonymous", password="ThisIsMyPrivatePassword").execute_query()
18+
permission = drive_item.create_link(
19+
"view", "anonymous", password="ThisIsMyPrivatePassword"
20+
).execute_query()
1921
print(permission.link)

examples/onedrive/files/download_default.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
remote_file = client.me.drive.root.get_by_path(remote_path)
1717
# 2. download file content
1818
with tempfile.TemporaryDirectory() as local_path:
19-
with open(os.path.join(local_path, os.path.basename(remote_path)), 'wb') as local_file:
19+
with open(
20+
os.path.join(local_path, os.path.basename(remote_path)), "wb"
21+
) as local_file:
2022
remote_file.download(local_file).execute_query()
2123
print("File has been downloaded into {0}".format(local_file.name))

examples/onedrive/files/download_large.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,17 @@ def print_progress(offset):
1919

2020
client = GraphClient(acquire_token_by_username_password)
2121
# # 1. address file by path and get file metadata
22-
file_item = client.me.drive.root.get_by_path("archive/big_buck_bunny.mp4").get().execute_query()
22+
file_item = (
23+
client.me.drive.root.get_by_path("archive/big_buck_bunny.mp4").get().execute_query()
24+
)
2325
# 2 download a large file (chunked file download)
2426
with tempfile.TemporaryDirectory() as local_path:
25-
with open(os.path.join(local_path, file_item.name), 'wb') as local_file:
26-
file_item.download_session(local_file, print_progress, chunk_size=1024 * 512).execute_query()
27-
print("File '{0}' has been downloaded into {1}".format(file_item.name, local_file.name))
27+
with open(os.path.join(local_path, file_item.name), "wb") as local_file:
28+
file_item.download_session(
29+
local_file, print_progress, chunk_size=1024 * 512
30+
).execute_query()
31+
print(
32+
"File '{0}' has been downloaded into {1}".format(
33+
file_item.name, local_file.name
34+
)
35+
)

examples/onedrive/files/export.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
drive = client.users[test_user_principal_name].drive # type: Drive
1717
with tempfile.TemporaryDirectory() as local_path:
1818
drive_items = drive.root.children.get().execute_query()
19-
file_items = [item for item in drive_items if item.file is not None] # files only
19+
file_items = [item for item in drive_items if item.file is not None] # files only
2020
for drive_item in file_items:
21-
with open(os.path.join(local_path, drive_item.name), 'wb') as local_file:
21+
with open(os.path.join(local_path, drive_item.name), "wb") as local_file:
2222
drive_item.download(local_file).execute_query() # download file content
2323
print("File '{0}' has been downloaded".format(local_file.name))
24-

examples/onedrive/files/list_versions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
from tests.graph_case import acquire_token_by_client_credentials
99

1010
client = GraphClient(acquire_token_by_client_credentials)
11-
file_item = client.sites.root.drive.root.get_by_path("Financial Sample.xlsx").expand(["versions"]).get().execute_query()
11+
file_item = (
12+
client.sites.root.drive.root.get_by_path("Financial Sample.xlsx")
13+
.expand(["versions"])
14+
.get()
15+
.execute_query()
16+
)
1217
for ver in file_item.versions: # type: DriveItemVersion
1318
print(ver)

examples/onedrive/files/share_invitation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222
message="Here's the file that we're collaborating on.",
2323
roles=["read"],
2424
expiration_datetime=None,
25-
password="password123").execute_query()
25+
password="password123",
26+
).execute_query()
2627
print(json.dumps(permissions.to_json(), indent=4))

examples/onedrive/files/upload.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
from tests.graph_case import acquire_token_by_client_credentials
1010

1111
client = GraphClient(acquire_token_by_client_credentials)
12-
folder = client.users.get_by_principal_name(test_user_principal_name_alt).drive.root.get_by_path("archive")
12+
folder = client.users.get_by_principal_name(
13+
test_user_principal_name_alt
14+
).drive.root.get_by_path("archive")
1315

1416
local_path = "../../data/Financial Sample.xlsx"
1517
file = folder.upload_file(local_path).execute_query()

examples/onedrive/files/upload_large.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ def print_progress(range_pos):
1818

1919
local_path = "../../../tests/data/big_buck_bunny.mp4"
2020
remote_folder = client.me.drive.root.get_by_path("archive")
21-
remote_file = remote_folder.resumable_upload(local_path, chunk_size=chunk_size,
22-
chunk_uploaded=print_progress).get().execute_query()
21+
remote_file = (
22+
remote_folder.resumable_upload(
23+
local_path, chunk_size=chunk_size, chunk_uploaded=print_progress
24+
)
25+
.get()
26+
.execute_query()
27+
)
2328
print(f"File {remote_file.web_url} has been uploaded")

0 commit comments

Comments
 (0)