diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2011-09-28 14:37:55 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2011-09-28 14:37:55 (GMT) |
commit | d8b509b192a67f0f217ae52ed81fc91bc27a1818 (patch) | |
tree | adab8922723e179e67d546100d19d06d444d7599 /Lib | |
parent | a6e50f589fa328a77b70cde0747f70210c650f49 (diff) | |
download | cpython-d8b509b192a67f0f217ae52ed81fc91bc27a1818.zip cpython-d8b509b192a67f0f217ae52ed81fc91bc27a1818.tar.gz cpython-d8b509b192a67f0f217ae52ed81fc91bc27a1818.tar.bz2 |
#13012: use splitlines(keepends=True/False) instead of splitlines(0/1).
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/argparse.py | 2 | ||||
-rw-r--r-- | Lib/codecs.py | 14 | ||||
-rw-r--r-- | Lib/collections/__init__.py | 2 | ||||
-rw-r--r-- | Lib/difflib.py | 20 | ||||
-rw-r--r-- | Lib/doctest.py | 6 | ||||
-rw-r--r-- | Lib/lib2to3/refactor.py | 4 | ||||
-rw-r--r-- | Lib/string.py | 2 | ||||
-rw-r--r-- | Lib/test/test_calendar.py | 2 | ||||
-rw-r--r-- | Lib/test/test_email/__init__.py | 2 | ||||
-rw-r--r-- | Lib/test/test_gzip.py | 4 | ||||
-rw-r--r-- | Lib/test/test_inspect.py | 2 | ||||
-rw-r--r-- | Lib/test/test_io.py | 4 | ||||
-rw-r--r-- | Lib/test/test_nntplib.py | 4 | ||||
-rw-r--r-- | Lib/test/test_pydoc.py | 4 | ||||
-rw-r--r-- | Lib/test/test_tokenize.py | 2 | ||||
-rw-r--r-- | Lib/unittest/case.py | 4 |
16 files changed, 39 insertions, 39 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py index f0cfe27..236e1e8 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -641,7 +641,7 @@ class RawDescriptionHelpFormatter(HelpFormatter): """ def _fill_text(self, text, width, indent): - return ''.join([indent + line for line in text.splitlines(True)]) + return ''.join(indent + line for line in text.splitlines(keepends=True)) class RawTextHelpFormatter(RawDescriptionHelpFormatter): diff --git a/Lib/codecs.py b/Lib/codecs.py index b150d64..e63a0c6 100644 --- a/Lib/codecs.py +++ b/Lib/codecs.py @@ -484,7 +484,7 @@ class StreamReader(Codec): if firstline: newchars, decodedbytes = \ self.decode(data[:exc.start], self.errors) - lines = newchars.splitlines(True) + lines = newchars.splitlines(keepends=True) if len(lines)<=1: raise else: @@ -526,7 +526,7 @@ class StreamReader(Codec): self.charbuffer = self.linebuffer[0] self.linebuffer = None if not keepends: - line = line.splitlines(False)[0] + line = line.splitlines(keepends=False)[0] return line readsize = size or 72 @@ -543,7 +543,7 @@ class StreamReader(Codec): data += self.read(size=1, chars=1) line += data - lines = line.splitlines(True) + lines = line.splitlines(keepends=True) if lines: if len(lines) > 1: # More than one line result; the first line is a full line @@ -559,10 +559,10 @@ class StreamReader(Codec): # only one remaining line, put it back into charbuffer self.charbuffer = lines[0] + self.charbuffer if not keepends: - line = line.splitlines(False)[0] + line = line.splitlines(keepends=False)[0] break line0withend = lines[0] - line0withoutend = lines[0].splitlines(False)[0] + line0withoutend = lines[0].splitlines(keepends=False)[0] if line0withend != line0withoutend: # We really have a line end # Put the rest back together and keep it until the next call self.charbuffer = self._empty_charbuffer.join(lines[1:]) + \ @@ -575,7 +575,7 @@ class StreamReader(Codec): # we didn't get anything or this was our only try if not data or size is not None: if line and not keepends: - line = line.splitlines(False)[0] + line = line.splitlines(keepends=False)[0] break if readsize < 8000: readsize *= 2 @@ -803,7 +803,7 @@ class StreamRecoder: data = self.reader.read() data, bytesencoded = self.encode(data, self.errors) - return data.splitlines(1) + return data.splitlines(keepends=True) def __next__(self): diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index e5e0277..3e864b6 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -1045,7 +1045,7 @@ class UserString(Sequence): return self.data.split(sep, maxsplit) def rsplit(self, sep=None, maxsplit=-1): return self.data.rsplit(sep, maxsplit) - def splitlines(self, keepends=0): return self.data.splitlines(keepends) + def splitlines(self, keepends=False): return self.data.splitlines(keepends) def startswith(self, prefix, start=0, end=_sys.maxsize): return self.data.startswith(prefix, start, end) def strip(self, chars=None): return self.__class__(self.data.strip(chars)) diff --git a/Lib/difflib.py b/Lib/difflib.py index e6cc6ee..d34bbca 100644 --- a/Lib/difflib.py +++ b/Lib/difflib.py @@ -800,7 +800,7 @@ class Differ: ... 2. Explicit is better than implicit. ... 3. Simple is better than complex. ... 4. Complex is better than complicated. - ... '''.splitlines(1) + ... '''.splitlines(keepends=True) >>> len(text1) 4 >>> text1[0][-1] @@ -809,7 +809,7 @@ class Differ: ... 3. Simple is better than complex. ... 4. Complicated is better than complex. ... 5. Flat is better than nested. - ... '''.splitlines(1) + ... '''.splitlines(keepends=True) Next we instantiate a Differ object: @@ -896,8 +896,8 @@ class Differ: Example: - >>> print(''.join(Differ().compare('one\ntwo\nthree\n'.splitlines(1), - ... 'ore\ntree\nemu\n'.splitlines(1))), + >>> print(''.join(Differ().compare('one\ntwo\nthree\n'.splitlines(True), + ... 'ore\ntree\nemu\n'.splitlines(True))), ... end="") - one ? ^ @@ -1269,8 +1269,8 @@ def context_diff(a, b, fromfile='', tofile='', Example: - >>> print(''.join(context_diff('one\ntwo\nthree\nfour\n'.splitlines(1), - ... 'zero\none\ntree\nfour\n'.splitlines(1), 'Original', 'Current')), + >>> print(''.join(context_diff('one\ntwo\nthree\nfour\n'.splitlines(True), + ... 'zero\none\ntree\nfour\n'.splitlines(True), 'Original', 'Current')), ... end="") *** Original --- Current @@ -1339,8 +1339,8 @@ def ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK): Example: - >>> diff = ndiff('one\ntwo\nthree\n'.splitlines(1), - ... 'ore\ntree\nemu\n'.splitlines(1)) + >>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True), + ... 'ore\ntree\nemu\n'.splitlines(keepends=True)) >>> print(''.join(diff), end="") - one ? ^ @@ -2034,8 +2034,8 @@ def restore(delta, which): Examples: - >>> diff = ndiff('one\ntwo\nthree\n'.splitlines(1), - ... 'ore\ntree\nemu\n'.splitlines(1)) + >>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True), + ... 'ore\ntree\nemu\n'.splitlines(keepends=True)) >>> diff = list(diff) >>> print(''.join(restore(diff, 1)), end="") one diff --git a/Lib/doctest.py b/Lib/doctest.py index be8cc23..9d1501c 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -1332,7 +1332,7 @@ class DocTestRunner: m = self.__LINECACHE_FILENAME_RE.match(filename) if m and m.group('name') == self.test.name: example = self.test.examples[int(m.group('examplenum'))] - return example.source.splitlines(True) + return example.source.splitlines(keepends=True) else: return self.save_linecache_getlines(filename, module_globals) @@ -1595,8 +1595,8 @@ class OutputChecker: # Check if we should use diff. if self._do_a_fancy_diff(want, got, optionflags): # Split want & got into lines. - want_lines = want.splitlines(True) # True == keep line ends - got_lines = got.splitlines(True) + want_lines = want.splitlines(keepends=True) + got_lines = got.splitlines(keepends=True) # Use difflib to find their differences. if optionflags & REPORT_UDIFF: diff = difflib.unified_diff(want_lines, got_lines, n=2) diff --git a/Lib/lib2to3/refactor.py b/Lib/lib2to3/refactor.py index ae5e40f..3c06405 100644 --- a/Lib/lib2to3/refactor.py +++ b/Lib/lib2to3/refactor.py @@ -560,7 +560,7 @@ class RefactoringTool(object): block_lineno = None indent = None lineno = 0 - for line in input.splitlines(True): + for line in input.splitlines(keepends=True): lineno += 1 if line.lstrip().startswith(self.PS1): if block is not None: @@ -604,7 +604,7 @@ class RefactoringTool(object): filename, lineno, err.__class__.__name__, err) return block if self.refactor_tree(tree, filename): - new = str(tree).splitlines(True) + new = str(tree).splitlines(keepends=True) # Undo the adjustment of the line numbers in wrap_toks() below. clipped, new = new[:lineno-1], new[lineno-1:] assert clipped == ["\n"] * (lineno-1), clipped diff --git a/Lib/string.py b/Lib/string.py index d4f9cd9..8bcd1dc 100644 --- a/Lib/string.py +++ b/Lib/string.py @@ -84,7 +84,7 @@ class Template(metaclass=_TemplateMetaclass): def _invalid(self, mo): i = mo.start('invalid') - lines = self.template[:i].splitlines(True) + lines = self.template[:i].splitlines(keepends=True) if not lines: colno = 1 lineno = 1 diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py index d3093ac..7180afe 100644 --- a/Lib/test/test_calendar.py +++ b/Lib/test/test_calendar.py @@ -177,7 +177,7 @@ class OutputTestCase(unittest.TestCase): return not c.isspace() and not c.isdigit() lines = [] - for line in s.splitlines(False): + for line in s.splitlines(keepends=False): # Drop texts, as they are locale dependent if line and not filter(neitherspacenordigit, line): lines.append(line) diff --git a/Lib/test/test_email/__init__.py b/Lib/test/test_email/__init__.py index 04fdf89..280afbd 100644 --- a/Lib/test/test_email/__init__.py +++ b/Lib/test/test_email/__init__.py @@ -38,7 +38,7 @@ class TestEmailBase(unittest.TestCase): return email.message_from_file(fp) def _bytes_repr(self, b): - return [repr(x) for x in b.splitlines(True)] + return [repr(x) for x in b.splitlines(keepends=True)] def assertBytesEqual(self, first, second, msg): """Our byte strings are really encoded strings; improve diff output""" diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py index 3ea5c41..9c7a96e 100644 --- a/Lib/test/test_gzip.py +++ b/Lib/test/test_gzip.py @@ -139,7 +139,7 @@ class TestGzip(unittest.TestCase): with io.BufferedReader(f) as r: lines = [line for line in r] - self.assertEqual(lines, 50 * data1.splitlines(True)) + self.assertEqual(lines, 50 * data1.splitlines(keepends=True)) def test_readline(self): self.test_write() @@ -340,7 +340,7 @@ class TestGzip(unittest.TestCase): def test_textio_readlines(self): # Issue #10791: TextIOWrapper.readlines() fails when wrapping GzipFile. - lines = (data1 * 50).decode("ascii").splitlines(True) + lines = (data1 * 50).decode("ascii").splitlines(keepends=True) self.test_write() with gzip.GzipFile(self.filename, 'r') as f: with io.TextIOWrapper(f, encoding="ascii") as t: diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 7666fe4..06132f2 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -304,7 +304,7 @@ class TestRetrievingSourceCode(GetSourceBase): getlines = linecache.getlines def monkey(filename, module_globals=None): if filename == fn: - return source.splitlines(True) + return source.splitlines(keepends=True) else: return getlines(filename, module_globals) linecache.getlines = monkey diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 2c502ab..117f8ab 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -1935,8 +1935,8 @@ class TextIOWrapperTest(unittest.TestCase): testdata = b"AAA\nBB\x00B\nCCC\rDDD\rEEE\r\nFFF\r\nGGG" normalized = testdata.replace(b"\r\n", b"\n").replace(b"\r", b"\n") for newline, expected in [ - (None, normalized.decode("ascii").splitlines(True)), - ("", testdata.decode("ascii").splitlines(True)), + (None, normalized.decode("ascii").splitlines(keepends=True)), + ("", testdata.decode("ascii").splitlines(keepends=True)), ("\n", ["AAA\n", "BB\x00B\n", "CCC\rDDD\rEEE\r\n", "FFF\r\n", "GGG"]), ("\r\n", ["AAA\nBB\x00B\nCCC\rDDD\rEEE\r\n", "FFF\r\n", "GGG"]), ("\r", ["AAA\nBB\x00B\nCCC\r", "DDD\r", "EEE\r", "\nFFF\r", "\nGGG"]), diff --git a/Lib/test/test_nntplib.py b/Lib/test/test_nntplib.py index ec790ad..d8e6332 100644 --- a/Lib/test/test_nntplib.py +++ b/Lib/test/test_nntplib.py @@ -1033,12 +1033,12 @@ class NNTPv1v2TestsMixin: self.assertEqual(resp, success_resp) # With an iterable of terminated lines def iterlines(b): - return iter(b.splitlines(True)) + return iter(b.splitlines(keepends=True)) resp = self._check_post_ihave_sub(func, *args, file_factory=iterlines) self.assertEqual(resp, success_resp) # With an iterable of non-terminated lines def iterlines(b): - return iter(b.splitlines(False)) + return iter(b.splitlines(keepends=False)) resp = self._check_post_ihave_sub(func, *args, file_factory=iterlines) self.assertEqual(resp, success_resp) diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index ae56996..6d3923f 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -238,8 +238,8 @@ def get_pydoc_text(module): def print_diffs(text1, text2): "Prints unified diffs for two texts" # XXX now obsolete, use unittest built-in support - lines1 = text1.splitlines(True) - lines2 = text2.splitlines(True) + lines1 = text1.splitlines(keepends=True) + lines2 = text2.splitlines(keepends=True) diffs = difflib.unified_diff(lines1, lines2, n=0, fromfile='expected', tofile='got') print('\n' + ''.join(diffs)) diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py index 9e9656c..af2bbf1 100644 --- a/Lib/test/test_tokenize.py +++ b/Lib/test/test_tokenize.py @@ -600,7 +600,7 @@ def roundtrip(f): f.close() tokens1 = [tok[:2] for tok in token_list] new_bytes = untokenize(tokens1) - readline = (line for line in new_bytes.splitlines(1)).__next__ + readline = (line for line in new_bytes.splitlines(keepends=True)).__next__ tokens2 = [tok[:2] for tok in tokenize(readline)] return tokens1 == tokens2 diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index d82fa20..cc5f0c3 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -1010,8 +1010,8 @@ class TestCase(object): if (len(first) > self._diffThreshold or len(second) > self._diffThreshold): self._baseAssertEqual(first, second, msg) - firstlines = first.splitlines(True) - secondlines = second.splitlines(True) + firstlines = first.splitlines(keepends=True) + secondlines = second.splitlines(keepends=True) if len(firstlines) == 1 and first.strip('\r\n') == first: firstlines = [first + '\n'] secondlines = [second + '\n'] |