Skip to content
This repository
Browse code

Python 2.5 compat!

  • Loading branch information...
commit 19861eee0b725e7a10bd6d56611b8ec5e1a5a4cc 1 parent 49d86a2
Ross Patterson authored March 15, 2012
6  pyramid_mailer/response.py
@@ -33,9 +33,6 @@
33 33
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 34
 # POSSIBILITY OF SUCH DAMAGE.
35 35
 
36  
-# BBB Python 2 vs 3 compat
37  
-from __future__ import unicode_literals
38  
-
39 36
 import os
40 37
 import sys
41 38
 import mimetypes
@@ -333,7 +330,8 @@ def to_message(mail):
333 330
 
334 331
     try:
335 332
         out = MIMEPart(ctype, **params)
336  
-    except TypeError as exc: # pragma: no cover
  333
+    except TypeError: # pragma: no cover
  334
+        exc = sys.exc_info()[1]
337 335
         raise EncodingError("Content-Type malformed, not allowed: %r; "
338 336
                             "%r (Python ERROR: %s" %
339 337
                             (ctype, params, exc.message))
30  pyramid_mailer/tests.py
... ...
@@ -1,11 +1,22 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3  
-# BBB Python 2 vs 3 compat
4  
-from __future__ import unicode_literals
5  
-
  3
+import sys
6 4
 import unittest
7 5
 import os
8  
-from io import StringIO
  6
+import errno
  7
+
  8
+# BBB Python 2.5 & 3 compat
  9
+try:
  10
+    str = unicode
  11
+except NameError:
  12
+    pass
  13
+
  14
+try:
  15
+    from io import StringIO
  16
+except ImportError:
  17
+    # BBB Python 2.5 compat
  18
+    from StringIO import StringIO
  19
+    
9 20
 
10 21
 from pyramid import testing
11 22
 
@@ -24,7 +35,7 @@ def test_data_from_file_obj(self):
24 35
 
25 36
         from pyramid_mailer.message import Attachment
26 37
 
27  
-        a = Attachment(data=StringIO("foo"))
  38
+        a = Attachment(data=StringIO(str("foo")))
28 39
         self.assert_(a.data == "foo")
29 40
 
30 41
 
@@ -440,9 +451,14 @@ def test_use_ssl_mailer(self):
440 451
             import socket
441 452
             try:
442 453
                 self.assert_(mailer.direct_delivery.mailer.smtp_factory())
443  
-            except socket.error as e:
  454
+            except socket.error:
  455
+                e = sys.exc_info()[1]
  456
+                error_number = e.args[0]
444 457
                 # smtp mailer might fail to resolve hostname
445  
-                self.assert_(e.args[0] == 61)
  458
+                self.assert_(error_number in
  459
+                             (errno.ENODATA,
  460
+                              errno.ECONNREFUSED  # BBB Python 2.5 compat
  461
+                              ))
446 462
 
447 463
                           
448 464
     def test_from_settings_factory(self):
2  tox.ini
... ...
@@ -1,6 +1,6 @@
1 1
 [tox]
2 2
 envlist = 
3  
-    py26,py27,py32,pypy,cover
  3
+    py25,py26,py27,py32,pypy,cover
4 4
 
5 5
 [testenv]
6 6
 commands = 

0 notes on commit 19861ee

Please sign in to comment.
Something went wrong with that request. Please try again.