~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockable_files.py

  • Committer: Aaron Bentley
  • Date: 2005-12-25 23:06:24 UTC
  • mto: (1185.67.11 bzr.revision-storage)
  • mto: This revision was merged to the branch mainline in revision 1550.
  • Revision ID: aaron.bentley@utoronto.ca-20051225230624-f61a1538912a578a
Added tests and fixes for LockableFiles.put_utf8(); imported IterableFile

Show diffs side-by-side

added added

removed removed

Lines of Context:
96
96
        :param f: A file-like or string object whose contents should be copied.
97
97
        """
98
98
        import codecs
 
99
        from iterablefile import IterableFile
99
100
        ctrl_files = []
100
 
        if isinstance(file, basestring):
101
 
            file = file.encode('utf-8', 'replace')
 
101
        def file_iterator(unicode_file, bufsize=32768):
 
102
            while True:
 
103
                b = unicode_file.read(bufsize)
 
104
                if len(b) == 0:
 
105
                    break
 
106
                yield b
 
107
        if hasattr(file, 'read'):
 
108
            iterator = file_iterator(file)
102
109
        else:
103
 
            file = codecs.getwriter('utf-8')(file, errors='replace')
104
 
        self.put(path, file)
 
110
            iterator = file
 
111
        encoded_file = IterableFile(b.encode('utf-8', 'replace') for b in 
 
112
                                    iterator)
 
113
        self.put(path, encoded_file)
105
114
 
106
115
    def lock_write(self):
107
116
        mutter("lock write: %s (%s)", self, self._lock_count)