本文整理汇总了Python中future.backports.email.parser.Parser方法的典型用法代码示例。如果您正苦于以下问题:Python parser.Parser方法的具体用法?Python parser.Parser怎么用?Python parser.Parser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类future.backports.email.parser
的用法示例。
在下文中一共展示了parser.Parser方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_headers
# 需要导入模块: from future.backports.email import parser [as 别名]
# 或者: from future.backports.email.parser import Parser [as 别名]
def parse_headers(fp, _class=HTTPMessage):
"""Parses only RFC2822 headers from a file pointer.
email Parser wants to see strings rather than bytes.
But a TextIOWrapper around self.rfile would buffer too many bytes
from the stream, bytes which we later need to read as bytes.
So we read the correct bytes here, as bytes, for email Parser
to parse.
"""
headers = []
while True:
line = fp.readline(_MAXLINE + 1)
if len(line) > _MAXLINE:
raise LineTooLong("header line")
headers.append(line)
if len(headers) > _MAXHEADERS:
raise HTTPException("got more than %d headers" % _MAXHEADERS)
if line in (b'\r\n', b'\n', b''):
break
hstring = bytes(b'').join(headers).decode('iso-8859-1')
return email_parser.Parser(_class=_class).parsestr(hstring)
示例2: message_from_string
# 需要导入模块: from future.backports.email import parser [as 别名]
# 或者: from future.backports.email.parser import Parser [as 别名]
def message_from_string(s, *args, **kws):
"""Parse a string into a Message object model.
Optional _class and strict are passed to the Parser constructor.
"""
from future.backports.email.parser import Parser
return Parser(*args, **kws).parsestr(s)
示例3: message_from_bytes
# 需要导入模块: from future.backports.email import parser [as 别名]
# 或者: from future.backports.email.parser import Parser [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 future.backports.email.parser import BytesParser
return BytesParser(*args, **kws).parsebytes(s)
示例4: message_from_file
# 需要导入模块: from future.backports.email import parser [as 别名]
# 或者: from future.backports.email.parser import Parser [as 别名]
def message_from_file(fp, *args, **kws):
"""Read a file and parse its contents into a Message object model.
Optional _class and strict are passed to the Parser constructor.
"""
from future.backports.email.parser import Parser
return Parser(*args, **kws).parse(fp)
示例5: message_from_binary_file
# 需要导入模块: from future.backports.email import parser [as 别名]
# 或者: from future.backports.email.parser import Parser [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 future.backports.email.parser import BytesParser
return BytesParser(*args, **kws).parse(fp)