本文整理汇总了Python中swift.common.swob.Request.message_length方法的典型用法代码示例。如果您正苦于以下问题:Python Request.message_length方法的具体用法?Python Request.message_length怎么用?Python Request.message_length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类swift.common.swob.Request
的用法示例。
在下文中一共展示了Request.message_length方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_object
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import message_length [as 别名]
def save_object(self, env):
# Restorer 데몬에 의해 호출됨
req = Request(env)
self._split_request_path(req)
try:
disk_file = self.get_diskfile(self.device, self.partition,
self.account, self.container,
self.obj)
except DiskFileDeviceUnavailable:
return HTTPInsufficientStorage(drive=self.device,
request=Request(env))
ori_meta = disk_file.read_metadata()
metadata = {}
metadata.update(val for val in req.headers.iteritems()
if is_user_meta('object', val[0]))
del metadata['X-Object-Meta-S3-Restored']
# Timestamp 값 유지
metadata['X-Timestamp'] = ori_meta['X-Timestamp']
metadata['Content-Type'] = ori_meta['Content-Type']
fsize = req.message_length()
etag = md5()
try:
with disk_file.create(size=fsize) as writer:
def timeout_reader():
with ChunkReadTimeout(60):
return req.environ['wsgi.input'].read(65536)
try:
for chunk in iter(lambda: timeout_reader(), ''):
etag.update(chunk)
writer.write(chunk)
except ChunkReadTimeout:
return HTTPRequestTimeout(request=req)
etag = etag.hexdigest()
metadata['ETag'] = etag
metadata['Content-Length'] = str(fsize)
writer.put(metadata)
except DiskFileNoSpace:
return HTTPInsufficientStorage(drive=self.device, request=req)
return HTTPCreated(request=req, etag=etag)