本文整理汇总了Python中entities.Entity.get_body方法的典型用法代码示例。如果您正苦于以下问题:Python Entity.get_body方法的具体用法?Python Entity.get_body怎么用?Python Entity.get_body使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类entities.Entity
的用法示例。
在下文中一共展示了Entity.get_body方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: body
# 需要导入模块: from entities import Entity [as 别名]
# 或者: from entities.Entity import get_body [as 别名]
def body(self):
# Case 1: nothing
body = self.soup_message.get_body()
if not body:
return {}
# Case 2: urlencoded
content_type, type_parameters = self.get_header('content-type')
if content_type == 'application/x-www-form-urlencoded':
return decode_query(body)
# Case 3: multipart
if content_type.startswith('multipart/'):
boundary = type_parameters.get('boundary')
boundary = '--%s' % boundary
form = {}
for part in body.split(boundary)[1:-1]:
# Parse the entity
entity = Entity(string=part)
# Find out the parameter name
header = entity.get_header('Content-Disposition')
value, header_parameters = header
name = header_parameters['name']
# Load the value
body = entity.get_body()
if 'filename' in header_parameters:
filename = header_parameters['filename']
if filename:
# Strip the path (for IE).
filename = filename.split('\\')[-1]
# Default content-type, see
# http://tools.ietf.org/html/rfc2045#section-5.2
if entity.has_header('content-type'):
mimetype = entity.get_header('content-type')[0]
else:
mimetype = 'text/plain'
form[name] = filename, mimetype, body
else:
if name not in form:
form[name] = body
else:
if isinstance(form[name], list):
form[name].append(body)
else:
form[name] = [form[name], body]
return form
# Case 4: This is useful for REST services
# XXX Should just return the body as a string? deserialized?
return {'body': body}