python-dropbox-api 0.1.3__py3-none-any.whl → 0.1.4__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/client.py +34 -8
- {python_dropbox_api-0.1.3.dist-info → python_dropbox_api-0.1.4.dist-info}/METADATA +1 -1
- {python_dropbox_api-0.1.3.dist-info → python_dropbox_api-0.1.4.dist-info}/RECORD +5 -5
- {python_dropbox_api-0.1.3.dist-info → python_dropbox_api-0.1.4.dist-info}/WHEEL +1 -1
- {python_dropbox_api-0.1.3.dist-info → python_dropbox_api-0.1.4.dist-info}/licenses/LICENSE +0 -0
python_dropbox_api/client.py
CHANGED
|
@@ -38,15 +38,24 @@ def parse_property_groups(property_groups: list[dict]) -> list[PropertyGroup]:
|
|
|
38
38
|
|
|
39
39
|
async def handle_common_errors(response: ClientResponse) -> None:
|
|
40
40
|
"""Handle common errors."""
|
|
41
|
-
|
|
41
|
+
if response.ok:
|
|
42
|
+
return
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
try:
|
|
45
|
+
response_json = await response.json(content_type=None)
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
error_summary = response_json.get("error_summary") if isinstance(response_json, dict) else None
|
|
48
|
+
|
|
49
|
+
if error_summary is not None:
|
|
50
|
+
if error_summary.startswith("invalid_access_token/"):
|
|
51
|
+
raise DropboxAuthException("Unauthorized")
|
|
52
|
+
if error_summary.startswith("path/not_found/"):
|
|
53
|
+
raise DropboxFileOrFolderNotFoundException("File or folder not found")
|
|
54
|
+
except (DropboxAuthException, DropboxFileOrFolderNotFoundException):
|
|
55
|
+
raise
|
|
56
|
+
except json.JSONDecodeError:
|
|
57
|
+
text = await response.text()
|
|
58
|
+
raise DropboxUnknownException(f"{response.status}: {text}")
|
|
50
59
|
|
|
51
60
|
response.raise_for_status()
|
|
52
61
|
|
|
@@ -299,6 +308,11 @@ class DropboxAPIClient:
|
|
|
299
308
|
)
|
|
300
309
|
offset += len(buffer)
|
|
301
310
|
|
|
311
|
+
# Empty file (or a stream that yielded no bytes): no session was ever
|
|
312
|
+
# started, so open one with no data before finishing.
|
|
313
|
+
if session_id is None:
|
|
314
|
+
session_id = await self._start_upload_session(content_api_url, b"")
|
|
315
|
+
|
|
302
316
|
# Finish upload session
|
|
303
317
|
await self._finish_upload_session(
|
|
304
318
|
content_api_url, session_id, offset, path, property_groups
|
|
@@ -429,7 +443,7 @@ class DropboxAPIClient:
|
|
|
429
443
|
chunk_size = 1024 * 1024 # 1MB
|
|
430
444
|
|
|
431
445
|
async with self._websession.post(url, headers=headers) as response:
|
|
432
|
-
response
|
|
446
|
+
await handle_common_errors(response)
|
|
433
447
|
async for chunk in response.content.iter_chunked(chunk_size):
|
|
434
448
|
if chunk:
|
|
435
449
|
yield chunk
|
|
@@ -465,6 +479,18 @@ class DropboxAPIClient:
|
|
|
465
479
|
url, headers=headers, json=payload
|
|
466
480
|
) as response:
|
|
467
481
|
await handle_common_errors(response)
|
|
482
|
+
|
|
483
|
+
response_json = await response.json()
|
|
484
|
+
|
|
485
|
+
# create_folder_v2 wraps the folder metadata under "metadata".
|
|
486
|
+
metadata = response_json["metadata"]
|
|
487
|
+
|
|
488
|
+
return FileOrFolderInfo(
|
|
489
|
+
is_folder=True,
|
|
490
|
+
name=metadata["name"],
|
|
491
|
+
size=None,
|
|
492
|
+
property_groups=None,
|
|
493
|
+
)
|
|
468
494
|
except (DropboxAuthException, DropboxFileOrFolderNotFoundException):
|
|
469
495
|
raise
|
|
470
496
|
except Exception as err:
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
python_dropbox_api/__init__.py,sha256=8NVlyqQZvA0Mgds5Pb80irBac5mGPJFwW4MEeMFPOvU,575
|
|
2
2
|
python_dropbox_api/auth.py,sha256=qrPop5F2_UGDmEtNOwhuYwgoHyaQ_wCjeP0B7tMNx38,448
|
|
3
|
-
python_dropbox_api/client.py,sha256=
|
|
3
|
+
python_dropbox_api/client.py,sha256=vbLmhwbq2yznZtoS5ErOw5qUOnv_51rCM3hUKXcje6k,23484
|
|
4
4
|
python_dropbox_api/exceptions.py,sha256=HZ8Cf1ET6uqMmMIOXmtRqgLaz59GdYm8fBKLPBnXt-M,706
|
|
5
5
|
python_dropbox_api/models.py,sha256=yhkfVMKPsMJxMzLA0KhSUPt_uoJkrvVjeskKffTKt-M,1604
|
|
6
6
|
python_dropbox_api/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
-
python_dropbox_api-0.1.
|
|
8
|
-
python_dropbox_api-0.1.
|
|
9
|
-
python_dropbox_api-0.1.
|
|
10
|
-
python_dropbox_api-0.1.
|
|
7
|
+
python_dropbox_api-0.1.4.dist-info/METADATA,sha256=Kl5T4KAcjUIUMQbSX1hAep_QBS4YBtyogqPGsiYm0-w,647
|
|
8
|
+
python_dropbox_api-0.1.4.dist-info/WHEEL,sha256=eY7nduwzv-ldUxpzbRlxwvC693Hg6PX8bWDjEHjZ_dk,88
|
|
9
|
+
python_dropbox_api-0.1.4.dist-info/licenses/LICENSE,sha256=KEwQxPRqHS1CBUYJkUYSb-dkreLlur_kqtOdilr7SC4,1075
|
|
10
|
+
python_dropbox_api-0.1.4.dist-info/RECORD,,
|
|
File without changes
|