~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/sftp.py

(vila) Make all transport put_bytes() raises TypeError when given unicode
 strings rather than bytes (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
593
593
                                    create_parent_dir=create_parent_dir,
594
594
                                    dir_mode=dir_mode)
595
595
 
596
 
    def put_bytes_non_atomic(self, relpath, bytes, mode=None,
 
596
    def put_bytes_non_atomic(self, relpath, raw_bytes, mode=None,
597
597
                             create_parent_dir=False,
598
598
                             dir_mode=None):
 
599
        if not isinstance(raw_bytes, str):
 
600
            raise TypeError(
 
601
                'raw_bytes must be a plain string, not %s' % type(raw_bytes))
 
602
 
599
603
        def writer(fout):
600
 
            fout.write(bytes)
 
604
            fout.write(raw_bytes)
601
605
        self._put_non_atomic_helper(relpath, writer, mode=mode,
602
606
                                    create_parent_dir=create_parent_dir,
603
607
                                    dir_mode=dir_mode)