thirdparty/google_appengine/google/appengine/api/mail_stub.py
changeset 686 df109be0567c
parent 109 620f9b141567
child 1278 a7766286a7be
equal deleted inserted replaced
685:a440ced9a75f 686:df109be0567c
    29 import mail
    29 import mail
    30 import mimetypes
    30 import mimetypes
    31 import subprocess
    31 import subprocess
    32 import smtplib
    32 import smtplib
    33 
    33 
    34 
    34 from google.appengine.api import apiproxy_stub
    35 class ServiceStub(object):
    35 
    36   """Service stub base class used to forward requests to methods.
    36 
    37 
    37 class MailServiceStub(apiproxy_stub.APIProxyStub):
    38   Use this base class to defined service stub classes.  Instead of overriding
       
    39   MakeSyncCall, the default implementation forwards the call to appropriate
       
    40   sub-class method.
       
    41 
       
    42   If the sub class defines a static string 'SERVICE', it will also check
       
    43   to make sure that calls to this service stub are always made to that named
       
    44   service.
       
    45   """
       
    46 
       
    47   def MakeSyncCall(self, service, call, request, response):
       
    48     """The main RPC entry point.
       
    49 
       
    50     Args:
       
    51       service: Must be name as defined by sub class variable SERVICE.
       
    52       call: A string representing the rpc to make.  Must be part of
       
    53         MailService.
       
    54       request: A protocol buffer of the type corresponding to 'call'.
       
    55       response: A protocol buffer of the type corresponding to 'call'.
       
    56     """
       
    57     assert not hasattr(self, 'SERVICE') or service == self.SERVICE
       
    58     explanation = []
       
    59     assert request.IsInitialized(explanation), explanation
       
    60 
       
    61     attr = getattr(self, '_Dynamic_' + call)
       
    62     attr(request, response)
       
    63 
       
    64 
       
    65 class MailServiceStub(ServiceStub):
       
    66   """Python only mail service stub.
    38   """Python only mail service stub.
    67 
    39 
    68   This stub does not actually attempt to send email.  instead it merely logs
    40   This stub does not actually attempt to send email.  instead it merely logs
    69   a description of the email to the developers console.
    41   a description of the email to the developers console.
    70 
    42 
    72     host: Host of SMTP server to use.  Blank disables sending SMTP.
    44     host: Host of SMTP server to use.  Blank disables sending SMTP.
    73     port: Port of SMTP server to use.
    45     port: Port of SMTP server to use.
    74     user: User to log in to SMTP server as.
    46     user: User to log in to SMTP server as.
    75     password: Password for SMTP server user.
    47     password: Password for SMTP server user.
    76   """
    48   """
    77   SERVICE = 'mail'
       
    78 
    49 
    79   def __init__(self,
    50   def __init__(self,
    80                host=None,
    51                host=None,
    81                port=25,
    52                port=25,
    82                user='',
    53                user='',
    83                password='',
    54                password='',
    84                enable_sendmail=False,
    55                enable_sendmail=False,
    85                show_mail_body=False):
    56                show_mail_body=False,
       
    57                service_name='mail'):
       
    58     """Constructor.
       
    59 
       
    60     Args:
       
    61       host: Host of SMTP mail server.
       
    62       post: Port of SMTP mail server.
       
    63       user: Sending user of SMTP mail.
       
    64       password: SMTP password.
       
    65       enable_sendmail: Whether sendmail enabled or not.
       
    66       show_mail_body: Whether to show mail body in log.
       
    67       service_name: Service name expected for all calls.
       
    68     """
       
    69     super(MailServiceStub, self).__init__(service_name)
    86     self._smtp_host = host
    70     self._smtp_host = host
    87     self._smtp_port = port
    71     self._smtp_port = port
    88     self._smtp_user = user
    72     self._smtp_user = user
    89     self._smtp_password = password
    73     self._smtp_password = password
    90     self._enable_sendmail = enable_sendmail
    74     self._enable_sendmail = enable_sendmail