~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockable_files.py

  • Committer: John Arbash Meinel
  • Date: 2007-02-09 23:39:24 UTC
  • mto: This revision was merged to the branch mainline in revision 2294.
  • Revision ID: john@arbash-meinel.com-20070209233924-k7qbjpta67k3ry2h
Audit Branch to ensure utf8 revision ids.
Requires a small update to lockable_files to allow us to directly
write byte strings, without needing to wrap in a StringIO

Show diffs side-by-side

added added

removed removed

Lines of Context:
196
196
        self._transport.put_file(self._escape(path), file, mode=self._file_mode)
197
197
 
198
198
    @needs_write_lock
 
199
    def put_bytes(self, path, a_string):
 
200
        """Write a string of bytes.
 
201
 
 
202
        :param path: The path to put the bytes, relative to the transport root.
 
203
        :param string: A string object, whose exact bytes are to be copied.
 
204
        """
 
205
        self._transport.put_bytes(self._escape(path), a_string,
 
206
                                  mode=self._file_mode)
 
207
 
 
208
    @needs_write_lock
199
209
    def put_utf8(self, path, a_string):
200
210
        """Write a string, encoding as utf-8.
201
211
 
202
212
        :param path: The path to put the string, relative to the transport root.
203
 
        :param string: A file-like or string object whose contents should be copied.
 
213
        :param string: A string or unicode object whose contents should be copied.
204
214
        """
205
215
        # IterableFile would not be needed if Transport.put took iterables
206
216
        # instead of files.  ADHB 2005-12-25
210
220
        # these are valuable files which should have exact contents.
211
221
        if not isinstance(a_string, basestring):
212
222
            raise errors.BzrBadParameterNotString(a_string)
213
 
        self.put(path, StringIO(a_string.encode('utf-8')))
 
223
        self.put_bytes(path, a_string.encode('utf-8'))
214
224
 
215
225
    def lock_write(self):
216
226
        # mutter("lock write: %s (%s)", self, self._lock_count)