Skip to content

Commit

Permalink
event check is done, I think
Browse files Browse the repository at this point in the history
  • Loading branch information
tobixen committed Nov 18, 2024
1 parent 4657d0f commit 1d4ac97
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 116 deletions.
19 changes: 17 additions & 2 deletions caldav/davclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +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
error.assert_(response.tag == dav.Response.tag)
for elem in response:
if elem.tag == dav.Status.tag:
Expand All @@ -223,13 +224,27 @@ 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':
## 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')
check_404 = True
else:
error.assert_(False)
## i.e. purelymail may contain one more tag, <error>...</error>
## This is probably not a breach of the standard. It may
## probably be ignored. But it's something we may want to
## know.
error.weirdness("unexpected element found in response", elem)
error.assert_(href)
if check_404:
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
## but different URLs for different elements?
## but different URLs for different elements? Perhaps href should always be made into an URL-object?
if ":" in href:
href = unquote(URL(href).path)
return (cast(str, href), propstats, status)
Expand Down
2 changes: 2 additions & 0 deletions caldav/lib/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


def xmlstring(root):
if isinstance(root, str):
return root
if hasattr(root, "xmlelement"):
root = root.xmlelement()
return etree.tostring(root, pretty_print=True).decode("utf-8")
Expand Down
11 changes: 8 additions & 3 deletions caldav/lib/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
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()

def assert_(condition: object) -> None:
try:
Expand All @@ -36,9 +43,7 @@ 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
2 changes: 1 addition & 1 deletion caldav/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ def _create(
if name:
try:
self.set_properties([display_name])
except:
except Exception as e:
## TODO: investigate. Those asserts break.
error.assert_(False)
try:
Expand Down
Loading

0 comments on commit 1d4ac97

Please sign in to comment.