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

Function body_encode

Lib/email/base64mime.py:73–94  ·  view source on GitHub ↗

r"""Encode a string with base64. Each line will be wrapped at, at most, maxlinelen characters (defaults to 76 characters). Each line of encoded text will end with eol, which defaults to "\n". Set this to "\r\n" if you will be using the result of this function directly in an em

(s, maxlinelen=76, eol=NL)

Source from the content-addressed store, hash-verified

71
72
73def body_encode(s, maxlinelen=76, eol=NL):
74 r"""Encode a string with base64.
75
76 Each line will be wrapped at, at most, maxlinelen characters (defaults to
77 76 characters).
78
79 Each line of encoded text will end with eol, which defaults to "\n". Set
80 this to "\r\n" if you will be using the result of this function directly
81 in an email.
82 """
83 if not s:
84 return ""
85
86 if not eol:
87 return b2a_base64(s, newline=False).decode("ascii")
88
89 # BAW: should encode() inherit b2a_base64()'s dubious behavior in
90 # adding a newline to the encoded string?
91 enc = b2a_base64(s, wrapcol=maxlinelen).decode("ascii")
92 if eol != NL:
93 enc = enc.replace(NL, eol)
94 return enc
95
96
97def decode(string):

Callers

nothing calls this directly

Calls 2

decodeMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…