本文整理汇总了Python中swift.common.swob.Request.content_length方法的典型用法代码示例。如果您正苦于以下问题:Python Request.content_length方法的具体用法?Python Request.content_length怎么用?Python Request.content_length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类swift.common.swob.Request
的用法示例。
在下文中一共展示了Request.content_length方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import content_length [as 别名]
def __call__(self, env, start_response):
req = Request(env)
try:
key = req.headers['X-AES-Key']
aes = AESCipher(key)
if req.method == 'PUT':
if req.content_length != None and req.body != None:
req.body = aes.encrypt(req.body)
req.content_length = len(req.body)
except Exception:
self.logger.info('No key provided')
return self.app(env, start_response)
示例2: _delete_multiple_objects
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import content_length [as 别名]
def _delete_multiple_objects(self, req):
def _object_key_iter(xml):
dom = parseString(xml)
delete = dom.getElementsByTagName('Delete')[0]
for obj in delete.getElementsByTagName('Object'):
key = obj.getElementsByTagName('Key')[0].firstChild.data
version = None
if obj.getElementsByTagName('VersionId').length > 0:
version = obj.getElementsByTagName('VersionId')[0]\
.firstChild.data
yield (key, version)
def _get_deleted_elem(key):
return ' <Deleted>\r\n' \
' <Key>%s</Key>\r\n' \
' </Deleted>\r\n' % (key)
def _get_err_elem(key, err_code, message):
return ' <Error>\r\n' \
' <Key>%s</Key>\r\n' \
' <Code>%s</Code>\r\n' \
' <Message>%s</Message>\r\n' \
' </Error>\r\n' % (key, err_code, message)
body = '<?xml version="1.0" encoding="UTF-8"?>\r\n' \
'<DeleteResult ' \
'xmlns="http://doc.s3.amazonaws.com/2006-03-01">\r\n'
for key, version in _object_key_iter(req.body):
if version is not None:
# TODO: delete the specific version of the object
return get_err_response('Unsupported')
sub_req = Request(req.environ.copy())
sub_req.query_string = ''
sub_req.content_length = 0
sub_req.method = 'DELETE'
controller = ObjectController(sub_req, self.app, self.account_name,
req.environ['HTTP_X_AUTH_TOKEN'],
self.container_name, key)
sub_resp = controller.DELETE(sub_req)
status = sub_resp.status_int
if status == HTTP_NO_CONTENT or status == HTTP_NOT_FOUND:
body += _get_deleted_elem(key)
else:
if status == HTTP_UNAUTHORIZED:
body += _get_err_elem(key, 'AccessDenied', 'Access Denied')
else:
body += _get_err_elem(key, 'InvalidURI', 'Invalid URI')
body += '</DeleteResult>\r\n'
return HTTPOk(body=body)