/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 breezy/iterablefile.py

  • Committer: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
 
18
 
from __future__ import absolute_import
19
 
 
20
18
 
21
19
class IterableFileBase(object):
22
20
    """Create a file-like object from any iterable"""
29
27
 
30
28
    def read_n(self, length):
31
29
        """
32
 
        >>> IterableFileBase(['This ', 'is ', 'a ', 'test.']).read_n(8)
33
 
        'This is '
 
30
        >>> IterableFileBase([b'This ', b'is ', b'a ', b'test.']).read_n(8)
 
31
        b'This is '
34
32
        """
35
33
        def test_length(result):
36
34
            if len(result) >= length:
41
39
 
42
40
    def read_to(self, sequence, length=None):
43
41
        """
44
 
        >>> f = IterableFileBase(['Th\\nis ', 'is \\n', 'a ', 'te\\nst.'])
45
 
        >>> f.read_to('\\n')
46
 
        'Th\\n'
47
 
        >>> f.read_to('\\n')
48
 
        'is is \\n'
 
42
        >>> f = IterableFileBase([b'Th\\nis ', b'is \\n', b'a ', b'te\\nst.'])
 
43
        >>> f.read_to(b'\\n')
 
44
        b'Th\\n'
 
45
        >>> f.read_to(b'\\n')
 
46
        b'is is \\n'
49
47
        """
50
48
        def test_contents(result):
51
49
            if length is not None:
79
77
 
80
78
    def read_all(self):
81
79
        """
82
 
        >>> IterableFileBase(['This ', 'is ', 'a ', 'test.']).read_all()
83
 
        'This is a test.'
 
80
        >>> IterableFileBase([b'This ', b'is ', b'a ', b'test.']).read_all()
 
81
        b'This is a test.'
84
82
        """
85
83
        def no_stop(result):
86
84
            return None
88
86
 
89
87
    def push_back(self, contents):
90
88
        """
91
 
        >>> f = IterableFileBase(['Th\\nis ', 'is \\n', 'a ', 'te\\nst.'])
92
 
        >>> f.read_to('\\n')
93
 
        'Th\\n'
94
 
        >>> f.push_back("Sh")
 
89
        >>> f = IterableFileBase([b'Th\\nis ', b'is \\n', b'a ', b'te\\nst.'])
 
90
        >>> f.read_to(b'\\n')
 
91
        b'Th\\n'
 
92
        >>> f.push_back(b"Sh")
95
93
        >>> f.read_all()
96
 
        'Shis is \\na te\\nst.'
 
94
        b'Shis is \\na te\\nst.'
97
95
        """
98
96
        self._buffer = contents + self._buffer
99
97
 
121
119
 
122
120
    def close(self):
123
121
        """
124
 
        >>> f = IterableFile(['This ', 'is ', 'a ', 'test.'])
 
122
        >>> f = IterableFile([b'This ', b'is ', b'a ', b'test.'])
125
123
        >>> f.closed
126
124
        False
127
125
        >>> f.close()
158
156
    def __next__(self):
159
157
        """Implementation of the iterator protocol's next()
160
158
 
161
 
        >>> f = IterableFile(['This \\n', 'is ', 'a ', 'test.'])
 
159
        >>> f = IterableFile([b'This \\n', b'is ', b'a ', b'test.'])
162
160
        >>> next(f)
163
 
        'This \\n'
 
161
        b'This \\n'
164
162
        >>> f.close()
165
163
        >>> next(f)
166
164
        Traceback (most recent call last):
167
165
        ValueError: File is closed.
168
 
        >>> f = IterableFile(['This \\n', 'is ', 'a ', 'test.\\n'])
169
 
        >>> next(f)
170
 
        'This \\n'
171
 
        >>> next(f)
172
 
        'is a test.\\n'
 
166
        >>> f = IterableFile([b'This \\n', b'is ', b'a ', b'test.\\n'])
 
167
        >>> next(f)
 
168
        b'This \\n'
 
169
        >>> next(f)
 
170
        b'is a test.\\n'
173
171
        >>> next(f)
174
172
        Traceback (most recent call last):
175
173
        StopIteration
181
179
 
182
180
    def __iter__(self):
183
181
        """
184
 
        >>> list(IterableFile(['Th\\nis ', 'is \\n', 'a ', 'te\\nst.']))
185
 
        ['Th\\n', 'is is \\n', 'a te\\n', 'st.']
186
 
        >>> f = IterableFile(['Th\\nis ', 'is \\n', 'a ', 'te\\nst.'])
 
182
        >>> list(IterableFile([b'Th\\nis ', b'is \\n', b'a ', b'te\\nst.']))
 
183
        [b'Th\\n', b'is is \\n', b'a te\\n', b'st.']
 
184
        >>> f = IterableFile([b'Th\\nis ', b'is \\n', b'a ', b'te\\nst.'])
187
185
        >>> f.close()
188
186
        >>> list(f)
189
187
        Traceback (most recent call last):
193
191
 
194
192
    def read(self, length=None):
195
193
        """
196
 
        >>> IterableFile(['This ', 'is ', 'a ', 'test.']).read()
197
 
        'This is a test.'
198
 
        >>> f = IterableFile(['This ', 'is ', 'a ', 'test.'])
 
194
        >>> IterableFile([b'This ', b'is ', b'a ', b'test.']).read()
 
195
        b'This is a test.'
 
196
        >>> f = IterableFile([b'This ', b'is ', b'a ', b'test.'])
199
197
        >>> f.read(10)
200
 
        'This is a '
201
 
        >>> f = IterableFile(['This ', 'is ', 'a ', 'test.'])
 
198
        b'This is a '
 
199
        >>> f = IterableFile([b'This ', b'is ', b'a ', b'test.'])
202
200
        >>> f.close()
203
201
        >>> f.read(10)
204
202
        Traceback (most recent call last):
215
213
        Read characters until a sequence is found, with optional max size.
216
214
        The specified sequence, if found, will be included in the result
217
215
 
218
 
        >>> f = IterableFile(['Th\\nis ', 'is \\n', 'a ', 'te\\nst.'])
219
 
        >>> f.read_to('i')
220
 
        'Th\\ni'
221
 
        >>> f.read_to('i')
222
 
        's i'
 
216
        >>> f = IterableFile([b'Th\\nis ', b'is \\n', b'a ', b'te\\nst.'])
 
217
        >>> f.read_to(b'i')
 
218
        b'Th\\ni'
 
219
        >>> f.read_to(b'i')
 
220
        b's i'
223
221
        >>> f.close()
224
 
        >>> f.read_to('i')
 
222
        >>> f.read_to(b'i')
225
223
        Traceback (most recent call last):
226
224
        ValueError: File is closed.
227
225
        """
230
228
 
231
229
    def readline(self, size=None):
232
230
        """
233
 
        >>> f = IterableFile(['Th\\nis ', 'is \\n', 'a ', 'te\\nst.'])
 
231
        >>> f = IterableFile([b'Th\\nis ', b'is \\n', b'a ', b'te\\nst.'])
234
232
        >>> f.readline()
235
 
        'Th\\n'
 
233
        b'Th\\n'
236
234
        >>> f.readline(4)
237
 
        'is i'
 
235
        b'is i'
238
236
        >>> f.close()
239
237
        >>> f.readline()
240
238
        Traceback (most recent call last):
244
242
 
245
243
    def readlines(self, sizehint=None):
246
244
        """
247
 
        >>> f = IterableFile(['Th\\nis ', 'is \\n', 'a ', 'te\\nst.'])
 
245
        >>> f = IterableFile([b'Th\\nis ', b'is \\n', b'a ', b'te\\nst.'])
248
246
        >>> f.readlines()
249
 
        ['Th\\n', 'is is \\n', 'a te\\n', 'st.']
250
 
        >>> f = IterableFile(['Th\\nis ', 'is \\n', 'a ', 'te\\nst.'])
 
247
        [b'Th\\n', b'is is \\n', b'a te\\n', b'st.']
 
248
        >>> f = IterableFile([b'Th\\nis ', b'is \\n', b'a ', b'te\\nst.'])
251
249
        >>> f.close()
252
250
        >>> f.readlines()
253
251
        Traceback (most recent call last):