Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Python 2.5 compat! #13

Merged
merged 6 commits into from

2 participants

Commits on Mar 15, 2012
  1. @rpatterson

    Python 2.5 compat!

    rpatterson authored
  2. @mcdonc @rpatterson

    dont shadow a global

    mcdonc authored rpatterson committed
  3. @mcdonc @rpatterson

    add changes

    mcdonc authored rpatterson committed
  4. @rpatterson
  5. @rpatterson

    Merge remote-tracking branch 'upstream/master'

    rpatterson authored
    Conflicts:
    	CHANGES.txt
  6. @rpatterson
This page is out of date. Refresh to see the latest.
View
5 CHANGES.txt
@@ -1,10 +1,7 @@
Next release
------------
-- Python 3.2 compatibility.
-
-- No longer compatible with Python 2.5 (and therefore no longer compatible
- with the current version of Jython).
+- Python 2.5, 2.6, 2.7, 3.2, jython and pypy compatibility.
- Requires repoze.sendmail 3.0+.
View
2  pyramid_mailer/message.py
@@ -136,7 +136,7 @@ def validate(self):
Checks if message is valid and raises appropriate exception.
"""
- if not self.recipients:
+ if not (self.recipients or self.cc or self.bcc):
raise InvalidMessage("No recipients have been added")
if not self.body and not self.html:
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
62 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")
@@ -147,6 +158,38 @@ def test_cc(self):
response = msg.get_response()
self.assert_("Cc: tosomeoneelse@example.com" in str(response))
+ def test_cc_without_recipients(self):
+
+ from pyramid_mailer.message import Message
+ from pyramid_mailer.mailer import Mailer
+
+ msg = Message(subject="testing",
+ sender="sender@example.com",
+ body="testing",
+ cc=["tosomeoneelse@example.com"])
+ mailer = Mailer()
+ msgid = mailer.send(msg)
+ response = msg.get_response()
+
+ self.assertTrue("Cc: tosomeoneelse@example.com" in str(response))
+ self.assertTrue(msgid)
+
+ def test_bcc_without_recipients(self):
+
+ from pyramid_mailer.message import Message
+ from pyramid_mailer.mailer import Mailer
+
+ msg = Message(subject="testing",
+ sender="sender@example.com",
+ body="testing",
+ bcc=["tosomeoneelse@example.com"])
+ mailer = Mailer()
+ msgid = mailer.send(msg)
+ response = msg.get_response()
+
+ self.assertFalse("Bcc: tosomeoneelse@example.com" in str(response))
+ self.assertTrue(msgid)
+
def test_attach(self):
from pyramid_mailer.message import Message
@@ -440,9 +483,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,jython,cover
[testenv]
commands =
Something went wrong with that request. Please try again.