# Path: saunter/exceptions.py
# class ProviderException(SaunterExceptions):
#     def _get_message(self):
#         return self._message
# 
#     def _set_message(self, message):
#         self._message = message
#     message = property(_get_message, _set_message)


import ConfigParser
import couchdb.client
import random
import socket
import saunter.ConfigWrapper
from saunter.exceptions import ProviderException


# as will this
class CouchProvider(object):
    def __init__(self, database):
        cf = saunter.ConfigWrapper.ConfigWrapper()

        # read url from the config
        if "couchdb" in cf and "url" in cf["couch"]:
            url = cf["saunter"]["couchdb"]["url"]
        else:
            url = None

        # make sure we can connect to the server
        server = couchdb.client.Server(url=url)
        try:
            server.version()
        except socket.error:
            raise ProviderException('couch server not found at %s' % url)

        # check that the database is in the server
        if database not in server:

# Path: saunter/exceptions.py
# class ProviderException(SaunterExceptions):
#     def _get_message(self):
#         return self._message
# 
#     def _set_message(self, message):
#         self._message = message
#     message = property(_get_message, _set_message)


# Path: saunter/providers/couch_provider.py
import ConfigParser
import couchdb.client
import random
import socket
import saunter.ConfigWrapper
from saunter.exceptions import ProviderException



# as will this
class CouchProvider(object):
    def __init__(self, database):
        cf = saunter.ConfigWrapper.ConfigWrapper()

        # read url from the config
        if "couchdb" in cf and "url" in cf["couch"]:
            url = cf["saunter"]["couchdb"]["url"]
        else:
            url = None

        # make sure we can connect to the server
        server = couchdb.client.Server(url=url)
        try:
            server.version()
        except socket.error:
            raise ProviderException('couch server not found at %s' % url)

        # check that the database is in the server
        if database not in server:

            raise ProviderException('database "%s" does not exist' % database)