From 76f794eef3a0445650cb7b58e8618beb5cecf0e7 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Mon, 27 Feb 2017 21:19:27 +0100 Subject: [PATCH] Module restructuring --- tests/__init__.py | 2 +- tests/storage/__init__.py | 5 +++-- tests/storage/dav/__init__.py | 4 ++-- tests/storage/test_filesystem.py | 2 +- tests/system/utils/test_main.py | 22 +++++++++------------- tests/unit/cli/test_config.py | 2 +- tests/unit/test_repair.py | 2 +- tests/unit/test_sync.py | 2 +- tests/unit/utils/test_vobject.py | 2 +- vdirsyncer/cli/config.py | 2 +- vdirsyncer/{utils => }/http.py | 4 ++-- vdirsyncer/storage/base.py | 1 - vdirsyncer/storage/dav.py | 9 +++++---- vdirsyncer/storage/filesystem.py | 3 ++- vdirsyncer/storage/http.py | 6 +++--- vdirsyncer/storage/remotestorage.py | 10 +++++----- vdirsyncer/storage/singlefile.py | 4 ++-- vdirsyncer/{utils => }/vobject.py | 2 +- 18 files changed, 41 insertions(+), 43 deletions(-) rename vdirsyncer/{utils => }/http.py (98%) rename vdirsyncer/{utils => }/vobject.py (99%) diff --git a/tests/__init__.py b/tests/__init__.py index e051c66..53b5cdb 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -5,7 +5,7 @@ Test suite for vdirsyncer. import hypothesis.strategies as st -from vdirsyncer.utils.vobject import normalize_item +from vdirsyncer.vobject import normalize_item def blow_up(*a, **kw): diff --git a/tests/storage/__init__.py b/tests/storage/__init__.py index 8cd00f8..c584e9f 100644 --- a/tests/storage/__init__.py +++ b/tests/storage/__init__.py @@ -11,8 +11,9 @@ from hypothesis import given import pytest -import vdirsyncer.exceptions as exceptions -from vdirsyncer.storage.base import Item, normalize_meta_value +from vdirsyncer import exceptions +from vdirsyncer.storage.base import normalize_meta_value +from vdirsyncer.vobject import Item from .. import EVENT_TEMPLATE, TASK_TEMPLATE, VCARD_TEMPLATE, \ assert_item_equals, normalize_item, printable_characters_strategy diff --git a/tests/storage/dav/__init__.py b/tests/storage/dav/__init__.py index ae0b812..5567973 100644 --- a/tests/storage/dav/__init__.py +++ b/tests/storage/dav/__init__.py @@ -9,8 +9,8 @@ import requests.exceptions from tests import assert_item_equals -import vdirsyncer.exceptions as exceptions -from vdirsyncer.storage.base import Item +from vdirsyncer import exceptions +from vdirsyncer.vobject import Item from .. import StorageTests, get_server_mixin diff --git a/tests/storage/test_filesystem.py b/tests/storage/test_filesystem.py index 11b5cc2..ddaa567 100644 --- a/tests/storage/test_filesystem.py +++ b/tests/storage/test_filesystem.py @@ -5,7 +5,7 @@ import subprocess import pytest from vdirsyncer.storage.filesystem import FilesystemStorage -from vdirsyncer.utils.vobject import Item +from vdirsyncer.vobject import Item from . import StorageTests diff --git a/tests/system/utils/test_main.py b/tests/system/utils/test_main.py index 6e84846..315b15f 100644 --- a/tests/system/utils/test_main.py +++ b/tests/system/utils/test_main.py @@ -8,11 +8,7 @@ import pytest import requests -from vdirsyncer import utils - -# These modules might be uninitialized and unavailable if not explicitly -# imported -import vdirsyncer.utils.http # noqa +from vdirsyncer import http, utils @pytest.fixture(autouse=True) @@ -33,10 +29,10 @@ def test_request_ssl(httpsserver): httpsserver.serve_content('') # we need to serve something with pytest.raises(requests.exceptions.SSLError) as excinfo: - utils.http.request('GET', httpsserver.url) + http.request('GET', httpsserver.url) assert 'certificate verify failed' in str(excinfo.value) - utils.http.request('GET', httpsserver.url, verify=False) + http.request('GET', httpsserver.url, verify=False) def _fingerprints_broken(): @@ -54,15 +50,15 @@ def _fingerprints_broken(): def test_request_ssl_fingerprints(httpsserver, fingerprint): httpsserver.serve_content('') # we need to serve something - utils.http.request('GET', httpsserver.url, verify=False, - verify_fingerprint=fingerprint) + http.request('GET', httpsserver.url, verify=False, + verify_fingerprint=fingerprint) with pytest.raises(requests.exceptions.SSLError) as excinfo: - utils.http.request('GET', httpsserver.url, - verify_fingerprint=fingerprint) + http.request('GET', httpsserver.url, + verify_fingerprint=fingerprint) with pytest.raises(requests.exceptions.SSLError) as excinfo: - utils.http.request('GET', httpsserver.url, verify=False, - verify_fingerprint=''.join(reversed(fingerprint))) + http.request('GET', httpsserver.url, verify=False, + verify_fingerprint=''.join(reversed(fingerprint))) assert 'Fingerprints did not match' in str(excinfo.value) diff --git a/tests/unit/cli/test_config.py b/tests/unit/cli/test_config.py index e391011..30e2ede 100644 --- a/tests/unit/cli/test_config.py +++ b/tests/unit/cli/test_config.py @@ -1,7 +1,7 @@ import os from vdirsyncer.cli.config import _resolve_conflict_via_command -from vdirsyncer.utils.vobject import Item +from vdirsyncer.vobject import Item def test_conflict_resolution_command(): diff --git a/tests/unit/test_repair.py b/tests/unit/test_repair.py index ad81e4b..0ba726e 100644 --- a/tests/unit/test_repair.py +++ b/tests/unit/test_repair.py @@ -7,7 +7,7 @@ from tests import uid_strategy from vdirsyncer.repair import IrreparableItem, repair_item, repair_storage from vdirsyncer.storage.memory import MemoryStorage from vdirsyncer.utils import href_safe -from vdirsyncer.utils.vobject import Item +from vdirsyncer.vobject import Item @given(uid=uid_strategy) diff --git a/tests/unit/test_sync.py b/tests/unit/test_sync.py index d1b5a34..4949003 100644 --- a/tests/unit/test_sync.py +++ b/tests/unit/test_sync.py @@ -10,10 +10,10 @@ import pytest from tests import blow_up, uid_strategy -from vdirsyncer.storage.base import Item from vdirsyncer.storage.memory import MemoryStorage, _random_string from vdirsyncer.sync import BothReadOnly, IdentConflict, PartialSync, \ StorageEmpty, SyncConflict, sync +from vdirsyncer.vobject import Item def empty_storage(x): diff --git a/tests/unit/utils/test_vobject.py b/tests/unit/utils/test_vobject.py index 587bb3d..b3984c0 100644 --- a/tests/unit/utils/test_vobject.py +++ b/tests/unit/utils/test_vobject.py @@ -12,7 +12,7 @@ from tests import BARE_EVENT_TEMPLATE, EVENT_TEMPLATE, \ EVENT_WITH_TIMEZONE_TEMPLATE, VCARD_TEMPLATE, normalize_item, \ uid_strategy -import vdirsyncer.utils.vobject as vobject +import vdirsyncer.vobject as vobject _simple_split = [ diff --git a/vdirsyncer/cli/config.py b/vdirsyncer/cli/config.py index b5ba920..0d68baf 100644 --- a/vdirsyncer/cli/config.py +++ b/vdirsyncer/cli/config.py @@ -314,7 +314,7 @@ def _resolve_conflict_via_command(a, b, command, a_name, b_name, if _check_call is None: from subprocess import check_call as _check_call - from ..utils.vobject import Item + from ..vobject import Item dir = tempfile.mkdtemp(prefix='vdirsyncer-conflict.') try: diff --git a/vdirsyncer/utils/http.py b/vdirsyncer/http.py similarity index 98% rename from vdirsyncer/utils/http.py rename to vdirsyncer/http.py index 81cbe61..f59d837 100644 --- a/vdirsyncer/utils/http.py +++ b/vdirsyncer/http.py @@ -3,8 +3,8 @@ import logging import requests -from . import expand_path -from .. import DOCS_HOME, exceptions +from .utils import expand_path +from . import DOCS_HOME, exceptions logger = logging.getLogger(__name__) diff --git a/vdirsyncer/storage/base.py b/vdirsyncer/storage/base.py index 09eeb9d..7b54de5 100644 --- a/vdirsyncer/storage/base.py +++ b/vdirsyncer/storage/base.py @@ -5,7 +5,6 @@ import functools from .. import exceptions from ..utils import uniq -from ..utils.vobject import Item # noqa def mutating_storage_method(f): diff --git a/vdirsyncer/storage/dav.py b/vdirsyncer/storage/dav.py index 15fbb7f..0d17ded 100644 --- a/vdirsyncer/storage/dav.py +++ b/vdirsyncer/storage/dav.py @@ -10,10 +10,11 @@ from inspect import getfullargspec import requests from requests.exceptions import HTTPError -from .base import Item, Storage, normalize_meta_value -from .. import exceptions, utils -from ..utils.http import HTTP_STORAGE_PARAMETERS, USERAGENT, prepare_auth, \ +from .base import Storage, normalize_meta_value +from .. import exceptions, http, utils +from ..http import HTTP_STORAGE_PARAMETERS, USERAGENT, prepare_auth, \ prepare_client_cert, prepare_verify +from ..vobject import Item dav_logger = logging.getLogger(__name__) @@ -362,7 +363,7 @@ class DAVSession(object): more = dict(self._settings) more.update(kwargs) - return utils.http.request(method, url, session=self._session, **more) + return http.request(method, url, session=self._session, **more) def get_default_headers(self): return { diff --git a/vdirsyncer/storage/filesystem.py b/vdirsyncer/storage/filesystem.py index f65306f..df0072a 100644 --- a/vdirsyncer/storage/filesystem.py +++ b/vdirsyncer/storage/filesystem.py @@ -7,9 +7,10 @@ import subprocess from atomicwrites import atomic_write -from .base import Item, Storage, normalize_meta_value +from .base import Storage, normalize_meta_value from .. import exceptions from ..utils import checkdir, expand_path, generate_href, get_etag_from_file +from ..vobject import Item logger = logging.getLogger(__name__) diff --git a/vdirsyncer/storage/http.py b/vdirsyncer/storage/http.py index 310dec7..c71c48c 100644 --- a/vdirsyncer/storage/http.py +++ b/vdirsyncer/storage/http.py @@ -2,11 +2,11 @@ import urllib.parse as urlparse -from .base import Item, Storage +from .base import Storage from .. import exceptions -from ..utils.http import HTTP_STORAGE_PARAMETERS, USERAGENT, prepare_auth, \ +from ..http import HTTP_STORAGE_PARAMETERS, USERAGENT, prepare_auth, \ prepare_client_cert, prepare_verify, request -from ..utils.vobject import split_collection +from ..vobject import Item, split_collection class HttpStorage(Storage): diff --git a/vdirsyncer/storage/remotestorage.py b/vdirsyncer/storage/remotestorage.py index e454188..2cd5e77 100644 --- a/vdirsyncer/storage/remotestorage.py +++ b/vdirsyncer/storage/remotestorage.py @@ -11,10 +11,11 @@ from urllib.parse import quote as urlquote, urljoin import click -from .base import Item, Storage, normalize_meta_value +from .base import Storage, normalize_meta_value from .http import HTTP_STORAGE_PARAMETERS, prepare_client_cert, \ prepare_verify -from .. import exceptions, utils +from .. import exceptions, utils, http +from ..vobject import Item REDIRECT_URI = 'https://vdirsyncer.5apps.com/' CLIENT_ID = 'https://vdirsyncer.5apps.com' @@ -77,8 +78,7 @@ class Session(object): settings = dict(self._settings) settings.update(kwargs) - return utils.http.request(method, url, - session=self._session, **settings) + return http.request(method, url, session=self._session, **settings) def _get_access_token(self): authorization_url, state = \ @@ -94,7 +94,7 @@ class Session(object): raise exceptions.UserError('Aborted!') def _discover_endpoints(self, subpath): - r = utils.http.request( + r = http.request( 'GET', 'https://{host}/.well-known/webfinger?resource=acct:{user}' .format(host=self.host, user=self.user), **self._settings diff --git a/vdirsyncer/storage/singlefile.py b/vdirsyncer/storage/singlefile.py index 689b37a..3aa9d25 100644 --- a/vdirsyncer/storage/singlefile.py +++ b/vdirsyncer/storage/singlefile.py @@ -9,10 +9,10 @@ import os from atomicwrites import atomic_write -from .base import Item, Storage +from .base import Storage from .. import exceptions from ..utils import checkfile, expand_path -from ..utils.vobject import join_collection, split_collection +from ..vobject import Item, join_collection, split_collection logger = logging.getLogger(__name__) diff --git a/vdirsyncer/utils/vobject.py b/vdirsyncer/vobject.py similarity index 99% rename from vdirsyncer/utils/vobject.py rename to vdirsyncer/vobject.py index 3dab219..573ffec 100644 --- a/vdirsyncer/utils/vobject.py +++ b/vdirsyncer/vobject.py @@ -3,7 +3,7 @@ import hashlib from itertools import chain, tee -from . import cached_property, uniq +from .utils import cached_property, uniq IGNORE_PROPS = (