mirror of https://github.com/python/cpython
merge heads
This commit is contained in:
commit
e56717c3d2
|
@ -641,7 +641,7 @@ class RawDescriptionHelpFormatter(HelpFormatter):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _fill_text(self, text, width, indent):
|
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):
|
class RawTextHelpFormatter(RawDescriptionHelpFormatter):
|
||||||
|
|
|
@ -484,7 +484,7 @@ class StreamReader(Codec):
|
||||||
if firstline:
|
if firstline:
|
||||||
newchars, decodedbytes = \
|
newchars, decodedbytes = \
|
||||||
self.decode(data[:exc.start], self.errors)
|
self.decode(data[:exc.start], self.errors)
|
||||||
lines = newchars.splitlines(True)
|
lines = newchars.splitlines(keepends=True)
|
||||||
if len(lines)<=1:
|
if len(lines)<=1:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
|
@ -526,7 +526,7 @@ class StreamReader(Codec):
|
||||||
self.charbuffer = self.linebuffer[0]
|
self.charbuffer = self.linebuffer[0]
|
||||||
self.linebuffer = None
|
self.linebuffer = None
|
||||||
if not keepends:
|
if not keepends:
|
||||||
line = line.splitlines(False)[0]
|
line = line.splitlines(keepends=False)[0]
|
||||||
return line
|
return line
|
||||||
|
|
||||||
readsize = size or 72
|
readsize = size or 72
|
||||||
|
@ -543,7 +543,7 @@ class StreamReader(Codec):
|
||||||
data += self.read(size=1, chars=1)
|
data += self.read(size=1, chars=1)
|
||||||
|
|
||||||
line += data
|
line += data
|
||||||
lines = line.splitlines(True)
|
lines = line.splitlines(keepends=True)
|
||||||
if lines:
|
if lines:
|
||||||
if len(lines) > 1:
|
if len(lines) > 1:
|
||||||
# More than one line result; the first line is a full line
|
# 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
|
# only one remaining line, put it back into charbuffer
|
||||||
self.charbuffer = lines[0] + self.charbuffer
|
self.charbuffer = lines[0] + self.charbuffer
|
||||||
if not keepends:
|
if not keepends:
|
||||||
line = line.splitlines(False)[0]
|
line = line.splitlines(keepends=False)[0]
|
||||||
break
|
break
|
||||||
line0withend = lines[0]
|
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
|
if line0withend != line0withoutend: # We really have a line end
|
||||||
# Put the rest back together and keep it until the next call
|
# Put the rest back together and keep it until the next call
|
||||||
self.charbuffer = self._empty_charbuffer.join(lines[1:]) + \
|
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
|
# we didn't get anything or this was our only try
|
||||||
if not data or size is not None:
|
if not data or size is not None:
|
||||||
if line and not keepends:
|
if line and not keepends:
|
||||||
line = line.splitlines(False)[0]
|
line = line.splitlines(keepends=False)[0]
|
||||||
break
|
break
|
||||||
if readsize < 8000:
|
if readsize < 8000:
|
||||||
readsize *= 2
|
readsize *= 2
|
||||||
|
@ -803,7 +803,7 @@ class StreamRecoder:
|
||||||
|
|
||||||
data = self.reader.read()
|
data = self.reader.read()
|
||||||
data, bytesencoded = self.encode(data, self.errors)
|
data, bytesencoded = self.encode(data, self.errors)
|
||||||
return data.splitlines(1)
|
return data.splitlines(keepends=True)
|
||||||
|
|
||||||
def __next__(self):
|
def __next__(self):
|
||||||
|
|
||||||
|
|
|
@ -1045,7 +1045,7 @@ class UserString(Sequence):
|
||||||
return self.data.split(sep, maxsplit)
|
return self.data.split(sep, maxsplit)
|
||||||
def rsplit(self, sep=None, maxsplit=-1):
|
def rsplit(self, sep=None, maxsplit=-1):
|
||||||
return self.data.rsplit(sep, maxsplit)
|
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):
|
def startswith(self, prefix, start=0, end=_sys.maxsize):
|
||||||
return self.data.startswith(prefix, start, end)
|
return self.data.startswith(prefix, start, end)
|
||||||
def strip(self, chars=None): return self.__class__(self.data.strip(chars))
|
def strip(self, chars=None): return self.__class__(self.data.strip(chars))
|
||||||
|
|
|
@ -800,7 +800,7 @@ class Differ:
|
||||||
... 2. Explicit is better than implicit.
|
... 2. Explicit is better than implicit.
|
||||||
... 3. Simple is better than complex.
|
... 3. Simple is better than complex.
|
||||||
... 4. Complex is better than complicated.
|
... 4. Complex is better than complicated.
|
||||||
... '''.splitlines(1)
|
... '''.splitlines(keepends=True)
|
||||||
>>> len(text1)
|
>>> len(text1)
|
||||||
4
|
4
|
||||||
>>> text1[0][-1]
|
>>> text1[0][-1]
|
||||||
|
@ -809,7 +809,7 @@ class Differ:
|
||||||
... 3. Simple is better than complex.
|
... 3. Simple is better than complex.
|
||||||
... 4. Complicated is better than complex.
|
... 4. Complicated is better than complex.
|
||||||
... 5. Flat is better than nested.
|
... 5. Flat is better than nested.
|
||||||
... '''.splitlines(1)
|
... '''.splitlines(keepends=True)
|
||||||
|
|
||||||
Next we instantiate a Differ object:
|
Next we instantiate a Differ object:
|
||||||
|
|
||||||
|
@ -896,8 +896,8 @@ class Differ:
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
>>> print(''.join(Differ().compare('one\ntwo\nthree\n'.splitlines(1),
|
>>> print(''.join(Differ().compare('one\ntwo\nthree\n'.splitlines(True),
|
||||||
... 'ore\ntree\nemu\n'.splitlines(1))),
|
... 'ore\ntree\nemu\n'.splitlines(True))),
|
||||||
... end="")
|
... end="")
|
||||||
- one
|
- one
|
||||||
? ^
|
? ^
|
||||||
|
@ -1269,8 +1269,8 @@ def context_diff(a, b, fromfile='', tofile='',
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
>>> print(''.join(context_diff('one\ntwo\nthree\nfour\n'.splitlines(1),
|
>>> print(''.join(context_diff('one\ntwo\nthree\nfour\n'.splitlines(True),
|
||||||
... 'zero\none\ntree\nfour\n'.splitlines(1), 'Original', 'Current')),
|
... 'zero\none\ntree\nfour\n'.splitlines(True), 'Original', 'Current')),
|
||||||
... end="")
|
... end="")
|
||||||
*** Original
|
*** Original
|
||||||
--- Current
|
--- Current
|
||||||
|
@ -1339,8 +1339,8 @@ def ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK):
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
>>> diff = ndiff('one\ntwo\nthree\n'.splitlines(1),
|
>>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True),
|
||||||
... 'ore\ntree\nemu\n'.splitlines(1))
|
... 'ore\ntree\nemu\n'.splitlines(keepends=True))
|
||||||
>>> print(''.join(diff), end="")
|
>>> print(''.join(diff), end="")
|
||||||
- one
|
- one
|
||||||
? ^
|
? ^
|
||||||
|
@ -2034,8 +2034,8 @@ def restore(delta, which):
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
>>> diff = ndiff('one\ntwo\nthree\n'.splitlines(1),
|
>>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True),
|
||||||
... 'ore\ntree\nemu\n'.splitlines(1))
|
... 'ore\ntree\nemu\n'.splitlines(keepends=True))
|
||||||
>>> diff = list(diff)
|
>>> diff = list(diff)
|
||||||
>>> print(''.join(restore(diff, 1)), end="")
|
>>> print(''.join(restore(diff, 1)), end="")
|
||||||
one
|
one
|
||||||
|
|
|
@ -1332,7 +1332,7 @@ class DocTestRunner:
|
||||||
m = self.__LINECACHE_FILENAME_RE.match(filename)
|
m = self.__LINECACHE_FILENAME_RE.match(filename)
|
||||||
if m and m.group('name') == self.test.name:
|
if m and m.group('name') == self.test.name:
|
||||||
example = self.test.examples[int(m.group('examplenum'))]
|
example = self.test.examples[int(m.group('examplenum'))]
|
||||||
return example.source.splitlines(True)
|
return example.source.splitlines(keepends=True)
|
||||||
else:
|
else:
|
||||||
return self.save_linecache_getlines(filename, module_globals)
|
return self.save_linecache_getlines(filename, module_globals)
|
||||||
|
|
||||||
|
@ -1595,8 +1595,8 @@ class OutputChecker:
|
||||||
# Check if we should use diff.
|
# Check if we should use diff.
|
||||||
if self._do_a_fancy_diff(want, got, optionflags):
|
if self._do_a_fancy_diff(want, got, optionflags):
|
||||||
# Split want & got into lines.
|
# Split want & got into lines.
|
||||||
want_lines = want.splitlines(True) # True == keep line ends
|
want_lines = want.splitlines(keepends=True)
|
||||||
got_lines = got.splitlines(True)
|
got_lines = got.splitlines(keepends=True)
|
||||||
# Use difflib to find their differences.
|
# Use difflib to find their differences.
|
||||||
if optionflags & REPORT_UDIFF:
|
if optionflags & REPORT_UDIFF:
|
||||||
diff = difflib.unified_diff(want_lines, got_lines, n=2)
|
diff = difflib.unified_diff(want_lines, got_lines, n=2)
|
||||||
|
|
|
@ -560,7 +560,7 @@ class RefactoringTool(object):
|
||||||
block_lineno = None
|
block_lineno = None
|
||||||
indent = None
|
indent = None
|
||||||
lineno = 0
|
lineno = 0
|
||||||
for line in input.splitlines(True):
|
for line in input.splitlines(keepends=True):
|
||||||
lineno += 1
|
lineno += 1
|
||||||
if line.lstrip().startswith(self.PS1):
|
if line.lstrip().startswith(self.PS1):
|
||||||
if block is not None:
|
if block is not None:
|
||||||
|
@ -604,7 +604,7 @@ class RefactoringTool(object):
|
||||||
filename, lineno, err.__class__.__name__, err)
|
filename, lineno, err.__class__.__name__, err)
|
||||||
return block
|
return block
|
||||||
if self.refactor_tree(tree, filename):
|
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.
|
# Undo the adjustment of the line numbers in wrap_toks() below.
|
||||||
clipped, new = new[:lineno-1], new[lineno-1:]
|
clipped, new = new[:lineno-1], new[lineno-1:]
|
||||||
assert clipped == ["\n"] * (lineno-1), clipped
|
assert clipped == ["\n"] * (lineno-1), clipped
|
||||||
|
|
|
@ -84,7 +84,7 @@ class Template(metaclass=_TemplateMetaclass):
|
||||||
|
|
||||||
def _invalid(self, mo):
|
def _invalid(self, mo):
|
||||||
i = mo.start('invalid')
|
i = mo.start('invalid')
|
||||||
lines = self.template[:i].splitlines(True)
|
lines = self.template[:i].splitlines(keepends=True)
|
||||||
if not lines:
|
if not lines:
|
||||||
colno = 1
|
colno = 1
|
||||||
lineno = 1
|
lineno = 1
|
||||||
|
|
|
@ -177,7 +177,7 @@ class OutputTestCase(unittest.TestCase):
|
||||||
return not c.isspace() and not c.isdigit()
|
return not c.isspace() and not c.isdigit()
|
||||||
|
|
||||||
lines = []
|
lines = []
|
||||||
for line in s.splitlines(False):
|
for line in s.splitlines(keepends=False):
|
||||||
# Drop texts, as they are locale dependent
|
# Drop texts, as they are locale dependent
|
||||||
if line and not filter(neitherspacenordigit, line):
|
if line and not filter(neitherspacenordigit, line):
|
||||||
lines.append(line)
|
lines.append(line)
|
||||||
|
|
|
@ -38,7 +38,7 @@ class TestEmailBase(unittest.TestCase):
|
||||||
return email.message_from_file(fp)
|
return email.message_from_file(fp)
|
||||||
|
|
||||||
def _bytes_repr(self, b):
|
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):
|
def assertBytesEqual(self, first, second, msg):
|
||||||
"""Our byte strings are really encoded strings; improve diff output"""
|
"""Our byte strings are really encoded strings; improve diff output"""
|
||||||
|
|
|
@ -139,7 +139,7 @@ class TestGzip(unittest.TestCase):
|
||||||
with io.BufferedReader(f) as r:
|
with io.BufferedReader(f) as r:
|
||||||
lines = [line for line in 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):
|
def test_readline(self):
|
||||||
self.test_write()
|
self.test_write()
|
||||||
|
@ -340,7 +340,7 @@ class TestGzip(unittest.TestCase):
|
||||||
|
|
||||||
def test_textio_readlines(self):
|
def test_textio_readlines(self):
|
||||||
# Issue #10791: TextIOWrapper.readlines() fails when wrapping GzipFile.
|
# 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()
|
self.test_write()
|
||||||
with gzip.GzipFile(self.filename, 'r') as f:
|
with gzip.GzipFile(self.filename, 'r') as f:
|
||||||
with io.TextIOWrapper(f, encoding="ascii") as t:
|
with io.TextIOWrapper(f, encoding="ascii") as t:
|
||||||
|
|
|
@ -304,7 +304,7 @@ class TestRetrievingSourceCode(GetSourceBase):
|
||||||
getlines = linecache.getlines
|
getlines = linecache.getlines
|
||||||
def monkey(filename, module_globals=None):
|
def monkey(filename, module_globals=None):
|
||||||
if filename == fn:
|
if filename == fn:
|
||||||
return source.splitlines(True)
|
return source.splitlines(keepends=True)
|
||||||
else:
|
else:
|
||||||
return getlines(filename, module_globals)
|
return getlines(filename, module_globals)
|
||||||
linecache.getlines = monkey
|
linecache.getlines = monkey
|
||||||
|
|
|
@ -1935,8 +1935,8 @@ class TextIOWrapperTest(unittest.TestCase):
|
||||||
testdata = b"AAA\nBB\x00B\nCCC\rDDD\rEEE\r\nFFF\r\nGGG"
|
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")
|
normalized = testdata.replace(b"\r\n", b"\n").replace(b"\r", b"\n")
|
||||||
for newline, expected in [
|
for newline, expected in [
|
||||||
(None, normalized.decode("ascii").splitlines(True)),
|
(None, normalized.decode("ascii").splitlines(keepends=True)),
|
||||||
("", testdata.decode("ascii").splitlines(True)),
|
("", testdata.decode("ascii").splitlines(keepends=True)),
|
||||||
("\n", ["AAA\n", "BB\x00B\n", "CCC\rDDD\rEEE\r\n", "FFF\r\n", "GGG"]),
|
("\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\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"]),
|
("\r", ["AAA\nBB\x00B\nCCC\r", "DDD\r", "EEE\r", "\nFFF\r", "\nGGG"]),
|
||||||
|
|
|
@ -1033,12 +1033,12 @@ class NNTPv1v2TestsMixin:
|
||||||
self.assertEqual(resp, success_resp)
|
self.assertEqual(resp, success_resp)
|
||||||
# With an iterable of terminated lines
|
# With an iterable of terminated lines
|
||||||
def iterlines(b):
|
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)
|
resp = self._check_post_ihave_sub(func, *args, file_factory=iterlines)
|
||||||
self.assertEqual(resp, success_resp)
|
self.assertEqual(resp, success_resp)
|
||||||
# With an iterable of non-terminated lines
|
# With an iterable of non-terminated lines
|
||||||
def iterlines(b):
|
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)
|
resp = self._check_post_ihave_sub(func, *args, file_factory=iterlines)
|
||||||
self.assertEqual(resp, success_resp)
|
self.assertEqual(resp, success_resp)
|
||||||
|
|
||||||
|
|
|
@ -238,8 +238,8 @@ def get_pydoc_text(module):
|
||||||
def print_diffs(text1, text2):
|
def print_diffs(text1, text2):
|
||||||
"Prints unified diffs for two texts"
|
"Prints unified diffs for two texts"
|
||||||
# XXX now obsolete, use unittest built-in support
|
# XXX now obsolete, use unittest built-in support
|
||||||
lines1 = text1.splitlines(True)
|
lines1 = text1.splitlines(keepends=True)
|
||||||
lines2 = text2.splitlines(True)
|
lines2 = text2.splitlines(keepends=True)
|
||||||
diffs = difflib.unified_diff(lines1, lines2, n=0, fromfile='expected',
|
diffs = difflib.unified_diff(lines1, lines2, n=0, fromfile='expected',
|
||||||
tofile='got')
|
tofile='got')
|
||||||
print('\n' + ''.join(diffs))
|
print('\n' + ''.join(diffs))
|
||||||
|
|
|
@ -600,7 +600,7 @@ def roundtrip(f):
|
||||||
f.close()
|
f.close()
|
||||||
tokens1 = [tok[:2] for tok in token_list]
|
tokens1 = [tok[:2] for tok in token_list]
|
||||||
new_bytes = untokenize(tokens1)
|
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)]
|
tokens2 = [tok[:2] for tok in tokenize(readline)]
|
||||||
return tokens1 == tokens2
|
return tokens1 == tokens2
|
||||||
|
|
||||||
|
|
|
@ -1010,8 +1010,8 @@ class TestCase(object):
|
||||||
if (len(first) > self._diffThreshold or
|
if (len(first) > self._diffThreshold or
|
||||||
len(second) > self._diffThreshold):
|
len(second) > self._diffThreshold):
|
||||||
self._baseAssertEqual(first, second, msg)
|
self._baseAssertEqual(first, second, msg)
|
||||||
firstlines = first.splitlines(True)
|
firstlines = first.splitlines(keepends=True)
|
||||||
secondlines = second.splitlines(True)
|
secondlines = second.splitlines(keepends=True)
|
||||||
if len(firstlines) == 1 and first.strip('\r\n') == first:
|
if len(firstlines) == 1 and first.strip('\r\n') == first:
|
||||||
firstlines = [first + '\n']
|
firstlines = [first + '\n']
|
||||||
secondlines = [second + '\n']
|
secondlines = [second + '\n']
|
||||||
|
|
Loading…
Reference in New Issue