本文整理匯總了Python中cms.db.FSObject.get_lobject方法的典型用法代碼示例。如果您正苦於以下問題:Python FSObject.get_lobject方法的具體用法?Python FSObject.get_lobject怎麽用?Python FSObject.get_lobject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cms.db.FSObject
的用法示例。
在下文中一共展示了FSObject.get_lobject方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: put_file
# 需要導入模塊: from cms.db import FSObject [as 別名]
# 或者: from cms.db.FSObject import get_lobject [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)
示例2: put_file
# 需要導入模塊: from cms.db import FSObject [as 別名]
# 或者: from cms.db.FSObject import get_lobject [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)