Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6d89775

Browse files
Merge branch 'master' into disable-wchar-cache
2 parents 2c62d96 + 349f76c commit 6d89775

26 files changed

Lines changed: 200 additions & 116 deletions

Doc/c-api/init_config.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ PyConfig
424424
:c:member:`~PyConfig.argv` is empty, an empty string is added to ensure
425425
that :data:`sys.argv` always exists and is never empty.
426426
427+
See also the :c:member:`~PyConfig.orig_argv` member.
428+
427429
.. c:member:: wchar_t* base_exec_prefix
428430
429431
:data:`sys.base_exec_prefix`.
@@ -586,6 +588,23 @@ PyConfig
586588
* 1: Remove assertions, set ``__debug__`` to ``False``
587589
* 2: Strip docstrings
588590
591+
.. c:member:: PyWideStringList orig_argv
592+
593+
The list of the original command line arguments passed to the Python
594+
executable.
595+
596+
If :c:member:`~PyConfig.orig_argv` list is empty and
597+
:c:member:`~PyConfig.argv` is not a list only containing an empty
598+
string, :c:func:`PyConfig_Read()` copies :c:member:`~PyConfig.argv` into
599+
:c:member:`~PyConfig.orig_argv` before modifying
600+
:c:member:`~PyConfig.argv` (if :c:member:`~PyConfig.parse_argv` is
601+
non-zero).
602+
603+
See also the :c:member:`~PyConfig.argv` member and the
604+
:c:func:`Py_GetArgcArgv` function.
605+
606+
.. versionadded:: 3.10
607+
589608
.. c:member:: int parse_argv
590609
591610
If non-zero, parse :c:member:`~PyConfig.argv` the same way the regular
@@ -982,6 +1001,8 @@ Py_GetArgcArgv()
9821001
9831002
Get the original command line arguments, before Python modified them.
9841003
1004+
See also :c:member:`PyConfig.orig_argv` member.
1005+
9851006
9861007
Multi-Phase Initialization Private Provisional API
9871008
--------------------------------------------------

Doc/c-api/unicode.rst

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -724,20 +724,6 @@ Extension modules can continue using them, as they will not be removed in Python
724724
.. versionadded:: 3.3
725725
726726
727-
.. c:function:: Py_UNICODE* PyUnicode_AsUnicodeCopy(PyObject *unicode)
728-
729-
Create a copy of a Unicode string ending with a null code point. Return ``NULL``
730-
and raise a :exc:`MemoryError` exception on memory allocation failure,
731-
otherwise return a new allocated buffer (use :c:func:`PyMem_Free` to free
732-
the buffer). Note that the resulting :c:type:`Py_UNICODE*` string may
733-
contain embedded null code points, which would cause the string to be
734-
truncated when used in most C functions.
735-
736-
.. versionadded:: 3.2
737-
738-
Please migrate to using :c:func:`PyUnicode_AsUCS4Copy` or similar new APIs.
739-
740-
741727
.. c:function:: Py_ssize_t PyUnicode_GetSize(PyObject *unicode)
742728
743729
Return the size of the deprecated :c:type:`Py_UNICODE` representation, in

Doc/data/refcounts.dat

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,9 +2419,6 @@ PyUnicode_AsUnicodeAndSize:Py_UNICODE*:::
24192419
PyUnicode_AsUnicodeAndSize:PyObject*:unicode:0:
24202420
PyUnicode_AsUnicodeAndSize:Py_ssize_t*:size::
24212421

2422-
PyUnicode_AsUnicodeCopy:Py_UNICODE*:::
2423-
PyUnicode_AsUnicodeCopy:PyObject*:unicode:0:
2424-
24252422
PyUnicode_GetSize:Py_ssize_t:::
24262423
PyUnicode_GetSize:PyObject*:unicode:0:
24272424

Doc/library/sys.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ always available.
6666
To loop over the standard input, or the list of files given on the
6767
command line, see the :mod:`fileinput` module.
6868

69+
See also :data:`sys.orig_argv`.
70+
6971
.. note::
7072
On Unix, command line arguments are passed by bytes from OS. Python decodes
7173
them with filesystem encoding and "surrogateescape" error handler.
@@ -1037,6 +1039,16 @@ always available.
10371039
deleting essential items from the dictionary may cause Python to fail.
10381040

10391041

1042+
.. data:: orig_argv
1043+
1044+
The list of the original command line arguments passed to the Python
1045+
executable.
1046+
1047+
See also :data:`sys.argv`.
1048+
1049+
.. versionadded:: 3.10
1050+
1051+
10401052
.. data:: path
10411053

10421054
.. index:: triple: module; search; path

Doc/whatsnew/3.10.rst

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ Added the *root_dir* and *dir_fd* parameters in :func:`~glob.glob` and
110110
:func:`~glob.iglob` which allow to specify the root directory for searching.
111111
(Contributed by Serhiy Storchaka in :issue:`38144`.)
112112

113+
sys
114+
---
115+
116+
Add :data:`sys.orig_argv` attribute: the list of the original command line
117+
arguments passed to the Python executable.
118+
(Contributed by Victor Stinner in :issue:`23427`.)
119+
113120

114121
Optimizations
115122
=============
@@ -150,10 +157,14 @@ C API Changes
150157
New Features
151158
------------
152159

153-
The result of :c:func:`PyNumber_Index` now always has exact type :class:`int`.
160+
* The result of :c:func:`PyNumber_Index` now always has exact type :class:`int`.
154161
Previously, the result could have been an instance of a subclass of ``int``.
155162
(Contributed by Serhiy Storchaka in :issue:`40792`.)
156163

164+
* Add a new :c:member:`~PyConfig.orig_argv` member to the :c:type:`PyConfig`
165+
structure: the list of the original command line arguments passed to the
166+
Python executable.
167+
(Contributed by Victor Stinner in :issue:`23427`.)
157168

158169
Porting to Python 3.10
159170
----------------------
@@ -229,3 +240,7 @@ Removed
229240

230241
* Removed ``PyLong_FromUnicode()``. Please migrate to :c:func:`PyLong_FromUnicodeObject`.
231242
(Contributed by Inada Naoki in :issue:`41103`.)
243+
244+
* Removed ``PyUnicode_AsUnicodeCopy()``. Please use :c:func:`PyUnicode_AsUCS4Copy` or
245+
:c:func:`PyUnicode_AsWideCharString`
246+
(Contributed by Inada Naoki in :issue:`41103`.)

Include/cpython/initconfig.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,15 @@ typedef struct {
408408
Default: 0. */
409409
int _isolated_interpreter;
410410

411-
/* Original command line arguments. If _orig_argv is empty and _argv is
412-
not equal to [''], PyConfig_Read() copies the configuration 'argv' list
413-
into '_orig_argv' list before modifying 'argv' list (if parse_argv
414-
is non-zero).
411+
/* The list of the original command line arguments passed to the Python
412+
executable.
413+
414+
If 'orig_argv' list is empty and 'argv' is not a list only containing an
415+
empty string, PyConfig_Read() copies 'argv' into 'orig_argv' before
416+
modifying 'argv' (if 'parse_argv is non-zero).
415417
416418
_PyConfig_Write() initializes Py_GetArgcArgv() to this list. */
417-
PyWideStringList _orig_argv;
419+
PyWideStringList orig_argv;
418420
} PyConfig;
419421

420422
PyAPI_FUNC(void) PyConfig_InitPythonConfig(PyConfig *config);
@@ -445,7 +447,7 @@ PyAPI_FUNC(PyStatus) PyConfig_SetWideStringList(PyConfig *config,
445447

446448
/* Get the original command line arguments, before Python modified them.
447449
448-
See also PyConfig._orig_argv. */
450+
See also PyConfig.orig_argv. */
449451
PyAPI_FUNC(void) Py_GetArgcArgv(int *argc, wchar_t ***argv);
450452

451453
#endif /* !Py_LIMITED_API */

Include/cpython/unicodeobject.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,14 +1183,6 @@ PyAPI_FUNC(int) _PyUnicode_IsAlpha(
11831183

11841184
PyAPI_FUNC(PyObject*) _PyUnicode_FormatLong(PyObject *, int, int, int);
11851185

1186-
/* Create a copy of a unicode string ending with a nul character. Return NULL
1187-
and raise a MemoryError exception on memory allocation failure, otherwise
1188-
return a new allocated buffer (use PyMem_Free() to free the buffer). */
1189-
1190-
Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE*) PyUnicode_AsUnicodeCopy(
1191-
PyObject *unicode
1192-
);
1193-
11941186
/* Return an interned Unicode object for an Identifier; may fail if there is no memory.*/
11951187
PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*);
11961188

Lib/idlelib/NEWS.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ Released on 2020-10-05?
33
======================================
44

55

6+
bpo-41152: The encoding of ``stdin``, ``stdout`` and ``stderr`` in IDLE
7+
is now always UTF-8.
8+
69
bpo-41144: Make Open Module open a special module such as os.path.
710

811
bpo-40723: Make test_idle pass when run after import.

Lib/idlelib/idle_test/test_outwin.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ def test_write(self):
5858
get = self.text.get
5959
write = self.window.write
6060

61-
# Test bytes.
62-
b = b'Test bytes.'
63-
eq(write(b), len(b))
64-
eq(get('1.0', '1.end'), b.decode())
65-
6661
# No new line - insert stays on same line.
6762
delete('1.0', 'end')
6863
test_text = 'test text'

Lib/idlelib/iomenu.py

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,52 +13,12 @@
1313
import idlelib
1414
from idlelib.config import idleConf
1515

16-
if idlelib.testing: # Set True by test.test_idle to avoid setlocale.
17-
encoding = 'utf-8'
18-
errors = 'surrogateescape'
16+
encoding = 'utf-8'
17+
if sys.platform == 'win32':
18+
errors = 'surrogatepass'
1919
else:
20-
# Try setting the locale, so that we can find out
21-
# what encoding to use
22-
try:
23-
import locale
24-
locale.setlocale(locale.LC_CTYPE, "")
25-
except (ImportError, locale.Error):
26-
pass
27-
28-
if sys.platform == 'win32':
29-
encoding = 'utf-8'
30-
errors = 'surrogateescape'
31-
else:
32-
try:
33-
# Different things can fail here: the locale module may not be
34-
# loaded, it may not offer nl_langinfo, or CODESET, or the
35-
# resulting codeset may be unknown to Python. We ignore all
36-
# these problems, falling back to ASCII
37-
locale_encoding = locale.nl_langinfo(locale.CODESET)
38-
if locale_encoding:
39-
codecs.lookup(locale_encoding)
40-
except (NameError, AttributeError, LookupError):
41-
# Try getdefaultlocale: it parses environment variables,
42-
# which may give a clue. Unfortunately, getdefaultlocale has
43-
# bugs that can cause ValueError.
44-
try:
45-
locale_encoding = locale.getdefaultlocale()[1]
46-
if locale_encoding:
47-
codecs.lookup(locale_encoding)
48-
except (ValueError, LookupError):
49-
pass
20+
errors = 'surrogateescape'
5021

51-
if locale_encoding:
52-
encoding = locale_encoding.lower()
53-
errors = 'strict'
54-
else:
55-
# POSIX locale or macOS
56-
encoding = 'ascii'
57-
errors = 'surrogateescape'
58-
# Encoding is used in multiple files; locale_encoding nowhere.
59-
# The only use of 'encoding' below is in _decode as initial value
60-
# of deprecated block asking user for encoding.
61-
# Perhaps use elsewhere should be reviewed.
6222

6323
coding_re = re.compile(r'^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)', re.ASCII)
6424
blank_re = re.compile(r'^[ \t\f]*(?:[#\r\n]|$)', re.ASCII)

0 commit comments

Comments
 (0)