本文整理汇总了Python中django.utils.six.BytesIO.mod_date方法的典型用法代码示例。如果您正苦于以下问题:Python BytesIO.mod_date方法的具体用法?Python BytesIO.mod_date怎么用?Python BytesIO.mod_date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.six.BytesIO
的用法示例。
在下文中一共展示了BytesIO.mod_date方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_postmark
# 需要导入模块: from django.utils.six import BytesIO [as 别名]
# 或者: from django.utils.six.BytesIO import mod_date [as 别名]
def parse_postmark(self, obj):
from_field = (obj["FromFull"]["Name"], obj["FromFull"]["Email"])
tos = [(o["Name"], o["Email"]) for o in obj["ToFull"]]
ccs = [(o["Name"], o["Email"]) for o in obj["CcFull"]]
attachments = []
for a in obj["Attachments"]:
attachment = BytesIO(base64.b64decode(a["Content"]))
attachment.content_type = a["ContentType"]
attachment.size = a["ContentLength"]
attachment.name = a["Name"]
attachment.create_date = None
attachment.mod_date = None
attachment.read_date = None
attachments.append(attachment)
return {
"msgobj": obj,
"date": self.parse_date(obj["Date"]),
"subject": obj["Subject"],
"body": obj["TextBody"],
"html": obj["HtmlBody"],
"from": from_field,
"to": tos,
"cc": ccs,
"resent_to": [],
"resent_cc": [],
"attachments": attachments,
}
示例2: parse_attachment
# 需要导入模块: from django.utils.six import BytesIO [as 别名]
# 或者: from django.utils.six.BytesIO import mod_date [as 别名]
def parse_attachment(self, message_part):
content_disposition = message_part.get("Content-Disposition", None)
if content_disposition:
dispo_type, dispo_dict = self.parse_dispositions(content_disposition)
if dispo_type == "attachment" or (dispo_type == 'inline' and
'filename' in dispo_dict):
content_type = message_part.get("Content-Type", None)
file_data = message_part.get_payload(decode=True)
if file_data is None:
payloads = message_part.get_payload()
file_data = '\n\n'.join([p.as_string() for p in payloads])
try:
file_data = file_data.encode('utf-8')
except:
pass
attachment = BytesIO(file_data)
attachment.content_type = message_part.get_content_type()
attachment.size = len(file_data)
attachment.name = None
attachment.create_date = None
attachment.mod_date = None
attachment.read_date = None
if "filename" in dispo_dict:
attachment.name = dispo_dict['filename']
if content_type:
_, content_dict = self.parse_dispositions(content_type)
if 'name' in content_dict:
attachment.name = content_dict['name']
if attachment.name is None and content_type == 'message/rfc822':
p = Parser()
msgobj = p.parse(BytesIO(attachment.getvalue()))
subject = self.parse_header_field(msgobj['Subject'])
if subject:
attachment.name = '%s.eml' % subject[:45]
if "create-date" in dispo_dict:
attachment.create_date = dispo_dict['create-date'] # TODO: datetime
if "modification-date" in dispo_dict:
attachment.mod_date = dispo_dict['modification-date'] # TODO: datetime
if "read-date" in dispo_dict:
attachment.read_date = dispo_dict['read-date'] # TODO: datetime
return attachment
return None
示例3: parse_attachment
# 需要导入模块: from django.utils.six import BytesIO [as 别名]
# 或者: from django.utils.six.BytesIO import mod_date [as 别名]
def parse_attachment(self, message_part):
content_disposition = message_part.get("Content-Disposition", None)
if content_disposition:
dispo_type, dispo_dict = self.parse_dispositions(content_disposition)
if dispo_type == "attachment" or (dispo_type == "inline" and "filename" in dispo_dict):
content_type = message_part.get("Content-Type", None)
file_data = message_part.get_payload(decode=True)
if file_data is None:
payloads = message_part.get_payload()
file_data = "\n\n".join([p.as_string() for p in payloads]).encode("utf-8")
attachment = BytesIO(file_data)
attachment.content_type = message_part.get_content_type()
attachment.size = len(file_data)
attachment.name = None
attachment.create_date = None
attachment.mod_date = None
attachment.read_date = None
if "filename" in dispo_dict:
attachment.name = dispo_dict["filename"]
if content_type:
_, content_dict = self.parse_dispositions(content_type)
if "name" in content_dict:
attachment.name = content_dict["name"]
if attachment.name is None and content_type == "message/rfc822":
p = Parser()
msgobj = p.parse(BytesIO(attachment.getvalue()))
subject = self.parse_header_field(msgobj["Subject"])
if subject:
attachment.name = "%s.eml" % subject[:45]
if "create-date" in dispo_dict:
attachment.create_date = dispo_dict["create-date"] # TODO: datetime
if "modification-date" in dispo_dict:
attachment.mod_date = dispo_dict["modification-date"] # TODO: datetime
if "read-date" in dispo_dict:
attachment.read_date = dispo_dict["read-date"] # TODO: datetime
return attachment
return None