don't expose CLIENT constant

This commit is contained in:
Jörn-Michael Miehe 2022-09-02 15:28:52 +00:00
parent b28d6fa4e7
commit eb69fa4ec6
3 changed files with 18 additions and 6 deletions

View file

@ -1,9 +1,21 @@
from webdav3.client import Client import functools
from typing import Any
from webdav3.client import Client, Resource
from .config import SETTINGS from .config import SETTINGS
CLIENT = Client({ _WEBDAV_CLIENT = Client({
"webdav_hostname": SETTINGS.webdav_url, "webdav_hostname": SETTINGS.webdav_url,
"webdav_login": SETTINGS.dav_username, "webdav_login": SETTINGS.dav_username,
"webdav_password": SETTINGS.dav_password, "webdav_password": SETTINGS.dav_password,
}) })
@functools.lru_cache
def webdav_resource(remote_path: Any) -> Resource:
return _WEBDAV_CLIENT.resource(remote_path)
def webdav_list(remote_path: str) -> list:
return _WEBDAV_CLIENT.list(remote_path)

View file

@ -8,7 +8,7 @@ from typing import Any, Optional
from async_lru import alru_cache from async_lru import alru_cache
from webdav3.client import Resource from webdav3.client import Resource
from . import CLIENT from . import webdav_resource
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@ -53,7 +53,7 @@ async def _get_buffer(
resource.write_to(buffer) resource.write_to(buffer)
return buffer return buffer
resource = CLIENT.resource(remote_path) resource = webdav_resource(remote_path)
return await buffer_inner(resource) return await buffer_inner(resource)

View file

@ -5,7 +5,7 @@ from typing import Iterator
from fastapi import HTTPException, status from fastapi import HTTPException, status
from webdav3.exceptions import RemoteResourceNotFound from webdav3.exceptions import RemoteResourceNotFound
from .. import CLIENT from .. import webdav_list
from ..dav_file import DavFile from ..dav_file import DavFile
@ -16,7 +16,7 @@ class FileNameLister:
def __call__(self) -> Iterator[str]: def __call__(self) -> Iterator[str]:
try: try:
file_names = CLIENT.list(self.remote_path) file_names = webdav_list(self.remote_path)
return ( return (
name name