Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions vdirsyncer/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def _process_conflict_resolution_param(
):
if conflict_resolution in (None, "a wins", "b wins"):
return conflict_resolution
elif (
if (
isinstance(conflict_resolution, list)
and len(conflict_resolution) > 1
and conflict_resolution[0] == "command"
Expand All @@ -271,8 +271,7 @@ def resolve(a, b):
return _resolve_conflict_via_command(a, b, command, a_name, b_name)

return resolve
else:
raise ValueError("Invalid value for `conflict_resolution`.")
raise ValueError("Invalid value for `conflict_resolution`.")

# The following parameters are lazily evaluated because evaluating
# self.config_a would expand all `x.fetch` parameters. This is costly and
Expand Down
11 changes: 5 additions & 6 deletions vdirsyncer/cli/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,20 @@ async def collections_for_pair(
cache_key = _get_collections_cache_key(pair)
if from_cache:
rv = load_status(status_path, pair.name, data_type="collections")
if rv.get("cache_key", None) == cache_key:
if rv and rv.get("cache_key", None) == cache_key:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change form me and is it necessary? The other changes here do not modify the program logic, that is they preserve all the bugs. But this change modifies the program logic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was from your original commit.

When I reviewed this earlier the change made sense to me because of the following elif rv. I realise now that it is unnecessary. It should not change the logic, assuming that rv is never None.

return list(
_expand_collections_cache(
rv["collections"], pair.config_a, pair.config_b
)
)
elif rv:
if rv:
raise exceptions.UserError(
"Detected change in config file, "
f"please run `vdirsyncer discover {pair.name}`."
)
else:
raise exceptions.UserError(
f"Please run `vdirsyncer discover {pair.name}` before synchronization."
)
raise exceptions.UserError(
f"Please run `vdirsyncer discover {pair.name}` before synchronization."
)

logger.info(f"Discovering collections for pair {pair.name}")

Expand Down
3 changes: 1 addition & 2 deletions vdirsyncer/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,7 @@ async def storage_instance_from_config(
create=False,
connector=connector,
)
else:
raise
raise
except Exception:
return handle_storage_init_error(cls, new_config)

Expand Down
4 changes: 2 additions & 2 deletions vdirsyncer/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ def prepare_auth(auth, username, password):
if username and password:
if auth == "basic" or auth is None:
return BasicAuthMethod(username, password)
elif auth == "digest":
if auth == "digest":
return DigestAuthMethod(username, password)
elif auth == "guess":
if auth == "guess":
raise exceptions.UserError(
"'Guess' authentication is not supported in this version of vdirsyncer. \n"
"Please explicitly specify either 'basic' or 'digest' auth instead. \n"
Expand Down
8 changes: 3 additions & 5 deletions vdirsyncer/storage/dav.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ def _fuzzy_matches_mimetype(strict, weak):
return True

mediatype, subtype = strict.split("/")
if subtype in weak:
return True
return False
return subtype in weak


class Discover:
Expand Down Expand Up @@ -237,7 +235,7 @@ def _check_collection_resource_type(self, response):
return True

props = _merge_xml(response.findall("{DAV:}propstat/{DAV:}prop"))
if props is None or not len(props):
if props is None or not props:
dav_logger.debug("Skipping, missing <prop>: %s", response)
return False
if props.find("{DAV:}resourcetype/" + self._resourcetype) is None:
Expand Down Expand Up @@ -626,7 +624,7 @@ def _parse_prop_responses(self, root, handled_hrefs=None):
continue

props = response.findall("{DAV:}propstat/{DAV:}prop")
if props is None or not len(props):
if props is None or not props:
dav_logger.debug(f"Skipping {href!r}, properties are missing.")
continue
else:
Expand Down
6 changes: 2 additions & 4 deletions vdirsyncer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
def expand_path(p: str) -> str:
"""Expand $HOME in a path and normalise slashes."""
p = os.path.expanduser(p)
p = os.path.normpath(p)
return p
return os.path.normpath(p)


def split_dict(d: dict, f: Callable):
Expand Down Expand Up @@ -177,8 +176,7 @@ def generate_href(ident=None, safe=SAFE_UID_CHARS):
"""
if not ident or not href_safe(ident, safe):
return str(uuid.uuid4())
else:
return ident
return ident


def synchronized(lock=None):
Expand Down
18 changes: 7 additions & 11 deletions vdirsyncer/vobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ def _get_item_type(components, wrappers):

if not i:
return None, None
else:
raise ValueError("Not sure how to join components.")
raise ValueError("Not sure how to join components.")


class _Component:
Expand Down Expand Up @@ -303,10 +302,9 @@ def parse(cls, lines, multiple=False):

if multiple:
return rv
elif len(rv) != 1:
if len(rv) != 1:
raise ValueError(f"Found {len(rv)} components, expected one.")
else:
return rv[0]
return rv[0]

def dump_lines(self):
yield f"BEGIN:{self.name}"
Expand All @@ -323,8 +321,7 @@ def __delitem__(self, key):
for line in lineiter:
if line.startswith(prefix):
break
else:
new_lines.append(line)
new_lines.append(line)
else:
break

Expand All @@ -347,10 +344,9 @@ def __contains__(self, obj):
return obj not in self.subcomponents and not any(
obj in x for x in self.subcomponents
)
elif isinstance(obj, str):
if isinstance(obj, str):
return self.get(obj, None) is not None
else:
raise ValueError(obj)
raise ValueError(obj)

def __getitem__(self, key):
prefix_without_params = f"{key}:"
Expand All @@ -360,7 +356,7 @@ def __getitem__(self, key):
if line.startswith(prefix_without_params):
rv = line[len(prefix_without_params) :]
break
elif line.startswith(prefix_with_params):
if line.startswith(prefix_with_params):
rv = line[len(prefix_with_params) :].split(":", 1)[-1]
break
else:
Expand Down