diff options
author | shadchin <[email protected]> | 2022-02-10 16:44:39 +0300 |
---|---|---|
committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:44:39 +0300 |
commit | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch) | |
tree | 64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/cython/Cython/Utils.py | |
parent | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff) |
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/cython/Cython/Utils.py')
-rw-r--r-- | contrib/tools/cython/Cython/Utils.py | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/contrib/tools/cython/Cython/Utils.py b/contrib/tools/cython/Cython/Utils.py index c1159a33811..d59d67d78b1 100644 --- a/contrib/tools/cython/Cython/Utils.py +++ b/contrib/tools/cython/Cython/Utils.py @@ -21,7 +21,7 @@ import re import io import codecs import shutil -import tempfile +import tempfile from contextlib import contextmanager modification_time = os.path.getmtime @@ -337,23 +337,23 @@ def get_cython_cache_dir(): def captured_fd(stream=2, encoding=None): orig_stream = os.dup(stream) # keep copy of original stream try: - with tempfile.TemporaryFile(mode="a+b") as temp_file: - def read_output(_output=[b'']): - if not temp_file.closed: - temp_file.seek(0) - _output[0] = temp_file.read() - return _output[0] - - os.dup2(temp_file.fileno(), stream) # replace stream by copy of pipe - try: - def get_output(): - result = read_output() - return result.decode(encoding) if encoding else result - - yield get_output - finally: - os.dup2(orig_stream, stream) # restore original stream - read_output() # keep the output in case it's used after closing the context manager + with tempfile.TemporaryFile(mode="a+b") as temp_file: + def read_output(_output=[b'']): + if not temp_file.closed: + temp_file.seek(0) + _output[0] = temp_file.read() + return _output[0] + + os.dup2(temp_file.fileno(), stream) # replace stream by copy of pipe + try: + def get_output(): + result = read_output() + return result.decode(encoding) if encoding else result + + yield get_output + finally: + os.dup2(orig_stream, stream) # restore original stream + read_output() # keep the output in case it's used after closing the context manager finally: os.close(orig_stream) @@ -427,7 +427,7 @@ def raise_error_if_module_name_forbidden(full_module_name): def build_hex_version(version_string): """ - Parse and translate '4.3a1' into the readable hex representation '0x040300A1' (like PY_VERSION_HEX). + Parse and translate '4.3a1' into the readable hex representation '0x040300A1' (like PY_VERSION_HEX). """ # First, parse '4.12a1' into [4, 12, 0, 0xA01]. digits = [] |