/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/mail_client.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-05 07:32:38 UTC
  • mto: (7290.1.21 work)
  • mto: This revision was merged to the branch mainline in revision 7311.
  • Revision ID: jelmer@jelmer.uk-20190305073238-zlqn981opwnqsmzi
Add appveyor configuration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
 
18
 
17
19
import errno
18
20
import os
19
21
import subprocess
30
32
    urlutils,
31
33
    registry,
32
34
    )
 
35
from .sixish import (
 
36
    PY3,
 
37
    text_type,
 
38
    )
33
39
 
34
40
mail_client_registry = registry.Registry()
35
41
 
166
172
            basename = 'attachment'
167
173
        pathname = osutils.mkdtemp(prefix='bzr-mail-')
168
174
        attach_path = osutils.pathjoin(pathname, basename + extension)
169
 
        with open(attach_path, 'wb') as outfile:
 
175
        outfile = open(attach_path, 'wb')
 
176
        try:
170
177
            outfile.write(attachment)
 
178
        finally:
 
179
            outfile.close()
171
180
        if body is not None:
172
181
            kwargs = {'body': body}
173
182
        else:
229
238
        :param  u:  possible unicode string.
230
239
        :return:    encoded string if u is unicode, u itself otherwise.
231
240
        """
 
241
        if not PY3 and isinstance(u, text_type):
 
242
            return u.encode(osutils.get_user_encoding(), 'replace')
232
243
        return u
233
244
 
234
245
    def _encode_path(self, path, kind):
240
251
                        path itself otherwise.
241
252
        :raise:         UnableEncodePath.
242
253
        """
 
254
        if not PY3 and isinstance(path, text_type):
 
255
            try:
 
256
                return path.encode(osutils.get_user_encoding())
 
257
            except UnicodeEncodeError:
 
258
                raise errors.UnableEncodePath(path, kind)
243
259
        return path
244
260
 
245
261