|
3 | 3 | import contextlib |
4 | 4 | import xml.etree.ElementTree as ET |
5 | 5 | from typing import Any |
| 6 | +from urllib.parse import quote as url_quote |
6 | 7 |
|
7 | 8 | import niquests |
8 | 9 | from urllib3.util import Retry |
@@ -275,16 +276,18 @@ async def trashbin_restore(self, trash_path: str) -> None: |
275 | 276 | """Restore a trashed item by MOVEing it to the restore folder.""" |
276 | 277 | session = await self._get_session() |
277 | 278 | user = self._config.user |
278 | | - src = f"{self._base_url}/remote.php/dav/trashbin/{user}/trash/{trash_path}" |
279 | | - dest = f"{self._base_url}/remote.php/dav/trashbin/{user}/restore/{trash_path}" |
| 279 | + encoded = url_quote(trash_path, safe="/") |
| 280 | + src = f"{self._base_url}/remote.php/dav/trashbin/{user}/trash/{encoded}" |
| 281 | + dest = f"{self._base_url}/remote.php/dav/trashbin/{user}/restore/{encoded}" |
280 | 282 | response = await session.request("MOVE", src, headers={"Destination": dest}) |
281 | 283 | _raise_for_status(response, f"Restore '{trash_path}'") |
282 | 284 |
|
283 | 285 | async def trashbin_delete(self, trash_path: str = "") -> None: |
284 | 286 | """Delete a single item or empty the entire trash (if path is empty).""" |
285 | 287 | session = await self._get_session() |
286 | 288 | user = self._config.user |
287 | | - url = f"{self._base_url}/remote.php/dav/trashbin/{user}/trash/{trash_path}" |
| 289 | + encoded = url_quote(trash_path, safe="/") if trash_path else "" |
| 290 | + url = f"{self._base_url}/remote.php/dav/trashbin/{user}/trash/{encoded}" |
288 | 291 | response = await session.delete(url) |
289 | 292 | _raise_for_status(response, "Empty trash" if not trash_path else f"Delete '{trash_path}' from trash") |
290 | 293 |
|
|
0 commit comments