[Python-checkins] r68380 - sandbox/trunk/iobench/iobench.py
antoine.pitrou
python-checkins at python.org
Wed Jan 7 18:56:18 CET 2009
Author: antoine.pitrou
Date: Wed Jan 7 18:56:17 2009
New Revision: 68380
Log:
Sprinkle some non-UNIX newlines in text test files to exercise newline translation.
Modified:
sandbox/trunk/iobench/iobench.py
Modified: sandbox/trunk/iobench/iobench.py
==============================================================================
--- sandbox/trunk/iobench/iobench.py (original)
+++ sandbox/trunk/iobench/iobench.py Wed Jan 7 18:56:17 2009
@@ -7,6 +7,7 @@
import sys
import hashlib
import functools
+import itertools
from optparse import OptionParser
out = sys.stdout
@@ -369,14 +370,16 @@
f.write(os.urandom(size))
# Text files
chunk = []
- with text_open(__file__, "r", encoding='utf8') as f:
+ with text_open(__file__, "rU", encoding='utf8') as f:
for line in f:
if line.startswith("# <iobench text chunk marker>"):
break
else:
raise RuntimeError(
"Couldn't find chunk marker in %s !" % __file__)
- chunk = "".join(f)
+ # Change some newlines to exercise newlines translation (in 3.x)
+ newlines = itertools.cycle(["\n", "\r", "\r\n"])
+ chunk = "".join(line.replace("\n", next(newlines)) for line in f)
if isinstance(chunk, bytes):
chunk = chunk.decode('utf8')
chunk = chunk.encode(TEXT_ENCODING)
More information about the Python-checkins
mailing list