~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smtp_connection.py

  • Committer: James Henstridge
  • Date: 2009-03-16 07:24:59 UTC
  • mto: This revision was merged to the branch mainline in revision 4203.
  • Revision ID: james@jamesh.id.au-20090316072459-b26rgmv3lln2j8he
Ensure that byte strings are passed to SMTP.login(), as passing unicode 
does not make sense and breaks in Python 2.6.

Show diffs side-by-side

added added

removed removed

Lines of Context:
111
111
            self._smtp_password = auth.get_password(
112
112
                'smtp', self._smtp_server, self._smtp_username)
113
113
 
 
114
        # smtplib requires that the username and password be byte
 
115
        # strings (and the relevant RFCs don't seem to address
 
116
        # character encoding for usernames and passwords).
 
117
        if isinstance(self._smtp_username, unicode):
 
118
            self._smtp_username = self._smtp_username.encode('ascii')
 
119
        if isinstance(self._smtp_password, unicode):
 
120
            self._smtp_password = self._smtp_password.encode('ascii')
 
121
 
114
122
        self._connection.login(self._smtp_username, self._smtp_password)
115
123
 
116
124
    @staticmethod