~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/local.py

  • Committer: Vincent Ladeuil
  • Date: 2016-01-21 17:48:07 UTC
  • mto: This revision was merged to the branch mainline in revision 6613.
  • Revision ID: v.ladeuil+lp@free.fr-20160121174807-g4ybpaij9ln5wj6a
Make all transport put_bytes() raises TypeError when given unicode strings rather than bytes.

There was a mix of AssertionError or UnicodeEncodeError.

Also deleted test_put_file_unicode() which was bogus, files contain bytes not unicode strings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2012, 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
184
184
            fp.close()
185
185
        return length
186
186
 
187
 
    def put_bytes(self, relpath, bytes, mode=None):
 
187
    def put_bytes(self, relpath, raw_bytes, mode=None):
188
188
        """Copy the string into the location.
189
189
 
190
190
        :param relpath: Location to put the contents, relative to base.
191
191
        :param bytes:   String
192
192
        """
193
 
 
 
193
        if not isinstance(raw_bytes, str):
 
194
            raise TypeError(
 
195
                'raw_bytes must be a plain string, not %s' % type(raw_bytes))
194
196
        path = relpath
195
197
        try:
196
198
            path = self._abspath(relpath)
200
202
            self._translate_error(e, path)
201
203
        try:
202
204
            if bytes:
203
 
                fp.write(bytes)
 
205
                fp.write(raw_bytes)
204
206
            fp.commit()
205
207
        finally:
206
208
            fp.close()