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


Python message.encode方法代码示例

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


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

示例1: _string_to_bytes

# 需要导入模块: from email import message [as 别名]
# 或者: from email.message import encode [as 别名]
def _string_to_bytes(self, message):
        # If a message is not 7bit clean, we refuse to handle it since it
        # likely came from reading invalid messages in text mode, and that way
        # lies mojibake.
        try:
            return message.encode('ascii')
        except UnicodeError:
            raise ValueError("String input must be ASCII-only; "
                "use bytes or a Message instead")

    # Whether each message must end in a newline 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:13,代码来源:mailbox.py

示例2: _install_message

# 需要导入模块: from email import message [as 别名]
# 或者: from email.message import encode [as 别名]
def _install_message(self, message):
        """Format a message and blindly write to self._file."""
        from_line = None
        if isinstance(message, str):
            message = self._string_to_bytes(message)
        if isinstance(message, bytes) and message.startswith(b'From '):
            newline = message.find(b'\n')
            if newline != -1:
                from_line = message[:newline]
                message = message[newline + 1:]
            else:
                from_line = message
                message = b''
        elif isinstance(message, _mboxMMDFMessage):
            author = message.get_from().encode('ascii')
            from_line = b'From ' + author
        elif isinstance(message, email.message.Message):
            from_line = message.get_unixfrom()  # May be None.
            if from_line is not None:
                from_line = from_line.encode('ascii')
        if from_line is None:
            from_line = b'From MAILER-DAEMON ' + time.asctime(time.gmtime()).encode()
        start = self._file.tell()
        self._file.write(from_line + linesep)
        self._dump_message(message, self._file, self._mangle_from_)
        stop = self._file.tell()
        return (start, stop) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:29,代码来源:mailbox.py

示例3: _pre_mailbox_hook

# 需要导入模块: from email import message [as 别名]
# 或者: from email.message import encode [as 别名]
def _pre_mailbox_hook(self, f):
        """Called before writing the mailbox to file f."""
        babyl = b'BABYL OPTIONS:' + linesep
        babyl += b'Version: 5' + linesep
        labels = self.get_labels()
        labels = (label.encode() for label in labels)
        babyl += b'Labels:' + b','.join(labels) + linesep
        babyl += b'\037'
        f.write(babyl) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:mailbox.py

示例4: write_message

# 需要导入模块: from email import message [as 别名]
# 或者: from email.message import encode [as 别名]
def write_message(self, message, binary=False):
        if binary:
            self._send(2, message)
        else:
            self._send(1, message.encode('utf8'))

    # Event handlers 
开发者ID:MozillaSecurity,项目名称:quokka,代码行数:9,代码来源:websocket.py


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