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

Function encode_7or8bit

Lib/email/encoders.py:47–61  ·  view source on GitHub ↗

Set the Content-Transfer-Encoding header to 7bit or 8bit.

(msg)

Source from the content-addressed store, hash-verified

45
46
47def encode_7or8bit(msg):
48 """Set the Content-Transfer-Encoding header to 7bit or 8bit."""
49 orig = msg.get_payload(decode=True)
50 if orig is None:
51 # There's no payload. For backwards compatibility we use 7bit
52 msg['Content-Transfer-Encoding'] = '7bit'
53 return
54 # We play a trick to make this go fast. If decoding from ASCII succeeds,
55 # we know the data must be 7bit, otherwise treat it as 8bit.
56 try:
57 orig.decode('ascii')
58 except UnicodeError:
59 msg['Content-Transfer-Encoding'] = '8bit'
60 else:
61 msg['Content-Transfer-Encoding'] = '7bit'
62
63
64def encode_noop(msg):

Callers

nothing calls this directly

Calls 2

get_payloadMethod · 0.80
decodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…