1 | n/a | # -*- coding: utf-8 -*- |
---|
2 | n/a | # This file should be kept compatible with both Python 2.6 and Python >= 3.0. |
---|
3 | n/a | |
---|
4 | n/a | import itertools |
---|
5 | n/a | import os |
---|
6 | n/a | import platform |
---|
7 | n/a | import re |
---|
8 | n/a | import sys |
---|
9 | n/a | import time |
---|
10 | n/a | from optparse import OptionParser |
---|
11 | n/a | |
---|
12 | n/a | out = sys.stdout |
---|
13 | n/a | |
---|
14 | n/a | TEXT_ENCODING = 'utf8' |
---|
15 | n/a | NEWLINES = 'lf' |
---|
16 | n/a | |
---|
17 | n/a | # Compatibility |
---|
18 | n/a | try: |
---|
19 | n/a | xrange |
---|
20 | n/a | except NameError: |
---|
21 | n/a | xrange = range |
---|
22 | n/a | |
---|
23 | n/a | def text_open(fn, mode, encoding=None): |
---|
24 | n/a | try: |
---|
25 | n/a | return open(fn, mode, encoding=encoding or TEXT_ENCODING) |
---|
26 | n/a | except TypeError: |
---|
27 | n/a | if 'r' in mode: |
---|
28 | n/a | mode += 'U' # 'U' mode is needed only in Python 2.x |
---|
29 | n/a | return open(fn, mode) |
---|
30 | n/a | |
---|
31 | n/a | def get_file_sizes(): |
---|
32 | n/a | for s in ['20 KB', '400 KB', '10 MB']: |
---|
33 | n/a | size, unit = s.split() |
---|
34 | n/a | size = int(size) * {'KB': 1024, 'MB': 1024 ** 2}[unit] |
---|
35 | n/a | yield s.replace(' ', ''), size |
---|
36 | n/a | |
---|
37 | n/a | def get_binary_files(): |
---|
38 | n/a | return ((name + ".bin", size) for name, size in get_file_sizes()) |
---|
39 | n/a | |
---|
40 | n/a | def get_text_files(): |
---|
41 | n/a | return (("%s-%s-%s.txt" % (name, TEXT_ENCODING, NEWLINES), size) |
---|
42 | n/a | for name, size in get_file_sizes()) |
---|
43 | n/a | |
---|
44 | n/a | def with_open_mode(mode): |
---|
45 | n/a | def decorate(f): |
---|
46 | n/a | f.file_open_mode = mode |
---|
47 | n/a | return f |
---|
48 | n/a | return decorate |
---|
49 | n/a | |
---|
50 | n/a | def with_sizes(*sizes): |
---|
51 | n/a | def decorate(f): |
---|
52 | n/a | f.file_sizes = sizes |
---|
53 | n/a | return f |
---|
54 | n/a | return decorate |
---|
55 | n/a | |
---|
56 | n/a | |
---|
57 | n/a | # Here begin the tests |
---|
58 | n/a | |
---|
59 | n/a | @with_open_mode("r") |
---|
60 | n/a | @with_sizes("medium") |
---|
61 | n/a | def read_bytewise(f): |
---|
62 | n/a | """ read one unit at a time """ |
---|
63 | n/a | f.seek(0) |
---|
64 | n/a | while f.read(1): |
---|
65 | n/a | pass |
---|
66 | n/a | |
---|
67 | n/a | @with_open_mode("r") |
---|
68 | n/a | @with_sizes("medium") |
---|
69 | n/a | def read_small_chunks(f): |
---|
70 | n/a | """ read 20 units at a time """ |
---|
71 | n/a | f.seek(0) |
---|
72 | n/a | while f.read(20): |
---|
73 | n/a | pass |
---|
74 | n/a | |
---|
75 | n/a | @with_open_mode("r") |
---|
76 | n/a | @with_sizes("medium") |
---|
77 | n/a | def read_big_chunks(f): |
---|
78 | n/a | """ read 4096 units at a time """ |
---|
79 | n/a | f.seek(0) |
---|
80 | n/a | while f.read(4096): |
---|
81 | n/a | pass |
---|
82 | n/a | |
---|
83 | n/a | @with_open_mode("r") |
---|
84 | n/a | @with_sizes("small", "medium", "large") |
---|
85 | n/a | def read_whole_file(f): |
---|
86 | n/a | """ read whole contents at once """ |
---|
87 | n/a | f.seek(0) |
---|
88 | n/a | while f.read(): |
---|
89 | n/a | pass |
---|
90 | n/a | |
---|
91 | n/a | @with_open_mode("rt") |
---|
92 | n/a | @with_sizes("medium") |
---|
93 | n/a | def read_lines(f): |
---|
94 | n/a | """ read one line at a time """ |
---|
95 | n/a | f.seek(0) |
---|
96 | n/a | for line in f: |
---|
97 | n/a | pass |
---|
98 | n/a | |
---|
99 | n/a | @with_open_mode("r") |
---|
100 | n/a | @with_sizes("medium") |
---|
101 | n/a | def seek_forward_bytewise(f): |
---|
102 | n/a | """ seek forward one unit at a time """ |
---|
103 | n/a | f.seek(0, 2) |
---|
104 | n/a | size = f.tell() |
---|
105 | n/a | f.seek(0, 0) |
---|
106 | n/a | for i in xrange(0, size - 1): |
---|
107 | n/a | f.seek(i, 0) |
---|
108 | n/a | |
---|
109 | n/a | @with_open_mode("r") |
---|
110 | n/a | @with_sizes("medium") |
---|
111 | n/a | def seek_forward_blockwise(f): |
---|
112 | n/a | """ seek forward 1000 units at a time """ |
---|
113 | n/a | f.seek(0, 2) |
---|
114 | n/a | size = f.tell() |
---|
115 | n/a | f.seek(0, 0) |
---|
116 | n/a | for i in xrange(0, size - 1, 1000): |
---|
117 | n/a | f.seek(i, 0) |
---|
118 | n/a | |
---|
119 | n/a | @with_open_mode("rb") |
---|
120 | n/a | @with_sizes("medium") |
---|
121 | n/a | def read_seek_bytewise(f): |
---|
122 | n/a | """ alternate read & seek one unit """ |
---|
123 | n/a | f.seek(0) |
---|
124 | n/a | while f.read(1): |
---|
125 | n/a | f.seek(1, 1) |
---|
126 | n/a | |
---|
127 | n/a | @with_open_mode("rb") |
---|
128 | n/a | @with_sizes("medium") |
---|
129 | n/a | def read_seek_blockwise(f): |
---|
130 | n/a | """ alternate read & seek 1000 units """ |
---|
131 | n/a | f.seek(0) |
---|
132 | n/a | while f.read(1000): |
---|
133 | n/a | f.seek(1000, 1) |
---|
134 | n/a | |
---|
135 | n/a | |
---|
136 | n/a | @with_open_mode("w") |
---|
137 | n/a | @with_sizes("small") |
---|
138 | n/a | def write_bytewise(f, source): |
---|
139 | n/a | """ write one unit at a time """ |
---|
140 | n/a | for i in xrange(0, len(source)): |
---|
141 | n/a | f.write(source[i:i+1]) |
---|
142 | n/a | |
---|
143 | n/a | @with_open_mode("w") |
---|
144 | n/a | @with_sizes("medium") |
---|
145 | n/a | def write_small_chunks(f, source): |
---|
146 | n/a | """ write 20 units at a time """ |
---|
147 | n/a | for i in xrange(0, len(source), 20): |
---|
148 | n/a | f.write(source[i:i+20]) |
---|
149 | n/a | |
---|
150 | n/a | @with_open_mode("w") |
---|
151 | n/a | @with_sizes("medium") |
---|
152 | n/a | def write_medium_chunks(f, source): |
---|
153 | n/a | """ write 4096 units at a time """ |
---|
154 | n/a | for i in xrange(0, len(source), 4096): |
---|
155 | n/a | f.write(source[i:i+4096]) |
---|
156 | n/a | |
---|
157 | n/a | @with_open_mode("w") |
---|
158 | n/a | @with_sizes("large") |
---|
159 | n/a | def write_large_chunks(f, source): |
---|
160 | n/a | """ write 1e6 units at a time """ |
---|
161 | n/a | for i in xrange(0, len(source), 1000000): |
---|
162 | n/a | f.write(source[i:i+1000000]) |
---|
163 | n/a | |
---|
164 | n/a | |
---|
165 | n/a | @with_open_mode("w+") |
---|
166 | n/a | @with_sizes("small") |
---|
167 | n/a | def modify_bytewise(f, source): |
---|
168 | n/a | """ modify one unit at a time """ |
---|
169 | n/a | f.seek(0) |
---|
170 | n/a | for i in xrange(0, len(source)): |
---|
171 | n/a | f.write(source[i:i+1]) |
---|
172 | n/a | |
---|
173 | n/a | @with_open_mode("w+") |
---|
174 | n/a | @with_sizes("medium") |
---|
175 | n/a | def modify_small_chunks(f, source): |
---|
176 | n/a | """ modify 20 units at a time """ |
---|
177 | n/a | f.seek(0) |
---|
178 | n/a | for i in xrange(0, len(source), 20): |
---|
179 | n/a | f.write(source[i:i+20]) |
---|
180 | n/a | |
---|
181 | n/a | @with_open_mode("w+") |
---|
182 | n/a | @with_sizes("medium") |
---|
183 | n/a | def modify_medium_chunks(f, source): |
---|
184 | n/a | """ modify 4096 units at a time """ |
---|
185 | n/a | f.seek(0) |
---|
186 | n/a | for i in xrange(0, len(source), 4096): |
---|
187 | n/a | f.write(source[i:i+4096]) |
---|
188 | n/a | |
---|
189 | n/a | @with_open_mode("wb+") |
---|
190 | n/a | @with_sizes("medium") |
---|
191 | n/a | def modify_seek_forward_bytewise(f, source): |
---|
192 | n/a | """ alternate write & seek one unit """ |
---|
193 | n/a | f.seek(0) |
---|
194 | n/a | for i in xrange(0, len(source), 2): |
---|
195 | n/a | f.write(source[i:i+1]) |
---|
196 | n/a | f.seek(i+2) |
---|
197 | n/a | |
---|
198 | n/a | @with_open_mode("wb+") |
---|
199 | n/a | @with_sizes("medium") |
---|
200 | n/a | def modify_seek_forward_blockwise(f, source): |
---|
201 | n/a | """ alternate write & seek 1000 units """ |
---|
202 | n/a | f.seek(0) |
---|
203 | n/a | for i in xrange(0, len(source), 2000): |
---|
204 | n/a | f.write(source[i:i+1000]) |
---|
205 | n/a | f.seek(i+2000) |
---|
206 | n/a | |
---|
207 | n/a | # XXX the 2 following tests don't work with py3k's text IO |
---|
208 | n/a | @with_open_mode("wb+") |
---|
209 | n/a | @with_sizes("medium") |
---|
210 | n/a | def read_modify_bytewise(f, source): |
---|
211 | n/a | """ alternate read & write one unit """ |
---|
212 | n/a | f.seek(0) |
---|
213 | n/a | for i in xrange(0, len(source), 2): |
---|
214 | n/a | f.read(1) |
---|
215 | n/a | f.write(source[i+1:i+2]) |
---|
216 | n/a | |
---|
217 | n/a | @with_open_mode("wb+") |
---|
218 | n/a | @with_sizes("medium") |
---|
219 | n/a | def read_modify_blockwise(f, source): |
---|
220 | n/a | """ alternate read & write 1000 units """ |
---|
221 | n/a | f.seek(0) |
---|
222 | n/a | for i in xrange(0, len(source), 2000): |
---|
223 | n/a | f.read(1000) |
---|
224 | n/a | f.write(source[i+1000:i+2000]) |
---|
225 | n/a | |
---|
226 | n/a | |
---|
227 | n/a | read_tests = [ |
---|
228 | n/a | read_bytewise, read_small_chunks, read_lines, read_big_chunks, |
---|
229 | n/a | None, read_whole_file, None, |
---|
230 | n/a | seek_forward_bytewise, seek_forward_blockwise, |
---|
231 | n/a | read_seek_bytewise, read_seek_blockwise, |
---|
232 | n/a | ] |
---|
233 | n/a | |
---|
234 | n/a | write_tests = [ |
---|
235 | n/a | write_bytewise, write_small_chunks, write_medium_chunks, write_large_chunks, |
---|
236 | n/a | ] |
---|
237 | n/a | |
---|
238 | n/a | modify_tests = [ |
---|
239 | n/a | modify_bytewise, modify_small_chunks, modify_medium_chunks, |
---|
240 | n/a | None, |
---|
241 | n/a | modify_seek_forward_bytewise, modify_seek_forward_blockwise, |
---|
242 | n/a | read_modify_bytewise, read_modify_blockwise, |
---|
243 | n/a | ] |
---|
244 | n/a | |
---|
245 | n/a | def run_during(duration, func): |
---|
246 | n/a | _t = time.time |
---|
247 | n/a | n = 0 |
---|
248 | n/a | start = os.times() |
---|
249 | n/a | start_timestamp = _t() |
---|
250 | n/a | real_start = start[4] or start_timestamp |
---|
251 | n/a | while True: |
---|
252 | n/a | func() |
---|
253 | n/a | n += 1 |
---|
254 | n/a | if _t() - start_timestamp > duration: |
---|
255 | n/a | break |
---|
256 | n/a | end = os.times() |
---|
257 | n/a | real = (end[4] if start[4] else time.time()) - real_start |
---|
258 | n/a | return n, real, sum(end[0:2]) - sum(start[0:2]) |
---|
259 | n/a | |
---|
260 | n/a | def warm_cache(filename): |
---|
261 | n/a | with open(filename, "rb") as f: |
---|
262 | n/a | f.read() |
---|
263 | n/a | |
---|
264 | n/a | |
---|
265 | n/a | def run_all_tests(options): |
---|
266 | n/a | def print_label(filename, func): |
---|
267 | n/a | name = re.split(r'[-.]', filename)[0] |
---|
268 | n/a | out.write( |
---|
269 | n/a | ("[%s] %s... " |
---|
270 | n/a | % (name.center(7), func.__doc__.strip()) |
---|
271 | n/a | ).ljust(52)) |
---|
272 | n/a | out.flush() |
---|
273 | n/a | |
---|
274 | n/a | def print_results(size, n, real, cpu): |
---|
275 | n/a | bw = n * float(size) / 1024 ** 2 / real |
---|
276 | n/a | bw = ("%4d MB/s" if bw > 100 else "%.3g MB/s") % bw |
---|
277 | n/a | out.write(bw.rjust(12) + "\n") |
---|
278 | n/a | if cpu < 0.90 * real: |
---|
279 | n/a | out.write(" warning: test above used only %d%% CPU, " |
---|
280 | n/a | "result may be flawed!\n" % (100.0 * cpu / real)) |
---|
281 | n/a | |
---|
282 | n/a | def run_one_test(name, size, open_func, test_func, *args): |
---|
283 | n/a | mode = test_func.file_open_mode |
---|
284 | n/a | print_label(name, test_func) |
---|
285 | n/a | if "w" not in mode or "+" in mode: |
---|
286 | n/a | warm_cache(name) |
---|
287 | n/a | with open_func(name) as f: |
---|
288 | n/a | n, real, cpu = run_during(1.5, lambda: test_func(f, *args)) |
---|
289 | n/a | print_results(size, n, real, cpu) |
---|
290 | n/a | |
---|
291 | n/a | def run_test_family(tests, mode_filter, files, open_func, *make_args): |
---|
292 | n/a | for test_func in tests: |
---|
293 | n/a | if test_func is None: |
---|
294 | n/a | out.write("\n") |
---|
295 | n/a | continue |
---|
296 | n/a | if mode_filter in test_func.file_open_mode: |
---|
297 | n/a | continue |
---|
298 | n/a | for s in test_func.file_sizes: |
---|
299 | n/a | name, size = files[size_names[s]] |
---|
300 | n/a | #name += file_ext |
---|
301 | n/a | args = tuple(f(name, size) for f in make_args) |
---|
302 | n/a | run_one_test(name, size, |
---|
303 | n/a | open_func, test_func, *args) |
---|
304 | n/a | |
---|
305 | n/a | size_names = { |
---|
306 | n/a | "small": 0, |
---|
307 | n/a | "medium": 1, |
---|
308 | n/a | "large": 2, |
---|
309 | n/a | } |
---|
310 | n/a | |
---|
311 | n/a | print("Python %s" % sys.version) |
---|
312 | n/a | if sys.version_info < (3, 3): |
---|
313 | n/a | if sys.maxunicode > 0xffff: |
---|
314 | n/a | text = "UCS-4 (wide build)" |
---|
315 | n/a | else: |
---|
316 | n/a | text = "UTF-16 (narrow build)" |
---|
317 | n/a | else: |
---|
318 | n/a | text = "PEP 393" |
---|
319 | n/a | print("Unicode: %s" % text) |
---|
320 | n/a | print(platform.platform()) |
---|
321 | n/a | binary_files = list(get_binary_files()) |
---|
322 | n/a | text_files = list(get_text_files()) |
---|
323 | n/a | if "b" in options: |
---|
324 | n/a | print("Binary unit = one byte") |
---|
325 | n/a | if "t" in options: |
---|
326 | n/a | print("Text unit = one character (%s-decoded)" % TEXT_ENCODING) |
---|
327 | n/a | |
---|
328 | n/a | # Binary reads |
---|
329 | n/a | if "b" in options and "r" in options: |
---|
330 | n/a | print("\n** Binary input **\n") |
---|
331 | n/a | run_test_family(read_tests, "t", binary_files, lambda fn: open(fn, "rb")) |
---|
332 | n/a | |
---|
333 | n/a | # Text reads |
---|
334 | n/a | if "t" in options and "r" in options: |
---|
335 | n/a | print("\n** Text input **\n") |
---|
336 | n/a | run_test_family(read_tests, "b", text_files, lambda fn: text_open(fn, "r")) |
---|
337 | n/a | |
---|
338 | n/a | # Binary writes |
---|
339 | n/a | if "b" in options and "w" in options: |
---|
340 | n/a | print("\n** Binary append **\n") |
---|
341 | n/a | def make_test_source(name, size): |
---|
342 | n/a | with open(name, "rb") as f: |
---|
343 | n/a | return f.read() |
---|
344 | n/a | run_test_family(write_tests, "t", binary_files, |
---|
345 | n/a | lambda fn: open(os.devnull, "wb"), make_test_source) |
---|
346 | n/a | |
---|
347 | n/a | # Text writes |
---|
348 | n/a | if "t" in options and "w" in options: |
---|
349 | n/a | print("\n** Text append **\n") |
---|
350 | n/a | def make_test_source(name, size): |
---|
351 | n/a | with text_open(name, "r") as f: |
---|
352 | n/a | return f.read() |
---|
353 | n/a | run_test_family(write_tests, "b", text_files, |
---|
354 | n/a | lambda fn: text_open(os.devnull, "w"), make_test_source) |
---|
355 | n/a | |
---|
356 | n/a | # Binary overwrites |
---|
357 | n/a | if "b" in options and "w" in options: |
---|
358 | n/a | print("\n** Binary overwrite **\n") |
---|
359 | n/a | def make_test_source(name, size): |
---|
360 | n/a | with open(name, "rb") as f: |
---|
361 | n/a | return f.read() |
---|
362 | n/a | run_test_family(modify_tests, "t", binary_files, |
---|
363 | n/a | lambda fn: open(fn, "r+b"), make_test_source) |
---|
364 | n/a | |
---|
365 | n/a | # Text overwrites |
---|
366 | n/a | if "t" in options and "w" in options: |
---|
367 | n/a | print("\n** Text overwrite **\n") |
---|
368 | n/a | def make_test_source(name, size): |
---|
369 | n/a | with text_open(name, "r") as f: |
---|
370 | n/a | return f.read() |
---|
371 | n/a | run_test_family(modify_tests, "b", text_files, |
---|
372 | n/a | lambda fn: text_open(fn, "r+"), make_test_source) |
---|
373 | n/a | |
---|
374 | n/a | |
---|
375 | n/a | def prepare_files(): |
---|
376 | n/a | print("Preparing files...") |
---|
377 | n/a | # Binary files |
---|
378 | n/a | for name, size in get_binary_files(): |
---|
379 | n/a | if os.path.isfile(name) and os.path.getsize(name) == size: |
---|
380 | n/a | continue |
---|
381 | n/a | with open(name, "wb") as f: |
---|
382 | n/a | f.write(os.urandom(size)) |
---|
383 | n/a | # Text files |
---|
384 | n/a | chunk = [] |
---|
385 | n/a | with text_open(__file__, "r", encoding='utf8') as f: |
---|
386 | n/a | for line in f: |
---|
387 | n/a | if line.startswith("# <iobench text chunk marker>"): |
---|
388 | n/a | break |
---|
389 | n/a | else: |
---|
390 | n/a | raise RuntimeError( |
---|
391 | n/a | "Couldn't find chunk marker in %s !" % __file__) |
---|
392 | n/a | if NEWLINES == "all": |
---|
393 | n/a | it = itertools.cycle(["\n", "\r", "\r\n"]) |
---|
394 | n/a | else: |
---|
395 | n/a | it = itertools.repeat( |
---|
396 | n/a | {"cr": "\r", "lf": "\n", "crlf": "\r\n"}[NEWLINES]) |
---|
397 | n/a | chunk = "".join(line.replace("\n", next(it)) for line in f) |
---|
398 | n/a | if isinstance(chunk, bytes): |
---|
399 | n/a | chunk = chunk.decode('utf8') |
---|
400 | n/a | chunk = chunk.encode(TEXT_ENCODING) |
---|
401 | n/a | for name, size in get_text_files(): |
---|
402 | n/a | if os.path.isfile(name) and os.path.getsize(name) == size: |
---|
403 | n/a | continue |
---|
404 | n/a | head = chunk * (size // len(chunk)) |
---|
405 | n/a | tail = chunk[:size % len(chunk)] |
---|
406 | n/a | # Adjust tail to end on a character boundary |
---|
407 | n/a | while True: |
---|
408 | n/a | try: |
---|
409 | n/a | tail.decode(TEXT_ENCODING) |
---|
410 | n/a | break |
---|
411 | n/a | except UnicodeDecodeError: |
---|
412 | n/a | tail = tail[:-1] |
---|
413 | n/a | with open(name, "wb") as f: |
---|
414 | n/a | f.write(head) |
---|
415 | n/a | f.write(tail) |
---|
416 | n/a | |
---|
417 | n/a | def main(): |
---|
418 | n/a | global TEXT_ENCODING, NEWLINES |
---|
419 | n/a | |
---|
420 | n/a | usage = "usage: %prog [-h|--help] [options]" |
---|
421 | n/a | parser = OptionParser(usage=usage) |
---|
422 | n/a | parser.add_option("-b", "--binary", |
---|
423 | n/a | action="store_true", dest="binary", default=False, |
---|
424 | n/a | help="run binary I/O tests") |
---|
425 | n/a | parser.add_option("-t", "--text", |
---|
426 | n/a | action="store_true", dest="text", default=False, |
---|
427 | n/a | help="run text I/O tests") |
---|
428 | n/a | parser.add_option("-r", "--read", |
---|
429 | n/a | action="store_true", dest="read", default=False, |
---|
430 | n/a | help="run read tests") |
---|
431 | n/a | parser.add_option("-w", "--write", |
---|
432 | n/a | action="store_true", dest="write", default=False, |
---|
433 | n/a | help="run write & modify tests") |
---|
434 | n/a | parser.add_option("-E", "--encoding", |
---|
435 | n/a | action="store", dest="encoding", default=None, |
---|
436 | n/a | help="encoding for text tests (default: %s)" % TEXT_ENCODING) |
---|
437 | n/a | parser.add_option("-N", "--newlines", |
---|
438 | n/a | action="store", dest="newlines", default='lf', |
---|
439 | n/a | help="line endings for text tests " |
---|
440 | n/a | "(one of: {lf (default), cr, crlf, all})") |
---|
441 | n/a | parser.add_option("-m", "--io-module", |
---|
442 | n/a | action="store", dest="io_module", default=None, |
---|
443 | n/a | help="io module to test (default: builtin open())") |
---|
444 | n/a | options, args = parser.parse_args() |
---|
445 | n/a | if args: |
---|
446 | n/a | parser.error("unexpected arguments") |
---|
447 | n/a | NEWLINES = options.newlines.lower() |
---|
448 | n/a | if NEWLINES not in ('lf', 'cr', 'crlf', 'all'): |
---|
449 | n/a | parser.error("invalid 'newlines' option: %r" % NEWLINES) |
---|
450 | n/a | |
---|
451 | n/a | test_options = "" |
---|
452 | n/a | if options.read: |
---|
453 | n/a | test_options += "r" |
---|
454 | n/a | if options.write: |
---|
455 | n/a | test_options += "w" |
---|
456 | n/a | elif not options.read: |
---|
457 | n/a | test_options += "rw" |
---|
458 | n/a | if options.text: |
---|
459 | n/a | test_options += "t" |
---|
460 | n/a | if options.binary: |
---|
461 | n/a | test_options += "b" |
---|
462 | n/a | elif not options.text: |
---|
463 | n/a | test_options += "tb" |
---|
464 | n/a | |
---|
465 | n/a | if options.encoding: |
---|
466 | n/a | TEXT_ENCODING = options.encoding |
---|
467 | n/a | |
---|
468 | n/a | if options.io_module: |
---|
469 | n/a | globals()['open'] = __import__(options.io_module, {}, {}, ['open']).open |
---|
470 | n/a | |
---|
471 | n/a | prepare_files() |
---|
472 | n/a | run_all_tests(test_options) |
---|
473 | n/a | |
---|
474 | n/a | if __name__ == "__main__": |
---|
475 | n/a | main() |
---|
476 | n/a | |
---|
477 | n/a | |
---|
478 | n/a | # -- This part to exercise text reading. Don't change anything! -- |
---|
479 | n/a | # <iobench text chunk marker> |
---|
480 | n/a | |
---|
481 | n/a | """ |
---|
482 | n/a | 1. |
---|
483 | n/a | Gáttir allar, |
---|
484 | n/a | áðr gangi fram, |
---|
485 | n/a | um skoðask skyli, |
---|
486 | n/a | um skyggnast skyli, |
---|
487 | n/a | þvà at óvÃst er at vita, |
---|
488 | n/a | hvar óvinir |
---|
489 | n/a | sitja á fleti fyrir. |
---|
490 | n/a | |
---|
491 | n/a | 2. |
---|
492 | n/a | Gefendr heilir! |
---|
493 | n/a | Gestr er inn kominn, |
---|
494 | n/a | hvar skal sitja sjá? |
---|
495 | n/a | Mjök er bráðr, |
---|
496 | n/a | sá er á bröndum skal |
---|
497 | n/a | sÃns of freista frama. |
---|
498 | n/a | |
---|
499 | n/a | 3. |
---|
500 | n/a | Elds er þörf, |
---|
501 | n/a | þeims inn er kominn |
---|
502 | n/a | ok á kné kalinn; |
---|
503 | n/a | matar ok váða |
---|
504 | n/a | er manni þörf, |
---|
505 | n/a | þeim er hefr um fjall farit. |
---|
506 | n/a | |
---|
507 | n/a | 4. |
---|
508 | n/a | Vatns er þörf, |
---|
509 | n/a | þeim er til verðar kemr, |
---|
510 | n/a | þerru ok þjóðlaðar, |
---|
511 | n/a | góðs of æðis, |
---|
512 | n/a | ef sér geta mætti, |
---|
513 | n/a | orðs ok endrþögu. |
---|
514 | n/a | |
---|
515 | n/a | 5. |
---|
516 | n/a | Vits er þörf, |
---|
517 | n/a | þeim er vÃða ratar; |
---|
518 | n/a | dælt er heima hvat; |
---|
519 | n/a | at augabragði verðr, |
---|
520 | n/a | sá er ekki kann |
---|
521 | n/a | ok með snotrum sitr. |
---|
522 | n/a | |
---|
523 | n/a | 6. |
---|
524 | n/a | At hyggjandi sinni |
---|
525 | n/a | skyli-t maðr hræsinn vera, |
---|
526 | n/a | heldr gætinn at geði; |
---|
527 | n/a | þá er horskr ok þögull |
---|
528 | n/a | kemr heimisgarða til, |
---|
529 | n/a | sjaldan verðr vÃti vörum, |
---|
530 | n/a | þvà at óbrigðra vin |
---|
531 | n/a | fær maðr aldregi |
---|
532 | n/a | en mannvit mikit. |
---|
533 | n/a | |
---|
534 | n/a | 7. |
---|
535 | n/a | Inn vari gestr, |
---|
536 | n/a | er til verðar kemr, |
---|
537 | n/a | þunnu hljóði þegir, |
---|
538 | n/a | eyrum hlýðir, |
---|
539 | n/a | en augum skoðar; |
---|
540 | n/a | svá nýsisk fróðra hverr fyrir. |
---|
541 | n/a | |
---|
542 | n/a | 8. |
---|
543 | n/a | Hinn er sæll, |
---|
544 | n/a | er sér of getr |
---|
545 | n/a | lof ok lÃknstafi; |
---|
546 | n/a | ódælla er við þat, |
---|
547 | n/a | er maðr eiga skal |
---|
548 | n/a | annars brjóstum Ã. |
---|
549 | n/a | """ |
---|
550 | n/a | |
---|
551 | n/a | """ |
---|
552 | n/a | C'est revenir tard, je le sens, sur un sujet trop rebattu et déjà presque oublié. Mon état, qui ne me permet plus aucun travail suivi, mon aversion pour le genre polémique, ont causé ma lenteur à écrire et ma répugnance à publier. J'aurais même tout à fait supprimé ces Lettres, ou plutôt je lie les aurais point écrites, s'il n'eût été question que de moi : Mais ma patrie ne m'est pas tellement devenue étrangère que je puisse voir tranquillement opprimer ses citoyens, surtout lorsqu'ils n'ont compromis leurs droits qu'en défendant ma cause. Je serais le dernier des hommes si dans une telle occasion j'écoutais un sentiment qui n'est plus ni douceur ni patience, mais faiblesse et lâcheté, dans celui qu'il empêche de remplir son devoir. |
---|
553 | n/a | Rien de moins important pour le public, j'en conviens, que la matière de ces lettres. La constitution d'une petite République, le sort d'un petit particulier, l'exposé de quelques injustices, la réfutation de quelques sophismes ; tout cela n'a rien en soi d'assez considérable pour mériter beaucoup de lecteurs : mais si mes sujets sont petits mes objets sont grands, et dignes de l'attention de tout honnête homme. Laissons Genève à sa place, et Rousseau dans sa dépression ; mais la religion, mais la liberté, la justice ! voilà , qui que vous soyez, ce qui n'est pas au-dessous de vous. |
---|
554 | n/a | Qu'on ne cherche pas même ici dans le style le dédommagement de l'aridité de la matière. Ceux que quelques traits heureux de ma plume ont si fort irrités trouveront de quoi s'apaiser dans ces lettres, L'honneur de défendre un opprimé eût enflammé mon coeur si j'avais parlé pour un autre. Réduit au triste emploi de me défendre moi-même, j'ai dû me borner à raisonner ; m'échauffer eût été m'avilir. J'aurai donc trouvé grâce en ce point devant ceux qui s'imaginent qu'il est essentiel à la vérité d'être dite froidement ; opinion que pourtant j'ai peine à comprendre. Lorsqu'une vive persuasion nous anime, le moyen d'employer un langage glacé ? Quand Archimède tout transporté courait nu dans les rues de Syracuse, en avait-il moins trouvé la vérité parce qu'il se passionnait pour elle ? Tout au contraire, celui qui la sent ne peut s'abstenir de l'adorer ; celui qui demeure froid ne l'a pas vue. |
---|
555 | n/a | Quoi qu'il en soit, je prie les lecteurs de vouloir bien mettre à part mon beau style, et d'examiner seulement si je raisonne bien ou mal ; car enfin, de cela seul qu'un auteur s'exprime en bons termes, je ne vois pas comment il peut s'ensuivre que cet auteur ne sait ce qu'il dit. |
---|
556 | n/a | """ |
---|