當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。