当前位置: 首页>>代码示例>>Python>>正文


Python Server.create方法代码示例

本文整理汇总了Python中couchdb.client.Server.create方法的典型用法代码示例。如果您正苦于以下问题:Python Server.create方法的具体用法?Python Server.create怎么用?Python Server.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在couchdb.client.Server的用法示例。


在下文中一共展示了Server.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CouchDBBackend

# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import create [as 别名]
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)
开发者ID:numahell,项目名称:daybed,代码行数:33,代码来源:backend.py

示例2: _open_couch_db

# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import create [as 别名]
 def _open_couch_db(dbname):
     server = Server(url=self._couch_url)
     try:
         server[dbname]
     except ResourceNotFound:
         server.create(dbname)
     return server[dbname]
开发者ID:MeanderingCode,项目名称:soledad,代码行数:9,代码来源:couch.py

示例3: CouchDBBackend

# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import create [as 别名]
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)
开发者ID:spiral-project,项目名称:daybed-browserid,代码行数:59,代码来源:__init__.py

示例4: get_db

# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import create [as 别名]
 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
开发者ID:jinks,项目名称:redditron,代码行数:9,代码来源:backends.py

示例5: couch_connect

# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import create [as 别名]
def couch_connect():
    server = Server()
    try:
        db = server.create('feedme')
    except:
        db = server['feedme']
    return db
开发者ID:bdunnette,项目名称:feedme,代码行数:9,代码来源:wikibooks-cookbook.py

示例6: connector

# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import create [as 别名]
def connector(collection):
  # Make a server connection
  svr = Server()
  if collection not in svr:
    return svr.create(collection)
  else:
    return svr[collection]
开发者ID:starcolon,项目名称:pantip-libr,代码行数:9,代码来源:couch.py

示例7: saveDocument

# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import create [as 别名]
 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()
开发者ID:megajandro,项目名称:py-blw,代码行数:10,代码来源:couchdbClie.py

示例8: Create_Couchdb_Instance

# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import create [as 别名]
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  
开发者ID:niranjan889,项目名称:TwitterFetch,代码行数:10,代码来源:get_frnds.py

示例9: initDatabase

# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import create [as 别名]
def initDatabase():
    server = Server('http://localhost:5984')
    del server['lazycrawler']    
    try:
        db = server.create('lazycrawler')
    except Exception:
        db = server['lazycrawler']
    return db
开发者ID:alexose,项目名称:lazycrawler,代码行数:10,代码来源:spider.py

示例10: main

# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import create [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    authn_policy = AuthTktAuthenticationPolicy(
        'sosecret', hashalg='sha512')
    authz_policy = ACLAuthorizationPolicy()
    config = Configurator(settings=settings, root_factory=RootFactory)
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)
    dbserver = Server(url = settings['couchdb.url'])
    if settings['couchdb.dbname'] not in dbserver:
        dbserver.create(settings['couchdb.dbname'])
    config.registry.settings['couchdb.server'] = dbserver
    config.add_renderer(".html", "pyramid.mako_templating.renderer_factory")
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('home', '/')
    config.add_route('item', '/item/*traverse', factory=Container)
    config.add_route('tag', '/tag/*traverse', factory=Tags)
    config.scan()
    return config.make_wsgi_app()
开发者ID:secjex,项目名称:mmo,代码行数:22,代码来源:__init__.py

示例11: init_boards

# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import create [as 别名]
def init_boards():
    """

    :rtype : object
    """
    server = Server()
    try:
        db = server.create("boards")
    except Exception:
        db = server["boards"]
    return db
开发者ID:GayathriSrinivas,项目名称:CMPE275-Pinterest,代码行数:13,代码来源:db_util.py

示例12: __init__

# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import create [as 别名]
    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
开发者ID:pallets,项目名称:werkzeug,代码行数:13,代码来源:application.py

示例13: __init__

# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import create [as 别名]
    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
开发者ID:0x19,项目名称:werkzeug,代码行数:15,代码来源:application.py

示例14: Connection

# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import create [as 别名]
class Connection(object):
    """
        Connect to CouchDb according to params in the settings.py file
        and store that internally.

        Access is made with this class cause it's a singleton.
    """

    _inst = None

    def __new__(cls, address=None, port=None, db_name=None,  *args, **kwargs):
        """
            Ensure we have only one instance for the connection.
        """
        if not cls._inst:
            cls._inst = object.__new__(cls, *args, **kwargs)
            cls._inst.connect(address, port, db_name)
        return cls._inst


    def close(self):
        Connection._inst = None


    def connect(self, address=None, port=None, db_name=None):
        """
            Connect to the CouchDB server and work on the databse mentioned in
            the settngs.
        """
        address = address or settings.SERVER_ADDRESS

        self.url = "%s:%s/" % (address.rstrip("/"), port or settings.SERVER_PORT)
        self.server = Server(self.url)

        db_name = db_name or settings.DATABASE_NAME
        try:
            self.db = self.server.create(db_name)
        except PreconditionFailed:
            self.db = self.server[db_name]


    def __unicode__(self):
        return u"Connected on %s - working on %s" % (self.url, self.db.name)

    def __str__(self):
        return unicode(self)

    def __repr__(self):
        return repr(self.db)
开发者ID:datawinners,项目名称:HniSpike,代码行数:51,代码来源:connection.py

示例15: TestCouchDBBackend

# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import create [as 别名]
class TestCouchDBBackend(BackendTestBase, TestCase):

    def setUp(self):
        self.server = Server('http://localhost:5984')
        self.db_name = 'test_%s' % uuid4()
        self.server.create(self.db_name)

        db = self.server[self.db_name]
        ViewDefinition.sync_many(db, couchdb_views)
        self.db = CouchDBDatabase(db, lambda: six.text_type(uuid4()))
        super(TestCouchDBBackend, self).setUp()

    def tearDown(self):
        del self.server[self.db_name]

    def test_server_unreachable(self):
        config = mock.Mock()
        config.registry = mock.Mock()
        config.registry.settings = defaultdict(str)
        config.registry.settings['backend.db_host'] = 'http://unreachable/'
        config.registry.settings['backend.db_name'] = 'daybed'

        with self.assertRaises(CouchDBBackendConnectionError):
            CouchDBBackend(config)
开发者ID:leplatrem,项目名称:daybed,代码行数:26,代码来源:test_backend.py


注:本文中的couchdb.client.Server.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。