marrow / mailer

A light-weight, modular, message representation and mail delivery framework for Python.
MIT License
278 stars 62 forks source link

marrow.mailer fails to load configuration directives in Python 2.6 with unicode_literals #2

Closed namn closed 13 years ago

namn commented 13 years ago

This code throws a TypeError:

from __future__ import unicode_literals

from datetime import datetime
import logging
from marrow.mailer import Message, Delivery
logging.basicConfig(level=logging.DEBUG)

mail = Delivery({
    'manager': 'immediate',
    'transport': 'smtp',
    'transport.host': 'secure.emailsrvr.com',
    'transport.tls': 'ssl',
    'transport.username': '',
    'transport.password': '',
    'transport.pipeline': 5
})

mail.start()
mail.stop()
amcgregor commented 13 years ago

This is a combination of two problems: first, is that the _load method of Delivery assumes non-strings to be instantiated objects; changing this to marrow.util.compat.basestring resolves this, though passing a bytes value in 3.x will remain an error.

Additionally, Python 2.x's built-in network libraries require string values for things like host and username/password, wrapping the configuration loading lines in marrow.mailer.transport.smtp.SMTPTransport.__init__ in marrow.util.compat.native resolves this and should protect against using bytes values in Python 3.x as well.