Permalink
Browse files

Squash some Python 3 deprecation warnings

  • Loading branch information...
1 parent 5c0d9b4 commit feb9d814536434e2d0deb1f8f707673f6fda5984 @rpatterson rpatterson committed Mar 20, 2013
Showing with 18 additions and 4 deletions.
  1. +10 −2 pyramid_mailer/response.py
  2. +8 −2 pyramid_mailer/tests.py
View
12 pyramid_mailer/response.py
@@ -33,14 +33,22 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
-import base64
import os
import quopri
import sys
import mimetypes
import string
from email.mime.base import MIMEBase
+try:
+ from base64 import encodebytes as base64_encodebytes
+ # pyflakes
+ base64_encodebytes # pragma: no cover
+except ImportError:
+ # BBB Python 2 compat
+ from base64 import encodestring as base64_encodebytes
+
+
from repoze.sendmail import encoding
@@ -427,7 +435,7 @@ def is_nonstr_iter(v): # pragma: no cover
def encode_string(encoding, data):
encoded = data
if encoding == 'base64':
- encoded = base64.encodestring(data).decode('ascii')
+ encoded = base64_encodebytes(data).decode('ascii')
elif encoding == 'quoted-printable':
encoded = quopri.encodestring(data).decode('ascii')
return encoded
View
10 pyramid_mailer/tests.py
@@ -962,7 +962,13 @@ def test_to_message_multipart_with_b64encoding(self):
from pyramid_mailer.response import MIMEPart
response = self._makeOne(To='To', From='From', Subject='Subject',
Body='Body', Html='Html')
- import base64
+ try:
+ from base64 import encodebytes as base64_encodebytes
+ # pyflakes
+ base64_encodebytes # pragma: no cover
+ except ImportError: # pragma: no cover
+ # BBB Python 2 compat
+ from base64 import encodestring as base64_encodebytes
import os
this = os.path.abspath(__file__)
data = self._read_filedata(this, mode='rb')
@@ -974,7 +980,7 @@ def test_to_message_multipart_with_b64encoding(self):
payload = message.get_payload()[0]
self.assertEqual(payload.get('Content-Transfer-Encoding'), 'base64')
self.assertEqual(payload.get_payload(),
- base64.encodestring(data).decode('ascii'))
+ base64_encodebytes(data).decode('ascii'))
def test_to_message_multipart_with_qpencoding(self):
from pyramid_mailer.response import MIMEPart

0 comments on commit feb9d81

Please sign in to comment.