Skip to content

Commit d6c0a05

Browse files
committed
Style fixes for tox linting
1 parent 29b7cd8 commit d6c0a05

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

radicale/app/report.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,31 @@
2323
import posixpath
2424
import socket
2525
import xml.etree.ElementTree as ET
26-
import vobject
2726
from http import client
2827
from typing import (Any, Callable, Iterable, Iterator, List, Optional,
2928
Sequence, Tuple, Union)
3029
from urllib.parse import unquote, urlparse
3130

31+
import vobject
3232
import vobject.base
3333
from vobject.base import ContentLine
3434

3535
import radicale.item as radicale_item
36-
from radicale import httputils, pathutils, storage, types, xmlutils, config
36+
from radicale import httputils, pathutils, storage, types, xmlutils
3737
from radicale.app.base import Access, ApplicationBase
3838
from radicale.item import filter as radicale_filter
3939
from radicale.log import logger
4040

41+
4142
def free_busy_report(base_prefix: str, path: str, xml_request: Optional[ET.Element],
4243
collection: storage.BaseCollection, encoding: str,
4344
unlock_storage_fn: Callable[[], None],
4445
max_occurrence: int
45-
) -> Tuple[int, str]:
46+
) -> Tuple[int, Union[ET.Element, str]]:
47+
# NOTE: this function returns both an Element and a string because
48+
# free-busy reports are an edge-case on the return type according
49+
# to the spec.
50+
4651
multistatus = ET.Element(xmlutils.make_clark("D:multistatus"))
4752
if xml_request is None:
4853
return client.MULTI_STATUS, multistatus
@@ -54,15 +59,16 @@ def free_busy_report(base_prefix: str, path: str, xml_request: Optional[ET.Eleme
5459
return client.FORBIDDEN, xmlutils.webdav_error("D:supported-report")
5560

5661
time_range_element = root.find(xmlutils.make_clark("C:time-range"))
62+
assert isinstance(time_range_element, ET.Element)
5763

5864
# Build a single filter from the free busy query for retrieval
5965
# TODO: filter for VFREEBUSY in additional to VEVENT but
6066
# test_filter doesn't support that yet.
6167
vevent_cf_element = ET.Element(xmlutils.make_clark("C:comp-filter"),
62-
attrib={'name':'VEVENT'})
68+
attrib={'name': 'VEVENT'})
6369
vevent_cf_element.append(time_range_element)
6470
vcalendar_cf_element = ET.Element(xmlutils.make_clark("C:comp-filter"),
65-
attrib={'name':'VCALENDAR'})
71+
attrib={'name': 'VCALENDAR'})
6672
vcalendar_cf_element.append(vevent_cf_element)
6773
filter_element = ET.Element(xmlutils.make_clark("C:filter"))
6874
filter_element.append(vcalendar_cf_element)
@@ -525,7 +531,7 @@ def do_REPORT(self, environ: types.WSGIEnviron, base_prefix: str,
525531
"Bad REPORT request on %r: %s", path, e, exc_info=True)
526532
return httputils.BAD_REQUEST
527533
headers = {"Content-Type": "text/calendar; charset=%s" % self._encoding}
528-
return status, headers, body
534+
return status, headers, str(body)
529535
else:
530536
try:
531537
status, xml_answer = xml_report(

radicale/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ def json_str(value: Any) -> dict:
301301
"type": positive_int})]))
302302
])
303303

304+
304305
def parse_compound_paths(*compound_paths: Optional[str]
305306
) -> List[Tuple[str, bool]]:
306307
"""Parse a compound path and return the individual paths.

radicale/item/filter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ def parse_time_range(time_filter: ET.Element) -> Tuple[datetime, datetime]:
7070
end = DATETIME_MAX
7171
return start, end
7272

73+
7374
def time_range_timestamps(time_filter: ET.Element) -> Tuple[int, int]:
7475
start, end = parse_time_range(time_filter)
7576
return (math.floor(start.timestamp()), math.ceil(end.timestamp()))
7677

78+
7779
def comp_match(item: "item.Item", filter_: ET.Element, level: int = 0) -> bool:
7880
"""Check whether the ``item`` matches the comp ``filter_``.
7981
@@ -202,6 +204,7 @@ def time_range_fill(vobject_item: vobject.base.Component,
202204

203205
start, end = parse_time_range(filter_)
204206
ranges: List[Tuple[datetime, datetime]] = []
207+
205208
def range_fn(range_start: datetime, range_end: datetime,
206209
is_recurrence: bool) -> bool:
207210
nonlocal ranges

radicale/tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
import tempfile
2828
import wsgiref.util
2929
import xml.etree.ElementTree as ET
30-
import vobject
3130
from io import BytesIO
3231
from typing import Any, Dict, List, Optional, Tuple, Union
3332

3433
import defusedxml.ElementTree as DefusedET
34+
import vobject
3535

3636
import radicale
3737
from radicale import app, config, types, xmlutils

radicale/tests/test_base.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323
import os
2424
import posixpath
25-
import vobject
2625
from typing import Any, Callable, ClassVar, Iterable, List, Optional, Tuple
2726

2827
import defusedxml.ElementTree as DefusedET
28+
import vobject
2929

3030
from radicale import storage, xmlutils
3131
from radicale.tests import RESPONSES, BaseTest
@@ -1369,26 +1369,28 @@ def test_report_free_busy(self) -> None:
13691369
"""Test free busy report on a few items"""
13701370
calendar_path = "/calendar.ics/"
13711371
self.mkcalendar(calendar_path)
1372-
for i in (1,2,10):
1372+
for i in (1, 2, 10):
13731373
filename = "event{}.ics".format(i)
13741374
event = get_file_content(filename)
13751375
self.put(posixpath.join(calendar_path, filename), event)
13761376
code, responses = self.report(calendar_path, """\
13771377
<?xml version="1.0" encoding="utf-8" ?>
13781378
<C:free-busy-query xmlns:C="urn:ietf:params:xml:ns:caldav">
13791379
<C:time-range start="20130901T140000Z" end="20130908T220000Z"/>
1380-
</C:free-busy-query>""", 200, is_xml = False)
1380+
</C:free-busy-query>""", 200, is_xml=False)
13811381
for response in responses.values():
13821382
assert isinstance(response, vobject.base.Component)
13831383
assert len(responses) == 1
13841384
vcalendar = list(responses.values())[0]
1385+
assert isinstance(vcalendar, vobject.base.Component)
13851386
assert len(vcalendar.vfreebusy_list) == 3
13861387
types = {}
13871388
for vfb in vcalendar.vfreebusy_list:
1388-
if vfb.fbtype.value not in types:
1389-
types[vfb.fbtype.value] = 0
1390-
types[vfb.fbtype.value] += 1
1391-
assert types == {'BUSY':2, 'FREE':1}
1389+
fbtype_val = vfb.fbtype.value
1390+
if fbtype_val not in types:
1391+
types[fbtype_val] = 0
1392+
types[fbtype_val] += 1
1393+
assert types == {'BUSY': 2, 'FREE': 1}
13921394

13931395
def _report_sync_token(
13941396
self, calendar_path: str, sync_token: Optional[str] = None

0 commit comments

Comments
 (0)