本文整理匯總了Python中email._policybase.Compat32方法的典型用法代碼示例。如果您正苦於以下問題:Python _policybase.Compat32方法的具體用法?Python _policybase.Compat32怎麽用?Python _policybase.Compat32使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類email._policybase
的用法示例。
在下文中一共展示了_policybase.Compat32方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: header_max_count
# 需要導入模塊: from email import _policybase [as 別名]
# 或者: from email._policybase import Compat32 [as 別名]
def header_max_count(self, name):
"""+
The implementation for this class returns the max_count attribute from
the specialized header class that would be used to construct a header
of type 'name'.
"""
return self.header_factory[name].max_count
# The logic of the next three methods is chosen such that it is possible to
# switch a Message object between a Compat32 policy and a policy derived
# from this class and have the results stay consistent. This allows a
# Message object constructed with this policy to be passed to a library
# that only handles Compat32 objects, or to receive such an object and
# convert it to use the newer style by just changing its policy. It is
# also chosen because it postpones the relatively expensive full rfc5322
# parse until as late as possible when parsing from source, since in many
# applications only a few headers will actually be inspected.
示例2: header_source_parse
# 需要導入模塊: from email import _policybase [as 別名]
# 或者: from email._policybase import Compat32 [as 別名]
def header_source_parse(self, sourcelines):
"""+
The name is parsed as everything up to the ':' and returned unmodified.
The value is determined by stripping leading whitespace off the
remainder of the first line, joining all subsequent lines together, and
stripping any trailing carriage return or linefeed characters. (This
is the same as Compat32).
"""
name, value = sourcelines[0].split(':', 1)
value = value.lstrip(' \t') + ''.join(sourcelines[1:])
return (name, value.rstrip('\r\n'))
示例3: _build_fetch_response
# 需要導入模塊: from email import _policybase [as 別名]
# 或者: from email._policybase import Compat32 [as 別名]
def _build_fetch_response(self, message, parts, by_uid=True):
response = ('%d FETCH (UID %s' % (message.id, message.uid)).encode() if by_uid \
else ('%d FETCH (' % message.id).encode()
for part in parts:
if part.startswith('(') or part.endswith(')'):
part = part.strip('()')
if not response.endswith(b' ') and not response.endswith(b'('):
response += b' '
if part == 'UID' and not by_uid:
response += ('UID %s' % message.uid).encode()
if part == 'BODY[]' or part == 'BODY.PEEK[]' or part == 'RFC822':
response += ('%s {%s}\r\n' % (part, len(message.as_bytes()))).encode() + message.as_bytes()
if part == 'BODY.PEEK[HEADER.FIELDS':
fetch_header = FETCH_HEADERS_RE.match(' '.join(parts))
if fetch_header:
headers = fetch_header.group('headers')
message_headers = Message(policy=Compat32(linesep='\r\n'))
for hk in headers.split():
message_headers[hk] = message.email.get(hk, '')
response += ('BODY[HEADER.FIELDS (%s)] {%d}\r\n' %
(headers, len(message_headers.as_bytes()))).encode() + message_headers.as_bytes()
if part == 'FLAGS':
response += ('FLAGS (%s)' % ' '.join(message.flags)).encode()
response = response.strip(b' ')
response += b')'
return response