Skip to content

Commit

Permalink
style fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tobixen committed Nov 18, 2024
1 parent 689e486 commit e9b3587
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 137 deletions.
12 changes: 7 additions & 5 deletions caldav/davclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def _parse_response(self, response) -> Tuple[str, List[_Element], Optional[Any]]
status = None
href: Optional[str] = None
propstats: List[_Element] = []
check_404 = False ## special for purelymail
check_404 = False ## special for purelymail
error.assert_(response.tag == dav.Response.tag)
for elem in response:
if elem.tag == dav.Status.tag:
Expand All @@ -224,13 +224,15 @@ def _parse_response(self, response) -> Tuple[str, List[_Element], Optional[Any]]
href = unquote(elem.text)
elif elem.tag == dav.PropStat.tag:
propstats.append(elem)
elif elem.tag == '{DAV:}error':
elif elem.tag == "{DAV:}error":
## This happens with purelymail on a 404.
## This code is mostly moot, but in debug
## mode I want to be sure we do not toss away any data
children = elem.getchildren()
error.assert_(len(children)==1)
error.assert_(children[0].tag=='{https://purelymail.com}does-not-exist')
error.assert_(len(children) == 1)
error.assert_(
children[0].tag == "{https://purelymail.com}does-not-exist"
)
check_404 = True
else:
## i.e. purelymail may contain one more tag, <error>...</error>
Expand All @@ -240,7 +242,7 @@ def _parse_response(self, response) -> Tuple[str, List[_Element], Optional[Any]]
error.weirdness("unexpected element found in response", elem)
error.assert_(href)
if check_404:
error.assert_('404' in status)
error.assert_("404" in status)
## TODO: is this safe/sane?
## Ref https://github.com/python-caldav/caldav/issues/435 the paths returned may be absolute URLs,
## but the caller expects them to be paths. Could we have issues when a server has same path
Expand Down
11 changes: 9 additions & 2 deletions caldav/lib/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@
else:
log.setLevel(logging.WARNING)


def weirdness(*reasons):
from caldav.lib.debug import xmlstring

reason = " : ".join([xmlstring(x) for x in reasons])
log.warning(f"Deviation from expectations found: {reason}")
if debugmode == "DEBUG_PDB":
log.error(f"Dropping into debugger due to {reason}")
import pdb; pdb.set_trace()
import pdb

pdb.set_trace()


def assert_(condition: object) -> None:
try:
Expand All @@ -43,7 +48,9 @@ def assert_(condition: object) -> None:
)
elif debugmode == "DEBUG_PDB":
log.error("Deviation from expectations found. Dropping into debugger")
import pdb; pdb.set_trace()
import pdb

pdb.set_trace()
else:
raise

Expand Down
Loading

0 comments on commit e9b3587

Please sign in to comment.