python-dropbox-api 0.1.0__py3-none-any.whl → 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_dropbox_api/__init__.py +6 -1
- python_dropbox_api/client.py +282 -210
- python_dropbox_api/exceptions.py +9 -0
- {python_dropbox_api-0.1.0.dist-info → python_dropbox_api-0.1.1.dist-info}/METADATA +1 -1
- python_dropbox_api-0.1.1.dist-info/RECORD +9 -0
- python_dropbox_api-0.1.0.dist-info/RECORD +0 -9
- {python_dropbox_api-0.1.0.dist-info → python_dropbox_api-0.1.1.dist-info}/WHEEL +0 -0
python_dropbox_api/__init__.py
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
from .auth import Auth
|
|
2
2
|
from .client import DropboxAPIClient
|
|
3
|
-
from .exceptions import
|
|
3
|
+
from .exceptions import (
|
|
4
|
+
DropboxAuthException,
|
|
5
|
+
DropboxFileOrFolderNotFoundException,
|
|
6
|
+
DropboxUnknownException,
|
|
7
|
+
)
|
|
4
8
|
from .models import (
|
|
5
9
|
AccountInfo,
|
|
6
10
|
PropertyField,
|
|
@@ -15,6 +19,7 @@ __all__ = [
|
|
|
15
19
|
"DropboxAPIClient",
|
|
16
20
|
"DropboxAuthException",
|
|
17
21
|
"DropboxFileOrFolderNotFoundException",
|
|
22
|
+
"DropboxUnknownException",
|
|
18
23
|
"PropertyField",
|
|
19
24
|
"PropertyFieldValue",
|
|
20
25
|
"PropertyGroup",
|
python_dropbox_api/client.py
CHANGED
|
@@ -4,7 +4,11 @@ import json
|
|
|
4
4
|
from aiohttp import ClientResponse
|
|
5
5
|
|
|
6
6
|
from .auth import Auth
|
|
7
|
-
from .exceptions import
|
|
7
|
+
from .exceptions import (
|
|
8
|
+
DropboxAuthException,
|
|
9
|
+
DropboxFileOrFolderNotFoundException,
|
|
10
|
+
DropboxUnknownException,
|
|
11
|
+
)
|
|
8
12
|
from .models import (
|
|
9
13
|
AccountInfo,
|
|
10
14
|
FileOrFolderInfo,
|
|
@@ -61,94 +65,105 @@ class DropboxAPIClient:
|
|
|
61
65
|
Returns:
|
|
62
66
|
AccountInfo containing account_id, email, and display_name.
|
|
63
67
|
"""
|
|
64
|
-
|
|
68
|
+
try:
|
|
69
|
+
access_token = await self._auth.async_get_access_token()
|
|
65
70
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
headers = {
|
|
72
|
+
"Authorization": f"Bearer {access_token}",
|
|
73
|
+
"Content-Type": "",
|
|
74
|
+
}
|
|
70
75
|
|
|
71
|
-
|
|
76
|
+
url = f"{DROPBOX_API_BASE_URL}/2/users/get_current_account"
|
|
72
77
|
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
async with self._websession.post(url, headers=headers) as response:
|
|
79
|
+
await handle_common_errors(response)
|
|
75
80
|
|
|
76
|
-
|
|
81
|
+
response_json = await response.json()
|
|
77
82
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
return AccountInfo(
|
|
84
|
+
account_id=response_json["account_id"],
|
|
85
|
+
email=response_json["email"],
|
|
86
|
+
display_name=response_json["name"]["display_name"],
|
|
87
|
+
)
|
|
88
|
+
except (DropboxAuthException, DropboxFileOrFolderNotFoundException):
|
|
89
|
+
raise
|
|
90
|
+
except Exception as err:
|
|
91
|
+
raise DropboxUnknownException(str(err)) from err
|
|
83
92
|
|
|
84
93
|
async def list_folder(
|
|
85
94
|
self, path: str, include_property_groups: list[str] | None = None
|
|
86
95
|
) -> list[FileOrFolderInfo]:
|
|
87
96
|
"""List the contents of a folder with pagination support."""
|
|
97
|
+
try:
|
|
98
|
+
access_token = await self._auth.async_get_access_token()
|
|
88
99
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
"Authorization": f"Bearer {access_token}",
|
|
93
|
-
"Content-Type": "application/json",
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
# Initial request data
|
|
97
|
-
data = {
|
|
98
|
-
"include_deleted": False,
|
|
99
|
-
"include_has_explicit_shared_members": False,
|
|
100
|
-
"include_media_info": False,
|
|
101
|
-
"include_mounted_folders": True,
|
|
102
|
-
"include_non_downloadable_files": False,
|
|
103
|
-
"path": path,
|
|
104
|
-
"recursive": False,
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if include_property_groups is not None:
|
|
108
|
-
data["include_property_groups"] = {
|
|
109
|
-
".tag": "filter_some",
|
|
110
|
-
"filter_some": include_property_groups,
|
|
100
|
+
headers = {
|
|
101
|
+
"Authorization": f"Bearer {access_token}",
|
|
102
|
+
"Content-Type": "application/json",
|
|
111
103
|
}
|
|
112
104
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
url = f"{DROPBOX_API_BASE_URL}/2/files/list_folder/continue"
|
|
124
|
-
request_data = {"cursor": cursor}
|
|
125
|
-
|
|
126
|
-
async with self._websession.post(
|
|
127
|
-
url, headers=headers, json=request_data
|
|
128
|
-
) as response:
|
|
129
|
-
await handle_common_errors(response)
|
|
130
|
-
|
|
131
|
-
response_json = await response.json()
|
|
105
|
+
# Initial request data
|
|
106
|
+
data = {
|
|
107
|
+
"include_deleted": False,
|
|
108
|
+
"include_has_explicit_shared_members": False,
|
|
109
|
+
"include_media_info": False,
|
|
110
|
+
"include_mounted_folders": True,
|
|
111
|
+
"include_non_downloadable_files": False,
|
|
112
|
+
"path": path,
|
|
113
|
+
"recursive": False,
|
|
114
|
+
}
|
|
132
115
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
size=file["size"] if file[".tag"] == "file" else None,
|
|
139
|
-
property_groups=parse_property_groups(file["property_groups"])
|
|
140
|
-
if "property_groups" in file
|
|
141
|
-
else None,
|
|
142
|
-
)
|
|
143
|
-
for file in response_json["entries"]
|
|
144
|
-
]
|
|
145
|
-
all_entries.extend(page_entries)
|
|
116
|
+
if include_property_groups is not None:
|
|
117
|
+
data["include_property_groups"] = {
|
|
118
|
+
".tag": "filter_some",
|
|
119
|
+
"filter_some": include_property_groups,
|
|
120
|
+
}
|
|
146
121
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
122
|
+
all_entries = []
|
|
123
|
+
cursor = None
|
|
124
|
+
has_more = True
|
|
150
125
|
|
|
151
|
-
|
|
126
|
+
while has_more:
|
|
127
|
+
# Use list_folder endpoint for first request, list_folder/continue for subsequent ones
|
|
128
|
+
if cursor is None:
|
|
129
|
+
url = f"{DROPBOX_API_BASE_URL}/2/files/list_folder"
|
|
130
|
+
request_data = data
|
|
131
|
+
else:
|
|
132
|
+
url = f"{DROPBOX_API_BASE_URL}/2/files/list_folder/continue"
|
|
133
|
+
request_data = {"cursor": cursor}
|
|
134
|
+
|
|
135
|
+
async with self._websession.post(
|
|
136
|
+
url, headers=headers, json=request_data
|
|
137
|
+
) as response:
|
|
138
|
+
await handle_common_errors(response)
|
|
139
|
+
|
|
140
|
+
response_json = await response.json()
|
|
141
|
+
|
|
142
|
+
# Add entries from this page to our collection
|
|
143
|
+
page_entries = [
|
|
144
|
+
FileOrFolderInfo(
|
|
145
|
+
is_folder=file[".tag"] == "folder",
|
|
146
|
+
name=file["name"],
|
|
147
|
+
size=file["size"] if file[".tag"] == "file" else None,
|
|
148
|
+
property_groups=parse_property_groups(
|
|
149
|
+
file["property_groups"]
|
|
150
|
+
)
|
|
151
|
+
if "property_groups" in file
|
|
152
|
+
else None,
|
|
153
|
+
)
|
|
154
|
+
for file in response_json["entries"]
|
|
155
|
+
]
|
|
156
|
+
all_entries.extend(page_entries)
|
|
157
|
+
|
|
158
|
+
# Check if there are more pages
|
|
159
|
+
has_more = response_json.get("has_more", False)
|
|
160
|
+
cursor = response_json.get("cursor")
|
|
161
|
+
|
|
162
|
+
return all_entries
|
|
163
|
+
except (DropboxAuthException, DropboxFileOrFolderNotFoundException):
|
|
164
|
+
raise
|
|
165
|
+
except Exception as err:
|
|
166
|
+
raise DropboxUnknownException(str(err)) from err
|
|
152
167
|
|
|
153
168
|
async def get_metadata(
|
|
154
169
|
self, path: str, include_property_groups: list[str] | None = None
|
|
@@ -162,41 +177,52 @@ class DropboxAPIClient:
|
|
|
162
177
|
Returns:
|
|
163
178
|
FileOrFolderInfo containing metadata for the file or folder.
|
|
164
179
|
"""
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
headers = {
|
|
168
|
-
"Authorization": f"Bearer {access_token}",
|
|
169
|
-
"Content-Type": "application/json",
|
|
170
|
-
}
|
|
180
|
+
try:
|
|
181
|
+
access_token = await self._auth.async_get_access_token()
|
|
171
182
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
"path": path,
|
|
177
|
-
}
|
|
183
|
+
headers = {
|
|
184
|
+
"Authorization": f"Bearer {access_token}",
|
|
185
|
+
"Content-Type": "application/json",
|
|
186
|
+
}
|
|
178
187
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
"
|
|
182
|
-
"
|
|
188
|
+
data = {
|
|
189
|
+
"include_deleted": False,
|
|
190
|
+
"include_has_explicit_shared_members": False,
|
|
191
|
+
"include_media_info": False,
|
|
192
|
+
"path": path,
|
|
183
193
|
}
|
|
184
194
|
|
|
185
|
-
|
|
195
|
+
if include_property_groups is not None:
|
|
196
|
+
data["include_property_groups"] = {
|
|
197
|
+
".tag": "filter_some",
|
|
198
|
+
"filter_some": include_property_groups,
|
|
199
|
+
}
|
|
186
200
|
|
|
187
|
-
|
|
188
|
-
await handle_common_errors(response)
|
|
201
|
+
url = f"{DROPBOX_API_BASE_URL}/2/files/get_metadata"
|
|
189
202
|
|
|
190
|
-
|
|
203
|
+
async with self._websession.post(
|
|
204
|
+
url, headers=headers, json=data
|
|
205
|
+
) as response:
|
|
206
|
+
await handle_common_errors(response)
|
|
191
207
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
208
|
+
response_json = await response.json()
|
|
209
|
+
|
|
210
|
+
return FileOrFolderInfo(
|
|
211
|
+
is_folder=response_json[".tag"] == "folder",
|
|
212
|
+
name=response_json["name"],
|
|
213
|
+
size=response_json["size"]
|
|
214
|
+
if response_json[".tag"] == "file"
|
|
215
|
+
else None,
|
|
216
|
+
property_groups=parse_property_groups(
|
|
217
|
+
response_json["property_groups"]
|
|
218
|
+
)
|
|
219
|
+
if "property_groups" in response_json
|
|
220
|
+
else None,
|
|
221
|
+
)
|
|
222
|
+
except (DropboxAuthException, DropboxFileOrFolderNotFoundException):
|
|
223
|
+
raise
|
|
224
|
+
except Exception as err:
|
|
225
|
+
raise DropboxUnknownException(str(err)) from err
|
|
200
226
|
|
|
201
227
|
async def upload_file(
|
|
202
228
|
self,
|
|
@@ -211,12 +237,17 @@ class DropboxAPIClient:
|
|
|
211
237
|
file_stream: An async iterator of bytes to upload.
|
|
212
238
|
property_groups: Optional list of property groups to attach to the uploaded file.
|
|
213
239
|
"""
|
|
214
|
-
|
|
240
|
+
try:
|
|
241
|
+
CHUNK_SIZE = 16 * 1024 * 1024 # 16MB chunks
|
|
215
242
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
243
|
+
# Always use chunked upload approach
|
|
244
|
+
await self._upload_file_chunked(
|
|
245
|
+
CONTENT_API_BASE_URL, path, file_stream, CHUNK_SIZE, property_groups
|
|
246
|
+
)
|
|
247
|
+
except (DropboxAuthException, DropboxFileOrFolderNotFoundException):
|
|
248
|
+
raise
|
|
249
|
+
except Exception as err:
|
|
250
|
+
raise DropboxUnknownException(str(err)) from err
|
|
220
251
|
|
|
221
252
|
async def _upload_file_chunked(
|
|
222
253
|
self,
|
|
@@ -386,21 +417,26 @@ class DropboxAPIClient:
|
|
|
386
417
|
Yields:
|
|
387
418
|
Chunks of file content as bytes.
|
|
388
419
|
"""
|
|
389
|
-
|
|
420
|
+
try:
|
|
421
|
+
access_token = await self._auth.async_get_access_token()
|
|
390
422
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
423
|
+
headers = {
|
|
424
|
+
"Authorization": f"Bearer {access_token}",
|
|
425
|
+
"Dropbox-API-Arg": json.dumps({"path": path}),
|
|
426
|
+
}
|
|
395
427
|
|
|
396
|
-
|
|
397
|
-
|
|
428
|
+
url = f"{CONTENT_API_BASE_URL}/2/files/download"
|
|
429
|
+
chunk_size = 1024 * 1024 # 1MB
|
|
398
430
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
431
|
+
async with self._websession.post(url, headers=headers) as response:
|
|
432
|
+
response.raise_for_status()
|
|
433
|
+
async for chunk in response.content.iter_chunked(chunk_size):
|
|
434
|
+
if chunk:
|
|
435
|
+
yield chunk
|
|
436
|
+
except (DropboxAuthException, DropboxFileOrFolderNotFoundException):
|
|
437
|
+
raise
|
|
438
|
+
except Exception as err:
|
|
439
|
+
raise DropboxUnknownException(str(err)) from err
|
|
404
440
|
|
|
405
441
|
async def create_folder(self, path: str) -> FileOrFolderInfo:
|
|
406
442
|
"""Create a folder in Dropbox.
|
|
@@ -411,23 +447,28 @@ class DropboxAPIClient:
|
|
|
411
447
|
Returns:
|
|
412
448
|
FileOrFolderInfo containing metadata for the created folder.
|
|
413
449
|
"""
|
|
414
|
-
|
|
450
|
+
try:
|
|
451
|
+
access_token = await self._auth.async_get_access_token()
|
|
415
452
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
453
|
+
headers = {
|
|
454
|
+
"Authorization": f"Bearer {access_token}",
|
|
455
|
+
"Content-Type": "application/json",
|
|
456
|
+
}
|
|
420
457
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
458
|
+
url = f"{DROPBOX_API_BASE_URL}/2/files/create_folder_v2"
|
|
459
|
+
payload = {
|
|
460
|
+
"path": path,
|
|
461
|
+
"autorename": False,
|
|
462
|
+
}
|
|
426
463
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
464
|
+
async with self._websession.post(
|
|
465
|
+
url, headers=headers, json=payload
|
|
466
|
+
) as response:
|
|
467
|
+
await handle_common_errors(response)
|
|
468
|
+
except (DropboxAuthException, DropboxFileOrFolderNotFoundException):
|
|
469
|
+
raise
|
|
470
|
+
except Exception as err:
|
|
471
|
+
raise DropboxUnknownException(str(err)) from err
|
|
431
472
|
|
|
432
473
|
async def delete_file(self, path: str) -> None:
|
|
433
474
|
"""Delete a file (moves to Dropbox trash).
|
|
@@ -435,20 +476,25 @@ class DropboxAPIClient:
|
|
|
435
476
|
Args:
|
|
436
477
|
path: The Dropbox path of the file to delete.
|
|
437
478
|
"""
|
|
438
|
-
|
|
479
|
+
try:
|
|
480
|
+
access_token = await self._auth.async_get_access_token()
|
|
439
481
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
482
|
+
headers = {
|
|
483
|
+
"Authorization": f"Bearer {access_token}",
|
|
484
|
+
"Content-Type": "application/json",
|
|
485
|
+
}
|
|
444
486
|
|
|
445
|
-
|
|
446
|
-
|
|
487
|
+
url = f"{DROPBOX_API_BASE_URL}/2/files/delete_v2"
|
|
488
|
+
payload = {"path": path}
|
|
447
489
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
490
|
+
async with self._websession.post(
|
|
491
|
+
url, headers=headers, json=payload
|
|
492
|
+
) as response:
|
|
493
|
+
await handle_common_errors(response)
|
|
494
|
+
except (DropboxAuthException, DropboxFileOrFolderNotFoundException):
|
|
495
|
+
raise
|
|
496
|
+
except Exception as err:
|
|
497
|
+
raise DropboxUnknownException(str(err)) from err
|
|
452
498
|
|
|
453
499
|
async def list_property_templates(self) -> list[str]:
|
|
454
500
|
"""List property group templates for the current user.
|
|
@@ -456,20 +502,25 @@ class DropboxAPIClient:
|
|
|
456
502
|
Returns:
|
|
457
503
|
A list of template IDs for property group templates.
|
|
458
504
|
"""
|
|
459
|
-
|
|
505
|
+
try:
|
|
506
|
+
access_token = await self._auth.async_get_access_token()
|
|
460
507
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
508
|
+
headers = {
|
|
509
|
+
"Authorization": f"Bearer {access_token}",
|
|
510
|
+
"Content-Type": "",
|
|
511
|
+
}
|
|
465
512
|
|
|
466
|
-
|
|
513
|
+
url = f"{DROPBOX_API_BASE_URL}/2/file_properties/templates/list_for_user"
|
|
467
514
|
|
|
468
|
-
|
|
469
|
-
|
|
515
|
+
async with self._websession.post(url, headers=headers) as response:
|
|
516
|
+
await handle_common_errors(response)
|
|
470
517
|
|
|
471
|
-
|
|
472
|
-
|
|
518
|
+
response_json = await response.json()
|
|
519
|
+
return response_json["template_ids"]
|
|
520
|
+
except (DropboxAuthException, DropboxFileOrFolderNotFoundException):
|
|
521
|
+
raise
|
|
522
|
+
except Exception as err:
|
|
523
|
+
raise DropboxUnknownException(str(err)) from err
|
|
473
524
|
|
|
474
525
|
async def add_property_template(self, template: PropertyTemplate) -> str:
|
|
475
526
|
"""Add a property group template for the current user.
|
|
@@ -480,34 +531,41 @@ class DropboxAPIClient:
|
|
|
480
531
|
Returns:
|
|
481
532
|
A string containing the template ID.
|
|
482
533
|
"""
|
|
483
|
-
|
|
534
|
+
try:
|
|
535
|
+
access_token = await self._auth.async_get_access_token()
|
|
484
536
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
537
|
+
headers = {
|
|
538
|
+
"Authorization": f"Bearer {access_token}",
|
|
539
|
+
"Content-Type": "application/json",
|
|
540
|
+
}
|
|
489
541
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
542
|
+
# Convert the template to the format expected by the API
|
|
543
|
+
data = {
|
|
544
|
+
"name": template.name,
|
|
545
|
+
"description": template.description,
|
|
546
|
+
"fields": [
|
|
547
|
+
{
|
|
548
|
+
"name": field.name,
|
|
549
|
+
"description": field.description,
|
|
550
|
+
"type": field.type,
|
|
551
|
+
}
|
|
552
|
+
for field in template.fields
|
|
553
|
+
],
|
|
554
|
+
}
|
|
503
555
|
|
|
504
|
-
|
|
556
|
+
url = f"{DROPBOX_API_BASE_URL}/2/file_properties/templates/add_for_user"
|
|
505
557
|
|
|
506
|
-
|
|
507
|
-
|
|
558
|
+
async with self._websession.post(
|
|
559
|
+
url, headers=headers, json=data
|
|
560
|
+
) as response:
|
|
561
|
+
await handle_common_errors(response)
|
|
508
562
|
|
|
509
|
-
|
|
510
|
-
|
|
563
|
+
response_json = await response.json()
|
|
564
|
+
return response_json["template_id"]
|
|
565
|
+
except (DropboxAuthException, DropboxFileOrFolderNotFoundException):
|
|
566
|
+
raise
|
|
567
|
+
except Exception as err:
|
|
568
|
+
raise DropboxUnknownException(str(err)) from err
|
|
511
569
|
|
|
512
570
|
async def remove_property_template(self, template_id: str) -> None:
|
|
513
571
|
"""Remove a property group template for the current user.
|
|
@@ -515,19 +573,26 @@ class DropboxAPIClient:
|
|
|
515
573
|
Args:
|
|
516
574
|
template_id: The ID of the property template to remove.
|
|
517
575
|
"""
|
|
518
|
-
|
|
576
|
+
try:
|
|
577
|
+
access_token = await self._auth.async_get_access_token()
|
|
519
578
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
579
|
+
headers = {
|
|
580
|
+
"Authorization": f"Bearer {access_token}",
|
|
581
|
+
"Content-Type": "application/json",
|
|
582
|
+
}
|
|
524
583
|
|
|
525
|
-
|
|
584
|
+
data = {"template_id": template_id}
|
|
526
585
|
|
|
527
|
-
|
|
586
|
+
url = f"{DROPBOX_API_BASE_URL}/2/file_properties/templates/remove_for_user"
|
|
528
587
|
|
|
529
|
-
|
|
530
|
-
|
|
588
|
+
async with self._websession.post(
|
|
589
|
+
url, headers=headers, json=data
|
|
590
|
+
) as response:
|
|
591
|
+
await handle_common_errors(response)
|
|
592
|
+
except (DropboxAuthException, DropboxFileOrFolderNotFoundException):
|
|
593
|
+
raise
|
|
594
|
+
except Exception as err:
|
|
595
|
+
raise DropboxUnknownException(str(err)) from err
|
|
531
596
|
|
|
532
597
|
async def get_property_template(self, template_id: str) -> PropertyTemplate:
|
|
533
598
|
"""Get a property group template for the current user.
|
|
@@ -538,35 +603,42 @@ class DropboxAPIClient:
|
|
|
538
603
|
Returns:
|
|
539
604
|
The PropertyTemplate.
|
|
540
605
|
"""
|
|
541
|
-
|
|
606
|
+
try:
|
|
607
|
+
access_token = await self._auth.async_get_access_token()
|
|
542
608
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
609
|
+
headers = {
|
|
610
|
+
"Authorization": f"Bearer {access_token}",
|
|
611
|
+
"Content-Type": "application/json",
|
|
612
|
+
}
|
|
547
613
|
|
|
548
|
-
|
|
614
|
+
data = {"template_id": template_id}
|
|
549
615
|
|
|
550
|
-
|
|
616
|
+
url = f"{DROPBOX_API_BASE_URL}/2/file_properties/templates/get_for_user"
|
|
551
617
|
|
|
552
|
-
|
|
553
|
-
|
|
618
|
+
async with self._websession.post(
|
|
619
|
+
url, headers=headers, json=data
|
|
620
|
+
) as response:
|
|
621
|
+
await handle_common_errors(response)
|
|
554
622
|
|
|
555
|
-
|
|
623
|
+
response_json = await response.json()
|
|
556
624
|
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
625
|
+
fields = [
|
|
626
|
+
PropertyField(
|
|
627
|
+
name=field["name"],
|
|
628
|
+
description=field["description"],
|
|
629
|
+
type=field["type"][".tag"]
|
|
630
|
+
if isinstance(field["type"], dict)
|
|
631
|
+
else field["type"],
|
|
632
|
+
)
|
|
633
|
+
for field in response_json["fields"]
|
|
634
|
+
]
|
|
567
635
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
636
|
+
return PropertyTemplate(
|
|
637
|
+
name=response_json["name"],
|
|
638
|
+
description=response_json["description"],
|
|
639
|
+
fields=fields,
|
|
640
|
+
)
|
|
641
|
+
except (DropboxAuthException, DropboxFileOrFolderNotFoundException):
|
|
642
|
+
raise
|
|
643
|
+
except Exception as err:
|
|
644
|
+
raise DropboxUnknownException(str(err)) from err
|
python_dropbox_api/exceptions.py
CHANGED
|
@@ -14,3 +14,12 @@ class DropboxAuthException(Exception):
|
|
|
14
14
|
"""Initialize exception."""
|
|
15
15
|
super().__init__(status)
|
|
16
16
|
self.status = status
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class DropboxUnknownException(Exception):
|
|
20
|
+
"""Raised when an unknown Dropbox error occurs."""
|
|
21
|
+
|
|
22
|
+
def __init__(self, status):
|
|
23
|
+
"""Initialize exception."""
|
|
24
|
+
super().__init__(status)
|
|
25
|
+
self.status = status
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
python_dropbox_api/__init__.py,sha256=8NVlyqQZvA0Mgds5Pb80irBac5mGPJFwW4MEeMFPOvU,575
|
|
2
|
+
python_dropbox_api/auth.py,sha256=qrPop5F2_UGDmEtNOwhuYwgoHyaQ_wCjeP0B7tMNx38,448
|
|
3
|
+
python_dropbox_api/client.py,sha256=J3_ZBamgEesGIy7fPn6qUXbPBMix-0KbqkEcrDWS914,22463
|
|
4
|
+
python_dropbox_api/exceptions.py,sha256=HZ8Cf1ET6uqMmMIOXmtRqgLaz59GdYm8fBKLPBnXt-M,706
|
|
5
|
+
python_dropbox_api/models.py,sha256=yhkfVMKPsMJxMzLA0KhSUPt_uoJkrvVjeskKffTKt-M,1604
|
|
6
|
+
python_dropbox_api/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
python_dropbox_api-0.1.1.dist-info/METADATA,sha256=9pASIq_zxOsms_JjTbP_6k7pboGKHjrJgc7aql8qgJE,516
|
|
8
|
+
python_dropbox_api-0.1.1.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
9
|
+
python_dropbox_api-0.1.1.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
python_dropbox_api/__init__.py,sha256=6UqnNiR92b4OKz9rdi9m4xbQqdpFjeu-z1ssDCTNjIc,502
|
|
2
|
-
python_dropbox_api/auth.py,sha256=qrPop5F2_UGDmEtNOwhuYwgoHyaQ_wCjeP0B7tMNx38,448
|
|
3
|
-
python_dropbox_api/client.py,sha256=Trvmiv0cZ0RuUBT_CmrDAHyygjAuDN_lrDKsieVCAyw,19116
|
|
4
|
-
python_dropbox_api/exceptions.py,sha256=oThpQJDjKwidCB2V5FlXfD9X9RyQci-ez3zSaJXMdvw,476
|
|
5
|
-
python_dropbox_api/models.py,sha256=yhkfVMKPsMJxMzLA0KhSUPt_uoJkrvVjeskKffTKt-M,1604
|
|
6
|
-
python_dropbox_api/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
-
python_dropbox_api-0.1.0.dist-info/METADATA,sha256=CV1GnFge3ZrNVEqL7p5nSO-muEx6tkB1R5seb76vNs0,516
|
|
8
|
-
python_dropbox_api-0.1.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
9
|
-
python_dropbox_api-0.1.0.dist-info/RECORD,,
|
|
File without changes
|