當前位置: 首頁>>代碼示例>>Python>>正文


Python parser.BytesParser方法代碼示例

本文整理匯總了Python中email.parser.BytesParser方法的典型用法代碼示例。如果您正苦於以下問題:Python parser.BytesParser方法的具體用法?Python parser.BytesParser怎麽用?Python parser.BytesParser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在email.parser的用法示例。


在下文中一共展示了parser.BytesParser方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: messages

# 需要導入模塊: from email import parser [as 別名]
# 或者: from email.parser import BytesParser [as 別名]
def messages(self, folder, limit=10, peek=True):
        """Return ``limit`` messages from ``folder``

        peek=False will also fetch message body
        """
        resp, count = self._imap.select('"%s"' % folder, readonly=True)
        if resp != 'OK':
            raise Exception(resp)
        
        last_message_id = int(count[0])
        msg_ids = range(last_message_id, last_message_id-limit, -1)
        
        mode = '(BODY.PEEK[HEADER])' if peek else '(RFC822)'

        messages = []
        for msg_id in msg_ids:
            resp, msg = self._imap.fetch(str(msg_id), mode)
            msg = msg[0][-1]

            messages.append(BytesParser().parsebytes(msg))
            if len(messages) >= limit:
                break
        return messages 
開發者ID:PacktPublishing,項目名稱:Modern-Python-Standard-Library-Cookbook,代碼行數:25,代碼來源:networking_02.py

示例2: get_metadata_for_wheel

# 需要導入模塊: from email import parser [as 別名]
# 或者: from email.parser import BytesParser [as 別名]
def get_metadata_for_wheel(url):
    data = requests.get(url).content
    with ZipFile(BytesIO(data)) as z:
        for n in z.namelist():
            if n.endswith(".dist-info/METADATA"):
                p = BytesParser()
                return p.parse(z.open(n), headersonly=True)

    # If we didn't find the metadata, return an empty dict
    return EmailMessage() 
開發者ID:sarugaku,項目名稱:resolvelib,代碼行數:12,代碼來源:pypi_wheel_provider.py

示例3: message_from_bytes

# 需要導入模塊: from email import parser [as 別名]
# 或者: from email.parser import BytesParser [as 別名]
def message_from_bytes(s, *args, **kws):
    """Parse a bytes string into a Message object model.

    Optional _class and strict are passed to the Parser constructor.
    """
    from email.parser import BytesParser
    return BytesParser(*args, **kws).parsebytes(s) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:9,代碼來源:__init__.py

示例4: message_from_binary_file

# 需要導入模塊: from email import parser [as 別名]
# 或者: from email.parser import BytesParser [as 別名]
def message_from_binary_file(fp, *args, **kws):
    """Read a binary file and parse its contents into a Message object model.

    Optional _class and strict are passed to the Parser constructor.
    """
    from email.parser import BytesParser
    return BytesParser(*args, **kws).parse(fp) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:9,代碼來源:__init__.py

示例5: process_email

# 需要導入模塊: from email import parser [as 別名]
# 或者: from email.parser import BytesParser [as 別名]
def process_email(raw_email):
    msg = BytesParser(policy=policy.default).parsebytes(raw_email)
    body = msg.get_body(preferencelist=['plain'])
    content = body.get_payload(decode=True)

    charset = body.get_content_charset()
    if not charset:
        charset = chardet.detect(content)['encoding']
    content = content.decode(charset)

    regex = re.compile('^[^+@]+\+(?P<token>[a-zA-Z0-9]{80})@[^@]+$')

    for addr in msg.get('To', '').split(','):
        m = regex.match(addr.strip())
        if m:
            break

    if not m:
        raise NoTokenFoundException

    token = m.group('token')

    try:
        in_reply_to, author = process_new_token(token)
    except InvalidTokenException:
        in_reply_to, author = process_old_token(token)

    subject = msg.get('Subject', '')

    Message.objects.create(thread=in_reply_to.thread, in_reply_to=in_reply_to, author=author, subject=subject, content=content) 
開發者ID:PonyConf,項目名稱:PonyConf,代碼行數:32,代碼來源:utils.py


注:本文中的email.parser.BytesParser方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。