mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-25 08:55:50 +00:00
Move 3k compat stuff to own module
This commit is contained in:
parent
4921d25e18
commit
179d9bc393
11 changed files with 47 additions and 33 deletions
|
|
@ -10,7 +10,7 @@
|
|||
'''
|
||||
|
||||
import vdirsyncer.log
|
||||
from vdirsyncer.utils import text_type
|
||||
from vdirsyncer.utils.compat import text_type
|
||||
from vdirsyncer.utils.vobject import normalize_item as _normalize_item
|
||||
vdirsyncer.log.set_level(vdirsyncer.log.logging.DEBUG)
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import pytest
|
|||
from .. import assert_item_equals, SIMPLE_TEMPLATE
|
||||
import vdirsyncer.exceptions as exceptions
|
||||
from vdirsyncer.storage.base import Item
|
||||
from vdirsyncer.utils import text_type, iteritems
|
||||
from vdirsyncer.utils.compat import text_type, iteritems
|
||||
|
||||
|
||||
class StorageTests(object):
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
from .. import exceptions
|
||||
from .. import utils
|
||||
from ..utils.compat import text_type
|
||||
|
||||
|
||||
class Item(object):
|
||||
|
|
@ -33,7 +34,7 @@ class Item(object):
|
|||
This is either the UID or the hash of the item's content.'''
|
||||
|
||||
def __init__(self, raw):
|
||||
assert isinstance(raw, utils.text_type)
|
||||
assert isinstance(raw, text_type)
|
||||
|
||||
for line in raw.splitlines():
|
||||
if line.startswith(u'UID:'):
|
||||
|
|
|
|||
|
|
@ -290,10 +290,10 @@ class DavStorage(Storage):
|
|||
raise ValueError(href)
|
||||
x = utils.urlparse.urljoin(self.session.url, href)
|
||||
assert x.startswith(self.session.url)
|
||||
return utils.urlunquote_plus(utils.urlparse.urlsplit(x).path)
|
||||
return utils.compat.urlunquote_plus(utils.urlparse.urlsplit(x).path)
|
||||
|
||||
def _get_href(self, item):
|
||||
href = utils.urlunquote_plus(item.ident) + self.fileext
|
||||
href = utils.compat.urlunquote_plus(item.ident) + self.fileext
|
||||
return self._normalize_href(href)
|
||||
|
||||
def get(self, href):
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ import os
|
|||
from .base import Item, Storage
|
||||
import vdirsyncer.exceptions as exceptions
|
||||
import vdirsyncer.log as log
|
||||
from vdirsyncer.utils import expand_path, text_type, safe_write, \
|
||||
get_etag_from_file, checkdir
|
||||
from ..utils import expand_path, safe_write, get_etag_from_file, checkdir
|
||||
from ..utils.compat import text_type
|
||||
|
||||
logger = log.get(__name__)
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@
|
|||
'''
|
||||
|
||||
from .base import Item, Storage
|
||||
from ..utils import expand_path, get_password, request, text_type, urlparse
|
||||
from ..utils import expand_path, get_password, request
|
||||
from ..utils.compat import text_type, urlparse
|
||||
from ..utils.vobject import split_collection
|
||||
from ..exceptions import NotFoundError
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,9 @@ import collections
|
|||
from .base import Item, Storage
|
||||
import vdirsyncer.exceptions as exceptions
|
||||
import vdirsyncer.log as log
|
||||
from vdirsyncer.utils import expand_path, safe_write, itervalues, checkfile
|
||||
from vdirsyncer.utils.vobject import split_collection, join_collection
|
||||
from ..utils import expand_path, safe_write, checkfile
|
||||
from ..utils.compat import itervalues
|
||||
from ..utils.vobject import split_collection, join_collection
|
||||
|
||||
logger = log.get(__name__)
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
import itertools
|
||||
|
||||
from . import exceptions, log
|
||||
from .utils import iteritems, text_type
|
||||
from .utils.compat import iteritems, text_type
|
||||
sync_logger = log.get(__name__)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,35 +8,15 @@
|
|||
'''
|
||||
|
||||
import os
|
||||
import sys
|
||||
import requests
|
||||
|
||||
from .. import log, exceptions
|
||||
from .compat import urlparse
|
||||
|
||||
|
||||
logger = log.get(__name__)
|
||||
|
||||
|
||||
PY2 = sys.version_info[0] == 2
|
||||
|
||||
|
||||
if PY2:
|
||||
import urlparse
|
||||
from urllib import \
|
||||
quote_plus as urlquote_plus, \
|
||||
unquote_plus as urlunquote_plus
|
||||
text_type = unicode # flake8: noqa
|
||||
iteritems = lambda x: x.iteritems()
|
||||
itervalues = lambda x: x.itervalues()
|
||||
else:
|
||||
import urllib.parse as urlparse
|
||||
urlquote_plus = urlparse.quote_plus
|
||||
urlunquote_plus = urlparse.unquote_plus
|
||||
text_type = str
|
||||
iteritems = lambda x: x.items()
|
||||
itervalues = lambda x: x.values()
|
||||
|
||||
|
||||
try:
|
||||
import keyring
|
||||
except ImportError:
|
||||
|
|
@ -284,6 +264,7 @@ def get_class_init_args(cls):
|
|||
|
||||
return all | s_all, required | s_required
|
||||
|
||||
|
||||
def checkdir(path, create=False):
|
||||
if not os.path.isdir(path):
|
||||
if os.path.exists(path):
|
||||
|
|
@ -296,6 +277,7 @@ def checkdir(path, create=False):
|
|||
'create it, or create it '
|
||||
'yourself.'.format(path))
|
||||
|
||||
|
||||
def checkfile(path, create=False):
|
||||
checkdir(os.path.dirname(path), create=create)
|
||||
if not os.path.isfile(path):
|
||||
|
|
|
|||
29
vdirsyncer/utils/compat.py
Normal file
29
vdirsyncer/utils/compat.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
vdirsyncer.utils.compat
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
:copyright: (c) 2014 Markus Unterwaditzer & contributors
|
||||
:license: MIT, see LICENSE for more details.
|
||||
'''
|
||||
|
||||
import sys
|
||||
|
||||
PY2 = sys.version_info[0] == 2
|
||||
|
||||
|
||||
if PY2:
|
||||
import urlparse
|
||||
from urllib import \
|
||||
quote_plus as urlquote_plus, \
|
||||
unquote_plus as urlunquote_plus
|
||||
text_type = unicode # flake8: noqa
|
||||
iteritems = lambda x: x.iteritems()
|
||||
itervalues = lambda x: x.itervalues()
|
||||
else:
|
||||
import urllib.parse as urlparse
|
||||
urlquote_plus = urlparse.quote_plus
|
||||
urlunquote_plus = urlparse.unquote_plus
|
||||
text_type = str
|
||||
iteritems = lambda x: x.items()
|
||||
itervalues = lambda x: x.values()
|
||||
|
|
@ -12,7 +12,7 @@ import icalendar.cal
|
|||
import icalendar.parser
|
||||
import icalendar.caselessdict
|
||||
|
||||
from . import text_type, itervalues
|
||||
from .compat import text_type, itervalues
|
||||
|
||||
|
||||
def _process_properties(*s):
|
||||
|
|
|
|||
Loading…
Reference in a new issue