Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 2.5 compat! #13

Merged
merged 6 commits into from
Mar 20, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -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+.

Expand Down
2 changes: 1 addition & 1 deletion pyramid_mailer/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions pyramid_mailer/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
62 changes: 55 additions & 7 deletions pyramid_mailer/tests.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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")


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py26,py27,py32,pypy,cover
py25,py26,py27,py32,pypy,jython,cover

[testenv]
commands =
Expand Down