本文整理汇总了Python中couchdb.client.Server类的典型用法代码示例。如果您正苦于以下问题:Python Server类的具体用法?Python Server怎么用?Python Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Server类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _open_couch_db
def _open_couch_db(dbname):
server = Server(url=self._couch_url)
try:
server[dbname]
except ResourceNotFound:
server.create(dbname)
return server[dbname]
示例2: couch_connect
def couch_connect():
server = Server()
try:
db = server.create('feedme')
except:
db = server['feedme']
return db
示例3: CouchDBBackend
class CouchDBBackend(object):
@property
def db(self):
return self.server[self.db_name]
def __init__(self, config):
settings = config.registry.settings
self.config = config
self.server = Server(settings['backend.db_host'])
self.db_name = os.environ.get('DB_NAME', settings['backend.db_name'])
self.create_db_if_not_exist()
self.sync_views()
self.config.add_subscriber(self.add_db_to_request, NewRequest)
def delete_db(self):
del self.server[self.db_name]
def create_db_if_not_exist(self):
try:
self.server.create(self.db_name)
logger.debug('Creating and using db "%s"' % self.db_name)
except PreconditionFailed:
logger.debug('Using db "%s".' % self.db_name)
def sync_views(self):
ViewDefinition.sync_many(self.db, docs)
def add_db_to_request(self, event):
event.request.db = Database(self.db)
示例4: connector
def connector(collection):
# Make a server connection
svr = Server()
if collection not in svr:
return svr.create(collection)
else:
return svr[collection]
示例5: get_db
def get_db(self, db_uri, db_name):
server = Server(db_uri)
try:
db = server[db_name]
except ResourceNotFound:
db = server.create(db_name)
return db
示例6: initDatabase
def initDatabase():
server = Server('http://localhost:5984')
del server['lazycrawler']
try:
db = server.create('lazycrawler')
except Exception:
db = server['lazycrawler']
return db
示例7: Create_Couchdb_Instance
def Create_Couchdb_Instance(dtbs_name):
server = Server("http://127.0.0.1:5984")
try:
db = server.create(dtbs_name)
except Exception:
db = server[dtbs_name]
return db
示例8: saveDocument
def saveDocument(self):
server = Server()
server.resource.credentials = ('secret', 'aedca29aed23e103f27f8e29dd6ec473')
# create database
db = server.create("new.job")
# associate NewJob to the db
NewJob.set_db(db)
self.save()
示例9: CouchDBBackend
class CouchDBBackend(object):
@classmethod
def load_from_config(cls, config):
settings = config.registry.settings
return CouchDBBackend(
host=settings['backend.db_host'],
db_name=os.environ.get('DB_NAME', settings['backend.db_name']),
)
def __init__(self, host, db_name, id_generator):
self.server = Server(host)
self.db_name = db_name
try:
self.create_db_if_not_exist()
except socket.error as e:
raise CouchDBBackendConnectionError(
"Unable to connect to the CouchDB server: %s - %s" % (host, e))
self._db = self.server[self.db_name]
self.sync_views()
def delete_db(self):
del self.server[self.db_name]
def create_db_if_not_exist(self):
try:
self.server.create(self.db_name)
logger.info('Creating and using db "%s"' % self.db_name)
except PreconditionFailed:
logger.info('Using db "%s".' % self.db_name)
def sync_views(self):
ViewDefinition.sync_many(self.server[self.db_name], docs)
def __get_raw_user_token(self, user_id):
try:
return views.usertokens(self._db, key=user_id).rows[0].value
except IndexError:
raise UserIdNotFound(user_id)
def get_user_token(self, user_id):
"""Returns the information associated with a user token"""
usertoken = dict(**self.__get_raw_user_token(user_id))
return usertoken['token']
def add_token(self, user_id, token):
# Check that the token doesn't already exist.
try:
self.__get_raw_user_token(user_id)
raise UserIdAlreadyExist(user_id)
except UserIdNotFound:
pass
doc = dict(token=token, user_id=user_id, type='usertoken')
self._db.save(doc)
示例10: __init__
def __init__(self, db_uri):
local.application = self
server = Server(db_uri)
try:
db = server.create("urls")
except Exception:
db = server["urls"]
self.dispatch = SharedDataMiddleware(self.dispatch, {"/static": STATIC_PATH})
URL.db = db
示例11: init_boards
def init_boards():
"""
:rtype : object
"""
server = Server()
try:
db = server.create("boards")
except Exception:
db = server["boards"]
return db
示例12: __init__
def __init__(self, db_uri):
local.application = self
server = Server(db_uri)
try:
db = server.create('urls')
except:
db = server['urls']
self.dispatch = SharedDataMiddleware(self.dispatch, {
'/static': STATIC_PATH
})
URL.db = db
示例13: __init__
def __init__(self):
"""Initialises a new connection to couch and
creates a new mis databse if nonexistent"""
LOG.info('initialising database')
database_name = CONFIG.get('couchdb', 'database')
host = CONFIG.get('couchdb', 'hostname')
port = CONFIG.get('couchdb', 'port')
database_uri = 'http://' + host + ':' + port + '/'
self.server = Server(database_uri)
try:
# This statement appears to do nothing, but is used to
# make sure the database is reachable.
self.server.version
except AttributeError as error:
if not test_tcp_connection(host, int(port)):
LOG.critical("couchdb cannot be reached at " + database_uri)
exit(1)
else:
LOG.error('unknown AttributeError thrown')
raise error
try:
LOG.debug('opening database')
self.database = self.server[database_name]
except(ResourceNotFound):
LOG.info('creating database')
# The database didn't exist. Lets create it.
self.database = self.server.create(database_name)
self.create_views()
示例14: __init__
def __init__(self, url, dbname, replica_uid=None, full_commit=True,
session=None):
"""
Create a new Couch data container.
@param url: the url of the couch database
@type url: str
@param dbname: the database name
@type dbname: str
@param replica_uid: an optional unique replica identifier
@type replica_uid: str
@param full_commit: turn on the X-Couch-Full-Commit header
@type full_commit: bool
@param session: an http.Session instance or None for a default session
@type session: http.Session
"""
# save params
self._url = url
self._full_commit = full_commit
self._session = session
# configure couch
self._server = Server(url=self._url,
full_commit=self._full_commit,
session=self._session)
self._dbname = dbname
# this will ensure that transaction and sync logs exist and are
# up-to-date.
try:
self._database = self._server[self._dbname]
except ResourceNotFound:
self._server.create(self._dbname)
self._database = self._server[self._dbname]
ObjectStoreDatabase.__init__(self, replica_uid=replica_uid)
示例15: __init__
def __init__(self, server, name):
self.server = Server(server)
if name in self.server:
self.db = self.server[name]
else:
self.db = self.server.create(name)
self._load_views()
self.view = self.db.view('_view/update/mtime')