mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
GH-90344: replace single-call io.IncrementalNewlineDecoder usage with non-incremental newline decoders (GH-30276)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Brett Cannon <brett@python.org>
This commit is contained in:
parent
f0a8bc737a
commit
453d886f85
4 changed files with 5 additions and 10 deletions
|
|
@ -104,7 +104,7 @@ def _test():
|
|||
import traceback
|
||||
import types
|
||||
import unittest
|
||||
from io import StringIO, IncrementalNewlineDecoder
|
||||
from io import StringIO, TextIOWrapper, BytesIO
|
||||
from collections import namedtuple
|
||||
import _colorize # Used in doctests
|
||||
from _colorize import ANSIColors, can_colorize
|
||||
|
|
@ -237,10 +237,6 @@ def _normalize_module(module, depth=2):
|
|||
else:
|
||||
raise TypeError("Expected a module, string, or None")
|
||||
|
||||
def _newline_convert(data):
|
||||
# The IO module provides a handy decoder for universal newline conversion
|
||||
return IncrementalNewlineDecoder(None, True).decode(data, True)
|
||||
|
||||
def _load_testfile(filename, package, module_relative, encoding):
|
||||
if module_relative:
|
||||
package = _normalize_module(package, 3)
|
||||
|
|
@ -252,10 +248,9 @@ def _load_testfile(filename, package, module_relative, encoding):
|
|||
pass
|
||||
if hasattr(loader, 'get_data'):
|
||||
file_contents = loader.get_data(filename)
|
||||
file_contents = file_contents.decode(encoding)
|
||||
# get_data() opens files as 'rb', so one must do the equivalent
|
||||
# conversion as universal newlines would do.
|
||||
return _newline_convert(file_contents), filename
|
||||
return TextIOWrapper(BytesIO(file_contents), encoding=encoding, newline=None).read(), filename
|
||||
with open(filename, encoding=encoding) as f:
|
||||
return f.read(), filename
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue