Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Python 2.5 compat!

  • Loading branch information...
commit 19861eee0b725e7a10bd6d56611b8ec5e1a5a4cc 1 parent 49d86a2
@rpatterson rpatterson authored
Showing with 26 additions and 12 deletions.
  1. +2 −4 pyramid_mailer/response.py
  2. +23 −7 pyramid_mailer/tests.py
  3. +1 −1  tox.ini
View
6 pyramid_mailer/response.py
@@ -33,9 +33,6 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
-# BBB Python 2 vs 3 compat
-from __future__ import unicode_literals
-
import os
import sys
import mimetypes
@@ -333,7 +330,8 @@ def to_message(mail):
try:
out = MIMEPart(ctype, **params)
- except TypeError as exc: # pragma: no cover
+ except TypeError: # pragma: no cover
+ exc = sys.exc_info()[1]
raise EncodingError("Content-Type malformed, not allowed: %r; "
"%r (Python ERROR: %s" %
(ctype, params, exc.message))
View
30 pyramid_mailer/tests.py
@@ -1,11 +1,22 @@
# -*- coding: utf-8 -*-
-# BBB Python 2 vs 3 compat
-from __future__ import unicode_literals
-
+import sys
import unittest
import os
-from io import StringIO
+import errno
+
+# BBB Python 2.5 & 3 compat
+try:
+ str = unicode
+except NameError:
+ pass
+
+try:
+ from io import StringIO
+except ImportError:
+ # BBB Python 2.5 compat
+ from StringIO import StringIO
+
from pyramid import testing
@@ -24,7 +35,7 @@ def test_data_from_file_obj(self):
from pyramid_mailer.message import Attachment
- a = Attachment(data=StringIO("foo"))
+ a = Attachment(data=StringIO(str("foo")))
self.assert_(a.data == "foo")
@@ -440,9 +451,14 @@ def test_use_ssl_mailer(self):
import socket
try:
self.assert_(mailer.direct_delivery.mailer.smtp_factory())
- except socket.error as e:
+ except socket.error:
+ e = sys.exc_info()[1]
+ error_number = e.args[0]
# smtp mailer might fail to resolve hostname
- self.assert_(e.args[0] == 61)
+ self.assert_(error_number in
+ (errno.ENODATA,
+ errno.ECONNREFUSED # BBB Python 2.5 compat
+ ))
def test_from_settings_factory(self):
View
2  tox.ini
@@ -1,6 +1,6 @@
[tox]
envlist =
- py26,py27,py32,pypy,cover
+ py25,py26,py27,py32,pypy,cover
[testenv]
commands =
Please sign in to comment.
Something went wrong with that request. Please try again.