diff --git a/tests/storage/__init__.py b/tests/storage/__init__.py index 52c6fa2..a629a32 100644 --- a/tests/storage/__init__.py +++ b/tests/storage/__init__.py @@ -6,14 +6,15 @@ :copyright: (c) 2014 Markus Unterwaditzer :license: MIT, see LICENSE for more details. ''' - -from vdirsyncer.storage.base import Item -import vdirsyncer.exceptions as exceptions -from vdirsyncer.utils import text_type -from .. import assert_item_equals import random + import pytest +from .. import assert_item_equals +import vdirsyncer.exceptions as exceptions +from vdirsyncer.storage.base import Item +from vdirsyncer.utils import text_type + class StorageTests(object): item_template = u'UID:{uid}\nX-SOMETHING:{r}' diff --git a/tests/storage/dav/servers/radicale/__init__.py b/tests/storage/dav/servers/radicale/__init__.py index 3b1c33f..8131c0d 100644 --- a/tests/storage/dav/servers/radicale/__init__.py +++ b/tests/storage/dav/servers/radicale/__init__.py @@ -1,13 +1,15 @@ # -*- coding: utf-8 -*- -import sys import os +import sys + import pytest -from vdirsyncer.utils import urlparse from werkzeug.test import Client from werkzeug.wrappers import BaseResponse as WerkzeugResponse +from vdirsyncer.utils import urlparse + RADICALE_SCHEMA = ''' create table collection ( diff --git a/tests/storage/dav/test_main.py b/tests/storage/dav/test_main.py index 1d7a721..7a57f7d 100644 --- a/tests/storage/dav/test_main.py +++ b/tests/storage/dav/test_main.py @@ -7,18 +7,19 @@ :license: MIT, see LICENSE for more details. ''' -import os -import pytest import datetime +import os from textwrap import dedent +import pytest + +import requests +import requests.exceptions + from .. import StorageTests import vdirsyncer.exceptions as exceptions from vdirsyncer.storage.base import Item from vdirsyncer.storage.dav import CaldavStorage, CarddavStorage -import vdirsyncer.exceptions -import requests -import requests.exceptions dav_server = os.environ.get('DAV_SERVER', '').strip() or 'radicale' @@ -239,7 +240,7 @@ class TestCaldavStorage(DavStorageTests): monkeypatch.setattr('requests.sessions.Session.request', request) - with pytest.raises(vdirsyncer.exceptions.StorageError): + with pytest.raises(exceptions.StorageError): self.storage_class(**args) assert len(calls) == 1 diff --git a/tests/storage/test_filesystem.py b/tests/storage/test_filesystem.py index 401d391..6415bc4 100644 --- a/tests/storage/test_filesystem.py +++ b/tests/storage/test_filesystem.py @@ -8,10 +8,12 @@ :license: MIT, see LICENSE for more details. ''' -import pytest import os -from vdirsyncer.storage.filesystem import FilesystemStorage + +import pytest + from . import StorageTests +from vdirsyncer.storage.filesystem import FilesystemStorage class TestFilesystemStorage(StorageTests): diff --git a/tests/storage/test_http.py b/tests/storage/test_http.py index 85c5f4d..b560957 100644 --- a/tests/storage/test_http.py +++ b/tests/storage/test_http.py @@ -7,9 +7,10 @@ :license: MIT, see LICENSE for more details. ''' -from vdirsyncer.storage.http import HttpStorage, split_collection from requests import Response +from vdirsyncer.storage.http import HttpStorage, split_collection + def test_split_collection_timezones(): items = [ diff --git a/tests/storage/test_memory.py b/tests/storage/test_memory.py index 3847b0c..bca4bb6 100644 --- a/tests/storage/test_memory.py +++ b/tests/storage/test_memory.py @@ -8,8 +8,8 @@ :license: MIT, see LICENSE for more details. ''' -from vdirsyncer.storage.memory import MemoryStorage from . import StorageTests +from vdirsyncer.storage.memory import MemoryStorage class TestMemoryStorage(StorageTests): diff --git a/tests/test_sync.py b/tests/test_sync.py index 25579f8..7a0dac3 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -8,11 +8,12 @@ ''' import pytest + +from . import assert_item_equals, normalize_item +import vdirsyncer.exceptions as exceptions from vdirsyncer.storage.base import Item from vdirsyncer.storage.memory import MemoryStorage from vdirsyncer.sync import sync -from . import assert_item_equals, normalize_item -import vdirsyncer.exceptions as exceptions def empty_storage(x): diff --git a/vdirsyncer/cli.py b/vdirsyncer/cli.py index d97620e..2b00441 100644 --- a/vdirsyncer/cli.py +++ b/vdirsyncer/cli.py @@ -7,16 +7,19 @@ :license: MIT, see LICENSE for more details. ''' +import json import os import sys -import json -from vdirsyncer.sync import sync -from vdirsyncer.utils import expand_path, split_dict, parse_options -from vdirsyncer.storage import storage_names -import vdirsyncer.log as log -import vdirsyncer.exceptions as exceptions + import argvard +from .storage import storage_names +from .sync import sync +from .utils import expand_path, parse_options, split_dict + +import vdirsyncer.exceptions as exceptions +import vdirsyncer.log as log + try: from ConfigParser import RawConfigParser diff --git a/vdirsyncer/storage/__init__.py b/vdirsyncer/storage/__init__.py index e915f5b..613f33b 100644 --- a/vdirsyncer/storage/__init__.py +++ b/vdirsyncer/storage/__init__.py @@ -12,8 +12,7 @@ :license: MIT, see LICENSE for more details. ''' -from .dav import CaldavStorage -from .dav import CarddavStorage +from .dav import CarddavStorage, CaldavStorage from .filesystem import FilesystemStorage from .http import HttpStorage diff --git a/vdirsyncer/storage/dav.py b/vdirsyncer/storage/dav.py index c0c7922..21f1f7d 100644 --- a/vdirsyncer/storage/dav.py +++ b/vdirsyncer/storage/dav.py @@ -6,16 +6,17 @@ :copyright: (c) 2014 Markus Unterwaditzer, Christian Geier and contributors :license: MIT, see LICENSE for more details. ''' - -from .base import Storage, Item -from .http import prepare_auth, prepare_verify, USERAGENT -from .. import exceptions -from .. import log -from ..utils import request, get_password, urlparse -import requests import datetime + from lxml import etree +import requests + +from .base import Item, Storage +from .http import prepare_auth, prepare_verify, USERAGENT + +from .. import exceptions, log, utils + dav_logger = log.get(__name__) @@ -58,7 +59,7 @@ class DavStorage(Storage): super(DavStorage, self).__init__(**kwargs) if username and not password: - password = get_password(username, url) + password = utils.get_password(username, url) self._settings = { 'verify': prepare_verify(verify), @@ -69,9 +70,9 @@ class DavStorage(Storage): url = url.rstrip('/') + '/' if collection is not None: - url = urlparse.urljoin(url, collection) + url = utils.urlparse.urljoin(url, collection) self.url = url.rstrip('/') + '/' - self.parsed_url = urlparse.urlparse(self.url) + self.parsed_url = utils.urlparse.urlparse(self.url) self.collection = collection headers = self._default_headers() @@ -103,7 +104,7 @@ class DavStorage(Storage): ssl_verify=kwargs.get('verify', True) ) for c in d.discover(): - collection = urlparse.urljoin(url, c['href']) + collection = utils.urlparse.urljoin(url, c['href']) if collection.startswith(url): collection = collection[len(url):] collection = collection.rstrip('/') @@ -114,9 +115,9 @@ class DavStorage(Storage): def _normalize_href(self, href): '''Normalize the href to be a path only relative to hostname and schema.''' - x = urlparse.urljoin(self.url, href) + x = utils.urlparse.urljoin(self.url, href) assert x.startswith(self.url) - return urlparse.urlsplit(x).path + return utils.urlparse.urlsplit(x).path def _get_href(self, uid): return self._normalize_href(super(DavStorage, self)._get_href(uid)) @@ -127,8 +128,8 @@ class DavStorage(Storage): if self._session is None: self._session = requests.session() url = self.parsed_url.scheme + '://' + self.parsed_url.netloc + path - return request(method, url, data=data, headers=headers, - session=self._session, **self._settings) + return utils.request(method, url, data=data, headers=headers, + session=self._session, **self._settings) @staticmethod def _check_response(response): diff --git a/vdirsyncer/storage/filesystem.py b/vdirsyncer/storage/filesystem.py index 0071364..7f24736 100644 --- a/vdirsyncer/storage/filesystem.py +++ b/vdirsyncer/storage/filesystem.py @@ -8,10 +8,12 @@ ''' import os -from vdirsyncer.storage.base import Storage, Item + +from .base import Item, Storage import vdirsyncer.exceptions as exceptions -from vdirsyncer.utils import expand_path, text_type import vdirsyncer.log as log +from vdirsyncer.utils import expand_path, text_type + logger = log.get(__name__) diff --git a/vdirsyncer/storage/http.py b/vdirsyncer/storage/http.py index ccc7517..c8e65b2 100644 --- a/vdirsyncer/storage/http.py +++ b/vdirsyncer/storage/http.py @@ -8,9 +8,9 @@ ''' import hashlib -from .base import Storage, Item -from vdirsyncer.utils import expand_path, get_password, request, urlparse, \ - text_type + +from .base import Item, Storage +from ..utils import expand_path, get_password, request, text_type, urlparse USERAGENT = 'vdirsyncer' diff --git a/vdirsyncer/storage/memory.py b/vdirsyncer/storage/memory.py index 5748823..eb53398 100644 --- a/vdirsyncer/storage/memory.py +++ b/vdirsyncer/storage/memory.py @@ -8,8 +8,9 @@ ''' import random -from vdirsyncer.storage.base import Storage + import vdirsyncer.exceptions as exceptions +from vdirsyncer.storage.base import Storage def _get_etag(): diff --git a/vdirsyncer/sync.py b/vdirsyncer/sync.py index 744ff62..07b0839 100644 --- a/vdirsyncer/sync.py +++ b/vdirsyncer/sync.py @@ -17,10 +17,9 @@ ''' import itertools -import vdirsyncer.exceptions as exceptions -import vdirsyncer.log +from . import exceptions, log from .utils import iteritems, itervalues -sync_logger = vdirsyncer.log.get(__name__) +sync_logger = log.get(__name__) def prepare_list(storage, href_to_status):