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


Python SqliteDict.pop方法代码示例

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


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

示例1: BucketObject

# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import pop [as 别名]

#.........这里部分代码省略.........
            while True:
                chunk = stream.read(4096)
                if not chunk:
                    break
                _file.write(chunk)

        hashes = {
            'content-md5': self.filehash(temp_filepath, hashlib.md5()),
            'content-sha1': self.filehash(temp_filepath, hashlib.sha1()),
            'content-sha256': self.filehash(temp_filepath, hashlib.sha256())        
        }

        if self.validate(temp_filepath, hashes):
            self._metadata.update(hashes)

            self.object_id = self._metadata[self.OBJECT_KEY_BASE]

            if hashes[self.OBJECT_KEY_BASE] not in self._objects_metadata:
                movefile(temp_filepath, self.filepath)
                self.metadata = self._metadata
            else:
                os.remove(temp_filepath)
                raise falcon.HTTPConflict(
                    title="ObjectAlreadyExists",
                    description="The object already exists into the storage.",
                    headers={
                        'content-md5':  self.metadata['content-md5'],
                        'content-sha1': self.metadata['content-sha1'],
                        'content-sha256': self.metadata['content-sha256'],
                    }
                )


    def filehash(self, filepath, hashfunc):
        ''' returns file hash
        '''
        block_size = 2 ** 20
        with open(filepath, 'rb') as _file:
            while True:
                data = _file.read(block_size)
                if not data:
                    break
                hashfunc.update(data)
        return hashfunc.hexdigest()


    def validate(self, filepath, filehashes):
        ''' validate recieved file object
        '''
        if os.path.getsize(filepath) == 0:
            os.remove(filepath)
            raise falcon.HTTPBadRequest(
                title='ZeroContentLength',
                description='The content size is 0'
            )

        if 'content-length' in self._metadata and \
            os.path.getsize(filepath) != self._metadata['content-length']:
            os.remove(filepath)
            raise falcon.HTTPBadRequest(
                title='BadContentLength',
                description='The Content-length did not match'
            )

        if 'content-md5' in self._metadata and \
            filehashes['md5'] != self._metadata['content-md5']:
            os.remove(filepath)
            raise falcon.HTTPBadRequest(
                title='BadDigest',
                description='The Content-MD5 did not match'
            )

        if 'content-sha1' in self._metadata and \
            filehashes['sha1'] != self._metadata['content-sha1']:
            os.remove(filepath)
            raise falcon.HTTPBadRequest(
                title='BadDigest',
                description='The Content-SHA1 did not match'
            )

        return True

    def delete(self):
        ''' delete object
        '''
        if self.exists():
            if os.path.exists(self.filepath):
                os.remove(self.filepath)
            else:
                raise falcon.HTTPNotFound()
            self._objects_metadata.pop(self.object_id)


    def info(self):
        ''' returns object's metadata
        '''
        if self.object_id and self.object_id in self._objects_metadata:
            return self._objects_metadata[self.object_id]
        else:
            return self._metadata
开发者ID:ownport,项目名称:objectstore,代码行数:104,代码来源:objects.py


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