Skip to content

Commit

Permalink
fix: typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentame committed Oct 28, 2024
1 parent 06f82b5 commit 3fb9f62
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/freebox_api/access.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import hmac
import json
import logging
from typing import Any
from typing import Any, Mapping
from typing import Dict
from typing import Optional
from urllib.parse import urljoin
Expand Down Expand Up @@ -138,7 +138,7 @@ async def get(
return await self._perform_request(self.session.get, end_url)

async def post(
self, end_url: str, payload: Optional[Dict[str, Any]] = None
self, end_url: str, payload: Optional[Mapping[str, Any]] = None
) -> Dict[str, Any]:
"""
Send post request and return results
Expand Down
44 changes: 31 additions & 13 deletions src/freebox_api/api/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"""

import base64
from typing import Any, TypedDict
from typing import Any, Required, TypedDict
from typing import Dict
from typing import Optional

from freebox_api.access import Access


class DownloadAddURL(TypedDict):
class _DownloadAddURL(TypedDict, total=False):
"""
Add download by URL parameters data structure.
Expand All @@ -30,17 +30,27 @@ class DownloadAddURL(TypedDict):
cookies : `str` – The http cookies (to be able to pass session cookies along with url)
"""

download_url: str
download_url_list: str
download_dir: Optional[str]
download_dir: str
recursive: bool
username: Optional[str]
password: Optional[str]
username: str
password: str
archive_password: str
cookies: str


class DownloadAddFile(TypedDict):
class DownloadAddURL(_DownloadAddURL):
"""Add download by URL parameters data structure."""

download_url: Required[str]


class DownloadAddURLList(_DownloadAddURL):
"""Add download by URL list parameters data structure."""

download_url_list: Required[str]


class DownloadAddFile(TypedDict, total=False):
"""
Add download by file upload parameters data structure.
Expand All @@ -53,8 +63,8 @@ class DownloadAddFile(TypedDict):
(only relevant for nzb)
"""

download_file: str
download_dir: Optional[str]
download_file: Required[str]
download_dir: str
archive_password: str


Expand All @@ -66,8 +76,14 @@ class Download:
def __init__(self, access: Access) -> None:
self._access = access

download_url_schema = {
download_url_schema: DownloadAddURL = {
"download_url": "",
"username": "",
"password": "",
"recursive": False,
"download_dir": "",
}
download_url_list_schema: DownloadAddURLList = {
"download_url_list": "", # items separated by /n
"username": "",
"password": "",
Expand Down Expand Up @@ -169,8 +185,9 @@ async def add_download_task_from_url(
"""
download_params: DownloadAddURL = {
"download_url": download_url,
"download_dir": download_dir,
}
if download_dir:
download_params["download_dir"] = download_dir
return await self.add_download_task(download_params)

async def add_download_task_from_file(
Expand All @@ -183,8 +200,9 @@ async def add_download_task_from_file(
"""
download_params: DownloadAddFile = {
"download_file": download_file,
"download_dir": download_dir,
}
if download_dir:
download_params["download_dir"] = download_dir
return await self.add_download_task(download_params)

# Download Stats
Expand Down

0 comments on commit 3fb9f62

Please sign in to comment.