/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/iterablefile.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
    def __init__(self, iterable):
24
24
        object.__init__(self)
25
25
        self._iter = iterable.__iter__()
26
 
        self._buffer = b""
 
26
        self._buffer = ""
27
27
        self.done = False
28
28
 
29
29
    def read_n(self, length):
67
67
        result = self._buffer
68
68
        while result_length(result) is None:
69
69
            try:
70
 
                result += next(self._iter)
 
70
                result += self._iter.next()
71
71
            except StopIteration:
72
72
                self.done = True
73
 
                self._buffer = b""
 
73
                self._buffer = ""
74
74
                return result
75
75
        output_length = result_length(result)
76
76
        self._buffer = result[output_length:]
110
110
    def _make_iterator(self):
111
111
        while not self._file_base.done:
112
112
            self._check_closed()
113
 
            result = self._file_base.read_to(b'\n')
114
 
            if result != b'':
 
113
            result = self._file_base.read_to('\n')
 
114
            if result != '':
115
115
                yield result
116
116
 
117
117
    def _check_closed(self):
132
132
 
133
133
    closed = property(lambda x: x._closed)
134
134
 
135
 
    def __enter__(self):
136
 
        return self
137
 
 
138
 
    def __exit__(self, exc_type, exc_val, exc_tb):
139
 
        # If there was an error raised, prefer the original one
140
 
        try:
141
 
            self.close()
142
 
        except:
143
 
            if exc_type is None:
144
 
                raise
145
 
        return False
146
 
 
147
135
    def flush(self):
148
136
        """No-op for standard compliance.
149
137
        >>> f = IterableFile([])
154
142
        """
155
143
        self._check_closed()
156
144
 
157
 
    def __next__(self):
 
145
    def next(self):
158
146
        """Implementation of the iterator protocol's next()
159
147
 
160
148
        >>> f = IterableFile(['This \\n', 'is ', 'a ', 'test.'])
161
 
        >>> next(f)
 
149
        >>> f.next()
162
150
        'This \\n'
163
151
        >>> f.close()
164
 
        >>> next(f)
 
152
        >>> f.next()
165
153
        Traceback (most recent call last):
166
154
        ValueError: File is closed.
167
155
        >>> f = IterableFile(['This \\n', 'is ', 'a ', 'test.\\n'])
168
 
        >>> next(f)
 
156
        >>> f.next()
169
157
        'This \\n'
170
 
        >>> next(f)
 
158
        >>> f.next()
171
159
        'is a test.\\n'
172
 
        >>> next(f)
 
160
        >>> f.next()
173
161
        Traceback (most recent call last):
174
162
        StopIteration
175
163
        """
176
164
        self._check_closed()
177
 
        return next(self._iter)
178
 
 
179
 
    next = __next__
 
165
        return self._iter.next()
180
166
 
181
167
    def __iter__(self):
182
168
        """
239
225
        Traceback (most recent call last):
240
226
        ValueError: File is closed.
241
227
        """
242
 
        return self.read_to(b'\n', size)
 
228
        return self.read_to('\n', size)
243
229
 
244
230
    def readlines(self, sizehint=None):
245
231
        """
255
241
        lines = []
256
242
        while True:
257
243
            line = self.readline()
258
 
            if line == b"":
 
244
            if line == "":
259
245
                return lines
260
246
            if sizehint is None:
261
247
                lines.append(line)