aboutsummaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorMax Deineko <max.deineko@gmail.com>2021-04-04 17:36:09 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2021-04-04 18:35:03 -0400
commitcb6b3340f8995605ad96a306fe0b5e6cbb57d1de (patch)
tree38ee4ea0c1d2bfb58c0a89dd0eca682d97e4596a /contrib
parent5398f3a24e988da4836f78fba62acf2ead1030b0 (diff)
downloadcalcurse-cb6b3340f8995605ad96a306fe0b5e6cbb57d1de.tar.gz
calcurse-cb6b3340f8995605ad96a306fe0b5e6cbb57d1de.zip
calcurse-caldav: always request href from server
Apparently, while some CalDAV servers return href values as is in their response, some might return them URL-quoted (which, if I am not mistaken, was the reason for e943b06). Assuming either behaviour when pushing local objects will lead to discrepancy with events dictionary retrieved from the server and thus bugs, hence we always want to use whatever form of href the server returns. Addresses GitHub issues #337 and #356. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/caldav/calcurse-caldav.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/contrib/caldav/calcurse-caldav.py b/contrib/caldav/calcurse-caldav.py
index 1dfb5ae..3f57fdf 100755
--- a/contrib/caldav/calcurse-caldav.py
+++ b/contrib/caldav/calcurse-caldav.py
@@ -9,7 +9,6 @@ import re
import subprocess
import sys
import textwrap
-import urllib.parse
import xml.etree.ElementTree as etree
import httplib2
@@ -420,18 +419,21 @@ def push_object(conn, objhash):
if not headers:
return None
-
- etag = None
headerdict = dict(headers)
- if 'etag' in headerdict:
- etag = headerdict['etag']
- while not etag:
+
+ # Retrieve href from server to match server-side format. Retrieve ETag
+ # unless it can be extracted from the PUT response already.
+ ret_href, ret_etag = None, headerdict.get('etag')
+ while not ret_etag or not ret_href:
etagdict = get_etags(conn, [href])
- if etagdict:
- etag = next(iter(etagdict.values()))
- etag = etag.strip('"')
+ if not etagdict:
+ continue
+ ret_href, new_etag = next(iter(etagdict.items()))
+ # Favor ETag from PUT response to avoid race condition.
+ if not ret_etag:
+ ret_etag = new_etag
- return (urllib.parse.quote(href), etag)
+ return (ret_href, ret_etag.strip('"'))
def push_objects(objhashes, conn, syncdb, etagdict):