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


Python Server.config方法代码示例

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


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

示例1: Store

# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import config [as 别名]
class Store(object):
    """
        ERS store
    """
    def __init__(self, url=DEFAULT_STORE_ADMIN_URI, **client_opts):
        self.logger = logging.getLogger('ers-store')
        self._server = Server(url=url, **client_opts)

        self.db_names = {'public': ERS_PUBLIC_DB,
                'private': ERS_PRIVATE_DB,
                'cache': ERS_CACHE_DB,}

        # Add aggregate functions
        # for method_name in ('docs_by_entity', 'by_property', 'by_property_value'):
        #    self.add_aggregate(method_name)

        # Check the status of the databases
        self._ers_dbs = {}
        self._repair()

    def __getitem__(self, dbname):
        return self._ers_dbs[dbname]
        # return ERSDatabase(self._db_uri(dbname), server=self)

    def __iter__(self):
        for dbname in self.all_dbs():
            yield self._ers_dbs[dbname]
            # yield ERSDatabase(self._db_uri(dbname), server=self)

    @classmethod
    def add_aggregate(cls, method_name):
        """
        """
        def aggregate(self, *args, **kwargs):
            return chain(*[getitem(self[db_name], method_name)(*args, **kwargs).iterator()
                            for db_name in ALL_DBS])
        aggregate.__doc__ = """Calls method {}() of all databases in the store and returns an iterator over combined results""".format(method_name)
        aggregate.__name__ = method_name
        setattr(cls, method_name, aggregate)

    def reset(self):
        for db_name in ALL_DBS:
            try:
                del self._server[db_name]
            except http.ResourceNotFound:
                pass
        self._repair()

    def by_property_value(self, property, value=None):
        results = []
        for db in self._ers_dbs.itervalues():
            for res in db.by_property_value(property, value):
                results.append(res)
        return results

    def get_ers_db(self, dbname, **params):
        """
        Try to return an ERSDatabase object for dbname.
        """
        return self._ers_dbs[dbname]

    def info(self):
        return self._server.config()['couchdb']

    def _repair(self):
        # Authenticate with the local store
        # user, password = auth
        try:
            state_db = self._server[ERS_STATE_DB]
        except http.ResourceNotFound:
            state_db = self._server.create(ERS_STATE_DB)
        if not '_local/state' in state_db:
            state_db.save(state_doc())
        if not '_design/index' in state_db:
            state_db.save(index_doc())
        self._ers_dbs[ERS_STATE_DB] = ERSDatabase(state_db)

        for dbname in ALL_DBS:
            # Recreate database if needed
            try:
                db = self._server[dbname]
            except http.ResourceNotFound:
                db = self._server.create(dbname)

            # Create index design doc if needed
            if not '_design/index' in db:
                db.save(index_doc())

            ## Create state doc in the public database if needed
            #if dbname == ERS_PUBLIC_DB:
            #    if not '_local/state' in db:
            #        db.save(state_doc())

            # Save the ERSDatabase object
            self._ers_dbs[dbname] = ERSDatabase(db)
开发者ID:grameh,项目名称:ers-node,代码行数:97,代码来源:store.py


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