MCPcopy Index your code
hub / github.com/python/cpython / header_encode

Method header_encode

Lib/email/charset.py:274–291  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 2

formataddrFunction · 0.95
test_codec_encodeableMethod · 0.95

Calls 2

_get_encoderMethod · 0.95
_encodeFunction · 0.70

Tested by 1

test_codec_encodeableMethod · 0.76