@@ -245,32 +245,26 @@ def append(self, s, charset=None, errors='strict'):
245245 that byte string, and a UnicodeError will be raised if the string
246246 cannot be decoded with that charset. If s is a Unicode string, then
247247 charset is a hint specifying the character set of the characters in
248- the string. In this case, when producing an RFC 2822 compliant header
249- using RFC 2047 rules, the Unicode string will be encoded using the
250- following charsets in order: us-ascii, the charset hint, utf-8. The
251- first character set not to provoke a UnicodeError is used .
248+ the string. In either case, when producing an RFC 2822 compliant
249+ header using RFC 2047 rules, the string will be encoded using the
250+ output codec of the charset. If the string cannot be encoded to the
251+ output codec, a UnicodeError will be raised .
252252
253- Optional `errors' is passed as the third argument to any unicode() or
254- ustr.encode() call.
253+ Optional `errors' is passed as the errors argument to the decode
254+ call if s is a byte string .
255255 """
256256 if charset is None :
257257 charset = self ._charset
258258 elif not isinstance (charset , Charset ):
259259 charset = Charset (charset )
260- if isinstance (s , str ):
261- # Convert the string from the input character set to the output
262- # character set and store the resulting bytes and the charset for
263- # composition later.
260+ if not isinstance (s , str ):
264261 input_charset = charset .input_codec or 'us-ascii'
265- input_bytes = s .encode (input_charset , errors )
266- else :
267- # We already have the bytes we will store internally.
268- input_bytes = s
262+ s = s .decode (input_charset , errors )
269263 # Ensure that the bytes we're storing can be decoded to the output
270264 # character set, otherwise an early error is thrown.
271265 output_charset = charset .output_codec or 'us-ascii'
272- output_string = input_bytes . decode (output_charset , errors )
273- self ._chunks .append ((output_string , charset ))
266+ s . encode (output_charset , errors )
267+ self ._chunks .append ((s , charset ))
274268
275269 def encode (self , splitchars = ';, \t ' , maxlinelen = None , linesep = '\n ' ):
276270 """Encode a message header into an RFC-compliant format.
0 commit comments