mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
Issue #6215: backport the 3.1 io lib
This commit is contained in:
parent
55bd1efb2a
commit
1969059327
21 changed files with 11865 additions and 3018 deletions
|
|
@ -29,7 +29,7 @@ __all__ = ["Error", "TestFailed", "ResourceDenied", "import_module",
|
|||
"run_with_locale", "set_memlimit", "bigmemtest", "bigaddrspacetest",
|
||||
"BasicTestRunner", "run_unittest", "run_doctest", "threading_setup",
|
||||
"threading_cleanup", "reap_children", "cpython_only",
|
||||
"check_impl_detail", "get_attribute"]
|
||||
"check_impl_detail", "get_attribute", "py3k_bytes"]
|
||||
|
||||
class Error(Exception):
|
||||
"""Base class for regression test exceptions."""
|
||||
|
|
@ -968,3 +968,18 @@ def reap_children():
|
|||
break
|
||||
except:
|
||||
break
|
||||
|
||||
def py3k_bytes(b):
|
||||
"""Emulate the py3k bytes() constructor.
|
||||
|
||||
NOTE: This is only a best effort function.
|
||||
"""
|
||||
try:
|
||||
# memoryview?
|
||||
return b.tobytes()
|
||||
except AttributeError:
|
||||
try:
|
||||
# iterable of ints?
|
||||
return b"".join(chr(x) for x in b)
|
||||
except TypeError:
|
||||
return bytes(b)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue