~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-26 00:11:10 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-20051226001110-cf590f668a99ba1a
Refactored a bit

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
from bzrlib.errors import LockError, ReadOnlyError
4
4
from bzrlib.trace import mutter
5
5
import bzrlib.transactions as transactions
 
6
from osutils import file_iterator
6
7
 
7
8
class LockableFiles(object):
8
9
    """Object representing a set of lockable files
98
99
        import codecs
99
100
        from iterablefile import IterableFile
100
101
        ctrl_files = []
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
102
        if hasattr(file, 'read'):
108
103
            iterator = file_iterator(file)
109
104
        else:
110
105
            iterator = file
 
106
        # IterableFile would not be needed if Transport.put took iterables
 
107
        # instead of files.  ADHB 2005-12-25
111
108
        encoded_file = IterableFile(b.encode('utf-8', 'replace') for b in 
112
109
                                    iterator)
113
110
        self.put(path, encoded_file)