mirror of
https://github.com/python/cpython.git
synced 2025-10-06 07:02:33 +00:00
#18891: Complete new provisional email API.
This adds EmailMessage and, MIMEPart subclasses of Message with new API methods, and a ContentManager class used by the new methods. Also a new policy setting, content_manager. Patch was reviewed by Stephen J. Turnbull and Serhiy Storchaka, and reflects their feedback. I will ideally add some examples of using the new API to the documentation before the final release.
This commit is contained in:
parent
1a16288197
commit
3da240fd01
15 changed files with 2539 additions and 26 deletions
|
@ -68,9 +68,13 @@ def _has_surrogates(s):
|
|||
# How to deal with a string containing bytes before handing it to the
|
||||
# application through the 'normal' interface.
|
||||
def _sanitize(string):
|
||||
# Turn any escaped bytes into unicode 'unknown' char.
|
||||
original_bytes = string.encode('ascii', 'surrogateescape')
|
||||
return original_bytes.decode('ascii', 'replace')
|
||||
# Turn any escaped bytes into unicode 'unknown' char. If the escaped
|
||||
# bytes happen to be utf-8 they will instead get decoded, even if they
|
||||
# were invalid in the charset the source was supposed to be in. This
|
||||
# seems like it is not a bad thing; a defect was still registered.
|
||||
original_bytes = string.encode('utf-8', 'surrogateescape')
|
||||
return original_bytes.decode('utf-8', 'replace')
|
||||
|
||||
|
||||
|
||||
# Helpers
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue