当前位置: 首页>>代码示例>>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;未经允许,请勿转载。