couchdb can now be imported without couchdb dependency

This commit is contained in:
Ask Solem 2014-06-02 17:18:07 +01:00
parent b0ce0a4524
commit 3624a37170
1 changed files with 20 additions and 9 deletions

View File

@ -11,7 +11,6 @@ CouchDB transport.
from __future__ import absolute_import
import socket
import couchdb
from anyjson import loads, dumps
@ -21,6 +20,11 @@ from kombu.utils.encoding import bytes_to_str
from . import virtual
try:
import couchdb
except ImportError: # pragma: no cover
couchdb = None # noqa
DEFAULT_PORT = 5984
DEFAULT_DATABASE = 'kombu_default'
@ -112,20 +116,27 @@ class Transport(virtual.Transport):
connection_errors = (
virtual.Transport.connection_errors + (
socket.error,
couchdb.HTTPError,
couchdb.ServerError,
couchdb.Unauthorized)
getattr(couchdb, 'HTTPError', None),
getattr(couchdb, 'ServerError', None),
getattr(couchdb, 'Unauthorized', None),
)
)
channel_errors = (
virtual.Transport.channel_errors + (
couchdb.HTTPError,
couchdb.ServerError,
couchdb.PreconditionFailed,
couchdb.ResourceConflict,
couchdb.ResourceNotFound)
getattr(couchdb, 'HTTPError', None),
getattr(couchdb, 'ServerError', None),
getattr(couchdb, 'PreconditionFailed', None),
getattr(couchdb, 'ResourceConflict', None),
getattr(couchdb, 'ResourceNotFound', None),
)
)
driver_type = 'couchdb'
driver_name = 'couchdb'
def __init__(self, *args, **kwargs):
if couchdb is None:
raise ImportError('Missing couchdb library (pip install couchdb)')
super(Transport, self).__init__(*args, **kwargs)
def driver_version(self):
return couchdb.__version__