Django

Code

Show
Ignore:
Timestamp:
03/21/08 16:52:34 (4 months ago)
Author:
gwilson
Message:

Fixed some styling issues in django/core/mail.py.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/mail.py

    r7349 r7350  
    33""" 
    44 
    5 from django.conf import settings 
    6 from django.utils.encoding import smart_str, force_unicode 
     5import mimetypes 
     6import os 
     7import smtplib 
     8import socket 
     9import time 
     10import random 
    711from email import Charset, Encoders 
    812from email.MIMEText import MIMEText 
     
    1115from email.Header import Header 
    1216from email.Utils import formatdate, parseaddr, formataddr 
    13 import mimetypes 
    14 import os 
    15 import smtplib 
    16 import socket 
    17 import time 
    18 import random 
     17 
     18from django.conf import settings 
     19from django.utils.encoding import smart_str, force_unicode 
    1920 
    2021# Don't BASE64-encode UTF-8 messages so that we avoid unwanted attention from 
     
    7071 
    7172def forbid_multi_line_headers(name, val): 
    72     "Forbids multi-line headers, to prevent header injection.
     73    """Forbids multi-line headers, to prevent header injection.""
    7374    if '\n' in val or '\r' in val: 
    7475        raise BadHeaderError("Header values can't contain newlines (got %r for header %r)" % (val, name)) 
     
    103104 
    104105    def __init__(self, host=None, port=None, username=None, password=None, 
    105             use_tls=None, fail_silently=False): 
     106                 use_tls=None, fail_silently=False): 
    106107        self.host = host or settings.EMAIL_HOST 
    107108        self.port = port or settings.EMAIL_PORT 
     
    114115    def open(self): 
    115116        """ 
    116         Ensure we have a connection to the email server. Returns whether or not 
    117         a new connection was required
     117        Ensures we have a connection to the email server. Returns whether or 
     118        not a new connection was required (True or False)
    118119        """ 
    119120        if self.connection: 
     
    137138 
    138139    def close(self): 
    139         """Close the connection to the email server.""" 
     140        """Closes the connection to the email server.""" 
    140141        try: 
    141142            try: 
     
    154155    def send_messages(self, email_messages): 
    155156        """ 
    156         Send one or more EmailMessage objects and return the number of email 
     157        Sends one or more EmailMessage objects and returns the number of email 
    157158        messages sent. 
    158159        """ 
     
    197198            connection=None, attachments=None, headers=None): 
    198199        """ 
    199         Initialise a single email message (which can be sent to multiple 
     200        Initialize a single email message (which can be sent to multiple 
    200201        recipients). 
    201202 
     
    226227    def message(self): 
    227228        encoding = self.encoding or settings.DEFAULT_CHARSET 
    228         msg = SafeMIMEText(smart_str(self.body, settings.DEFAULT_CHARSET), self.content_subtype, encoding) 
     229        msg = SafeMIMEText(smart_str(self.body, settings.DEFAULT_CHARSET), 
     230                           self.content_subtype, encoding) 
    229231        if self.attachments: 
    230232            body_msg = msg 
     
    254256 
    255257    def send(self, fail_silently=False): 
    256         """Send the email message.""" 
     258        """Sends the email message.""" 
    257259        return self.get_connection(fail_silently).send_messages([self]) 
    258260 
     
    281283    def _create_attachment(self, filename, content, mimetype=None): 
    282284        """ 
    283         Convert the filename, content, mimetype triple into a MIME attachment 
     285        Converts the filename, content, mimetype triple into a MIME attachment 
    284286        object. 
    285287        """ 
     
    298300            Encoders.encode_base64(attachment) 
    299301        if filename: 
    300             attachment.add_header('Content-Disposition', 'attachment', filename=filename) 
     302            attachment.add_header('Content-Disposition', 'attachment', 
     303                                  filename=filename) 
    301304        return attachment 
    302305 
     
    313316        self.attach(content=content, mimetype=mimetype) 
    314317 
    315 def send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=None, auth_password=None): 
     318def send_mail(subject, message, from_email, recipient_list, 
     319              fail_silently=False, auth_user=None, auth_password=None): 
    316320    """ 
    317321    Easy wrapper for sending a single message to a recipient list. All members 
     
    325329    """ 
    326330    connection = SMTPConnection(username=auth_user, password=auth_password, 
    327                                  fail_silently=fail_silently) 
    328     return EmailMessage(subject, message, from_email, recipient_list, connection=connection).send() 
    329  
    330 def send_mass_mail(datatuple, fail_silently=False, auth_user=None, auth_password=None): 
     331                                fail_silently=fail_silently) 
     332    return EmailMessage(subject, message, from_email, recipient_list, 
     333                        connection=connection).send() 
     334 
     335def send_mass_mail(datatuple, fail_silently=False, auth_user=None, 
     336                   auth_password=None): 
    331337    """ 
    332338    Given a datatuple of (subject, message, from_email, recipient_list), sends 
     
    342348    """ 
    343349    connection = SMTPConnection(username=auth_user, password=auth_password, 
    344                                  fail_silently=fail_silently) 
    345     messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple] 
     350                                fail_silently=fail_silently) 
     351    messages = [EmailMessage(subject, message, sender, recipient) 
     352                for subject, message, sender, recipient in datatuple] 
    346353    return connection.send_messages(messages) 
    347354 
    348355def mail_admins(subject, message, fail_silently=False): 
    349     "Sends a message to the admins, as defined by the ADMINS setting.
     356    """Sends a message to the admins, as defined by the ADMINS setting.""
    350357    EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message, 
    351             settings.SERVER_EMAIL, [a[1] for a in 
    352                 settings.ADMINS]).send(fail_silently=fail_silently) 
     358                 settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS] 
     359                ).send(fail_silently=fail_silently) 
    353360 
    354361def mail_managers(subject, message, fail_silently=False): 
    355     "Sends a message to the managers, as defined by the MANAGERS setting.
     362    """Sends a message to the managers, as defined by the MANAGERS setting.""
    356363    EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message, 
    357             settings.SERVER_EMAIL, [a[1] for a in 
    358                 settings.MANAGERS]).send(fail_silently=fail_silently) 
    359  
     364                 settings.SERVER_EMAIL, [a[1] for a in settings.MANAGERS] 
     365                 ).send(fail_silently=fail_silently)