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


Python Config.update方法代码示例

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


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

示例1: DatacatCore

# 需要导入模块: from flask.config import Config [as 别名]
# 或者: from flask.config.Config import update [as 别名]
class DatacatCore(object):
    def __init__(self, config=None):
        self.config = Config()
        if config is not None:
            self.config.update(config)

    @property
    def db(self):
        if getattr(self, '_db', None) is None:
            self._db = connect(**self.config['DATABASE'])
            self._db.autocommit = False
        return self._db

    @property
    def admin_db(self):
        if getattr(self, '_admin_db', None) is None:
            self._admin_db = connect(**self.config['DATABASE'])
            self._admin_db.autocommit = True
        return self._admin_db

    def create_tables(self):
        create_tables(self.admin_db)

    def drop_tables(self):
        drop_tables(self.admin_db)

    # ------------------------------------------------------------
    # Resource data CRUD
    # ------------------------------------------------------------

    def resource_data_iter(self):
        """Iterate over resource attributes"""

        with self.db, self.db.cursor() as cur:
            cur.execute("SELECT * FROM resource_data")
            for row in cur.fetchall():
                yield row

    def resource_data_create(self, stream, metadata=None, mimetype=None):
        """Create resource data from a stream"""

        resource_hash = hashlib.sha1()
        with self.db, self.db.cursor() as cur:
            lobj = self.db.lobject(oid=0, mode='wb')
            oid = lobj.oid
            for chunk in file_read_chunks(stream):
                lobj.write(chunk)
                resource_hash.update(chunk)
            lobj.close()

            data = {
                'ctime': datetime.now(),
                'mtime': datetime.now(),
                'metadata': json.dumps(metadata),
                'mimetype': mimetype or 'application/octet-stream',
                'data_oid': oid,
                'hash': 'sha1:{0}'.format(resource_hash.hexdigest()),
            }

            query = querybuilder.insert('resource_data', data)
            cur.execute(query, data)
            resource_data_id = cur.fetchone()[0]

        return resource_data_id

    def resource_data_get_info(self, objid):
        query = querybuilder.select_pk('resource_data')
        with self.db, self.db.cursor() as cur:
            cur.execute(query, {'id': objid})
            return cur.fetchone()

    def resource_data_read(self, objid):
        resource = self.resource_data_get_info(objid)
        with self.db:
            lobj = self.db.lobject(oid=resource['data_oid'], mode='rb')
            return lobj.read()

    def resource_data_copy(self, objid, dest):
        resource = self.resource_data_get_info(objid)
        with self.db:
            lobj = self.db.lobject(oid=resource['data_oid'], mode='rb')
            for chunk in file_read_chunks(lobj):
                dest.write(chunk)

    def resource_data_update(self, objid, stream=None, metadata=None,
                             mimetype=None):

        # Get the original object, to check for its existence
        # and to get the oid of the lobject holding the data.
        original = self.resource_data_get_info(objid)

        data = {
            'id': objid,
            'mtime': datetime.now(),
        }

        if metadata is not None:
            data['metadata'] = json.dumps(metadata)
        if mimetype is not None:
            data['mimetype'] = mimetype
#.........这里部分代码省略.........
开发者ID:rshk-archive,项目名称:datacat-poc-141007,代码行数:103,代码来源:core.py


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