1
0
Fork 0
mirror of https://github.com/Kozea/Radicale.git synced 2025-06-26 16:45:52 +00:00

Style fixes for tox linting

This commit is contained in:
Ray 2024-08-14 11:15:30 -06:00
parent 29b7cd8d54
commit d6c0a05771
5 changed files with 26 additions and 14 deletions

View file

@ -23,26 +23,31 @@ import datetime
import posixpath import posixpath
import socket import socket
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
import vobject
from http import client from http import client
from typing import (Any, Callable, Iterable, Iterator, List, Optional, from typing import (Any, Callable, Iterable, Iterator, List, Optional,
Sequence, Tuple, Union) Sequence, Tuple, Union)
from urllib.parse import unquote, urlparse from urllib.parse import unquote, urlparse
import vobject
import vobject.base import vobject.base
from vobject.base import ContentLine from vobject.base import ContentLine
import radicale.item as radicale_item import radicale.item as radicale_item
from radicale import httputils, pathutils, storage, types, xmlutils, config from radicale import httputils, pathutils, storage, types, xmlutils
from radicale.app.base import Access, ApplicationBase from radicale.app.base import Access, ApplicationBase
from radicale.item import filter as radicale_filter from radicale.item import filter as radicale_filter
from radicale.log import logger from radicale.log import logger
def free_busy_report(base_prefix: str, path: str, xml_request: Optional[ET.Element], def free_busy_report(base_prefix: str, path: str, xml_request: Optional[ET.Element],
collection: storage.BaseCollection, encoding: str, collection: storage.BaseCollection, encoding: str,
unlock_storage_fn: Callable[[], None], unlock_storage_fn: Callable[[], None],
max_occurrence: int max_occurrence: int
) -> Tuple[int, str]: ) -> Tuple[int, Union[ET.Element, str]]:
# NOTE: this function returns both an Element and a string because
# free-busy reports are an edge-case on the return type according
# to the spec.
multistatus = ET.Element(xmlutils.make_clark("D:multistatus")) multistatus = ET.Element(xmlutils.make_clark("D:multistatus"))
if xml_request is None: if xml_request is None:
return client.MULTI_STATUS, multistatus return client.MULTI_STATUS, multistatus
@ -54,6 +59,7 @@ def free_busy_report(base_prefix: str, path: str, xml_request: Optional[ET.Eleme
return client.FORBIDDEN, xmlutils.webdav_error("D:supported-report") return client.FORBIDDEN, xmlutils.webdav_error("D:supported-report")
time_range_element = root.find(xmlutils.make_clark("C:time-range")) time_range_element = root.find(xmlutils.make_clark("C:time-range"))
assert isinstance(time_range_element, ET.Element)
# Build a single filter from the free busy query for retrieval # Build a single filter from the free busy query for retrieval
# TODO: filter for VFREEBUSY in additional to VEVENT but # TODO: filter for VFREEBUSY in additional to VEVENT but
@ -525,7 +531,7 @@ class ApplicationPartReport(ApplicationBase):
"Bad REPORT request on %r: %s", path, e, exc_info=True) "Bad REPORT request on %r: %s", path, e, exc_info=True)
return httputils.BAD_REQUEST return httputils.BAD_REQUEST
headers = {"Content-Type": "text/calendar; charset=%s" % self._encoding} headers = {"Content-Type": "text/calendar; charset=%s" % self._encoding}
return status, headers, body return status, headers, str(body)
else: else:
try: try:
status, xml_answer = xml_report( status, xml_answer = xml_report(

View file

@ -301,6 +301,7 @@ DEFAULT_CONFIG_SCHEMA: types.CONFIG_SCHEMA = OrderedDict([
"type": positive_int})])) "type": positive_int})]))
]) ])
def parse_compound_paths(*compound_paths: Optional[str] def parse_compound_paths(*compound_paths: Optional[str]
) -> List[Tuple[str, bool]]: ) -> List[Tuple[str, bool]]:
"""Parse a compound path and return the individual paths. """Parse a compound path and return the individual paths.

View file

@ -70,10 +70,12 @@ def parse_time_range(time_filter: ET.Element) -> Tuple[datetime, datetime]:
end = DATETIME_MAX end = DATETIME_MAX
return start, end return start, end
def time_range_timestamps(time_filter: ET.Element) -> Tuple[int, int]: def time_range_timestamps(time_filter: ET.Element) -> Tuple[int, int]:
start, end = parse_time_range(time_filter) start, end = parse_time_range(time_filter)
return (math.floor(start.timestamp()), math.ceil(end.timestamp())) return (math.floor(start.timestamp()), math.ceil(end.timestamp()))
def comp_match(item: "item.Item", filter_: ET.Element, level: int = 0) -> bool: def comp_match(item: "item.Item", filter_: ET.Element, level: int = 0) -> bool:
"""Check whether the ``item`` matches the comp ``filter_``. """Check whether the ``item`` matches the comp ``filter_``.
@ -202,6 +204,7 @@ def time_range_fill(vobject_item: vobject.base.Component,
start, end = parse_time_range(filter_) start, end = parse_time_range(filter_)
ranges: List[Tuple[datetime, datetime]] = [] ranges: List[Tuple[datetime, datetime]] = []
def range_fn(range_start: datetime, range_end: datetime, def range_fn(range_start: datetime, range_end: datetime,
is_recurrence: bool) -> bool: is_recurrence: bool) -> bool:
nonlocal ranges nonlocal ranges

View file

@ -27,11 +27,11 @@ import sys
import tempfile import tempfile
import wsgiref.util import wsgiref.util
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
import vobject
from io import BytesIO from io import BytesIO
from typing import Any, Dict, List, Optional, Tuple, Union from typing import Any, Dict, List, Optional, Tuple, Union
import defusedxml.ElementTree as DefusedET import defusedxml.ElementTree as DefusedET
import vobject
import radicale import radicale
from radicale import app, config, types, xmlutils from radicale import app, config, types, xmlutils

View file

@ -22,10 +22,10 @@ Radicale tests with simple requests.
import os import os
import posixpath import posixpath
import vobject
from typing import Any, Callable, ClassVar, Iterable, List, Optional, Tuple from typing import Any, Callable, ClassVar, Iterable, List, Optional, Tuple
import defusedxml.ElementTree as DefusedET import defusedxml.ElementTree as DefusedET
import vobject
from radicale import storage, xmlutils from radicale import storage, xmlutils
from radicale.tests import RESPONSES, BaseTest from radicale.tests import RESPONSES, BaseTest
@ -1382,12 +1382,14 @@ permissions: RrWw""")
assert isinstance(response, vobject.base.Component) assert isinstance(response, vobject.base.Component)
assert len(responses) == 1 assert len(responses) == 1
vcalendar = list(responses.values())[0] vcalendar = list(responses.values())[0]
assert isinstance(vcalendar, vobject.base.Component)
assert len(vcalendar.vfreebusy_list) == 3 assert len(vcalendar.vfreebusy_list) == 3
types = {} types = {}
for vfb in vcalendar.vfreebusy_list: for vfb in vcalendar.vfreebusy_list:
if vfb.fbtype.value not in types: fbtype_val = vfb.fbtype.value
types[vfb.fbtype.value] = 0 if fbtype_val not in types:
types[vfb.fbtype.value] += 1 types[fbtype_val] = 0
types[fbtype_val] += 1
assert types == {'BUSY': 2, 'FREE': 1} assert types == {'BUSY': 2, 'FREE': 1}
def _report_sync_token( def _report_sync_token(