当前位置: 首页>>代码示例>>Python>>正文


Python BytesIO.name方法代码示例

本文整理汇总了Python中django.utils.six.BytesIO.name方法的典型用法代码示例。如果您正苦于以下问题:Python BytesIO.name方法的具体用法?Python BytesIO.name怎么用?Python BytesIO.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.utils.six.BytesIO的用法示例。


在下文中一共展示了BytesIO.name方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse_postmark

# 需要导入模块: from django.utils.six import BytesIO [as 别名]
# 或者: from django.utils.six.BytesIO import name [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,
        }
开发者ID:gabelula,项目名称:froide,代码行数:30,代码来源:email_utils.py

示例2: parse_attachment

# 需要导入模块: from django.utils.six import BytesIO [as 别名]
# 或者: from django.utils.six.BytesIO import name [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
开发者ID:Bastiantorres,项目名称:votainteligente-portal-electoral,代码行数:45,代码来源:froide_email_utils.py

示例3: parse_attachment

# 需要导入模块: from django.utils.six import BytesIO [as 别名]
# 或者: from django.utils.six.BytesIO import name [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
开发者ID:gabelula,项目名称:froide,代码行数:39,代码来源:email_utils.py

示例4: test_comment_image_upload_invalid

# 需要导入模块: from django.utils.six import BytesIO [as 别名]
# 或者: from django.utils.six.BytesIO import name [as 别名]
 def test_comment_image_upload_invalid(self):
     """
     comment image upload, invalid image
     """
     utils.login(self)
     image = BytesIO(b'BAD\x02D\x01\x00;')
     image.name = 'image.gif'
     image.content_type = 'image/gif'
     files = {'image': SimpleUploadedFile(image.name, image.read()), }
     response = self.client.post(reverse('spirit:comment:image-upload-ajax'),
                                 HTTP_X_REQUESTED_WITH='XMLHttpRequest',
                                 data=files)
     res = json.loads(response.content.decode('utf-8'))
     self.assertIn('error', res.keys())
     self.assertIn('image', res['error'].keys())
开发者ID:beedesk,项目名称:django-spirit,代码行数:17,代码来源:tests.py

示例5: test_comment_image_upload_invalid

# 需要导入模块: from django.utils.six import BytesIO [as 别名]
# 或者: from django.utils.six.BytesIO import name [as 别名]
 def test_comment_image_upload_invalid(self):
     """
     comment image upload, invalid image
     """
     utils.login(self)
     image = BytesIO(b"BAD\x02D\x01\x00;")
     image.name = "image.gif"
     image.content_type = "image/gif"
     files = {"image": SimpleUploadedFile(image.name, image.read())}
     response = self.client.post(
         reverse("spirit:comment:image-upload-ajax"), HTTP_X_REQUESTED_WITH="XMLHttpRequest", data=files
     )
     res = json.loads(response.content.decode("utf-8"))
     self.assertIn("error", res.keys())
     self.assertIn("image", res["error"].keys())
开发者ID:alesdotio,项目名称:Spirit,代码行数:17,代码来源:tests.py

示例6: _open

# 需要导入模块: from django.utils.six import BytesIO [as 别名]
# 或者: from django.utils.six.BytesIO import name [as 别名]
    def _open(self, name, mode='rb'):
        """Open a file from database.

        @param name filename or relative path to file based on base_url. path should contain only "/", but not "\". Apache sends pathes with "/".
        If there is no such file in the db, returs None
        """

        assert mode == 'rb', "You've tried to open binary file without specifying binary mode! You specified: %s"%mode

        row = self.cursor.execute("SELECT %s from %s where %s = '%s'"%(self.blob_column,self.db_table,self.fname_column,name) ).fetchone()
        if row is None:
            return None
        inMemFile = BytesIO(row[0])
        inMemFile.name = name
        inMemFile.mode = mode

        retFile = File(inMemFile)
        return retFile
开发者ID:YikSanChan,项目名称:15637-final,代码行数:20,代码来源:database.py


注:本文中的django.utils.six.BytesIO.name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。