summaryrefslogtreecommitdiffstats
path: root/Lib/email/base64mime.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2007-08-30 02:10:49 (GMT)
committerBarry Warsaw <barry@python.org>2007-08-30 02:10:49 (GMT)
commit8b3d659692b6d092991dc3b5b4042547f885fa8c (patch)
tree49fc0c7a89c31479389f2dfb38d71f519ba4cb23 /Lib/email/base64mime.py
parentce36ad8a467d914eb5c91f33835b9eaea18ee93b (diff)
downloadcpython-8b3d659692b6d092991dc3b5b4042547f885fa8c.zip
cpython-8b3d659692b6d092991dc3b5b4042547f885fa8c.tar.gz
cpython-8b3d659692b6d092991dc3b5b4042547f885fa8c.tar.bz2
Fix a more bytes/str confusion.
Use str.encode('raw-unicode-escape') consistently instead of bytes(string). Remove the convert_eols argument from base64mime.decode(). This matches previous API changes done to the quoprimime module.
Diffstat (limited to 'Lib/email/base64mime.py')
-rw-r--r--Lib/email/base64mime.py28
1 files changed, 11 insertions, 17 deletions
diff --git a/Lib/email/base64mime.py b/Lib/email/base64mime.py
index 0319bbb..e309f30 100644
--- a/Lib/email/base64mime.py
+++ b/Lib/email/base64mime.py
@@ -109,7 +109,7 @@ def header_encode(header, charset='iso-8859-1', keep_eols=False,
lines = []
for line in base64ed:
# Ignore the last character of each line if it is a newline
- if line.endswith(NL):
+ if line[-1] == ord(NL):
line = line[:-1]
# Add the chrome
lines.append('=?%s?b?%s?=' % (charset, line))
@@ -158,25 +158,19 @@ encodestring = encode
-def decode(s, convert_eols=False):
+def decode(string):
"""Decode a raw base64 string, returning a bytes object.
- If convert_eols is set to a string value, all canonical email linefeeds,
- e.g. "\\r\\n", in the decoded text will be converted to the value of
- convert_eols. os.linesep is a good choice for convert_eols if you are
- decoding a text attachment.
-
- 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.
+ This function does not parse a full MIME header value encoded with base64
+ (like =?iso-8895-1?b?bmloISBuaWgh?=) -- use the high level
+ email.Header class for that functionality.
"""
- if not s:
- return s
-
- dec = a2b_base64(s)
- if convert_eols:
- return dec.replace(CRLF, convert_eols)
- return dec
+ if not string:
+ return bytes()
+ elif isinstance(string, str):
+ return a2b_base64(string.encode('raw-unicode-escape'))
+ else:
+ return a2b_base64(string)
# For convenience and backwards compatibility w/ standard base64 module