本文整理汇总了Python中cms.db.FSObject.digest方法的典型用法代码示例。如果您正苦于以下问题:Python FSObject.digest方法的具体用法?Python FSObject.digest怎么用?Python FSObject.digest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cms.db.FSObject
的用法示例。
在下文中一共展示了FSObject.digest方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: commit_file
# 需要导入模块: from cms.db import FSObject [as 别名]
# 或者: from cms.db.FSObject import digest [as 别名]
def commit_file(self, fobj, digest, desc=""):
"""See FileCacherBackend.commit_file().
"""
fobj.close()
try:
with SessionGen() as session:
fso = FSObject(description=desc)
fso.digest = digest
fso.loid = fobj.loid
session.add(fso)
session.commit()
logger.info("File %s (%s) stored on the database.",
digest, desc)
except IntegrityError:
# If someone beat us to adding the same object to the database, we
# should at least drop the large object.
LargeObject.unlink(fobj.loid)
logger.warning("File %s (%s) caused an IntegrityError, ignoring.",
digest, desc)
return False
return True
示例2: put_file
# 需要导入模块: from cms.db import FSObject [as 别名]
# 或者: from cms.db.FSObject import digest [as 别名]
def put_file(self, digest, origin, description=""):
"""See FileCacherBackend.put_file().
"""
try:
with SessionGen() as session:
# Check digest uniqueness
if FSObject.get_from_digest(digest, session) is not None:
logger.debug("File %s already on database, "
"dropping this one." % digest)
session.rollback()
# If it is not already present, copy the file into the
# lobject
else:
fso = FSObject(description=description)
logger.debug("Sending file %s to the database." % digest)
with open(origin, 'rb') as temp_file:
with fso.get_lobject(session, mode='wb') \
as lobject:
logger.debug("Large object created.")
buf = temp_file.read(self.CHUNK_SIZE)
while buf != '':
while len(buf) > 0:
written = lobject.write(buf)
buf = buf[written:]
# Cooperative yield
gevent.sleep(0)
buf = temp_file.read(self.CHUNK_SIZE)
fso.digest = digest
session.add(fso)
session.commit()
logger.debug("File %s sent to the database." % digest)
except IntegrityError:
logger.warning("File %s caused an IntegrityError, ignoring..."
% digest)
示例3: put_file
# 需要导入模块: from cms.db import FSObject [as 别名]
# 或者: from cms.db.FSObject import digest [as 别名]
def put_file(self, digest, desc=""):
"""See FileCacherBackend.put_file().
"""
try:
with SessionGen() as session:
fso = FSObject.get_from_digest(digest, session)
# Check digest uniqueness
if fso is not None:
logger.debug("File %s already stored on database, not "
"sending it again." % digest)
session.rollback()
return None
# If it is not already present, copy the file into the
# lobject
else:
fso = FSObject(description=desc)
fso.digest = digest
session.add(fso)
logger.debug("File %s stored on the database." % digest)
# FIXME There is a remote possibility that someone
# will try to access this file, believing it has
# already been stored (since its FSObject exists),
# while we're still sending its content.
lobject = fso.get_lobject(mode='wb')
session.commit()
return lobject
except IntegrityError:
logger.warning("File %s caused an IntegrityError, ignoring..." %
digest)