Python email.parser 模块,HeaderParser() 实例源码
我们从Python开源项目中,提取了以下35个代码示例,用于说明如何使用email.parser.HeaderParser()。
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title,body,Metadata).
"""
docstring = trim_docstring(docstring)
parts = re.split(r'\n{2,}', docstring)
title = parts[0]
if len(parts) == 1:
body = ''
Metadata = {}
else:
parser = HeaderParser()
try:
Metadata = parser.parsestr(parts[-1])
except HeaderParseError:
Metadata = {}
body = "\n\n".join(parts[1:])
else:
Metadata = dict(Metadata.items())
if Metadata:
body = "\n\n".join(parts[1:-1])
else:
body = "\n\n".join(parts[1:])
return title, body, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def test_message_rfc822_only(self):
# Issue 7970: message/rfc822 not in multipart parsed by
# HeaderParser caused an exception when flattened.
with openfile(findfile('msg_46.txt')) as fp:
msgdata = fp.read()
parser = HeaderParser()
msg = parser.parsestr(msgdata)
out = StringIO()
gen = Generator(out, True, 0)
gen.flatten(msg, False)
self.assertEqual(out.getvalue(), msgdata)
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Returns (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, Metadata
def test_message_rfc822_only(self):
# Issue 7970: message/rfc822 not in multipart parsed by
# HeaderParser caused an exception when flattened.
with openfile('msg_46.txt') as fp:
msgdata = fp.read()
parser = HeaderParser()
msg = parser.parsestr(msgdata)
out = StringIO()
gen = Generator(out, msgdata)
def test_message_rfc822_only(self):
# Issue 7970: message/rfc822 not in multipart parsed by
# HeaderParser caused an exception when flattened.
with openfile('msg_46.txt') as fp:
msgdata = fp.read()
parser = HeaderParser()
msg = parser.parsestr(msgdata)
out = StringIO()
gen = Generator(out, msgdata)
def header_charset(s):
p = HeaderParser()
return p.parsestr(s).get_content_charset()
def header_charset(s):
p = HeaderParser()
return p.parsestr(s.encode('utf-8', 'ignore')).get_content_charset()
def test_message_rfc822_only(self):
# Issue 7970: message/rfc822 not in multipart parsed by
# HeaderParser caused an exception when flattened.
with openfile('msg_46.txt') as fp:
msgdata = fp.read()
parser = HeaderParser()
msg = parser.parsestr(msgdata)
out = StringIO()
gen = Generator(out, msgdata)
def main():
outdir = os.path.join(os.path.dirname('__file__'), 'build')
try:
shutil.rmtree(outdir)
except FileNotFoundError:
pass
os.mkdir(outdir)
filenames = []
names = {}
for filename in sorted(glob.glob("pep-*.rst")):
outbasename = os.path.basename(filename[:-4] + '.html')
filenames.append(outbasename)
outfilename = os.path.join(outdir, outbasename)
pepnum = get_pepnum(outfilename)
print(filename, '->', outfilename)
with open(filename) as inf, open(outfilename, 'w') as outf:
fix_rst_pep(inf, outf, filename, pepnum)
with open(filename) as inf:
parser = HeaderParser()
Metadata = parser.parse(inf)
names[pepnum] = Metadata['Title']
index_filename = os.path.join(outdir, 'index.html')
print(index_filename)
with open(index_filename, 'w') as f:
f.write('<html><head><title>Draft PEP index</title></head>')
f.write('<body><h1>Draft PEP index</h1><ul>')
for filename in filenames:
pepnum = get_pepnum(filename)
f.write('<li>{num}: <a href="{link}">{name}</a></li>'.format(
link=filename, num=pepnum, name=names[pepnum]))
f.write('</ul></body></html>')
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。