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


Python parser.Parser方法代码示例

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


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

示例1: handle

# 需要导入模块: from email import parser [as 别名]
# 或者: from email.parser import Parser [as 别名]
def handle(self, *args, **options):
        uid = Configuration.conf('imap_act')

        if uid == '':
            raise ValueError('Incoming message user not configured')

        user = User.objects.get(pk=uid)
        server = Configuration.get_imap_server()
        typ, data = server.search(None, "UnSeen")

        for num in data[0].split():
            #logging.debug("** Processing message %s" % num)
            typ, data = server.fetch(num, "(RFC822)")
            # parsestr() seems to return an email.message?
            msg = Parser().parsestr(data[0][1])
            Note.from_email(msg, user)
            #server.copy(num, 'servo')
            server.store(num, '+FLAGS', '\\Seen')

        server.close()
        server.logout() 
开发者ID:fpsw,项目名称:Servo,代码行数:23,代码来源:checkmail.py

示例2: wheel_version

# 需要导入模块: from email import parser [as 别名]
# 或者: from email.parser import Parser [as 别名]
def wheel_version(source_dir):
    """
    Return the Wheel-Version of an extracted wheel, if possible.

    Otherwise, return False if we couldn't parse / extract it.
    """
    try:
        dist = [d for d in pkg_resources.find_on_path(None, source_dir)][0]

        wheel_data = dist.get_metadata('WHEEL')
        wheel_data = Parser().parsestr(wheel_data)

        version = wheel_data['Wheel-Version'].strip()
        version = tuple(map(int, version.split('.')))
        return version
    except:
        return False 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:wheel.py

示例3: test_dumps_deps

# 需要导入模块: from email import parser [as 别名]
# 或者: from email.parser import Parser [as 别名]
def test_dumps_deps(requirements_path: Path):
    path = requirements_path / 'egg-info'
    converter = EggInfoConverter()
    resolver = converter.load_resolver(path)
    reqs = Requirement.from_graph(graph=resolver.graph, lock=False)
    assert len(reqs) > 2

    content = converter.dumps(reqs=reqs, project=resolver.graph.metainfo)
    assert 'Requires-Dist: requests' in content

    parsed = Parser().parsestr(content)
    needed = {
        'attrs', 'cached-property', 'packaging', 'requests',
        'libtest', 'colorama; extra == "windows"',
    }
    assert set(parsed.get_all('Requires-Dist')) == needed 
开发者ID:dephell,项目名称:dephell,代码行数:18,代码来源:test_egginfo.py

示例4: test_make_pkg_info_multi_constraints_dependency

# 需要导入模块: from email import parser [as 别名]
# 或者: from email.parser import Parser [as 别名]
def test_make_pkg_info_multi_constraints_dependency():
    poetry = Factory().create_poetry(
        Path(__file__).parent.parent.parent
        / "fixtures"
        / "project_with_multi_constraints_dependency"
    )

    builder = SdistBuilder(poetry, NullEnv(), NullIO())
    pkg_info = builder.build_pkg_info()
    p = Parser()
    parsed = p.parsestr(to_str(pkg_info))

    requires = parsed.get_all("Requires-Dist")
    assert requires == [
        'pendulum (>=1.5,<2.0); python_version < "3.4"',
        'pendulum (>=2.0,<3.0); python_version >= "3.4" and python_version < "4.0"',
    ] 
开发者ID:python-poetry,项目名称:poetry,代码行数:19,代码来源:test_sdist.py

示例5: test_metadata_with_url_dependencies

# 需要导入模块: from email import parser [as 别名]
# 或者: from email.parser import Parser [as 别名]
def test_metadata_with_url_dependencies():
    builder = Builder(
        Factory().create_poetry(
            Path(__file__).parent / "fixtures" / "with_url_dependency"
        ),
        NullEnv(),
        NullIO(),
    )

    metadata = Parser().parsestr(builder.get_metadata_content())

    requires_dist = metadata["Requires-Dist"]

    assert (
        "demo @ https://python-poetry.org/distributions/demo-0.1.0-py2.py3-none-any.whl"
        == requires_dist
    ) 
开发者ID:python-poetry,项目名称:poetry,代码行数:19,代码来源:test_builder.py

示例6: testExtractOpenPGPHeader

# 需要导入模块: from email import parser [as 别名]
# 或者: from email.parser import Parser [as 别名]
def testExtractOpenPGPHeader(self):
        """
        Test the OpenPGP header key extraction
        """
        KEYURL = "https://leap.se/key.txt"
        OpenPGP = "id=12345678; url=\"%s\"; preference=signencrypt" % (KEYURL,)

        message = Parser().parsestr(self.EMAIL)
        message.add_header("OpenPGP", OpenPGP)
        self.fetcher._keymanager.fetch_key = Mock(
            return_value=defer.succeed(None))

        def fetch_key_called(ret):
            self.fetcher._keymanager.fetch_key.assert_called_once_with(
                ADDRESS_2, KEYURL)

        d = self._create_incoming_email(message.as_string())
        d.addCallback(
            lambda email:
            self._mock_soledad_get_from_index(fields.JUST_MAIL_IDX, [email]))
        d.addCallback(lambda _: self.fetcher.fetch())
        d.addCallback(fetch_key_called)
        return d 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:25,代码来源:test_incoming_mail.py

示例7: testExtractOpenPGPHeaderInvalidUrl

# 需要导入模块: from email import parser [as 别名]
# 或者: from email.parser import Parser [as 别名]
def testExtractOpenPGPHeaderInvalidUrl(self):
        """
        Test the OpenPGP header key extraction
        """
        KEYURL = "https://someotherdomain.com/key.txt"
        OpenPGP = "id=12345678; url=\"%s\"; preference=signencrypt" % (KEYURL,)

        message = Parser().parsestr(self.EMAIL)
        message.add_header("OpenPGP", OpenPGP)
        self.fetcher._keymanager.fetch_key = Mock()

        def fetch_key_called(ret):
            self.assertFalse(self.fetcher._keymanager.fetch_key.called)

        d = self._create_incoming_email(message.as_string())
        d.addCallback(
            lambda email:
            self._mock_soledad_get_from_index(fields.JUST_MAIL_IDX, [email]))
        d.addCallback(lambda _: self.fetcher.fetch())
        d.addCallback(fetch_key_called)
        return d 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:23,代码来源:test_incoming_mail.py

示例8: test_empty_multipart_idempotent

# 需要导入模块: from email import parser [as 别名]
# 或者: from email.parser import Parser [as 别名]
def test_empty_multipart_idempotent(self):
        text = """\
Content-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain


--BOUNDARY


--BOUNDARY--
"""
        msg = Parser().parsestr(text)
        self.ndiffAssertEqual(text, msg.as_string()) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_email_renamed.py

示例9: test_boundary_without_trailing_newline

# 需要导入模块: from email import parser [as 别名]
# 或者: from email.parser import Parser [as 别名]
def test_boundary_without_trailing_newline(self):
        m = Parser().parsestr("""\
Content-Type: multipart/mixed; boundary="===============0012394164=="
MIME-Version: 1.0

--===============0012394164==
Content-Type: image/file1.jpg
MIME-Version: 1.0
Content-Transfer-Encoding: base64

YXNkZg==
--===============0012394164==--""")
        self.assertEqual(m.get_payload(0).get_payload(), 'YXNkZg==')



# Test some badly formatted messages 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_email_renamed.py

示例10: test__all__

# 需要导入模块: from email import parser [as 别名]
# 或者: from email.parser import Parser [as 别名]
def test__all__(self):
        module = __import__('email')
        # Can't use sorted() here due to Python 2.3 compatibility
        all = module.__all__[:]
        all.sort()
        self.assertEqual(all, [
            # Old names
            'Charset', 'Encoders', 'Errors', 'Generator',
            'Header', 'Iterators', 'MIMEAudio', 'MIMEBase',
            'MIMEImage', 'MIMEMessage', 'MIMEMultipart',
            'MIMENonMultipart', 'MIMEText', 'Message',
            'Parser', 'Utils', 'base64MIME',
            # new names
            'base64mime', 'charset', 'encoders', 'errors', 'generator',
            'header', 'iterators', 'message', 'message_from_file',
            'message_from_string', 'mime', 'parser',
            'quopriMIME', 'quoprimime', 'utils',
            ]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_email_renamed.py

示例11: wheel_version

# 需要导入模块: from email import parser [as 别名]
# 或者: from email.parser import Parser [as 别名]
def wheel_version(source_dir):
    # type: (Optional[str]) -> Optional[Tuple[int, ...]]
    """
    Return the Wheel-Version of an extracted wheel, if possible.

    Otherwise, return None if we couldn't parse / extract it.
    """
    try:
        dist = [d for d in pkg_resources.find_on_path(None, source_dir)][0]

        wheel_data = dist.get_metadata('WHEEL')
        wheel_data = Parser().parsestr(wheel_data)

        version = wheel_data['Wheel-Version'].strip()
        version = tuple(map(int, version.split('.')))
        return version
    except Exception:
        return None 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:20,代码来源:wheel.py

示例12: check_mail

# 需要导入模块: from email import parser [as 别名]
# 或者: from email.parser import Parser [as 别名]
def check_mail():
    """Checks IMAP box for incoming mail"""
    uid = Configuration.conf('imap_act')

    if empty(uid):
        raise ConfigurationError('Incoming message user not configured')

    counter = 0
    user = User.objects.get(pk=uid)
    server = Configuration.get_imap_server()
    typ, data = server.search(None, "UnSeen")

    for num in data[0].split():
        #logging.debug("** Processing message %s" % num)
        typ, data = server.fetch(num, "(RFC822)")
        # parsestr() seems to return an email.message?
        msg = Parser().parsestr(data[0][1])
        Note.from_email(msg, user)
        #server.copy(num, 'servo')
        server.store(num, '+FLAGS', '\\Seen')
        counter += 1

    server.close()
    server.logout()

    return '%d messages processed' % counter 
开发者ID:fpsw,项目名称:Servo,代码行数:28,代码来源:tasks.py

示例13: test_to_records_with_Mapping_type

# 需要导入模块: from email import parser [as 别名]
# 或者: from email.parser import Parser [as 别名]
def test_to_records_with_Mapping_type(self):
        import email
        from email.parser import Parser

        compat.Mapping.register(email.message.Message)

        headers = Parser().parsestr('From: <user@example.com>\n'
                                    'To: <someone_else@example.com>\n'
                                    'Subject: Test message\n'
                                    '\n'
                                    'Body would go here\n')

        frame = DataFrame.from_records([headers])
        all(x in frame for x in ['Type', 'Subject', 'From']) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:16,代码来源:test_convert_to.py


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