Skip to content

Commit 2ee7eae

Browse files
committed
Issue #17173: Remove uses of locale-dependent C functions (isalpha() etc.) in the interpreter.
I've left a couple of them in: zlib (third-party lib), getaddrinfo.c (doesn't include Python.h, and probably obsolete), _sre.c (legitimate use for the re.LOCALE flag), mpdecimal (needs to build without Python.h).
2 parents b9006e9 + 0b7a839 commit 2ee7eae

706 files changed

Lines changed: 40555 additions & 65549 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.hgignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.gdb_history
22
.purify
33
.svn/
4+
DS_Store
45
Makefile$
56
Makefile.pre$
67
TAGS$
@@ -17,6 +18,8 @@ platform$
1718
pyconfig.h$
1819
python$
1920
python.exe$
21+
python-config$
22+
python-config.py$
2023
reflog.txt$
2124
tags$
2225
Lib/plat-mac/errors.rsrc.df.rsrc
@@ -26,6 +29,7 @@ Doc/tools/jinja/
2629
Doc/tools/jinja2/
2730
Doc/tools/pygments/
2831
Misc/python.pc
32+
Misc/python-config.sh$
2933
Modules/Setup$
3034
Modules/Setup.config
3135
Modules/Setup.local

Doc/c-api/object.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,15 @@ is considered sufficient for this determination.
342342
returned. This is the equivalent to the Python expression ``len(o)``.
343343
344344
345+
.. c:function:: Py_ssize_t PyObject_LengthHint(PyObject *o, Py_ssize_t default)
346+
347+
Return an estimated length for the object *o*. First trying to return its
348+
actual length, then an estimate using ``__length_hint__``, and finally
349+
returning the default value. On error ``-1`` is returned. This is the
350+
equivalent to the Python expression ``operator.length_hint(o, default)``.
351+
352+
.. versionadded:: 3.4
353+
345354
.. c:function:: PyObject* PyObject_GetItem(PyObject *o, PyObject *key)
346355
347356
Return element of *o* corresponding to the object *key* or *NULL* on failure.

Doc/faq/library.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ using curses, but curses is a fairly large module to learn.
209209
try:
210210
c = sys.stdin.read(1)
211211
print("Got character", repr(c))
212-
except IOError:
212+
except OSError:
213213
pass
214214
finally:
215215
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
@@ -222,7 +222,11 @@ using curses, but curses is a fairly large module to learn.
222222
:func:`termios.tcsetattr` turns off stdin's echoing and disables canonical
223223
mode. :func:`fcntl.fnctl` is used to obtain stdin's file descriptor flags
224224
and modify them for non-blocking mode. Since reading stdin when it is empty
225-
results in an :exc:`IOError`, this error is caught and ignored.
225+
results in an :exc:`OSError`, this error is caught and ignored.
226+
227+
.. versionchanged:: 3.3
228+
*sys.stdin.read* used to raise :exc:`IOError`. Starting from Python 3.3
229+
:exc:`IOError` is alias for :exc:`OSError`.
226230
227231
228232
Threads

Doc/howto/logging-cookbook.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,9 +741,7 @@ the basis for code meeting your own specific requirements::
741741
break
742742
logger = logging.getLogger(record.name)
743743
logger.handle(record) # No level or filter logic applied - just do it!
744-
except (KeyboardInterrupt, SystemExit):
745-
raise
746-
except:
744+
except Exception:
747745
import sys, traceback
748746
print('Whoops! Problem:', file=sys.stderr)
749747
traceback.print_exc(file=sys.stderr)

Doc/library/2to3.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ and off individually. They are described here in more detail.
342342
343343
Handles the move of :func:`reduce` to :func:`functools.reduce`.
344344
345+
.. 2to3fixer:: reload
346+
347+
Converts :func:`reload` to :func:`imp.reload`.
348+
345349
.. 2to3fixer:: renames
346350
347351
Changes :data:`sys.maxint` to :data:`sys.maxsize`.

Doc/library/abc.rst

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
--------------
1313

1414
This module provides the infrastructure for defining :term:`abstract base
15-
classes <abstract base class>` (ABCs) in Python, as outlined in :pep:`3119`; see the PEP for why this
16-
was added to Python. (See also :pep:`3141` and the :mod:`numbers` module
17-
regarding a type hierarchy for numbers based on ABCs.)
15+
classes <abstract base class>` (ABCs) in Python, as outlined in :pep:`3119`;
16+
see the PEP for why this was added to Python. (See also :pep:`3141` and the
17+
:mod:`numbers` module regarding a type hierarchy for numbers based on ABCs.)
1818

1919
The :mod:`collections` module has some concrete classes that derive from
2020
ABCs; these can, of course, be further derived. In addition the
@@ -23,7 +23,7 @@ a class or instance provides a particular interface, for example, is it
2323
hashable or a mapping.
2424

2525

26-
This module provides the following class:
26+
This module provides the following classes:
2727

2828
.. class:: ABCMeta
2929

@@ -127,6 +127,19 @@ This module provides the following class:
127127
available as a method of ``Foo``, so it is provided separately.
128128

129129

130+
.. class:: ABC
131+
132+
A helper class that has :class:`ABCMeta` as its metaclass. With this class,
133+
an abstract base class can be created by simply deriving from :class:`ABC`,
134+
avoiding sometimes confusing metaclass usage.
135+
136+
Note that the type of :class:`ABC` is still :class:`ABCMeta`, therefore
137+
inheriting from :class:`ABC` requires the usual precautions regarding metaclass
138+
usage, as multiple inheritance may lead to metaclass conflicts.
139+
140+
.. versionadded:: 3.4
141+
142+
130143
The :mod:`abc` module also provides the following decorators:
131144

132145
.. decorator:: abstractmethod

Doc/library/aifc.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ Module :mod:`aifc` defines the following function:
5151
used for writing, the file object should be seekable, unless you know ahead of
5252
time how many samples you are going to write in total and use
5353
:meth:`writeframesraw` and :meth:`setnframes`.
54+
Objects returned by :func:`.open` also supports the :keyword:`with` statement.
55+
56+
.. versionchanged:: 3.4
57+
Support for the :keyword:`with` statement was added.
5458

5559
Objects returned by :func:`.open` when a file is opened for reading have the
5660
following methods:

Doc/library/argparse.rst

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -976,9 +976,9 @@ See the section on the default_ keyword argument for information on when the
976976
``type`` argument is applied to default arguments.
977977

978978
To ease the use of various types of files, the argparse module provides the
979-
factory FileType which takes the ``mode=`` and ``bufsize=`` arguments of the
980-
:func:`open` function. For example, ``FileType('w')`` can be used to create a
981-
writable file::
979+
factory FileType which takes the ``mode=``, ``bufsize=``, ``encoding=`` and
980+
``errors=`` arguments of the :func:`open` function. For example,
981+
``FileType('w')`` can be used to create a writable file::
982982

983983
>>> parser = argparse.ArgumentParser()
984984
>>> parser.add_argument('bar', type=argparse.FileType('w'))
@@ -1618,17 +1618,19 @@ Sub-commands
16181618
FileType objects
16191619
^^^^^^^^^^^^^^^^
16201620

1621-
.. class:: FileType(mode='r', bufsize=None)
1621+
.. class:: FileType(mode='r', bufsize=-1, encoding=None, errors=None)
16221622

16231623
The :class:`FileType` factory creates objects that can be passed to the type
16241624
argument of :meth:`ArgumentParser.add_argument`. Arguments that have
1625-
:class:`FileType` objects as their type will open command-line arguments as files
1626-
with the requested modes and buffer sizes::
1625+
:class:`FileType` objects as their type will open command-line arguments as
1626+
files with the requested modes, buffer sizes, encodings and error handling
1627+
(see the :func:`open` function for more details)::
16271628

16281629
>>> parser = argparse.ArgumentParser()
1629-
>>> parser.add_argument('--output', type=argparse.FileType('wb', 0))
1630-
>>> parser.parse_args(['--output', 'out'])
1631-
Namespace(output=<_io.BufferedWriter name='out'>)
1630+
>>> parser.add_argument('--raw', type=argparse.FileType('wb', 0))
1631+
>>> parser.add_argument('out', type=argparse.FileType('w', encoding='UTF-8'))
1632+
>>> parser.parse_args(['--raw', 'raw.dat', 'file.txt'])
1633+
Namespace(out=<_io.TextIOWrapper name='file.txt' mode='w' encoding='UTF-8'>, raw=<_io.FileIO name='raw.dat' mode='wb'>)
16321634

16331635
FileType objects understand the pseudo-argument ``'-'`` and automatically
16341636
convert this into ``sys.stdin`` for readable :class:`FileType` objects and

Doc/library/collections.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,19 @@ The class can be used to simulate nested scopes and is useful in templating.
7676
be modified to change which mappings are searched. The list should
7777
always contain at least one mapping.
7878

79-
.. method:: new_child()
79+
.. method:: new_child(m=None)
8080

81-
Returns a new :class:`ChainMap` containing a new :class:`dict` followed by
82-
all of the maps in the current instance. A call to ``d.new_child()`` is
83-
equivalent to: ``ChainMap({}, *d.maps)``. This method is used for
81+
Returns a new :class:`ChainMap` containing a new map followed by
82+
all of the maps in the current instance. If ``m`` is specified,
83+
it becomes the new map at the front of the list of mappings; if not
84+
specified, an empty dict is used, so that a call to ``d.new_child()``
85+
is equivalent to: ``ChainMap({}, *d.maps)``. This method is used for
8486
creating subcontexts that can be updated without altering values in any
8587
of the parent mappings.
8688

89+
.. versionchanged:: 3.4
90+
The optional ``m`` parameter was added.
91+
8792
.. attribute:: parents
8893

8994
Property returning a new :class:`ChainMap` containing all of the maps in

Doc/library/doctest.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,16 @@ The second group of options controls how test failures are reported:
633633
the output is suppressed.
634634

635635

636+
.. data:: FAIL_FAST
637+
638+
When specified, exit after the first failing example and don't attempt to run
639+
the remaining examples. Thus, the number of failures reported will be at most
640+
1. This flag may be useful during debugging, since examples after the first
641+
failure won't even produce debugging output.
642+
643+
.. versionadded:: 3.4
644+
645+
636646
.. data:: REPORTING_FLAGS
637647

638648
A bitmask or'ing together all the reporting flags above.

0 commit comments

Comments
 (0)