mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Simplify some statements
This commit is contained in:
parent
6da84c7881
commit
9677cf9812
8 changed files with 19 additions and 24 deletions
|
|
@ -64,6 +64,7 @@ extend-select = [
|
||||||
"E",
|
"E",
|
||||||
"I",
|
"I",
|
||||||
"RSE",
|
"RSE",
|
||||||
|
"SIM",
|
||||||
"TID",
|
"TID",
|
||||||
"UP",
|
"UP",
|
||||||
"W",
|
"W",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import contextlib
|
||||||
import datetime
|
import datetime
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
|
|
@ -30,11 +31,9 @@ class TestCalDAVStorage(DAVStorageTests):
|
||||||
async def test_doesnt_accept_vcard(self, item_type, get_storage_args):
|
async def test_doesnt_accept_vcard(self, item_type, get_storage_args):
|
||||||
s = self.storage_class(item_types=(item_type,), **await get_storage_args())
|
s = self.storage_class(item_types=(item_type,), **await get_storage_args())
|
||||||
|
|
||||||
try:
|
# Most storages hard-fail, but xandikos doesn't.
|
||||||
|
with contextlib.suppress(exceptions.Error, aiohttp.ClientResponseError):
|
||||||
await s.upload(format_item(VCARD_TEMPLATE))
|
await s.upload(format_item(VCARD_TEMPLATE))
|
||||||
except (exceptions.Error, aiohttp.ClientResponseError):
|
|
||||||
# Most storages hard-fail, but xandikos doesn't.
|
|
||||||
pass
|
|
||||||
|
|
||||||
assert not await aiostream.stream.list(s.list())
|
assert not await aiostream.stream.list(s.list())
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,13 @@ import pytest
|
||||||
class ServerMixin:
|
class ServerMixin:
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def get_storage_args(self, slow_create_collection, aio_connector, request):
|
def get_storage_args(self, slow_create_collection, aio_connector, request):
|
||||||
if "item_type" in request.fixturenames:
|
if (
|
||||||
if request.getfixturevalue("item_type") == "VTODO":
|
"item_type" in request.fixturenames
|
||||||
# Fastmail has non-standard support for TODOs
|
and request.getfixturevalue("item_type") == "VTODO"
|
||||||
# See https://github.com/pimutils/vdirsyncer/issues/824
|
):
|
||||||
pytest.skip("Fastmail has non-standard VTODO support.")
|
# Fastmail has non-standard support for TODOs
|
||||||
|
# See https://github.com/pimutils/vdirsyncer/issues/824
|
||||||
|
pytest.skip("Fastmail has non-standard VTODO support.")
|
||||||
|
|
||||||
async def inner(collection="test"):
|
async def inner(collection="test"):
|
||||||
args = {
|
args = {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class CombinedStorage(Storage):
|
||||||
storage_name = "http_and_singlefile"
|
storage_name = "http_and_singlefile"
|
||||||
|
|
||||||
def __init__(self, url, path, *, connector, **kwargs):
|
def __init__(self, url, path, *, connector, **kwargs):
|
||||||
if kwargs.get("collection", None) is not None:
|
if kwargs.get("collection") is not None:
|
||||||
raise ValueError
|
raise ValueError
|
||||||
|
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
|
||||||
|
|
@ -642,10 +642,7 @@ class SyncMachine(RuleBasedStateMachine):
|
||||||
|
|
||||||
errors = []
|
errors = []
|
||||||
|
|
||||||
if with_error_callback:
|
error_callback = errors.append if with_error_callback else None
|
||||||
error_callback = errors.append
|
|
||||||
else:
|
|
||||||
error_callback = None
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# If one storage is read-only, double-sync because changes don't
|
# If one storage is read-only, double-sync because changes don't
|
||||||
|
|
|
||||||
|
|
@ -181,7 +181,7 @@ async def request(
|
||||||
logger.debug("=" * 20)
|
logger.debug("=" * 20)
|
||||||
logger.debug(f"{method} {url}")
|
logger.debug(f"{method} {url}")
|
||||||
logger.debug(kwargs.get("headers", {}))
|
logger.debug(kwargs.get("headers", {}))
|
||||||
logger.debug(kwargs.get("data", None))
|
logger.debug(kwargs.get("data"))
|
||||||
logger.debug("Sending request...")
|
logger.debug("Sending request...")
|
||||||
|
|
||||||
assert isinstance(kwargs.get("data", b""), bytes)
|
assert isinstance(kwargs.get("data", b""), bytes)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import contextlib
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
import urllib.parse as urlparse
|
import urllib.parse as urlparse
|
||||||
|
|
@ -217,10 +218,8 @@ class Discover:
|
||||||
|
|
||||||
async def find_collections(self):
|
async def find_collections(self):
|
||||||
rv = None
|
rv = None
|
||||||
try:
|
with contextlib.suppress(aiohttp.ClientResponseError, exceptions.Error):
|
||||||
rv = await aiostream.stream.list(self._find_collections_impl(""))
|
rv = await aiostream.stream.list(self._find_collections_impl(""))
|
||||||
except (aiohttp.ClientResponseError, exceptions.Error):
|
|
||||||
pass
|
|
||||||
|
|
||||||
if rv:
|
if rv:
|
||||||
return rv
|
return rv
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import contextlib
|
||||||
import errno
|
import errno
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
@ -65,9 +66,7 @@ class FilesystemStorage(Storage):
|
||||||
def _validate_collection(cls, path):
|
def _validate_collection(cls, path):
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
return False
|
return False
|
||||||
if os.path.basename(path).startswith("."):
|
return not os.path.basename(path).startswith(".")
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def create_collection(cls, collection, **kwargs):
|
async def create_collection(cls, collection, **kwargs):
|
||||||
|
|
@ -205,10 +204,8 @@ class FilesystemStorage(Storage):
|
||||||
|
|
||||||
fpath = os.path.join(self.path, key)
|
fpath = os.path.join(self.path, key)
|
||||||
if value is None:
|
if value is None:
|
||||||
try:
|
with contextlib.suppress(OSError):
|
||||||
os.remove(fpath)
|
os.remove(fpath)
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
with atomic_write(fpath, mode="wb", overwrite=True) as f:
|
with atomic_write(fpath, mode="wb", overwrite=True) as f:
|
||||||
f.write(value.encode(self.encoding))
|
f.write(value.encode(self.encoding))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue