Header-encode a string by converting it first to bytes. The type of encoding (base64 or quoted-printable) will be based on this charset's `header_encoding`. :param string: A unicode string for the header. It must be possible to encode this string to bytes using
(self, string)
| 272 | return self.output_charset or self.input_charset |
| 273 | |
| 274 | def header_encode(self, string): |
| 275 | """Header-encode a string by converting it first to bytes. |
| 276 | |
| 277 | The type of encoding (base64 or quoted-printable) will be based on |
| 278 | this charset's `header_encoding`. |
| 279 | |
| 280 | :param string: A unicode string for the header. It must be possible |
| 281 | to encode this string to bytes using the character set's |
| 282 | output codec. |
| 283 | :return: The encoded string, with RFC 2047 chrome. |
| 284 | """ |
| 285 | codec = self.output_codec or 'us-ascii' |
| 286 | header_bytes = _encode(string, codec) |
| 287 | # 7bit/8bit encodings return the string unchanged (modulo conversions) |
| 288 | encoder_module = self._get_encoder(header_bytes) |
| 289 | if encoder_module is None: |
| 290 | return string |
| 291 | return encoder_module.header_encode(header_bytes, codec) |
| 292 | |
| 293 | def header_encode_lines(self, string, maxlengths): |
| 294 | """Header-encode a string by converting it first to bytes. |