Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

All notable changes to this project will be documented in this file.

## [0.6.1 - 202x-xx-xx]
## [0.7.0 - 2022-12-2x]

### Added

- set_handlers: `enabled_handler`, `heartbeat_handler` now can be async(Coroutines). #175

### Changed

- drop Python 3.9 support. #180
- internal code refactoring and clean-up #177

## [0.6.0 - 2023-12-06]

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![codecov](https://codecov.io/github/cloud-py-api/nc_py_api/branch/main/graph/badge.svg?token=C91PL3FYDQ)](https://codecov.io/github/cloud-py-api/nc_py_api)

![NextcloudVersion](https://img.shields.io/badge/Nextcloud-26%20%7C%2027%20%7C%2028-blue)
![PythonVersion](https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue)
![PythonVersion](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue)
![impl](https://img.shields.io/pypi/implementation/nc_py_api)
![pypi](https://img.shields.io/pypi/v/nc_py_api.svg)

Expand Down
4 changes: 2 additions & 2 deletions benchmarks/aa_overhead_dav_download.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from getpass import getuser
from random import randbytes
from time import perf_counter
from typing import Any, Union
from typing import Any

import matplotlib.pyplot as plt
from aa_overhead_common import measure_overhead, os_id
Expand All @@ -12,7 +12,7 @@
CACHE_SESS = False


def measure_download_1mb(nc_obj: Union[Nextcloud, NextcloudApp]) -> [Any, float]:
def measure_download_1mb(nc_obj: Nextcloud | NextcloudApp) -> [Any, float]:
__result = None
small_file_name = "1Mb.bin"
small_file = randbytes(1024 * 1024)
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/aa_overhead_dav_download_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from io import BytesIO
from random import randbytes
from time import perf_counter
from typing import Any, Union
from typing import Any

import matplotlib.pyplot as plt
from aa_overhead_common import measure_overhead, os_id
Expand All @@ -13,7 +13,7 @@
CACHE_SESS = False


def measure_download_100mb(nc_obj: Union[Nextcloud, NextcloudApp]) -> [Any, float]:
def measure_download_100mb(nc_obj: Nextcloud | NextcloudApp) -> [Any, float]:
__result = None
medium_file_name = "100Mb.bin"
medium_file = BytesIO()
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/aa_overhead_dav_upload.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from getpass import getuser
from random import randbytes
from time import perf_counter
from typing import Any, Union
from typing import Any

import matplotlib.pyplot as plt
from aa_overhead_common import measure_overhead, os_id
Expand All @@ -12,7 +12,7 @@
CACHE_SESS = False


def measure_upload_1mb(nc_obj: Union[Nextcloud, NextcloudApp]) -> [Any, float]:
def measure_upload_1mb(nc_obj: Nextcloud | NextcloudApp) -> [Any, float]:
__result = None
small_file_name = "1Mb.bin"
small_file = randbytes(1024 * 1024)
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/aa_overhead_dav_upload_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from io import BytesIO
from random import randbytes
from time import perf_counter
from typing import Any, Union
from typing import Any

import matplotlib.pyplot as plt
from aa_overhead_common import measure_overhead, os_id
Expand All @@ -13,7 +13,7 @@
CACHE_SESS = False


def measure_upload_100mb(nc_obj: Union[Nextcloud, NextcloudApp]) -> [Any, float]:
def measure_upload_100mb(nc_obj: Nextcloud | NextcloudApp) -> [Any, float]:
__result = None
medium_file_name = "100Mb.bin"
medium_file = BytesIO()
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/aa_overhead_ocs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from getpass import getuser
from time import perf_counter
from typing import Any, Union
from typing import Any

import matplotlib.pyplot as plt
from aa_overhead_common import measure_overhead, os_id
Expand All @@ -11,7 +11,7 @@
CACHE_SESS = False


def measure_get_details(nc_obj: Union[Nextcloud, NextcloudApp]) -> [Any, float]:
def measure_get_details(nc_obj: Nextcloud | NextcloudApp) -> [Any, float]:
__result = None
start_time = perf_counter()
for _ in range(ITERS):
Expand Down
8 changes: 3 additions & 5 deletions benchmarks/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional

from nc_py_api import Nextcloud, NextcloudApp

NC_CFGS = {
Expand Down Expand Up @@ -39,19 +37,19 @@
}


def init_nc(url, cfg) -> Optional[Nextcloud]:
def init_nc(url, cfg) -> Nextcloud | None:
if cfg.get("nc_auth_user", "") and cfg.get("nc_auth_pass", ""):
return Nextcloud(nc_auth_user=cfg["nc_auth_user"], nc_auth_pass=cfg["nc_auth_pass"], nextcloud_url=url)
return None


def init_nc_by_app_pass(url, cfg) -> Optional[Nextcloud]:
def init_nc_by_app_pass(url, cfg) -> Nextcloud | None:
if cfg.get("nc_auth_user", "") and cfg.get("nc_auth_app_pass", ""):
return Nextcloud(nc_auth_user=cfg["nc_auth_user"], nc_auth_pass=cfg["nc_auth_app_pass"], nextcloud_url=url)
return None


def init_nc_app(url, cfg) -> Optional[NextcloudApp]:
def init_nc_app(url, cfg) -> NextcloudApp | None:
if cfg.get("secret", "") and cfg.get("app_id", ""):
return NextcloudApp(
app_id=cfg["app_id"],
Expand Down
6 changes: 3 additions & 3 deletions nc_py_api/_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import secrets
from base64 import b64decode
from collections.abc import Callable
from datetime import datetime, timezone
from string import ascii_letters, digits
from typing import Callable, Union

from ._exceptions import NextcloudMissingCapabilities

Expand All @@ -28,7 +28,7 @@ def clear_from_params_empty(keys: list[str], params: dict) -> None:
params.pop(key)


def require_capabilities(capabilities: Union[str, list[str]], srv_capabilities: dict) -> None:
def require_capabilities(capabilities: str | list[str], srv_capabilities: dict) -> None:
"""Checks for capabilities and raises an exception if any of them are missing."""
result = check_capabilities(capabilities, srv_capabilities)
if result:
Expand All @@ -52,7 +52,7 @@ def __check_sub_capability(split_capabilities: list[str], srv_capabilities: dict
return True


def check_capabilities(capabilities: Union[str, list[str]], srv_capabilities: dict) -> list[str]:
def check_capabilities(capabilities: str | list[str], srv_capabilities: dict) -> list[str]:
"""Checks for capabilities and returns a list of missing ones."""
if isinstance(capabilities, str):
capabilities = [capabilities]
Expand Down
7 changes: 3 additions & 4 deletions nc_py_api/_preferences_ex.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Nextcloud API for working with apps V2's storage w/wo user context(table oc_appconfig_ex/oc_preferences_ex)."""

import dataclasses
import typing

from ._exceptions import NextcloudExceptionNotFound
from ._misc import require_capabilities
Expand All @@ -26,7 +25,7 @@ class _BasicAppCfgPref:
def __init__(self, session: NcSessionBasic):
self._session = session

def get_value(self, key: str, default=None) -> typing.Optional[str]:
def get_value(self, key: str, default=None) -> str | None:
"""Returns the value of the key, if found, or the specified default value."""
if not key:
raise ValueError("`key` parameter can not be empty")
Expand All @@ -47,7 +46,7 @@ def get_values(self, keys: list[str]) -> list[CfgRecord]:
results = self._session.ocs("POST", f"{self._session.ae_url}/{self._url_suffix}/get-values", json=data)
return [CfgRecord(i) for i in results]

def delete(self, keys: typing.Union[str, list[str]], not_fail=True) -> None:
def delete(self, keys: str | list[str], not_fail=True) -> None:
"""Deletes config/preference entries by the provided keys."""
if isinstance(keys, str):
keys = [keys]
Expand Down Expand Up @@ -82,7 +81,7 @@ class AppConfigExAPI(_BasicAppCfgPref):

_url_suffix = "ex-app/config"

def set_value(self, key: str, value: str, sensitive: typing.Optional[bool] = None) -> None:
def set_value(self, key: str, value: str, sensitive: bool | None = None) -> None:
"""Sets a value and if specified the sensitive flag for a key.

.. note:: A sensitive flag ensures key values are truncated in Nextcloud logs.
Expand Down
14 changes: 7 additions & 7 deletions nc_py_api/_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class ServerVersion(typing.TypedDict):
@dataclass
class RuntimeOptions:
xdebug_session: str
timeout: typing.Optional[int]
timeout_dav: typing.Optional[int]
_nc_cert: typing.Union[str, bool]
timeout: int | None
timeout_dav: int | None
_nc_cert: str | bool
upload_chunk_v2: bool

def __init__(self, **kwargs):
Expand All @@ -62,7 +62,7 @@ def __init__(self, **kwargs):
self.upload_chunk_v2 = kwargs.get("chunked_upload_v2", options.CHUNKED_UPLOAD_V2)

@property
def nc_cert(self) -> typing.Union[str, bool]:
def nc_cert(self) -> str | bool:
return self._nc_cert


Expand Down Expand Up @@ -158,9 +158,9 @@ def ocs(
method: str,
path: str,
*,
content: typing.Optional[typing.Union[bytes, str, typing.Iterable[bytes], typing.AsyncIterable[bytes]]] = None,
json: typing.Optional[typing.Union[dict, list]] = None,
params: typing.Optional[dict] = None,
content: bytes | str | typing.Iterable[bytes] | typing.AsyncIterable[bytes] | None = None,
json: dict | list | None = None,
params: dict | None = None,
**kwargs,
):
self.init_adapter()
Expand Down
Loading