client.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:HyperStream 作者: IRC-SPHERE 项目源码 文件源码
def connect(self, server_config):
        """Connect using the configuration given

        :param server_config: The server configuration
        """
        if 'connection_string' in server_config:
            self.client = pymongo.MongoClient(
                    server_config['connection_string'])
            self.db = self.client[server_config['db']]
        else:
            self.client = pymongo.MongoClient(
                server_config['host'],
                server_config['port'],
                tz_aware=self.get_config_value('tz_aware', True))

            self.db = self.client[server_config['db']]

        if ('authentication_database' in server_config and
                server_config['authentication_database']):
            self.db.authenticate(
                    server_config['username'], server_config['password'],
                    source=server_config['authentication_database'])
        else:
            if 'username' in server_config:
                if 'password' in server_config:
                    self.db.authenticate(server_config['username'],
                                         server_config['password'])
                else:
                    self.db.authenticate(server_config['username'])

        # Mongo Engine connection
        d = dict((k, v) for k, v in server_config.items()
                 if k not in ['modalities', 'summaries'])
        if 'authentication_database' in d:
            d['authentication_source'] = d['authentication_database']
            del d['authentication_database']

        self.session = connect(alias="hyperstream", **d)

        # TODO: This sets the default connection of mongoengine, but seems to be a bit of a hack
        if "default" not in connection._connections:
            connection._connections["default"] = connection._connections["hyperstream"]
            connection._connection_settings["default"] = connection._connection_settings["hyperstream"]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号