本文整理汇总了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()
示例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
示例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
示例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"',
]
示例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
)
示例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
示例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
示例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())
示例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
示例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',
])
示例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
示例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
示例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'])