Back to index

python3.2  3.2.2
Functions | Variables
email.base64mime Namespace Reference

Functions

def header_length
def header_encode
def body_encode
def decode

Variables

list __all__
string CRLF = '\r\n'
string NL = '\n'
string EMPTYSTRING = ''
int MISC_LEN = 7
 body_decode = decode
 decodestring = decode

Function Documentation

def email.base64mime.body_encode (   s,
  maxlinelen = 76,
  eol = NL 
)

Definition at line 76 of file base64mime.py.

00076 
00077 def body_encode(s, maxlinelen=76, eol=NL):
00078     r"""Encode a string with base64.
00079 
00080     Each line will be wrapped at, at most, maxlinelen characters (defaults to
00081     76 characters).
00082 
00083     Each line of encoded text will end with eol, which defaults to "\n".  Set
00084     this to "\r\n" if you will be using the result of this function directly
00085     in an email.
00086     """
00087     if not s:
00088         return s
00089 
00090     encvec = []
00091     max_unencoded = maxlinelen * 3 // 4
00092     for i in range(0, len(s), max_unencoded):
00093         # BAW: should encode() inherit b2a_base64()'s dubious behavior in
00094         # adding a newline to the encoded string?
00095         enc = b2a_base64(s[i:i + max_unencoded]).decode("ascii")
00096         if enc.endswith(NL) and eol != NL:
00097             enc = enc[:-1] + eol
00098         encvec.append(enc)
00099     return EMPTYSTRING.join(encvec)
00100 
00101 


Here is the call graph for this function:

Here is the caller graph for this function:

def email.base64mime.decode (   string)
Decode a raw base64 string, returning a bytes object.

This function does not parse a full MIME header value encoded with
base64 (like =?iso-8895-1?b?bmloISBuaWgh?=) -- please use the high
level email.header class for that functionality.

Definition at line 102 of file base64mime.py.

00102 
00103 def decode(string):
00104     """Decode a raw base64 string, returning a bytes object.
00105 
00106     This function does not parse a full MIME header value encoded with
00107     base64 (like =?iso-8895-1?b?bmloISBuaWgh?=) -- please use the high
00108     level email.header class for that functionality.
00109     """
00110     if not string:
00111         return bytes()
00112     elif isinstance(string, str):
00113         return a2b_base64(string.encode('raw-unicode-escape'))
00114     else:
00115         return a2b_base64(string)
00116 
00117 
# For convenience and backwards compatibility w/ standard base64 module

Here is the caller graph for this function:

def email.base64mime.header_encode (   header_bytes,
  charset = 'iso-8859-1' 
)
Encode a single header line with Base64 encoding in a given charset.

charset names the character set to use to encode the header.  It defaults
to iso-8859-1.  Base64 encoding is defined in RFC 2045.

Definition at line 61 of file base64mime.py.

00061 
00062 def header_encode(header_bytes, charset='iso-8859-1'):
00063     """Encode a single header line with Base64 encoding in a given charset.
00064 
00065     charset names the character set to use to encode the header.  It defaults
00066     to iso-8859-1.  Base64 encoding is defined in RFC 2045.
00067     """
00068     if not header_bytes:
00069         return ""
00070     if isinstance(header_bytes, str):
00071         header_bytes = header_bytes.encode(charset)
00072     encoded = b64encode(header_bytes).decode("ascii")
00073     return '=?%s?b?%s?=' % (charset, encoded)
00074 
00075 


Here is the call graph for this function:

def email.base64mime.header_length (   bytearray)
Return the length of s when it is encoded with base64.

Definition at line 50 of file base64mime.py.

00050 
00051 def header_length(bytearray):
00052     """Return the length of s when it is encoded with base64."""
00053     groups_of_3, leftover = divmod(len(bytearray), 3)
00054     # 4 bytes out for each 3 bytes (or nonzero fraction thereof) in.
00055     n = groups_of_3 * 4
00056     if leftover:
00057         n += 4
00058     return n
00059 
00060 


Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Initial value:
00001 [
00002     'body_decode',
00003     'body_encode',
00004     'decode',
00005     'decodestring',
00006     'header_encode',
00007     'header_length',
00008     ]

Definition at line 27 of file base64mime.py.

Definition at line 118 of file base64mime.py.

Definition at line 40 of file base64mime.py.

Definition at line 119 of file base64mime.py.

Definition at line 42 of file base64mime.py.

Definition at line 45 of file base64mime.py.

Definition at line 41 of file base64mime.py.