This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Unicode support in email.Utils.encode
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: barry Nosy List: barry, loewis, mzabaluev
Priority: normal Keywords: patch

Created on 2001-12-07 23:11 by mzabaluev, last changed 2022-04-10 16:04 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Python-email-hdrencode.patch mzabaluev, 2001-12-07 23:11
Python-email-hdrencode.patch mzabaluev, 2001-12-11 22:52 isinstance instead of type
Messages (5)
msg38374 - (view) Author: Mikhail Zabaluev (mzabaluev) Date: 2001-12-07 23:11
It's essentially an updated patch 486375, this time
making a distinction of type for the passed string; if
it's Unicode, the function encodes it to the character
set specified as the charset parameter.
The reasons:
1. The function in its current version doesn't support
Unicode, throwing an exception if any non-ASCII
characters are found within it.
2. With this patch, we reach a sort of operational
symmetry on email.Utils.encode vs email.Utils.decode,
as it can be seen in the tests.
msg38375 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2001-12-11 18:28
Logged In: YES 
user_id=21627

The patch looks good, except that I cannot really see the
value in using "replace" for .encode. Wouldn't it be better
to get an exception if the Unicode string contains an
un-encodable character?

Also, the Python 2.2 way to spell the type test is

  if isinstance(s, unicode)

This makes use of the fact that the unicode builtin is a
type now, and it supports unicode subtypes. This is a minor
change, of course.
msg38376 - (view) Author: Mikhail Zabaluev (mzabaluev) Date: 2001-12-11 22:52
Logged In: YES 
user_id=313104

2loewis:
In a typical email application, it'd be better to display
partially encoded text than to face a hard stop when trying
to process a message, hence 'replace'. Actually, the
encoding mode could be an optional parameter, but I don't
feel like deciding on parameters for a function not
developed by me. Barry?
The isinstance part seems to be valid, I'm updating the
patch here accordingly.
msg38377 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2002-06-29 03:37
Logged In: YES 
user_id=12800

Sigh, sorry for taking so long to get to this.

email.Utils.encode() is deprecated now, and I'd actually
like to remove it rather than patch it. ;) 

Shouldn't the Header class be used instead?
msg38378 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2002-07-09 02:06
Logged In: YES 
user_id=12800

I'm changing the status to Pending since I think this patch
is no longer relevant given that email.Utils.encode() is
deprecated.
History
Date User Action Args
2022-04-10 16:04:44adminsetgithub: 35697
2001-12-07 23:11:51mzabaluevcreate