2007-08-15 11:28:22 -03:00
|
|
|
|
:mod:`codecs` --- Codec registry and base classes
|
|
|
|
|
=================================================
|
|
|
|
|
|
|
|
|
|
.. module:: codecs
|
|
|
|
|
:synopsis: Encode and decode data and streams.
|
2016-06-11 16:02:54 -03:00
|
|
|
|
|
2012-08-11 11:51:50 -03:00
|
|
|
|
.. moduleauthor:: Marc-André Lemburg <mal@lemburg.com>
|
|
|
|
|
.. sectionauthor:: Marc-André Lemburg <mal@lemburg.com>
|
2007-08-15 11:28:22 -03:00
|
|
|
|
.. sectionauthor:: Martin v. Löwis <martin@v.loewis.de>
|
|
|
|
|
|
2014-03-19 17:23:01 -03:00
|
|
|
|
**Source code:** :source:`Lib/codecs.py`
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
.. index::
|
|
|
|
|
single: Unicode
|
|
|
|
|
single: Codecs
|
|
|
|
|
pair: Codecs; encode
|
|
|
|
|
pair: Codecs; decode
|
|
|
|
|
single: streams
|
|
|
|
|
pair: stackable; streams
|
|
|
|
|
|
2016-06-11 16:02:54 -03:00
|
|
|
|
--------------
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
This module defines base classes for standard Python codecs (encoders and
|
2015-01-06 10:22:00 -04:00
|
|
|
|
decoders) and provides access to the internal Python codec registry, which
|
|
|
|
|
manages the codec and error handling lookup process. Most standard codecs
|
|
|
|
|
are :term:`text encodings <text encoding>`, which encode text to bytes,
|
|
|
|
|
but there are also codecs provided that encode text to text, and bytes to
|
|
|
|
|
bytes. Custom codecs may encode and decode between arbitrary types, but some
|
|
|
|
|
module features are restricted to use specifically with
|
|
|
|
|
:term:`text encodings <text encoding>`, or with codecs that encode to
|
|
|
|
|
:class:`bytes`.
|
|
|
|
|
|
|
|
|
|
The module defines the following functions for encoding and decoding with
|
|
|
|
|
any codec:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2013-10-13 11:22:13 -03:00
|
|
|
|
.. function:: encode(obj, encoding='utf-8', errors='strict')
|
|
|
|
|
|
|
|
|
|
Encodes *obj* using the codec registered for *encoding*.
|
|
|
|
|
|
|
|
|
|
*Errors* may be given to set the desired error handling scheme. The
|
2015-01-06 10:22:00 -04:00
|
|
|
|
default error handler is ``'strict'`` meaning that encoding errors raise
|
2013-10-13 11:22:13 -03:00
|
|
|
|
:exc:`ValueError` (or a more codec specific subclass, such as
|
|
|
|
|
:exc:`UnicodeEncodeError`). Refer to :ref:`codec-base-classes` for more
|
|
|
|
|
information on codec error handling.
|
|
|
|
|
|
|
|
|
|
.. function:: decode(obj, encoding='utf-8', errors='strict')
|
|
|
|
|
|
|
|
|
|
Decodes *obj* using the codec registered for *encoding*.
|
|
|
|
|
|
|
|
|
|
*Errors* may be given to set the desired error handling scheme. The
|
2015-01-06 10:22:00 -04:00
|
|
|
|
default error handler is ``'strict'`` meaning that decoding errors raise
|
2013-10-13 11:22:13 -03:00
|
|
|
|
:exc:`ValueError` (or a more codec specific subclass, such as
|
|
|
|
|
:exc:`UnicodeDecodeError`). Refer to :ref:`codec-base-classes` for more
|
|
|
|
|
information on codec error handling.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
The full details for each codec can also be looked up directly:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
.. function:: lookup(encoding)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
Looks up the codec info in the Python codec registry and returns a
|
|
|
|
|
:class:`CodecInfo` object as defined below.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
Encodings are first looked up in the registry's cache. If not found, the list of
|
|
|
|
|
registered search functions is scanned. If no :class:`CodecInfo` object is
|
|
|
|
|
found, a :exc:`LookupError` is raised. Otherwise, the :class:`CodecInfo` object
|
|
|
|
|
is stored in the cache and returned to the caller.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
.. class:: CodecInfo(encode, decode, streamreader=None, streamwriter=None, incrementalencoder=None, incrementaldecoder=None, name=None)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
Codec details when looking up the codec registry. The constructor
|
|
|
|
|
arguments are stored in attributes of the same name:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
.. attribute:: name
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
The name of the encoding.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
Merged revisions 75365,75394,75402-75403,75418,75459,75484,75592-75596,75600,75602-75607,75610-75613,75616-75617,75623,75627,75640,75647,75696,75795 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r75365 | georg.brandl | 2009-10-11 22:16:16 +0200 (So, 11 Okt 2009) | 1 line
Fix broken links found by "make linkcheck". scipy.org seems to be done right now, so I could not verify links going there.
........
r75394 | georg.brandl | 2009-10-13 20:10:59 +0200 (Di, 13 Okt 2009) | 1 line
Fix markup.
........
r75402 | georg.brandl | 2009-10-14 17:51:48 +0200 (Mi, 14 Okt 2009) | 1 line
#7125: fix typo.
........
r75403 | georg.brandl | 2009-10-14 17:57:46 +0200 (Mi, 14 Okt 2009) | 1 line
#7126: os.environ changes *do* take effect in subprocesses started with os.system().
........
r75418 | georg.brandl | 2009-10-14 20:48:32 +0200 (Mi, 14 Okt 2009) | 1 line
#7116: str.join() takes an iterable.
........
r75459 | georg.brandl | 2009-10-17 10:57:43 +0200 (Sa, 17 Okt 2009) | 1 line
Fix refleaks in _ctypes PyCSimpleType_New, which fixes the refleak seen in test___all__.
........
r75484 | georg.brandl | 2009-10-18 09:58:12 +0200 (So, 18 Okt 2009) | 1 line
Fix missing word.
........
r75592 | georg.brandl | 2009-10-22 09:05:48 +0200 (Do, 22 Okt 2009) | 1 line
Fix punctuation.
........
r75593 | georg.brandl | 2009-10-22 09:06:49 +0200 (Do, 22 Okt 2009) | 1 line
Revert unintended change.
........
r75594 | georg.brandl | 2009-10-22 09:56:02 +0200 (Do, 22 Okt 2009) | 1 line
Fix markup.
........
r75595 | georg.brandl | 2009-10-22 09:56:56 +0200 (Do, 22 Okt 2009) | 1 line
Fix duplicate target.
........
r75596 | georg.brandl | 2009-10-22 10:05:04 +0200 (Do, 22 Okt 2009) | 1 line
Add a new directive marking up implementation details and start using it.
........
r75600 | georg.brandl | 2009-10-22 13:01:46 +0200 (Do, 22 Okt 2009) | 1 line
Make it more robust.
........
r75602 | georg.brandl | 2009-10-22 13:28:06 +0200 (Do, 22 Okt 2009) | 1 line
Document new directive.
........
r75603 | georg.brandl | 2009-10-22 13:28:23 +0200 (Do, 22 Okt 2009) | 1 line
Allow short form with text as argument.
........
r75604 | georg.brandl | 2009-10-22 13:36:50 +0200 (Do, 22 Okt 2009) | 1 line
Fix stylesheet for multi-paragraph impl-details.
........
r75605 | georg.brandl | 2009-10-22 13:48:10 +0200 (Do, 22 Okt 2009) | 1 line
Use "impl-detail" directive where applicable.
........
r75606 | georg.brandl | 2009-10-22 17:00:06 +0200 (Do, 22 Okt 2009) | 1 line
#6324: membership test tries iteration via __iter__.
........
r75607 | georg.brandl | 2009-10-22 17:04:09 +0200 (Do, 22 Okt 2009) | 1 line
#7088: document new functions in signal as Unix-only.
........
r75610 | georg.brandl | 2009-10-22 17:27:24 +0200 (Do, 22 Okt 2009) | 1 line
Reorder __slots__ fine print and add a clarification.
........
r75611 | georg.brandl | 2009-10-22 17:42:32 +0200 (Do, 22 Okt 2009) | 1 line
#7035: improve docs of the various <method>_errors() functions, and give them docstrings.
........
r75612 | georg.brandl | 2009-10-22 17:52:15 +0200 (Do, 22 Okt 2009) | 1 line
#7156: document curses as Unix-only.
........
r75613 | georg.brandl | 2009-10-22 17:54:35 +0200 (Do, 22 Okt 2009) | 1 line
#6977: getopt does not support optional option arguments.
........
r75616 | georg.brandl | 2009-10-22 18:17:05 +0200 (Do, 22 Okt 2009) | 1 line
Add proper references.
........
r75617 | georg.brandl | 2009-10-22 18:20:55 +0200 (Do, 22 Okt 2009) | 1 line
Make printout margin important.
........
r75623 | georg.brandl | 2009-10-23 10:14:44 +0200 (Fr, 23 Okt 2009) | 1 line
#7188: fix optionxform() docs.
........
r75627 | fred.drake | 2009-10-23 15:04:51 +0200 (Fr, 23 Okt 2009) | 2 lines
add further note about what's passed to optionxform
........
r75640 | neil.schemenauer | 2009-10-23 21:58:17 +0200 (Fr, 23 Okt 2009) | 2 lines
Improve some docstrings in the 'warnings' module.
........
r75647 | georg.brandl | 2009-10-24 12:04:19 +0200 (Sa, 24 Okt 2009) | 1 line
Fix markup.
........
r75696 | georg.brandl | 2009-10-25 21:25:43 +0100 (So, 25 Okt 2009) | 1 line
Fix a demo.
........
r75795 | georg.brandl | 2009-10-27 16:10:22 +0100 (Di, 27 Okt 2009) | 1 line
Fix a strange mis-edit.
........
2009-10-27 12:28:25 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
.. attribute:: encode
|
|
|
|
|
decode
|
Merged revisions 75365,75394,75402-75403,75418,75459,75484,75592-75596,75600,75602-75607,75610-75613,75616-75617,75623,75627,75640,75647,75696,75795 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r75365 | georg.brandl | 2009-10-11 22:16:16 +0200 (So, 11 Okt 2009) | 1 line
Fix broken links found by "make linkcheck". scipy.org seems to be done right now, so I could not verify links going there.
........
r75394 | georg.brandl | 2009-10-13 20:10:59 +0200 (Di, 13 Okt 2009) | 1 line
Fix markup.
........
r75402 | georg.brandl | 2009-10-14 17:51:48 +0200 (Mi, 14 Okt 2009) | 1 line
#7125: fix typo.
........
r75403 | georg.brandl | 2009-10-14 17:57:46 +0200 (Mi, 14 Okt 2009) | 1 line
#7126: os.environ changes *do* take effect in subprocesses started with os.system().
........
r75418 | georg.brandl | 2009-10-14 20:48:32 +0200 (Mi, 14 Okt 2009) | 1 line
#7116: str.join() takes an iterable.
........
r75459 | georg.brandl | 2009-10-17 10:57:43 +0200 (Sa, 17 Okt 2009) | 1 line
Fix refleaks in _ctypes PyCSimpleType_New, which fixes the refleak seen in test___all__.
........
r75484 | georg.brandl | 2009-10-18 09:58:12 +0200 (So, 18 Okt 2009) | 1 line
Fix missing word.
........
r75592 | georg.brandl | 2009-10-22 09:05:48 +0200 (Do, 22 Okt 2009) | 1 line
Fix punctuation.
........
r75593 | georg.brandl | 2009-10-22 09:06:49 +0200 (Do, 22 Okt 2009) | 1 line
Revert unintended change.
........
r75594 | georg.brandl | 2009-10-22 09:56:02 +0200 (Do, 22 Okt 2009) | 1 line
Fix markup.
........
r75595 | georg.brandl | 2009-10-22 09:56:56 +0200 (Do, 22 Okt 2009) | 1 line
Fix duplicate target.
........
r75596 | georg.brandl | 2009-10-22 10:05:04 +0200 (Do, 22 Okt 2009) | 1 line
Add a new directive marking up implementation details and start using it.
........
r75600 | georg.brandl | 2009-10-22 13:01:46 +0200 (Do, 22 Okt 2009) | 1 line
Make it more robust.
........
r75602 | georg.brandl | 2009-10-22 13:28:06 +0200 (Do, 22 Okt 2009) | 1 line
Document new directive.
........
r75603 | georg.brandl | 2009-10-22 13:28:23 +0200 (Do, 22 Okt 2009) | 1 line
Allow short form with text as argument.
........
r75604 | georg.brandl | 2009-10-22 13:36:50 +0200 (Do, 22 Okt 2009) | 1 line
Fix stylesheet for multi-paragraph impl-details.
........
r75605 | georg.brandl | 2009-10-22 13:48:10 +0200 (Do, 22 Okt 2009) | 1 line
Use "impl-detail" directive where applicable.
........
r75606 | georg.brandl | 2009-10-22 17:00:06 +0200 (Do, 22 Okt 2009) | 1 line
#6324: membership test tries iteration via __iter__.
........
r75607 | georg.brandl | 2009-10-22 17:04:09 +0200 (Do, 22 Okt 2009) | 1 line
#7088: document new functions in signal as Unix-only.
........
r75610 | georg.brandl | 2009-10-22 17:27:24 +0200 (Do, 22 Okt 2009) | 1 line
Reorder __slots__ fine print and add a clarification.
........
r75611 | georg.brandl | 2009-10-22 17:42:32 +0200 (Do, 22 Okt 2009) | 1 line
#7035: improve docs of the various <method>_errors() functions, and give them docstrings.
........
r75612 | georg.brandl | 2009-10-22 17:52:15 +0200 (Do, 22 Okt 2009) | 1 line
#7156: document curses as Unix-only.
........
r75613 | georg.brandl | 2009-10-22 17:54:35 +0200 (Do, 22 Okt 2009) | 1 line
#6977: getopt does not support optional option arguments.
........
r75616 | georg.brandl | 2009-10-22 18:17:05 +0200 (Do, 22 Okt 2009) | 1 line
Add proper references.
........
r75617 | georg.brandl | 2009-10-22 18:20:55 +0200 (Do, 22 Okt 2009) | 1 line
Make printout margin important.
........
r75623 | georg.brandl | 2009-10-23 10:14:44 +0200 (Fr, 23 Okt 2009) | 1 line
#7188: fix optionxform() docs.
........
r75627 | fred.drake | 2009-10-23 15:04:51 +0200 (Fr, 23 Okt 2009) | 2 lines
add further note about what's passed to optionxform
........
r75640 | neil.schemenauer | 2009-10-23 21:58:17 +0200 (Fr, 23 Okt 2009) | 2 lines
Improve some docstrings in the 'warnings' module.
........
r75647 | georg.brandl | 2009-10-24 12:04:19 +0200 (Sa, 24 Okt 2009) | 1 line
Fix markup.
........
r75696 | georg.brandl | 2009-10-25 21:25:43 +0100 (So, 25 Okt 2009) | 1 line
Fix a demo.
........
r75795 | georg.brandl | 2009-10-27 16:10:22 +0100 (Di, 27 Okt 2009) | 1 line
Fix a strange mis-edit.
........
2009-10-27 12:28:25 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
The stateless encoding and decoding functions. These must be
|
|
|
|
|
functions or methods which have the same interface as
|
|
|
|
|
the :meth:`~Codec.encode` and :meth:`~Codec.decode` methods of Codec
|
|
|
|
|
instances (see :ref:`Codec Interface <codec-objects>`).
|
|
|
|
|
The functions or methods are expected to work in a stateless mode.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
.. attribute:: incrementalencoder
|
|
|
|
|
incrementaldecoder
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
Incremental encoder and decoder classes or factory functions.
|
|
|
|
|
These have to provide the interface defined by the base classes
|
|
|
|
|
:class:`IncrementalEncoder` and :class:`IncrementalDecoder`,
|
|
|
|
|
respectively. Incremental codecs can maintain state.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
.. attribute:: streamwriter
|
|
|
|
|
streamreader
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
Stream writer and reader classes or factory functions. These have to
|
|
|
|
|
provide the interface defined by the base classes
|
|
|
|
|
:class:`StreamWriter` and :class:`StreamReader`, respectively.
|
|
|
|
|
Stream codecs can maintain state.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
To simplify access to the various codec components, the module provides
|
|
|
|
|
these additional functions which use :func:`lookup` for the codec lookup:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
.. function:: getencoder(encoding)
|
|
|
|
|
|
|
|
|
|
Look up the codec for the given encoding and return its encoder function.
|
|
|
|
|
|
|
|
|
|
Raises a :exc:`LookupError` in case the encoding cannot be found.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: getdecoder(encoding)
|
|
|
|
|
|
|
|
|
|
Look up the codec for the given encoding and return its decoder function.
|
|
|
|
|
|
|
|
|
|
Raises a :exc:`LookupError` in case the encoding cannot be found.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: getincrementalencoder(encoding)
|
|
|
|
|
|
|
|
|
|
Look up the codec for the given encoding and return its incremental encoder
|
|
|
|
|
class or factory function.
|
|
|
|
|
|
|
|
|
|
Raises a :exc:`LookupError` in case the encoding cannot be found or the codec
|
|
|
|
|
doesn't support an incremental encoder.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: getincrementaldecoder(encoding)
|
|
|
|
|
|
|
|
|
|
Look up the codec for the given encoding and return its incremental decoder
|
|
|
|
|
class or factory function.
|
|
|
|
|
|
|
|
|
|
Raises a :exc:`LookupError` in case the encoding cannot be found or the codec
|
|
|
|
|
doesn't support an incremental decoder.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: getreader(encoding)
|
|
|
|
|
|
2016-05-21 08:56:35 -03:00
|
|
|
|
Look up the codec for the given encoding and return its :class:`StreamReader`
|
|
|
|
|
class or factory function.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
Raises a :exc:`LookupError` in case the encoding cannot be found.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: getwriter(encoding)
|
|
|
|
|
|
2016-05-21 08:56:35 -03:00
|
|
|
|
Look up the codec for the given encoding and return its :class:`StreamWriter`
|
|
|
|
|
class or factory function.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
Raises a :exc:`LookupError` in case the encoding cannot be found.
|
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
Custom codecs are made available by registering a suitable codec search
|
|
|
|
|
function:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
.. function:: register(search_function)
|
2014-11-25 12:59:20 -04:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
Register a codec search function. Search functions are expected to take one
|
|
|
|
|
argument, being the encoding name in all lower case letters, and return a
|
|
|
|
|
:class:`CodecInfo` object. In case a search function cannot find
|
|
|
|
|
a given encoding, it should return ``None``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
2020-09-28 18:41:11 -03:00
|
|
|
|
.. function:: unregister(search_function)
|
|
|
|
|
|
|
|
|
|
Unregister a codec search function and clear the registry's cache.
|
|
|
|
|
If the search function is not registered, do nothing.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 3.10
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
While the builtin :func:`open` and the associated :mod:`io` module are the
|
|
|
|
|
recommended approach for working with encoded text files, this module
|
|
|
|
|
provides additional utility functions and classes that allow the use of a
|
|
|
|
|
wider range of codecs when working with binary files:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2018-10-19 21:22:31 -03:00
|
|
|
|
.. function:: open(filename, mode='r', encoding=None, errors='strict', buffering=-1)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
Open an encoded file using the given *mode* and return an instance of
|
|
|
|
|
:class:`StreamReaderWriter`, providing transparent encoding/decoding.
|
|
|
|
|
The default file mode is ``'r'``, meaning to open the file in read mode.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60873 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60850 | amaury.forgeotdarc | 2008-02-16 01:16:50 +0100 (Sat, 16 Feb 2008) | 3 lines
mmap.PROT_READ does not exists on win32;
Skip this test created by r60830.
........
r60851 | raymond.hettinger | 2008-02-16 02:22:54 +0100 (Sat, 16 Feb 2008) | 1 line
Add __all__ to logging module.
........
r60855 | georg.brandl | 2008-02-16 10:37:32 +0100 (Sat, 16 Feb 2008) | 2 lines
#2120: broken links in advocacy document.
........
r60860 | amaury.forgeotdarc | 2008-02-16 15:34:57 +0100 (Sat, 16 Feb 2008) | 23 lines
Crashers of the day: Py_CLEAR must be used when there is a chance that the
function can be called recursively.
This was discussed in issue1020188.
In python codebase, all occurrences of Py_[X]DECREF(xxx->yyy) are suspect,
except when they appear in tp_new or tp_dealloc functions, or when
the member cannot be of a user-defined class.
Note that tp_init is not safe.
I do have a (crashing) example for every changed line.
Is it worth adding them to the test suite?
Example:
class SpecialStr(str):
def __del__(self):
s.close()
import cStringIO
s = cStringIO.StringIO(SpecialStr("text"))
s.close() # Segfault
........
r60871 | amaury.forgeotdarc | 2008-02-16 21:55:24 +0100 (Sat, 16 Feb 2008) | 3 lines
Prevent a crash with nested scopes, again caused by calling Py_DECREF when the pointer
is still present in the containing structure.
........
r60872 | brett.cannon | 2008-02-17 02:59:18 +0100 (Sun, 17 Feb 2008) | 4 lines
Move test_logging over to doctest.
Thanks to Christopher White from GHOP.
........
r60873 | georg.brandl | 2008-02-17 12:33:38 +0100 (Sun, 17 Feb 2008) | 2 lines
#2131: note that codecs.open() always opens files in binary mode.
........
2008-02-17 09:31:39 -04:00
|
|
|
|
.. note::
|
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
Underlying encoded files are always opened in binary mode.
|
|
|
|
|
No automatic conversion of ``'\n'`` is done on reading and writing.
|
|
|
|
|
The *mode* argument may be any binary mode acceptable to the built-in
|
|
|
|
|
:func:`open` function; the ``'b'`` is automatically added.
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60873 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60850 | amaury.forgeotdarc | 2008-02-16 01:16:50 +0100 (Sat, 16 Feb 2008) | 3 lines
mmap.PROT_READ does not exists on win32;
Skip this test created by r60830.
........
r60851 | raymond.hettinger | 2008-02-16 02:22:54 +0100 (Sat, 16 Feb 2008) | 1 line
Add __all__ to logging module.
........
r60855 | georg.brandl | 2008-02-16 10:37:32 +0100 (Sat, 16 Feb 2008) | 2 lines
#2120: broken links in advocacy document.
........
r60860 | amaury.forgeotdarc | 2008-02-16 15:34:57 +0100 (Sat, 16 Feb 2008) | 23 lines
Crashers of the day: Py_CLEAR must be used when there is a chance that the
function can be called recursively.
This was discussed in issue1020188.
In python codebase, all occurrences of Py_[X]DECREF(xxx->yyy) are suspect,
except when they appear in tp_new or tp_dealloc functions, or when
the member cannot be of a user-defined class.
Note that tp_init is not safe.
I do have a (crashing) example for every changed line.
Is it worth adding them to the test suite?
Example:
class SpecialStr(str):
def __del__(self):
s.close()
import cStringIO
s = cStringIO.StringIO(SpecialStr("text"))
s.close() # Segfault
........
r60871 | amaury.forgeotdarc | 2008-02-16 21:55:24 +0100 (Sat, 16 Feb 2008) | 3 lines
Prevent a crash with nested scopes, again caused by calling Py_DECREF when the pointer
is still present in the containing structure.
........
r60872 | brett.cannon | 2008-02-17 02:59:18 +0100 (Sun, 17 Feb 2008) | 4 lines
Move test_logging over to doctest.
Thanks to Christopher White from GHOP.
........
r60873 | georg.brandl | 2008-02-17 12:33:38 +0100 (Sun, 17 Feb 2008) | 2 lines
#2131: note that codecs.open() always opens files in binary mode.
........
2008-02-17 09:31:39 -04:00
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
*encoding* specifies the encoding which is to be used for the file.
|
2015-01-06 10:22:00 -04:00
|
|
|
|
Any encoding that encodes to and decodes from bytes is allowed, and
|
|
|
|
|
the data types supported by the file methods depend on the codec used.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
*errors* may be given to define the error handling. It defaults to ``'strict'``
|
|
|
|
|
which causes a :exc:`ValueError` to be raised in case an encoding error occurs.
|
|
|
|
|
|
2018-10-19 21:22:31 -03:00
|
|
|
|
*buffering* has the same meaning as for the built-in :func:`open` function.
|
|
|
|
|
It defaults to -1 which means that the default buffer size will be used.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
|
.. function:: EncodedFile(file, data_encoding, file_encoding=None, errors='strict')
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
Return a :class:`StreamRecoder` instance, a wrapped version of *file*
|
|
|
|
|
which provides transparent transcoding. The original file is closed
|
|
|
|
|
when the wrapped version is closed.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
Data written to the wrapped file is decoded according to the given
|
|
|
|
|
*data_encoding* and then written to the original file as bytes using
|
|
|
|
|
*file_encoding*. Bytes read from the original file are decoded
|
|
|
|
|
according to *file_encoding*, and the result is encoded
|
|
|
|
|
using *data_encoding*.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
|
If *file_encoding* is not given, it defaults to *data_encoding*.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
|
*errors* may be given to define the error handling. It defaults to
|
|
|
|
|
``'strict'``, which causes :exc:`ValueError` to be raised in case an encoding
|
|
|
|
|
error occurs.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
|
.. function:: iterencode(iterator, encoding, errors='strict', **kwargs)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
Uses an incremental encoder to iteratively encode the input provided by
|
2015-01-06 10:22:00 -04:00
|
|
|
|
*iterator*. This function is a :term:`generator`.
|
|
|
|
|
The *errors* argument (as well as any
|
#1370: Finish the merge r58749, log below, by resolving all conflicts in Doc/.
Merged revisions 58221-58741 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58221 | georg.brandl | 2007-09-20 10:57:59 -0700 (Thu, 20 Sep 2007) | 2 lines
Patch #1181: add os.environ.clear() method.
........
r58225 | sean.reifschneider | 2007-09-20 23:33:28 -0700 (Thu, 20 Sep 2007) | 3 lines
Issue1704287: "make install" fails unless you do "make" first. Make
oldsharedmods and sharedmods in "libinstall".
........
r58232 | guido.van.rossum | 2007-09-22 13:18:03 -0700 (Sat, 22 Sep 2007) | 4 lines
Patch # 188 by Philip Jenvey.
Make tell() mark CRLF as a newline.
With unit test.
........
r58242 | georg.brandl | 2007-09-24 10:55:47 -0700 (Mon, 24 Sep 2007) | 2 lines
Fix typo and double word.
........
r58245 | georg.brandl | 2007-09-24 10:59:28 -0700 (Mon, 24 Sep 2007) | 2 lines
#1196: document default radix for int().
........
r58247 | georg.brandl | 2007-09-24 11:08:24 -0700 (Mon, 24 Sep 2007) | 2 lines
#1177: accept 2xx responses for https too, not only http.
........
r58249 | andrew.kuchling | 2007-09-24 16:45:51 -0700 (Mon, 24 Sep 2007) | 1 line
Remove stray odd character; grammar fix
........
r58250 | andrew.kuchling | 2007-09-24 16:46:28 -0700 (Mon, 24 Sep 2007) | 1 line
Typo fix
........
r58251 | andrew.kuchling | 2007-09-24 17:09:42 -0700 (Mon, 24 Sep 2007) | 1 line
Add various items
........
r58268 | vinay.sajip | 2007-09-26 22:34:45 -0700 (Wed, 26 Sep 2007) | 1 line
Change to flush and close logic to fix #1760556.
........
r58269 | vinay.sajip | 2007-09-26 22:38:51 -0700 (Wed, 26 Sep 2007) | 1 line
Change to basicConfig() to fix #1021.
........
r58270 | georg.brandl | 2007-09-26 23:26:58 -0700 (Wed, 26 Sep 2007) | 2 lines
#1208: document match object's boolean value.
........
r58271 | vinay.sajip | 2007-09-26 23:56:13 -0700 (Wed, 26 Sep 2007) | 1 line
Minor date change.
........
r58272 | vinay.sajip | 2007-09-27 00:35:10 -0700 (Thu, 27 Sep 2007) | 1 line
Change to LogRecord.__init__() to fix #1206. Note that archaic use of type(x) == types.DictType is because of keeping 1.5.2 compatibility. While this is much less relevant these days, there probably needs to be a separate commit for removing all archaic constructs at the same time.
........
r58288 | brett.cannon | 2007-09-30 12:45:10 -0700 (Sun, 30 Sep 2007) | 9 lines
tuple.__repr__ did not consider a reference loop as it is not possible from
Python code; but it is possible from C. object.__str__ had the issue of not
expecting a type to doing something within it's tp_str implementation that
could trigger an infinite recursion, but it could in C code.. Both found
thanks to BaseException and how it handles its repr.
Closes issue #1686386. Thanks to Thomas Herve for taking an initial stab at
coming up with a solution.
........
r58289 | brett.cannon | 2007-09-30 13:37:19 -0700 (Sun, 30 Sep 2007) | 3 lines
Fix error introduced by r58288; if a tuple is length 0 return its repr and
don't worry about any self-referring tuples.
........
r58294 | facundo.batista | 2007-10-02 10:01:24 -0700 (Tue, 02 Oct 2007) | 11 lines
Made the various is_* operations return booleans. This was discussed
with Cawlishaw by mail, and he basically confirmed that to these is_*
operations, there's no need to return Decimal(0) and Decimal(1) if
the language supports the False and True booleans.
Also added a few tests for the these functions in extra.decTest, since
they are mostly untested (apart from the doctests).
Thanks Mark Dickinson
........
r58295 | facundo.batista | 2007-10-02 11:21:18 -0700 (Tue, 02 Oct 2007) | 4 lines
Added a class to store the digits of log(10), so that they can be made
available when necessary without recomputing. Thanks Mark Dickinson
........
r58299 | mark.summerfield | 2007-10-03 01:53:21 -0700 (Wed, 03 Oct 2007) | 4 lines
Added note in footnote about string comparisons about
unicodedata.normalize().
........
r58304 | raymond.hettinger | 2007-10-03 14:18:11 -0700 (Wed, 03 Oct 2007) | 1 line
enumerate() is no longer bounded to using sequences shorter than LONG_MAX. The possibility of overflow was sending some newsgroup posters into a tizzy.
........
r58305 | raymond.hettinger | 2007-10-03 17:20:27 -0700 (Wed, 03 Oct 2007) | 1 line
itertools.count() no longer limited to sys.maxint.
........
r58306 | kurt.kaiser | 2007-10-03 18:49:54 -0700 (Wed, 03 Oct 2007) | 3 lines
Assume that the user knows when he wants to end the line; don't insert
something he didn't select or complete.
........
r58307 | kurt.kaiser | 2007-10-03 19:07:50 -0700 (Wed, 03 Oct 2007) | 2 lines
Remove unused theme that was causing a fault in p3k.
........
r58308 | kurt.kaiser | 2007-10-03 19:09:17 -0700 (Wed, 03 Oct 2007) | 2 lines
Clean up EditorWindow close.
........
r58309 | kurt.kaiser | 2007-10-03 19:53:07 -0700 (Wed, 03 Oct 2007) | 7 lines
textView cleanup. Patch 1718043 Tal Einat.
M idlelib/EditorWindow.py
M idlelib/aboutDialog.py
M idlelib/textView.py
M idlelib/NEWS.txt
........
r58310 | kurt.kaiser | 2007-10-03 20:11:12 -0700 (Wed, 03 Oct 2007) | 3 lines
configDialog cleanup. Patch 1730217 Tal Einat.
........
r58311 | neal.norwitz | 2007-10-03 23:00:48 -0700 (Wed, 03 Oct 2007) | 4 lines
Coverity #151: Remove deadcode.
All this code already exists above starting at line 653.
........
r58325 | fred.drake | 2007-10-04 19:46:12 -0700 (Thu, 04 Oct 2007) | 1 line
wrap lines to <80 characters before fixing errors
........
r58326 | raymond.hettinger | 2007-10-04 19:47:07 -0700 (Thu, 04 Oct 2007) | 6 lines
Add __asdict__() to NamedTuple and refine the docs.
Add maxlen support to deque() and fixup docs.
Partially fix __reduce__(). The None as a third arg was no longer supported.
Still needs work on __reduce__() to handle recursive inputs.
........
r58327 | fred.drake | 2007-10-04 19:48:32 -0700 (Thu, 04 Oct 2007) | 3 lines
move descriptions of ac_(in|out)_buffer_size to the right place
http://bugs.python.org/issue1053
........
r58329 | neal.norwitz | 2007-10-04 20:39:17 -0700 (Thu, 04 Oct 2007) | 3 lines
dict could be NULL, so we need to XDECREF.
Fix a compiler warning about passing a PyTypeObject* instead of PyObject*.
........
r58330 | neal.norwitz | 2007-10-04 20:41:19 -0700 (Thu, 04 Oct 2007) | 2 lines
Fix Coverity #158: Check the correct variable.
........
r58332 | neal.norwitz | 2007-10-04 22:01:38 -0700 (Thu, 04 Oct 2007) | 7 lines
Fix Coverity #159.
This code was broken if save() returned a negative number since i contained
a boolean value and then we compared i < 0 which should never be true.
Will backport (assuming it's necessary)
........
r58334 | neal.norwitz | 2007-10-04 22:29:17 -0700 (Thu, 04 Oct 2007) | 1 line
Add a note about fixing some more warnings found by Coverity.
........
r58338 | raymond.hettinger | 2007-10-05 12:07:31 -0700 (Fri, 05 Oct 2007) | 1 line
Restore BEGIN/END THREADS macros which were squashed in the previous checkin
........
r58343 | gregory.p.smith | 2007-10-06 00:48:10 -0700 (Sat, 06 Oct 2007) | 3 lines
Stab in the dark attempt to fix the test_bsddb3 failure on sparc and S-390
ubuntu buildbots.
........
r58344 | gregory.p.smith | 2007-10-06 00:51:59 -0700 (Sat, 06 Oct 2007) | 2 lines
Allows BerkeleyDB 4.6.x >= 4.6.21 for the bsddb module.
........
r58348 | gregory.p.smith | 2007-10-06 08:47:37 -0700 (Sat, 06 Oct 2007) | 3 lines
Use the host the author likely meant in the first place. pop.gmail.com is
reliable. gmail.org is someones personal domain.
........
r58351 | neal.norwitz | 2007-10-06 12:16:28 -0700 (Sat, 06 Oct 2007) | 3 lines
Ensure that this test will pass even if another test left an unwritable TESTFN.
Also use the safe unlink in test_support instead of rolling our own here.
........
r58368 | georg.brandl | 2007-10-08 00:50:24 -0700 (Mon, 08 Oct 2007) | 3 lines
#1123: fix the docs for the str.split(None, sep) case.
Also expand a few other methods' docs, which had more info in the deprecated string module docs.
........
r58369 | georg.brandl | 2007-10-08 01:06:05 -0700 (Mon, 08 Oct 2007) | 2 lines
Update docstring of sched, also remove an unused assignment.
........
r58370 | raymond.hettinger | 2007-10-08 02:14:28 -0700 (Mon, 08 Oct 2007) | 5 lines
Add comments to NamedTuple code.
Let the field spec be either a string or a non-string sequence (suggested by Martin Blais with use cases).
Improve the error message in the case of a SyntaxError (caused by a duplicate field name).
........
r58371 | raymond.hettinger | 2007-10-08 02:56:29 -0700 (Mon, 08 Oct 2007) | 1 line
Missed a line in the docs
........
r58372 | raymond.hettinger | 2007-10-08 03:11:51 -0700 (Mon, 08 Oct 2007) | 1 line
Better variable names
........
r58376 | georg.brandl | 2007-10-08 07:12:47 -0700 (Mon, 08 Oct 2007) | 3 lines
#1199: docs for tp_as_{number,sequence,mapping}, by Amaury Forgeot d'Arc.
No need to merge this to py3k!
........
r58380 | raymond.hettinger | 2007-10-08 14:26:58 -0700 (Mon, 08 Oct 2007) | 1 line
Eliminate camelcase function name
........
r58381 | andrew.kuchling | 2007-10-08 16:23:03 -0700 (Mon, 08 Oct 2007) | 1 line
Eliminate camelcase function name
........
r58382 | raymond.hettinger | 2007-10-08 18:36:23 -0700 (Mon, 08 Oct 2007) | 1 line
Make the error messages more specific
........
r58384 | gregory.p.smith | 2007-10-08 23:02:21 -0700 (Mon, 08 Oct 2007) | 10 lines
Splits Modules/_bsddb.c up into bsddb.h and _bsddb.c and adds a C API
object available as bsddb.db.api. This is based on the patch submitted
by Duncan Grisby here:
http://sourceforge.net/tracker/index.php?func=detail&aid=1551895&group_id=13900&atid=313900
See this thread for additional info:
http://sourceforge.net/mailarchive/forum.php?thread_name=E1GAVDK-0002rk-Iw%40apasphere.com&forum_name=pybsddb-users
It also cleans up the code a little by removing some ifdef/endifs for
python prior to 2.1 and for unsupported Berkeley DB <= 3.2.
........
r58385 | gregory.p.smith | 2007-10-08 23:50:43 -0700 (Mon, 08 Oct 2007) | 5 lines
Fix a double free when positioning a database cursor to a non-existant
string key (and probably a few other situations with string keys).
This was reported with a patch as pybsddb sourceforge bug 1708868 by
jjjhhhlll at gmail.
........
r58386 | gregory.p.smith | 2007-10-09 00:19:11 -0700 (Tue, 09 Oct 2007) | 3 lines
Use the highest cPickle protocol in bsddb.dbshelve. This comes from
sourceforge pybsddb patch 1551443 by w_barnes.
........
r58394 | gregory.p.smith | 2007-10-09 11:26:02 -0700 (Tue, 09 Oct 2007) | 2 lines
remove another sleepycat reference
........
r58396 | kurt.kaiser | 2007-10-09 12:31:30 -0700 (Tue, 09 Oct 2007) | 3 lines
Allow interrupt only when executing user code in subprocess
Patch 1225 Tal Einat modified from IDLE-Spoon.
........
r58399 | brett.cannon | 2007-10-09 17:07:50 -0700 (Tue, 09 Oct 2007) | 5 lines
Remove file-level typedefs that were inconsistently used throughout the file.
Just move over to the public API names.
Closes issue1238.
........
r58401 | raymond.hettinger | 2007-10-09 17:26:46 -0700 (Tue, 09 Oct 2007) | 1 line
Accept Jim Jewett's api suggestion to use None instead of -1 to indicate unbounded deques.
........
r58403 | kurt.kaiser | 2007-10-09 17:55:40 -0700 (Tue, 09 Oct 2007) | 2 lines
Allow cursor color change w/o restart. Patch 1725576 Tal Einat.
........
r58404 | kurt.kaiser | 2007-10-09 18:06:47 -0700 (Tue, 09 Oct 2007) | 2 lines
show paste if > 80 columns. Patch 1659326 Tal Einat.
........
r58415 | thomas.heller | 2007-10-11 12:51:32 -0700 (Thu, 11 Oct 2007) | 5 lines
On OS X, use os.uname() instead of gestalt.sysv(...) to get the
operating system version. This allows to use ctypes when Python
was configured with --disable-toolbox-glue.
........
r58419 | neal.norwitz | 2007-10-11 20:01:01 -0700 (Thu, 11 Oct 2007) | 1 line
Get rid of warning about not being able to create an existing directory.
........
r58420 | neal.norwitz | 2007-10-11 20:01:30 -0700 (Thu, 11 Oct 2007) | 1 line
Get rid of warnings on a bunch of platforms by using a proper prototype.
........
r58421 | neal.norwitz | 2007-10-11 20:01:54 -0700 (Thu, 11 Oct 2007) | 4 lines
Get rid of compiler warning about retval being used (returned) without
being initialized. (gcc warning and Coverity 202)
........
r58422 | neal.norwitz | 2007-10-11 20:03:23 -0700 (Thu, 11 Oct 2007) | 1 line
Fix Coverity 168: Close the file before returning (exiting).
........
r58423 | neal.norwitz | 2007-10-11 20:04:18 -0700 (Thu, 11 Oct 2007) | 4 lines
Fix Coverity 180: Don't overallocate. We don't need structs, but pointers.
Also fix a memory leak.
........
r58424 | neal.norwitz | 2007-10-11 20:05:19 -0700 (Thu, 11 Oct 2007) | 5 lines
Fix Coverity 185-186: If the passed in FILE is NULL, uninitialized memory
would be accessed.
Will backport.
........
r58425 | neal.norwitz | 2007-10-11 20:52:34 -0700 (Thu, 11 Oct 2007) | 1 line
Get this module to compile with bsddb versions prior to 4.3
........
r58430 | martin.v.loewis | 2007-10-12 01:56:52 -0700 (Fri, 12 Oct 2007) | 3 lines
Bug #1216: Restore support for Visual Studio 2002.
Will backport to 2.5.
........
r58433 | raymond.hettinger | 2007-10-12 10:53:11 -0700 (Fri, 12 Oct 2007) | 1 line
Fix test of count.__repr__() to ignore the 'L' if the count is a long
........
r58434 | gregory.p.smith | 2007-10-12 11:44:06 -0700 (Fri, 12 Oct 2007) | 4 lines
Fixes http://bugs.python.org/issue1233 - bsddb.dbshelve.DBShelf.append
was useless due to inverted logic. Also adds a test case for RECNO dbs
to test_dbshelve.
........
r58445 | georg.brandl | 2007-10-13 06:20:03 -0700 (Sat, 13 Oct 2007) | 2 lines
Fix email example.
........
r58450 | gregory.p.smith | 2007-10-13 16:02:05 -0700 (Sat, 13 Oct 2007) | 2 lines
Fix an uncollectable reference leak in bsddb.db.DBShelf.append
........
r58453 | neal.norwitz | 2007-10-13 17:18:40 -0700 (Sat, 13 Oct 2007) | 8 lines
Let the O/S supply a port if none of the default ports can be used.
This should make the tests more robust at the expense of allowing
tests to be sloppier by not requiring them to cleanup after themselves.
(It will legitamitely help when running two test suites simultaneously
or if another process is already using one of the predefined ports.)
Also simplifies (slightLy) the exception handling elsewhere.
........
r58459 | neal.norwitz | 2007-10-14 11:30:21 -0700 (Sun, 14 Oct 2007) | 2 lines
Don't raise a string exception, they don't work anymore.
........
r58460 | neal.norwitz | 2007-10-14 11:40:37 -0700 (Sun, 14 Oct 2007) | 1 line
Use unittest for assertions
........
r58468 | armin.rigo | 2007-10-15 00:48:35 -0700 (Mon, 15 Oct 2007) | 2 lines
test_bigbits was not testing what it seemed to.
........
r58471 | guido.van.rossum | 2007-10-15 08:54:11 -0700 (Mon, 15 Oct 2007) | 3 lines
Change a PyErr_Print() into a PyErr_Clear(),
per discussion in issue 1031213.
........
r58500 | raymond.hettinger | 2007-10-16 12:18:30 -0700 (Tue, 16 Oct 2007) | 1 line
Improve error messages
........
r58506 | raymond.hettinger | 2007-10-16 14:28:32 -0700 (Tue, 16 Oct 2007) | 1 line
More docs, error messages, and tests
........
r58507 | andrew.kuchling | 2007-10-16 15:58:03 -0700 (Tue, 16 Oct 2007) | 1 line
Add items
........
r58508 | brett.cannon | 2007-10-16 16:24:06 -0700 (Tue, 16 Oct 2007) | 3 lines
Remove ``:const:`` notation on None in parameter list. Since the markup is not
rendered for parameters it just showed up as ``:const:`None` `` in the output.
........
r58509 | brett.cannon | 2007-10-16 16:26:45 -0700 (Tue, 16 Oct 2007) | 3 lines
Re-order some functions whose parameters differ between PyObject and const char
* so that they are next to each other.
........
r58522 | armin.rigo | 2007-10-17 11:46:37 -0700 (Wed, 17 Oct 2007) | 5 lines
Fix the overflow checking of list_repeat.
Introduce overflow checking into list_inplace_repeat.
Backport candidate, possibly.
........
r58530 | facundo.batista | 2007-10-17 20:16:03 -0700 (Wed, 17 Oct 2007) | 7 lines
Issue #1580738. When HTTPConnection reads the whole stream with read(),
it closes itself. When the stream is read in several calls to read(n),
it should behave in the same way if HTTPConnection knows where the end
of the stream is (through self.length). Added a test case for this
behaviour.
........
r58531 | facundo.batista | 2007-10-17 20:44:48 -0700 (Wed, 17 Oct 2007) | 3 lines
Issue 1289, just a typo.
........
r58532 | gregory.p.smith | 2007-10-18 00:56:54 -0700 (Thu, 18 Oct 2007) | 4 lines
cleanup test_dbtables to use mkdtemp. cleanup dbtables to pass txn as a
keyword argument whenever possible to avoid bugs and confusion. (dbtables.py
line 447 self.db.get using txn as a non-keyword was an actual bug due to this)
........
r58533 | gregory.p.smith | 2007-10-18 01:34:20 -0700 (Thu, 18 Oct 2007) | 4 lines
Fix a weird bug in dbtables: if it chose a random rowid string that contained
NULL bytes it would cause the database all sorts of problems in the future
leading to very strange random failures and corrupt dbtables.bsdTableDb dbs.
........
r58534 | gregory.p.smith | 2007-10-18 09:32:02 -0700 (Thu, 18 Oct 2007) | 3 lines
A cleaner fix than the one committed last night. Generate random rowids that
do not contain null bytes.
........
r58537 | gregory.p.smith | 2007-10-18 10:17:57 -0700 (Thu, 18 Oct 2007) | 2 lines
mention bsddb fixes.
........
r58538 | raymond.hettinger | 2007-10-18 14:13:06 -0700 (Thu, 18 Oct 2007) | 1 line
Remove useless warning
........
r58539 | gregory.p.smith | 2007-10-19 00:31:20 -0700 (Fri, 19 Oct 2007) | 2 lines
squelch the warning that this test is supposed to trigger.
........
r58542 | georg.brandl | 2007-10-19 05:32:39 -0700 (Fri, 19 Oct 2007) | 2 lines
Clarify wording for apply().
........
r58544 | mark.summerfield | 2007-10-19 05:48:17 -0700 (Fri, 19 Oct 2007) | 3 lines
Added a cross-ref to each other.
........
r58545 | georg.brandl | 2007-10-19 10:38:49 -0700 (Fri, 19 Oct 2007) | 2 lines
#1284: "S" means "seen", not unread.
........
r58548 | thomas.heller | 2007-10-19 11:11:41 -0700 (Fri, 19 Oct 2007) | 4 lines
Fix ctypes on 32-bit systems when Python is configured --with-system-ffi.
See also https://bugs.launchpad.net/bugs/72505.
Ported from release25-maint branch.
........
r58550 | facundo.batista | 2007-10-19 12:25:57 -0700 (Fri, 19 Oct 2007) | 8 lines
The constructor from tuple was way too permissive: it allowed bad
coefficient numbers, floats in the sign, and other details that
generated directly the wrong number in the best case, or triggered
misfunctionality in the alorithms.
Test cases added for these issues. Thanks Mark Dickinson.
........
r58559 | georg.brandl | 2007-10-20 06:22:53 -0700 (Sat, 20 Oct 2007) | 2 lines
Fix code being interpreted as a target.
........
r58561 | georg.brandl | 2007-10-20 06:36:24 -0700 (Sat, 20 Oct 2007) | 2 lines
Document new "cmdoption" directive.
........
r58562 | georg.brandl | 2007-10-20 08:21:22 -0700 (Sat, 20 Oct 2007) | 2 lines
Make a path more Unix-standardy.
........
r58564 | georg.brandl | 2007-10-20 10:51:39 -0700 (Sat, 20 Oct 2007) | 2 lines
Document new directive "envvar".
........
r58567 | georg.brandl | 2007-10-20 11:08:14 -0700 (Sat, 20 Oct 2007) | 6 lines
* Add new toplevel chapter, "Using Python." (how to install,
configure and setup python on different platforms -- at least
in theory.)
* Move the Python on Mac docs in that chapter.
* Add a new chapter about the command line invocation, by stargaming.
........
r58568 | georg.brandl | 2007-10-20 11:33:20 -0700 (Sat, 20 Oct 2007) | 2 lines
Change title, for now.
........
r58569 | georg.brandl | 2007-10-20 11:39:25 -0700 (Sat, 20 Oct 2007) | 2 lines
Add entry to ACKS.
........
r58570 | georg.brandl | 2007-10-20 12:05:45 -0700 (Sat, 20 Oct 2007) | 2 lines
Clarify -E docs.
........
r58571 | georg.brandl | 2007-10-20 12:08:36 -0700 (Sat, 20 Oct 2007) | 2 lines
Even more clarification.
........
r58572 | andrew.kuchling | 2007-10-20 12:25:37 -0700 (Sat, 20 Oct 2007) | 1 line
Fix protocol name
........
r58573 | andrew.kuchling | 2007-10-20 12:35:18 -0700 (Sat, 20 Oct 2007) | 1 line
Various items
........
r58574 | andrew.kuchling | 2007-10-20 12:39:35 -0700 (Sat, 20 Oct 2007) | 1 line
Use correct header line
........
r58576 | armin.rigo | 2007-10-21 02:14:15 -0700 (Sun, 21 Oct 2007) | 3 lines
Add a crasher for the long-standing issue with closing a file
while another thread uses it.
........
r58577 | georg.brandl | 2007-10-21 03:01:56 -0700 (Sun, 21 Oct 2007) | 2 lines
Remove duplicate crasher.
........
r58578 | georg.brandl | 2007-10-21 03:24:20 -0700 (Sun, 21 Oct 2007) | 2 lines
Unify "byte code" to "bytecode". Also sprinkle :term: markup for it.
........
r58579 | georg.brandl | 2007-10-21 03:32:54 -0700 (Sun, 21 Oct 2007) | 2 lines
Add markup to new function descriptions.
........
r58580 | georg.brandl | 2007-10-21 03:45:46 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for descriptors.
........
r58581 | georg.brandl | 2007-10-21 03:46:24 -0700 (Sun, 21 Oct 2007) | 2 lines
Unify "file-descriptor" to "file descriptor".
........
r58582 | georg.brandl | 2007-10-21 03:52:38 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term: for generators.
........
r58583 | georg.brandl | 2007-10-21 05:10:28 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for iterator.
........
r58584 | georg.brandl | 2007-10-21 05:15:05 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for "new-style class".
........
r58588 | neal.norwitz | 2007-10-21 21:47:54 -0700 (Sun, 21 Oct 2007) | 1 line
Add Chris Monson so he can edit PEPs.
........
r58594 | guido.van.rossum | 2007-10-22 09:27:19 -0700 (Mon, 22 Oct 2007) | 4 lines
Issue #1307, patch by Derek Shockey.
When "MAIL" is received without args, an exception happens instead of
sending a 501 syntax error response.
........
r58598 | travis.oliphant | 2007-10-22 19:40:56 -0700 (Mon, 22 Oct 2007) | 1 line
Add phuang patch from Issue 708374 which adds offset parameter to mmap module.
........
r58601 | neal.norwitz | 2007-10-22 22:44:27 -0700 (Mon, 22 Oct 2007) | 2 lines
Bug #1313, fix typo (wrong variable name) in example.
........
r58609 | georg.brandl | 2007-10-23 11:21:35 -0700 (Tue, 23 Oct 2007) | 2 lines
Update Pygments version from externals.
........
r58618 | guido.van.rossum | 2007-10-23 12:25:41 -0700 (Tue, 23 Oct 2007) | 3 lines
Issue 1307 by Derek Shockey, fox the same bug for RCPT.
Neal: please backport!
........
r58620 | raymond.hettinger | 2007-10-23 13:37:41 -0700 (Tue, 23 Oct 2007) | 1 line
Shorter name for namedtuple()
........
r58621 | andrew.kuchling | 2007-10-23 13:55:47 -0700 (Tue, 23 Oct 2007) | 1 line
Update name
........
r58622 | raymond.hettinger | 2007-10-23 14:23:07 -0700 (Tue, 23 Oct 2007) | 1 line
Fixup news entry
........
r58623 | raymond.hettinger | 2007-10-23 18:28:33 -0700 (Tue, 23 Oct 2007) | 1 line
Optimize sum() for integer and float inputs.
........
r58624 | raymond.hettinger | 2007-10-23 19:05:51 -0700 (Tue, 23 Oct 2007) | 1 line
Fixup error return and add support for intermixed ints and floats/
........
r58628 | vinay.sajip | 2007-10-24 03:47:06 -0700 (Wed, 24 Oct 2007) | 1 line
Bug #1321: Fixed logic error in TimedRotatingFileHandler.__init__()
........
r58641 | facundo.batista | 2007-10-24 12:11:08 -0700 (Wed, 24 Oct 2007) | 4 lines
Issue 1290. CharacterData.__repr__ was constructing a string
in response that keeped having a non-ascii character.
........
r58643 | thomas.heller | 2007-10-24 12:50:45 -0700 (Wed, 24 Oct 2007) | 1 line
Added unittest for calling a function with paramflags (backport from py3k branch).
........
r58645 | matthias.klose | 2007-10-24 13:00:44 -0700 (Wed, 24 Oct 2007) | 2 lines
- Build using system ffi library on arm*-linux*.
........
r58651 | georg.brandl | 2007-10-24 14:40:38 -0700 (Wed, 24 Oct 2007) | 2 lines
Bug #1287: make os.environ.pop() work as expected.
........
r58652 | raymond.hettinger | 2007-10-24 19:26:58 -0700 (Wed, 24 Oct 2007) | 1 line
Missing DECREFs
........
r58653 | matthias.klose | 2007-10-24 23:37:24 -0700 (Wed, 24 Oct 2007) | 2 lines
- Build using system ffi library on arm*-linux*, pass --with-system-ffi to CONFIG_ARGS
........
r58655 | thomas.heller | 2007-10-25 12:47:32 -0700 (Thu, 25 Oct 2007) | 2 lines
ffi_type_longdouble may be already #defined.
See issue 1324.
........
r58656 | kurt.kaiser | 2007-10-25 15:43:45 -0700 (Thu, 25 Oct 2007) | 3 lines
Correct an ancient bug in an unused path by removing that path: register() is
now idempotent.
........
r58660 | kurt.kaiser | 2007-10-25 17:10:09 -0700 (Thu, 25 Oct 2007) | 4 lines
1. Add comments to provide top-level documentation.
2. Refactor to use more descriptive names.
3. Enhance tests in main().
........
r58675 | georg.brandl | 2007-10-26 11:30:41 -0700 (Fri, 26 Oct 2007) | 2 lines
Fix new pop() method on os.environ on ignorecase-platforms.
........
r58696 | neal.norwitz | 2007-10-27 15:32:21 -0700 (Sat, 27 Oct 2007) | 1 line
Update URL for Pygments. 0.8.1 is no longer available
........
r58697 | hyeshik.chang | 2007-10-28 04:19:02 -0700 (Sun, 28 Oct 2007) | 3 lines
- Add support for FreeBSD 8 which is recently forked from FreeBSD 7.
- Regenerate IN module for most recent maintenance tree of FreeBSD 6 and 7.
........
r58698 | hyeshik.chang | 2007-10-28 05:38:09 -0700 (Sun, 28 Oct 2007) | 2 lines
Enable platform-specific tweaks for FreeBSD 8 (exactly same to FreeBSD 7's yet)
........
r58700 | kurt.kaiser | 2007-10-28 12:03:59 -0700 (Sun, 28 Oct 2007) | 2 lines
Add confirmation dialog before printing. Patch 1717170 Tal Einat.
........
r58706 | guido.van.rossum | 2007-10-29 13:52:45 -0700 (Mon, 29 Oct 2007) | 3 lines
Patch 1353 by Jacob Winther.
Add mp4 mapping to mimetypes.py.
........
r58709 | guido.van.rossum | 2007-10-29 15:15:05 -0700 (Mon, 29 Oct 2007) | 6 lines
Backport fixes for the code that decodes octal escapes (and for PyString
also hex escapes) -- this was reaching beyond the end of the input string
buffer, even though it is not supposed to be \0-terminated.
This has no visible effect but is clearly the correct thing to do.
(In 3.0 it had a visible effect after removing ob_sstate from PyString.)
........
r58710 | kurt.kaiser | 2007-10-29 19:38:54 -0700 (Mon, 29 Oct 2007) | 7 lines
check in Tal Einat's update to tabpage.py
Patch 1612746
M configDialog.py
M NEWS.txt
AM tabbedpages.py
........
r58715 | georg.brandl | 2007-10-30 10:51:18 -0700 (Tue, 30 Oct 2007) | 2 lines
Use correct markup.
........
r58716 | georg.brandl | 2007-10-30 10:57:12 -0700 (Tue, 30 Oct 2007) | 2 lines
Make example about hiding None return values at the prompt clearer.
........
r58728 | neal.norwitz | 2007-10-30 23:33:20 -0700 (Tue, 30 Oct 2007) | 1 line
Fix some compiler warnings for signed comparisons on Unix and Windows.
........
r58731 | martin.v.loewis | 2007-10-31 10:19:33 -0700 (Wed, 31 Oct 2007) | 2 lines
Adding Christian Heimes.
........
r58737 | raymond.hettinger | 2007-10-31 14:57:58 -0700 (Wed, 31 Oct 2007) | 1 line
Clarify the reasons why pickle is almost always better than marshal
........
r58739 | raymond.hettinger | 2007-10-31 15:15:49 -0700 (Wed, 31 Oct 2007) | 1 line
Sets are marshalable.
........
2007-11-01 17:32:30 -03:00
|
|
|
|
other keyword argument) is passed through to the incremental encoder.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2016-10-14 21:56:47 -03:00
|
|
|
|
This function requires that the codec accept text :class:`str` objects
|
|
|
|
|
to encode. Therefore it does not support bytes-to-bytes encoders such as
|
|
|
|
|
``base64_codec``.
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
|
.. function:: iterdecode(iterator, encoding, errors='strict', **kwargs)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
Uses an incremental decoder to iteratively decode the input provided by
|
2015-01-06 10:22:00 -04:00
|
|
|
|
*iterator*. This function is a :term:`generator`.
|
|
|
|
|
The *errors* argument (as well as any
|
#1370: Finish the merge r58749, log below, by resolving all conflicts in Doc/.
Merged revisions 58221-58741 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58221 | georg.brandl | 2007-09-20 10:57:59 -0700 (Thu, 20 Sep 2007) | 2 lines
Patch #1181: add os.environ.clear() method.
........
r58225 | sean.reifschneider | 2007-09-20 23:33:28 -0700 (Thu, 20 Sep 2007) | 3 lines
Issue1704287: "make install" fails unless you do "make" first. Make
oldsharedmods and sharedmods in "libinstall".
........
r58232 | guido.van.rossum | 2007-09-22 13:18:03 -0700 (Sat, 22 Sep 2007) | 4 lines
Patch # 188 by Philip Jenvey.
Make tell() mark CRLF as a newline.
With unit test.
........
r58242 | georg.brandl | 2007-09-24 10:55:47 -0700 (Mon, 24 Sep 2007) | 2 lines
Fix typo and double word.
........
r58245 | georg.brandl | 2007-09-24 10:59:28 -0700 (Mon, 24 Sep 2007) | 2 lines
#1196: document default radix for int().
........
r58247 | georg.brandl | 2007-09-24 11:08:24 -0700 (Mon, 24 Sep 2007) | 2 lines
#1177: accept 2xx responses for https too, not only http.
........
r58249 | andrew.kuchling | 2007-09-24 16:45:51 -0700 (Mon, 24 Sep 2007) | 1 line
Remove stray odd character; grammar fix
........
r58250 | andrew.kuchling | 2007-09-24 16:46:28 -0700 (Mon, 24 Sep 2007) | 1 line
Typo fix
........
r58251 | andrew.kuchling | 2007-09-24 17:09:42 -0700 (Mon, 24 Sep 2007) | 1 line
Add various items
........
r58268 | vinay.sajip | 2007-09-26 22:34:45 -0700 (Wed, 26 Sep 2007) | 1 line
Change to flush and close logic to fix #1760556.
........
r58269 | vinay.sajip | 2007-09-26 22:38:51 -0700 (Wed, 26 Sep 2007) | 1 line
Change to basicConfig() to fix #1021.
........
r58270 | georg.brandl | 2007-09-26 23:26:58 -0700 (Wed, 26 Sep 2007) | 2 lines
#1208: document match object's boolean value.
........
r58271 | vinay.sajip | 2007-09-26 23:56:13 -0700 (Wed, 26 Sep 2007) | 1 line
Minor date change.
........
r58272 | vinay.sajip | 2007-09-27 00:35:10 -0700 (Thu, 27 Sep 2007) | 1 line
Change to LogRecord.__init__() to fix #1206. Note that archaic use of type(x) == types.DictType is because of keeping 1.5.2 compatibility. While this is much less relevant these days, there probably needs to be a separate commit for removing all archaic constructs at the same time.
........
r58288 | brett.cannon | 2007-09-30 12:45:10 -0700 (Sun, 30 Sep 2007) | 9 lines
tuple.__repr__ did not consider a reference loop as it is not possible from
Python code; but it is possible from C. object.__str__ had the issue of not
expecting a type to doing something within it's tp_str implementation that
could trigger an infinite recursion, but it could in C code.. Both found
thanks to BaseException and how it handles its repr.
Closes issue #1686386. Thanks to Thomas Herve for taking an initial stab at
coming up with a solution.
........
r58289 | brett.cannon | 2007-09-30 13:37:19 -0700 (Sun, 30 Sep 2007) | 3 lines
Fix error introduced by r58288; if a tuple is length 0 return its repr and
don't worry about any self-referring tuples.
........
r58294 | facundo.batista | 2007-10-02 10:01:24 -0700 (Tue, 02 Oct 2007) | 11 lines
Made the various is_* operations return booleans. This was discussed
with Cawlishaw by mail, and he basically confirmed that to these is_*
operations, there's no need to return Decimal(0) and Decimal(1) if
the language supports the False and True booleans.
Also added a few tests for the these functions in extra.decTest, since
they are mostly untested (apart from the doctests).
Thanks Mark Dickinson
........
r58295 | facundo.batista | 2007-10-02 11:21:18 -0700 (Tue, 02 Oct 2007) | 4 lines
Added a class to store the digits of log(10), so that they can be made
available when necessary without recomputing. Thanks Mark Dickinson
........
r58299 | mark.summerfield | 2007-10-03 01:53:21 -0700 (Wed, 03 Oct 2007) | 4 lines
Added note in footnote about string comparisons about
unicodedata.normalize().
........
r58304 | raymond.hettinger | 2007-10-03 14:18:11 -0700 (Wed, 03 Oct 2007) | 1 line
enumerate() is no longer bounded to using sequences shorter than LONG_MAX. The possibility of overflow was sending some newsgroup posters into a tizzy.
........
r58305 | raymond.hettinger | 2007-10-03 17:20:27 -0700 (Wed, 03 Oct 2007) | 1 line
itertools.count() no longer limited to sys.maxint.
........
r58306 | kurt.kaiser | 2007-10-03 18:49:54 -0700 (Wed, 03 Oct 2007) | 3 lines
Assume that the user knows when he wants to end the line; don't insert
something he didn't select or complete.
........
r58307 | kurt.kaiser | 2007-10-03 19:07:50 -0700 (Wed, 03 Oct 2007) | 2 lines
Remove unused theme that was causing a fault in p3k.
........
r58308 | kurt.kaiser | 2007-10-03 19:09:17 -0700 (Wed, 03 Oct 2007) | 2 lines
Clean up EditorWindow close.
........
r58309 | kurt.kaiser | 2007-10-03 19:53:07 -0700 (Wed, 03 Oct 2007) | 7 lines
textView cleanup. Patch 1718043 Tal Einat.
M idlelib/EditorWindow.py
M idlelib/aboutDialog.py
M idlelib/textView.py
M idlelib/NEWS.txt
........
r58310 | kurt.kaiser | 2007-10-03 20:11:12 -0700 (Wed, 03 Oct 2007) | 3 lines
configDialog cleanup. Patch 1730217 Tal Einat.
........
r58311 | neal.norwitz | 2007-10-03 23:00:48 -0700 (Wed, 03 Oct 2007) | 4 lines
Coverity #151: Remove deadcode.
All this code already exists above starting at line 653.
........
r58325 | fred.drake | 2007-10-04 19:46:12 -0700 (Thu, 04 Oct 2007) | 1 line
wrap lines to <80 characters before fixing errors
........
r58326 | raymond.hettinger | 2007-10-04 19:47:07 -0700 (Thu, 04 Oct 2007) | 6 lines
Add __asdict__() to NamedTuple and refine the docs.
Add maxlen support to deque() and fixup docs.
Partially fix __reduce__(). The None as a third arg was no longer supported.
Still needs work on __reduce__() to handle recursive inputs.
........
r58327 | fred.drake | 2007-10-04 19:48:32 -0700 (Thu, 04 Oct 2007) | 3 lines
move descriptions of ac_(in|out)_buffer_size to the right place
http://bugs.python.org/issue1053
........
r58329 | neal.norwitz | 2007-10-04 20:39:17 -0700 (Thu, 04 Oct 2007) | 3 lines
dict could be NULL, so we need to XDECREF.
Fix a compiler warning about passing a PyTypeObject* instead of PyObject*.
........
r58330 | neal.norwitz | 2007-10-04 20:41:19 -0700 (Thu, 04 Oct 2007) | 2 lines
Fix Coverity #158: Check the correct variable.
........
r58332 | neal.norwitz | 2007-10-04 22:01:38 -0700 (Thu, 04 Oct 2007) | 7 lines
Fix Coverity #159.
This code was broken if save() returned a negative number since i contained
a boolean value and then we compared i < 0 which should never be true.
Will backport (assuming it's necessary)
........
r58334 | neal.norwitz | 2007-10-04 22:29:17 -0700 (Thu, 04 Oct 2007) | 1 line
Add a note about fixing some more warnings found by Coverity.
........
r58338 | raymond.hettinger | 2007-10-05 12:07:31 -0700 (Fri, 05 Oct 2007) | 1 line
Restore BEGIN/END THREADS macros which were squashed in the previous checkin
........
r58343 | gregory.p.smith | 2007-10-06 00:48:10 -0700 (Sat, 06 Oct 2007) | 3 lines
Stab in the dark attempt to fix the test_bsddb3 failure on sparc and S-390
ubuntu buildbots.
........
r58344 | gregory.p.smith | 2007-10-06 00:51:59 -0700 (Sat, 06 Oct 2007) | 2 lines
Allows BerkeleyDB 4.6.x >= 4.6.21 for the bsddb module.
........
r58348 | gregory.p.smith | 2007-10-06 08:47:37 -0700 (Sat, 06 Oct 2007) | 3 lines
Use the host the author likely meant in the first place. pop.gmail.com is
reliable. gmail.org is someones personal domain.
........
r58351 | neal.norwitz | 2007-10-06 12:16:28 -0700 (Sat, 06 Oct 2007) | 3 lines
Ensure that this test will pass even if another test left an unwritable TESTFN.
Also use the safe unlink in test_support instead of rolling our own here.
........
r58368 | georg.brandl | 2007-10-08 00:50:24 -0700 (Mon, 08 Oct 2007) | 3 lines
#1123: fix the docs for the str.split(None, sep) case.
Also expand a few other methods' docs, which had more info in the deprecated string module docs.
........
r58369 | georg.brandl | 2007-10-08 01:06:05 -0700 (Mon, 08 Oct 2007) | 2 lines
Update docstring of sched, also remove an unused assignment.
........
r58370 | raymond.hettinger | 2007-10-08 02:14:28 -0700 (Mon, 08 Oct 2007) | 5 lines
Add comments to NamedTuple code.
Let the field spec be either a string or a non-string sequence (suggested by Martin Blais with use cases).
Improve the error message in the case of a SyntaxError (caused by a duplicate field name).
........
r58371 | raymond.hettinger | 2007-10-08 02:56:29 -0700 (Mon, 08 Oct 2007) | 1 line
Missed a line in the docs
........
r58372 | raymond.hettinger | 2007-10-08 03:11:51 -0700 (Mon, 08 Oct 2007) | 1 line
Better variable names
........
r58376 | georg.brandl | 2007-10-08 07:12:47 -0700 (Mon, 08 Oct 2007) | 3 lines
#1199: docs for tp_as_{number,sequence,mapping}, by Amaury Forgeot d'Arc.
No need to merge this to py3k!
........
r58380 | raymond.hettinger | 2007-10-08 14:26:58 -0700 (Mon, 08 Oct 2007) | 1 line
Eliminate camelcase function name
........
r58381 | andrew.kuchling | 2007-10-08 16:23:03 -0700 (Mon, 08 Oct 2007) | 1 line
Eliminate camelcase function name
........
r58382 | raymond.hettinger | 2007-10-08 18:36:23 -0700 (Mon, 08 Oct 2007) | 1 line
Make the error messages more specific
........
r58384 | gregory.p.smith | 2007-10-08 23:02:21 -0700 (Mon, 08 Oct 2007) | 10 lines
Splits Modules/_bsddb.c up into bsddb.h and _bsddb.c and adds a C API
object available as bsddb.db.api. This is based on the patch submitted
by Duncan Grisby here:
http://sourceforge.net/tracker/index.php?func=detail&aid=1551895&group_id=13900&atid=313900
See this thread for additional info:
http://sourceforge.net/mailarchive/forum.php?thread_name=E1GAVDK-0002rk-Iw%40apasphere.com&forum_name=pybsddb-users
It also cleans up the code a little by removing some ifdef/endifs for
python prior to 2.1 and for unsupported Berkeley DB <= 3.2.
........
r58385 | gregory.p.smith | 2007-10-08 23:50:43 -0700 (Mon, 08 Oct 2007) | 5 lines
Fix a double free when positioning a database cursor to a non-existant
string key (and probably a few other situations with string keys).
This was reported with a patch as pybsddb sourceforge bug 1708868 by
jjjhhhlll at gmail.
........
r58386 | gregory.p.smith | 2007-10-09 00:19:11 -0700 (Tue, 09 Oct 2007) | 3 lines
Use the highest cPickle protocol in bsddb.dbshelve. This comes from
sourceforge pybsddb patch 1551443 by w_barnes.
........
r58394 | gregory.p.smith | 2007-10-09 11:26:02 -0700 (Tue, 09 Oct 2007) | 2 lines
remove another sleepycat reference
........
r58396 | kurt.kaiser | 2007-10-09 12:31:30 -0700 (Tue, 09 Oct 2007) | 3 lines
Allow interrupt only when executing user code in subprocess
Patch 1225 Tal Einat modified from IDLE-Spoon.
........
r58399 | brett.cannon | 2007-10-09 17:07:50 -0700 (Tue, 09 Oct 2007) | 5 lines
Remove file-level typedefs that were inconsistently used throughout the file.
Just move over to the public API names.
Closes issue1238.
........
r58401 | raymond.hettinger | 2007-10-09 17:26:46 -0700 (Tue, 09 Oct 2007) | 1 line
Accept Jim Jewett's api suggestion to use None instead of -1 to indicate unbounded deques.
........
r58403 | kurt.kaiser | 2007-10-09 17:55:40 -0700 (Tue, 09 Oct 2007) | 2 lines
Allow cursor color change w/o restart. Patch 1725576 Tal Einat.
........
r58404 | kurt.kaiser | 2007-10-09 18:06:47 -0700 (Tue, 09 Oct 2007) | 2 lines
show paste if > 80 columns. Patch 1659326 Tal Einat.
........
r58415 | thomas.heller | 2007-10-11 12:51:32 -0700 (Thu, 11 Oct 2007) | 5 lines
On OS X, use os.uname() instead of gestalt.sysv(...) to get the
operating system version. This allows to use ctypes when Python
was configured with --disable-toolbox-glue.
........
r58419 | neal.norwitz | 2007-10-11 20:01:01 -0700 (Thu, 11 Oct 2007) | 1 line
Get rid of warning about not being able to create an existing directory.
........
r58420 | neal.norwitz | 2007-10-11 20:01:30 -0700 (Thu, 11 Oct 2007) | 1 line
Get rid of warnings on a bunch of platforms by using a proper prototype.
........
r58421 | neal.norwitz | 2007-10-11 20:01:54 -0700 (Thu, 11 Oct 2007) | 4 lines
Get rid of compiler warning about retval being used (returned) without
being initialized. (gcc warning and Coverity 202)
........
r58422 | neal.norwitz | 2007-10-11 20:03:23 -0700 (Thu, 11 Oct 2007) | 1 line
Fix Coverity 168: Close the file before returning (exiting).
........
r58423 | neal.norwitz | 2007-10-11 20:04:18 -0700 (Thu, 11 Oct 2007) | 4 lines
Fix Coverity 180: Don't overallocate. We don't need structs, but pointers.
Also fix a memory leak.
........
r58424 | neal.norwitz | 2007-10-11 20:05:19 -0700 (Thu, 11 Oct 2007) | 5 lines
Fix Coverity 185-186: If the passed in FILE is NULL, uninitialized memory
would be accessed.
Will backport.
........
r58425 | neal.norwitz | 2007-10-11 20:52:34 -0700 (Thu, 11 Oct 2007) | 1 line
Get this module to compile with bsddb versions prior to 4.3
........
r58430 | martin.v.loewis | 2007-10-12 01:56:52 -0700 (Fri, 12 Oct 2007) | 3 lines
Bug #1216: Restore support for Visual Studio 2002.
Will backport to 2.5.
........
r58433 | raymond.hettinger | 2007-10-12 10:53:11 -0700 (Fri, 12 Oct 2007) | 1 line
Fix test of count.__repr__() to ignore the 'L' if the count is a long
........
r58434 | gregory.p.smith | 2007-10-12 11:44:06 -0700 (Fri, 12 Oct 2007) | 4 lines
Fixes http://bugs.python.org/issue1233 - bsddb.dbshelve.DBShelf.append
was useless due to inverted logic. Also adds a test case for RECNO dbs
to test_dbshelve.
........
r58445 | georg.brandl | 2007-10-13 06:20:03 -0700 (Sat, 13 Oct 2007) | 2 lines
Fix email example.
........
r58450 | gregory.p.smith | 2007-10-13 16:02:05 -0700 (Sat, 13 Oct 2007) | 2 lines
Fix an uncollectable reference leak in bsddb.db.DBShelf.append
........
r58453 | neal.norwitz | 2007-10-13 17:18:40 -0700 (Sat, 13 Oct 2007) | 8 lines
Let the O/S supply a port if none of the default ports can be used.
This should make the tests more robust at the expense of allowing
tests to be sloppier by not requiring them to cleanup after themselves.
(It will legitamitely help when running two test suites simultaneously
or if another process is already using one of the predefined ports.)
Also simplifies (slightLy) the exception handling elsewhere.
........
r58459 | neal.norwitz | 2007-10-14 11:30:21 -0700 (Sun, 14 Oct 2007) | 2 lines
Don't raise a string exception, they don't work anymore.
........
r58460 | neal.norwitz | 2007-10-14 11:40:37 -0700 (Sun, 14 Oct 2007) | 1 line
Use unittest for assertions
........
r58468 | armin.rigo | 2007-10-15 00:48:35 -0700 (Mon, 15 Oct 2007) | 2 lines
test_bigbits was not testing what it seemed to.
........
r58471 | guido.van.rossum | 2007-10-15 08:54:11 -0700 (Mon, 15 Oct 2007) | 3 lines
Change a PyErr_Print() into a PyErr_Clear(),
per discussion in issue 1031213.
........
r58500 | raymond.hettinger | 2007-10-16 12:18:30 -0700 (Tue, 16 Oct 2007) | 1 line
Improve error messages
........
r58506 | raymond.hettinger | 2007-10-16 14:28:32 -0700 (Tue, 16 Oct 2007) | 1 line
More docs, error messages, and tests
........
r58507 | andrew.kuchling | 2007-10-16 15:58:03 -0700 (Tue, 16 Oct 2007) | 1 line
Add items
........
r58508 | brett.cannon | 2007-10-16 16:24:06 -0700 (Tue, 16 Oct 2007) | 3 lines
Remove ``:const:`` notation on None in parameter list. Since the markup is not
rendered for parameters it just showed up as ``:const:`None` `` in the output.
........
r58509 | brett.cannon | 2007-10-16 16:26:45 -0700 (Tue, 16 Oct 2007) | 3 lines
Re-order some functions whose parameters differ between PyObject and const char
* so that they are next to each other.
........
r58522 | armin.rigo | 2007-10-17 11:46:37 -0700 (Wed, 17 Oct 2007) | 5 lines
Fix the overflow checking of list_repeat.
Introduce overflow checking into list_inplace_repeat.
Backport candidate, possibly.
........
r58530 | facundo.batista | 2007-10-17 20:16:03 -0700 (Wed, 17 Oct 2007) | 7 lines
Issue #1580738. When HTTPConnection reads the whole stream with read(),
it closes itself. When the stream is read in several calls to read(n),
it should behave in the same way if HTTPConnection knows where the end
of the stream is (through self.length). Added a test case for this
behaviour.
........
r58531 | facundo.batista | 2007-10-17 20:44:48 -0700 (Wed, 17 Oct 2007) | 3 lines
Issue 1289, just a typo.
........
r58532 | gregory.p.smith | 2007-10-18 00:56:54 -0700 (Thu, 18 Oct 2007) | 4 lines
cleanup test_dbtables to use mkdtemp. cleanup dbtables to pass txn as a
keyword argument whenever possible to avoid bugs and confusion. (dbtables.py
line 447 self.db.get using txn as a non-keyword was an actual bug due to this)
........
r58533 | gregory.p.smith | 2007-10-18 01:34:20 -0700 (Thu, 18 Oct 2007) | 4 lines
Fix a weird bug in dbtables: if it chose a random rowid string that contained
NULL bytes it would cause the database all sorts of problems in the future
leading to very strange random failures and corrupt dbtables.bsdTableDb dbs.
........
r58534 | gregory.p.smith | 2007-10-18 09:32:02 -0700 (Thu, 18 Oct 2007) | 3 lines
A cleaner fix than the one committed last night. Generate random rowids that
do not contain null bytes.
........
r58537 | gregory.p.smith | 2007-10-18 10:17:57 -0700 (Thu, 18 Oct 2007) | 2 lines
mention bsddb fixes.
........
r58538 | raymond.hettinger | 2007-10-18 14:13:06 -0700 (Thu, 18 Oct 2007) | 1 line
Remove useless warning
........
r58539 | gregory.p.smith | 2007-10-19 00:31:20 -0700 (Fri, 19 Oct 2007) | 2 lines
squelch the warning that this test is supposed to trigger.
........
r58542 | georg.brandl | 2007-10-19 05:32:39 -0700 (Fri, 19 Oct 2007) | 2 lines
Clarify wording for apply().
........
r58544 | mark.summerfield | 2007-10-19 05:48:17 -0700 (Fri, 19 Oct 2007) | 3 lines
Added a cross-ref to each other.
........
r58545 | georg.brandl | 2007-10-19 10:38:49 -0700 (Fri, 19 Oct 2007) | 2 lines
#1284: "S" means "seen", not unread.
........
r58548 | thomas.heller | 2007-10-19 11:11:41 -0700 (Fri, 19 Oct 2007) | 4 lines
Fix ctypes on 32-bit systems when Python is configured --with-system-ffi.
See also https://bugs.launchpad.net/bugs/72505.
Ported from release25-maint branch.
........
r58550 | facundo.batista | 2007-10-19 12:25:57 -0700 (Fri, 19 Oct 2007) | 8 lines
The constructor from tuple was way too permissive: it allowed bad
coefficient numbers, floats in the sign, and other details that
generated directly the wrong number in the best case, or triggered
misfunctionality in the alorithms.
Test cases added for these issues. Thanks Mark Dickinson.
........
r58559 | georg.brandl | 2007-10-20 06:22:53 -0700 (Sat, 20 Oct 2007) | 2 lines
Fix code being interpreted as a target.
........
r58561 | georg.brandl | 2007-10-20 06:36:24 -0700 (Sat, 20 Oct 2007) | 2 lines
Document new "cmdoption" directive.
........
r58562 | georg.brandl | 2007-10-20 08:21:22 -0700 (Sat, 20 Oct 2007) | 2 lines
Make a path more Unix-standardy.
........
r58564 | georg.brandl | 2007-10-20 10:51:39 -0700 (Sat, 20 Oct 2007) | 2 lines
Document new directive "envvar".
........
r58567 | georg.brandl | 2007-10-20 11:08:14 -0700 (Sat, 20 Oct 2007) | 6 lines
* Add new toplevel chapter, "Using Python." (how to install,
configure and setup python on different platforms -- at least
in theory.)
* Move the Python on Mac docs in that chapter.
* Add a new chapter about the command line invocation, by stargaming.
........
r58568 | georg.brandl | 2007-10-20 11:33:20 -0700 (Sat, 20 Oct 2007) | 2 lines
Change title, for now.
........
r58569 | georg.brandl | 2007-10-20 11:39:25 -0700 (Sat, 20 Oct 2007) | 2 lines
Add entry to ACKS.
........
r58570 | georg.brandl | 2007-10-20 12:05:45 -0700 (Sat, 20 Oct 2007) | 2 lines
Clarify -E docs.
........
r58571 | georg.brandl | 2007-10-20 12:08:36 -0700 (Sat, 20 Oct 2007) | 2 lines
Even more clarification.
........
r58572 | andrew.kuchling | 2007-10-20 12:25:37 -0700 (Sat, 20 Oct 2007) | 1 line
Fix protocol name
........
r58573 | andrew.kuchling | 2007-10-20 12:35:18 -0700 (Sat, 20 Oct 2007) | 1 line
Various items
........
r58574 | andrew.kuchling | 2007-10-20 12:39:35 -0700 (Sat, 20 Oct 2007) | 1 line
Use correct header line
........
r58576 | armin.rigo | 2007-10-21 02:14:15 -0700 (Sun, 21 Oct 2007) | 3 lines
Add a crasher for the long-standing issue with closing a file
while another thread uses it.
........
r58577 | georg.brandl | 2007-10-21 03:01:56 -0700 (Sun, 21 Oct 2007) | 2 lines
Remove duplicate crasher.
........
r58578 | georg.brandl | 2007-10-21 03:24:20 -0700 (Sun, 21 Oct 2007) | 2 lines
Unify "byte code" to "bytecode". Also sprinkle :term: markup for it.
........
r58579 | georg.brandl | 2007-10-21 03:32:54 -0700 (Sun, 21 Oct 2007) | 2 lines
Add markup to new function descriptions.
........
r58580 | georg.brandl | 2007-10-21 03:45:46 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for descriptors.
........
r58581 | georg.brandl | 2007-10-21 03:46:24 -0700 (Sun, 21 Oct 2007) | 2 lines
Unify "file-descriptor" to "file descriptor".
........
r58582 | georg.brandl | 2007-10-21 03:52:38 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term: for generators.
........
r58583 | georg.brandl | 2007-10-21 05:10:28 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for iterator.
........
r58584 | georg.brandl | 2007-10-21 05:15:05 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for "new-style class".
........
r58588 | neal.norwitz | 2007-10-21 21:47:54 -0700 (Sun, 21 Oct 2007) | 1 line
Add Chris Monson so he can edit PEPs.
........
r58594 | guido.van.rossum | 2007-10-22 09:27:19 -0700 (Mon, 22 Oct 2007) | 4 lines
Issue #1307, patch by Derek Shockey.
When "MAIL" is received without args, an exception happens instead of
sending a 501 syntax error response.
........
r58598 | travis.oliphant | 2007-10-22 19:40:56 -0700 (Mon, 22 Oct 2007) | 1 line
Add phuang patch from Issue 708374 which adds offset parameter to mmap module.
........
r58601 | neal.norwitz | 2007-10-22 22:44:27 -0700 (Mon, 22 Oct 2007) | 2 lines
Bug #1313, fix typo (wrong variable name) in example.
........
r58609 | georg.brandl | 2007-10-23 11:21:35 -0700 (Tue, 23 Oct 2007) | 2 lines
Update Pygments version from externals.
........
r58618 | guido.van.rossum | 2007-10-23 12:25:41 -0700 (Tue, 23 Oct 2007) | 3 lines
Issue 1307 by Derek Shockey, fox the same bug for RCPT.
Neal: please backport!
........
r58620 | raymond.hettinger | 2007-10-23 13:37:41 -0700 (Tue, 23 Oct 2007) | 1 line
Shorter name for namedtuple()
........
r58621 | andrew.kuchling | 2007-10-23 13:55:47 -0700 (Tue, 23 Oct 2007) | 1 line
Update name
........
r58622 | raymond.hettinger | 2007-10-23 14:23:07 -0700 (Tue, 23 Oct 2007) | 1 line
Fixup news entry
........
r58623 | raymond.hettinger | 2007-10-23 18:28:33 -0700 (Tue, 23 Oct 2007) | 1 line
Optimize sum() for integer and float inputs.
........
r58624 | raymond.hettinger | 2007-10-23 19:05:51 -0700 (Tue, 23 Oct 2007) | 1 line
Fixup error return and add support for intermixed ints and floats/
........
r58628 | vinay.sajip | 2007-10-24 03:47:06 -0700 (Wed, 24 Oct 2007) | 1 line
Bug #1321: Fixed logic error in TimedRotatingFileHandler.__init__()
........
r58641 | facundo.batista | 2007-10-24 12:11:08 -0700 (Wed, 24 Oct 2007) | 4 lines
Issue 1290. CharacterData.__repr__ was constructing a string
in response that keeped having a non-ascii character.
........
r58643 | thomas.heller | 2007-10-24 12:50:45 -0700 (Wed, 24 Oct 2007) | 1 line
Added unittest for calling a function with paramflags (backport from py3k branch).
........
r58645 | matthias.klose | 2007-10-24 13:00:44 -0700 (Wed, 24 Oct 2007) | 2 lines
- Build using system ffi library on arm*-linux*.
........
r58651 | georg.brandl | 2007-10-24 14:40:38 -0700 (Wed, 24 Oct 2007) | 2 lines
Bug #1287: make os.environ.pop() work as expected.
........
r58652 | raymond.hettinger | 2007-10-24 19:26:58 -0700 (Wed, 24 Oct 2007) | 1 line
Missing DECREFs
........
r58653 | matthias.klose | 2007-10-24 23:37:24 -0700 (Wed, 24 Oct 2007) | 2 lines
- Build using system ffi library on arm*-linux*, pass --with-system-ffi to CONFIG_ARGS
........
r58655 | thomas.heller | 2007-10-25 12:47:32 -0700 (Thu, 25 Oct 2007) | 2 lines
ffi_type_longdouble may be already #defined.
See issue 1324.
........
r58656 | kurt.kaiser | 2007-10-25 15:43:45 -0700 (Thu, 25 Oct 2007) | 3 lines
Correct an ancient bug in an unused path by removing that path: register() is
now idempotent.
........
r58660 | kurt.kaiser | 2007-10-25 17:10:09 -0700 (Thu, 25 Oct 2007) | 4 lines
1. Add comments to provide top-level documentation.
2. Refactor to use more descriptive names.
3. Enhance tests in main().
........
r58675 | georg.brandl | 2007-10-26 11:30:41 -0700 (Fri, 26 Oct 2007) | 2 lines
Fix new pop() method on os.environ on ignorecase-platforms.
........
r58696 | neal.norwitz | 2007-10-27 15:32:21 -0700 (Sat, 27 Oct 2007) | 1 line
Update URL for Pygments. 0.8.1 is no longer available
........
r58697 | hyeshik.chang | 2007-10-28 04:19:02 -0700 (Sun, 28 Oct 2007) | 3 lines
- Add support for FreeBSD 8 which is recently forked from FreeBSD 7.
- Regenerate IN module for most recent maintenance tree of FreeBSD 6 and 7.
........
r58698 | hyeshik.chang | 2007-10-28 05:38:09 -0700 (Sun, 28 Oct 2007) | 2 lines
Enable platform-specific tweaks for FreeBSD 8 (exactly same to FreeBSD 7's yet)
........
r58700 | kurt.kaiser | 2007-10-28 12:03:59 -0700 (Sun, 28 Oct 2007) | 2 lines
Add confirmation dialog before printing. Patch 1717170 Tal Einat.
........
r58706 | guido.van.rossum | 2007-10-29 13:52:45 -0700 (Mon, 29 Oct 2007) | 3 lines
Patch 1353 by Jacob Winther.
Add mp4 mapping to mimetypes.py.
........
r58709 | guido.van.rossum | 2007-10-29 15:15:05 -0700 (Mon, 29 Oct 2007) | 6 lines
Backport fixes for the code that decodes octal escapes (and for PyString
also hex escapes) -- this was reaching beyond the end of the input string
buffer, even though it is not supposed to be \0-terminated.
This has no visible effect but is clearly the correct thing to do.
(In 3.0 it had a visible effect after removing ob_sstate from PyString.)
........
r58710 | kurt.kaiser | 2007-10-29 19:38:54 -0700 (Mon, 29 Oct 2007) | 7 lines
check in Tal Einat's update to tabpage.py
Patch 1612746
M configDialog.py
M NEWS.txt
AM tabbedpages.py
........
r58715 | georg.brandl | 2007-10-30 10:51:18 -0700 (Tue, 30 Oct 2007) | 2 lines
Use correct markup.
........
r58716 | georg.brandl | 2007-10-30 10:57:12 -0700 (Tue, 30 Oct 2007) | 2 lines
Make example about hiding None return values at the prompt clearer.
........
r58728 | neal.norwitz | 2007-10-30 23:33:20 -0700 (Tue, 30 Oct 2007) | 1 line
Fix some compiler warnings for signed comparisons on Unix and Windows.
........
r58731 | martin.v.loewis | 2007-10-31 10:19:33 -0700 (Wed, 31 Oct 2007) | 2 lines
Adding Christian Heimes.
........
r58737 | raymond.hettinger | 2007-10-31 14:57:58 -0700 (Wed, 31 Oct 2007) | 1 line
Clarify the reasons why pickle is almost always better than marshal
........
r58739 | raymond.hettinger | 2007-10-31 15:15:49 -0700 (Wed, 31 Oct 2007) | 1 line
Sets are marshalable.
........
2007-11-01 17:32:30 -03:00
|
|
|
|
other keyword argument) is passed through to the incremental decoder.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2016-10-14 21:56:47 -03:00
|
|
|
|
This function requires that the codec accept :class:`bytes` objects
|
|
|
|
|
to decode. Therefore it does not support text-to-text encoders such as
|
|
|
|
|
``rot_13``, although ``rot_13`` may be used equivalently with
|
|
|
|
|
:func:`iterencode`.
|
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
The module also provides the following constants which are useful for reading
|
|
|
|
|
and writing to platform dependent files:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. data:: BOM
|
|
|
|
|
BOM_BE
|
|
|
|
|
BOM_LE
|
|
|
|
|
BOM_UTF8
|
|
|
|
|
BOM_UTF16
|
|
|
|
|
BOM_UTF16_BE
|
|
|
|
|
BOM_UTF16_LE
|
|
|
|
|
BOM_UTF32
|
|
|
|
|
BOM_UTF32_BE
|
|
|
|
|
BOM_UTF32_LE
|
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
These constants define various byte sequences,
|
|
|
|
|
being Unicode byte order marks (BOMs) for several encodings. They are
|
|
|
|
|
used in UTF-16 and UTF-32 data streams to indicate the byte order used,
|
|
|
|
|
and in UTF-8 as a Unicode signature. :const:`BOM_UTF16` is either
|
2007-08-15 11:28:22 -03:00
|
|
|
|
:const:`BOM_UTF16_BE` or :const:`BOM_UTF16_LE` depending on the platform's
|
|
|
|
|
native byte order, :const:`BOM` is an alias for :const:`BOM_UTF16`,
|
|
|
|
|
:const:`BOM_LE` for :const:`BOM_UTF16_LE` and :const:`BOM_BE` for
|
|
|
|
|
:const:`BOM_UTF16_BE`. The others represent the BOM in UTF-8 and UTF-32
|
|
|
|
|
encodings.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. _codec-base-classes:
|
|
|
|
|
|
|
|
|
|
Codec Base Classes
|
|
|
|
|
------------------
|
|
|
|
|
|
|
|
|
|
The :mod:`codecs` module defines a set of base classes which define the
|
2015-01-06 10:22:00 -04:00
|
|
|
|
interfaces for working with codec objects, and can also be used as the basis
|
|
|
|
|
for custom codec implementations.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
Each codec has to define four interfaces to make it usable as codec in Python:
|
|
|
|
|
stateless encoder, stateless decoder, stream reader and stream writer. The
|
|
|
|
|
stream reader and writers typically reuse the stateless encoder/decoder to
|
2015-01-06 10:22:00 -04:00
|
|
|
|
implement the file protocols. Codec authors also need to define how the
|
|
|
|
|
codec will handle encoding and decoding errors.
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 23:14:47 -04:00
|
|
|
|
.. _surrogateescape:
|
2015-01-06 10:22:00 -04:00
|
|
|
|
.. _error-handlers:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
Error Handlers
|
|
|
|
|
^^^^^^^^^^^^^^
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
To simplify and standardize error handling,
|
|
|
|
|
codecs may implement different error handling schemes by
|
2019-09-12 04:41:32 -03:00
|
|
|
|
accepting the *errors* string argument. The following string values are
|
2015-01-06 10:22:00 -04:00
|
|
|
|
defined and implemented by all standard Python codecs:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2013-03-28 09:28:44 -03:00
|
|
|
|
.. tabularcolumns:: |l|L|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
+-------------------------+-----------------------------------------------+
|
|
|
|
|
| Value | Meaning |
|
|
|
|
|
+=========================+===============================================+
|
|
|
|
|
| ``'strict'`` | Raise :exc:`UnicodeError` (or a subclass); |
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| | this is the default. Implemented in |
|
2015-01-06 10:22:00 -04:00
|
|
|
|
| | :func:`strict_errors`. |
|
2007-08-15 11:28:22 -03:00
|
|
|
|
+-------------------------+-----------------------------------------------+
|
2015-01-06 10:22:00 -04:00
|
|
|
|
| ``'ignore'`` | Ignore the malformed data and continue |
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| | without further notice. Implemented in |
|
2015-01-06 10:22:00 -04:00
|
|
|
|
| | :func:`ignore_errors`. |
|
2007-08-15 11:28:22 -03:00
|
|
|
|
+-------------------------+-----------------------------------------------+
|
2015-01-06 10:22:00 -04:00
|
|
|
|
|
|
|
|
|
The following error handlers are only applicable to
|
|
|
|
|
:term:`text encodings <text encoding>`:
|
|
|
|
|
|
2018-10-28 08:41:26 -03:00
|
|
|
|
.. index::
|
|
|
|
|
single: ? (question mark); replacement character
|
|
|
|
|
single: \ (backslash); escape sequence
|
|
|
|
|
single: \x; escape sequence
|
|
|
|
|
single: \u; escape sequence
|
|
|
|
|
single: \U; escape sequence
|
|
|
|
|
single: \N; escape sequence
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
+-------------------------+-----------------------------------------------+
|
2015-01-06 10:22:00 -04:00
|
|
|
|
| Value | Meaning |
|
|
|
|
|
+=========================+===============================================+
|
2007-08-15 11:28:22 -03:00
|
|
|
|
| ``'replace'`` | Replace with a suitable replacement |
|
2015-01-06 10:22:00 -04:00
|
|
|
|
| | marker; Python will use the official |
|
|
|
|
|
| | ``U+FFFD`` REPLACEMENT CHARACTER for the |
|
|
|
|
|
| | built-in codecs on decoding, and '?' on |
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| | encoding. Implemented in |
|
2015-01-06 10:22:00 -04:00
|
|
|
|
| | :func:`replace_errors`. |
|
2007-08-15 11:28:22 -03:00
|
|
|
|
+-------------------------+-----------------------------------------------+
|
|
|
|
|
| ``'xmlcharrefreplace'`` | Replace with the appropriate XML character |
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| | reference (only for encoding). Implemented |
|
2015-01-06 10:22:00 -04:00
|
|
|
|
| | in :func:`xmlcharrefreplace_errors`. |
|
2007-08-15 11:28:22 -03:00
|
|
|
|
+-------------------------+-----------------------------------------------+
|
2015-01-25 16:56:57 -04:00
|
|
|
|
| ``'backslashreplace'`` | Replace with backslashed escape sequences. |
|
|
|
|
|
| | Implemented in |
|
2015-01-06 10:22:00 -04:00
|
|
|
|
| | :func:`backslashreplace_errors`. |
|
2007-08-15 11:28:22 -03:00
|
|
|
|
+-------------------------+-----------------------------------------------+
|
2014-11-25 07:57:17 -04:00
|
|
|
|
| ``'namereplace'`` | Replace with ``\N{...}`` escape sequences |
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| | (only for encoding). Implemented in |
|
2015-01-06 23:14:47 -04:00
|
|
|
|
| | :func:`namereplace_errors`. |
|
2014-11-25 07:57:17 -04:00
|
|
|
|
+-------------------------+-----------------------------------------------+
|
2015-01-06 10:22:00 -04:00
|
|
|
|
| ``'surrogateescape'`` | On decoding, replace byte with individual |
|
|
|
|
|
| | surrogate code ranging from ``U+DC80`` to |
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| | ``U+DCFF``. This code will then be turned |
|
2015-01-06 10:22:00 -04:00
|
|
|
|
| | back into the same byte when the |
|
|
|
|
|
| | ``'surrogateescape'`` error handler is used |
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| | when encoding the data. (See :pep:`383` for |
|
2015-01-06 10:22:00 -04:00
|
|
|
|
| | more.) |
|
2009-05-05 01:43:17 -03:00
|
|
|
|
+-------------------------+-----------------------------------------------+
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
In addition, the following error handler is specific to the given codecs:
|
2009-05-02 15:52:14 -03:00
|
|
|
|
|
2013-11-19 05:32:41 -04:00
|
|
|
|
+-------------------+------------------------+-------------------------------------------+
|
2015-01-06 10:22:00 -04:00
|
|
|
|
| Value | Codecs | Meaning |
|
2013-11-19 05:32:41 -04:00
|
|
|
|
+===================+========================+===========================================+
|
|
|
|
|
|``'surrogatepass'``| utf-8, utf-16, utf-32, | Allow encoding and decoding of surrogate |
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| | utf-16-be, utf-16-le, | codes. These codecs normally treat the |
|
2015-01-06 10:22:00 -04:00
|
|
|
|
| | utf-32-be, utf-32-le | presence of surrogates as an error. |
|
2013-11-19 05:32:41 -04:00
|
|
|
|
+-------------------+------------------------+-------------------------------------------+
|
2009-05-02 15:52:14 -03:00
|
|
|
|
|
|
|
|
|
.. versionadded:: 3.1
|
2009-05-10 05:15:24 -03:00
|
|
|
|
The ``'surrogateescape'`` and ``'surrogatepass'`` error handlers.
|
2009-05-02 15:52:14 -03:00
|
|
|
|
|
2013-11-19 05:32:41 -04:00
|
|
|
|
.. versionchanged:: 3.4
|
|
|
|
|
The ``'surrogatepass'`` error handlers now works with utf-16\* and utf-32\* codecs.
|
|
|
|
|
|
2014-11-25 12:59:20 -04:00
|
|
|
|
.. versionadded:: 3.5
|
2014-11-25 07:57:17 -04:00
|
|
|
|
The ``'namereplace'`` error handler.
|
|
|
|
|
|
2015-01-25 16:56:57 -04:00
|
|
|
|
.. versionchanged:: 3.5
|
|
|
|
|
The ``'backslashreplace'`` error handlers now works with decoding and
|
|
|
|
|
translating.
|
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
The set of allowed values can be extended by registering a new named error
|
|
|
|
|
handler:
|
|
|
|
|
|
|
|
|
|
.. function:: register_error(name, error_handler)
|
|
|
|
|
|
|
|
|
|
Register the error handling function *error_handler* under the name *name*.
|
|
|
|
|
The *error_handler* argument will be called during encoding and decoding
|
|
|
|
|
in case of an error, when *name* is specified as the errors parameter.
|
|
|
|
|
|
|
|
|
|
For encoding, *error_handler* will be called with a :exc:`UnicodeEncodeError`
|
|
|
|
|
instance, which contains information about the location of the error. The
|
|
|
|
|
error handler must either raise this or a different exception, or return a
|
|
|
|
|
tuple with a replacement for the unencodable part of the input and a position
|
|
|
|
|
where encoding should continue. The replacement may be either :class:`str` or
|
2019-09-12 04:41:32 -03:00
|
|
|
|
:class:`bytes`. If the replacement is bytes, the encoder will simply copy
|
2015-01-06 10:22:00 -04:00
|
|
|
|
them into the output buffer. If the replacement is a string, the encoder will
|
2019-09-12 04:41:32 -03:00
|
|
|
|
encode the replacement. Encoding continues on original input at the
|
2015-01-06 10:22:00 -04:00
|
|
|
|
specified position. Negative position values will be treated as being
|
|
|
|
|
relative to the end of the input string. If the resulting position is out of
|
|
|
|
|
bound an :exc:`IndexError` will be raised.
|
|
|
|
|
|
|
|
|
|
Decoding and translating works similarly, except :exc:`UnicodeDecodeError` or
|
|
|
|
|
:exc:`UnicodeTranslateError` will be passed to the handler and that the
|
|
|
|
|
replacement from the error handler will be put into the output directly.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Previously registered error handlers (including the standard error handlers)
|
|
|
|
|
can be looked up by name:
|
|
|
|
|
|
|
|
|
|
.. function:: lookup_error(name)
|
|
|
|
|
|
|
|
|
|
Return the error handler previously registered under the name *name*.
|
|
|
|
|
|
|
|
|
|
Raises a :exc:`LookupError` in case the handler cannot be found.
|
|
|
|
|
|
|
|
|
|
The following standard error handlers are also made available as module level
|
|
|
|
|
functions:
|
|
|
|
|
|
|
|
|
|
.. function:: strict_errors(exception)
|
|
|
|
|
|
|
|
|
|
Implements the ``'strict'`` error handling: each encoding or
|
|
|
|
|
decoding error raises a :exc:`UnicodeError`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: replace_errors(exception)
|
|
|
|
|
|
|
|
|
|
Implements the ``'replace'`` error handling (for :term:`text encodings
|
|
|
|
|
<text encoding>` only): substitutes ``'?'`` for encoding errors
|
|
|
|
|
(to be encoded by the codec), and ``'\ufffd'`` (the Unicode replacement
|
2015-02-25 08:05:53 -04:00
|
|
|
|
character) for decoding errors.
|
2015-01-06 10:22:00 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: ignore_errors(exception)
|
|
|
|
|
|
|
|
|
|
Implements the ``'ignore'`` error handling: malformed data is ignored and
|
|
|
|
|
encoding or decoding is continued without further notice.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: xmlcharrefreplace_errors(exception)
|
|
|
|
|
|
|
|
|
|
Implements the ``'xmlcharrefreplace'`` error handling (for encoding with
|
|
|
|
|
:term:`text encodings <text encoding>` only): the
|
|
|
|
|
unencodable character is replaced by an appropriate XML character reference.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: backslashreplace_errors(exception)
|
|
|
|
|
|
2015-01-25 16:56:57 -04:00
|
|
|
|
Implements the ``'backslashreplace'`` error handling (for
|
|
|
|
|
:term:`text encodings <text encoding>` only): malformed data is
|
|
|
|
|
replaced by a backslashed escape sequence.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:37:01 -04:00
|
|
|
|
.. function:: namereplace_errors(exception)
|
|
|
|
|
|
2015-01-06 23:14:47 -04:00
|
|
|
|
Implements the ``'namereplace'`` error handling (for encoding with
|
|
|
|
|
:term:`text encodings <text encoding>` only): the
|
2015-01-06 10:37:01 -04:00
|
|
|
|
unencodable character is replaced by a ``\N{...}`` escape sequence.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 3.5
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. _codec-objects:
|
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
Stateless Encoding and Decoding
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
The base :class:`Codec` class defines these methods which also define the
|
|
|
|
|
function interfaces of the stateless encoder and decoder:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: Codec.encode(input[, errors])
|
|
|
|
|
|
|
|
|
|
Encodes the object *input* and returns a tuple (output object, length consumed).
|
2015-01-06 10:22:00 -04:00
|
|
|
|
For instance, :term:`text encoding` converts
|
|
|
|
|
a string object to a bytes object using a particular
|
2007-08-15 11:28:22 -03:00
|
|
|
|
character set encoding (e.g., ``cp1252`` or ``iso-8859-1``).
|
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
The *errors* argument defines the error handling to apply.
|
|
|
|
|
It defaults to ``'strict'`` handling.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
The method may not store state in the :class:`Codec` instance. Use
|
2015-07-30 12:26:10 -03:00
|
|
|
|
:class:`StreamWriter` for codecs which have to keep state in order to make
|
|
|
|
|
encoding efficient.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
The encoder must be able to handle zero length input and return an empty object
|
|
|
|
|
of the output object type in this situation.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: Codec.decode(input[, errors])
|
|
|
|
|
|
2008-05-11 11:52:00 -03:00
|
|
|
|
Decodes the object *input* and returns a tuple (output object, length
|
2019-09-12 04:41:32 -03:00
|
|
|
|
consumed). For instance, for a :term:`text encoding`, decoding converts
|
2015-01-06 10:22:00 -04:00
|
|
|
|
a bytes object encoded using a particular
|
2008-05-11 11:52:00 -03:00
|
|
|
|
character set encoding to a string object.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
For text encodings and bytes-to-bytes codecs,
|
|
|
|
|
*input* must be a bytes object or one which provides the read-only
|
2008-05-11 11:52:00 -03:00
|
|
|
|
buffer interface -- for example, buffer objects and memory mapped files.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
The *errors* argument defines the error handling to apply.
|
|
|
|
|
It defaults to ``'strict'`` handling.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
The method may not store state in the :class:`Codec` instance. Use
|
2015-07-30 12:26:10 -03:00
|
|
|
|
:class:`StreamReader` for codecs which have to keep state in order to make
|
|
|
|
|
decoding efficient.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
The decoder must be able to handle zero length input and return an empty object
|
|
|
|
|
of the output object type in this situation.
|
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
|
|
|
|
|
Incremental Encoding and Decoding
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
The :class:`IncrementalEncoder` and :class:`IncrementalDecoder` classes provide
|
|
|
|
|
the basic interface for incremental encoding and decoding. Encoding/decoding the
|
|
|
|
|
input isn't done with one call to the stateless encoder/decoder function, but
|
2013-10-13 17:09:14 -03:00
|
|
|
|
with multiple calls to the
|
|
|
|
|
:meth:`~IncrementalEncoder.encode`/:meth:`~IncrementalDecoder.decode` method of
|
|
|
|
|
the incremental encoder/decoder. The incremental encoder/decoder keeps track of
|
|
|
|
|
the encoding/decoding process during method calls.
|
|
|
|
|
|
|
|
|
|
The joined output of calls to the
|
|
|
|
|
:meth:`~IncrementalEncoder.encode`/:meth:`~IncrementalDecoder.decode` method is
|
|
|
|
|
the same as if all the single inputs were joined into one, and this input was
|
2007-08-15 11:28:22 -03:00
|
|
|
|
encoded/decoded with the stateless encoder/decoder.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. _incremental-encoder-objects:
|
|
|
|
|
|
|
|
|
|
IncrementalEncoder Objects
|
2015-01-06 10:22:00 -04:00
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
The :class:`IncrementalEncoder` class is used for encoding an input in multiple
|
|
|
|
|
steps. It defines the following methods which every incremental encoder must
|
|
|
|
|
define in order to be compatible with the Python codec registry.
|
|
|
|
|
|
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
.. class:: IncrementalEncoder(errors='strict')
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
Constructor for an :class:`IncrementalEncoder` instance.
|
|
|
|
|
|
|
|
|
|
All incremental encoders must provide this constructor interface. They are free
|
|
|
|
|
to add additional keyword arguments, but only the ones defined here are used by
|
|
|
|
|
the Python codec registry.
|
|
|
|
|
|
|
|
|
|
The :class:`IncrementalEncoder` may implement different error handling schemes
|
2015-01-06 10:22:00 -04:00
|
|
|
|
by providing the *errors* keyword argument. See :ref:`error-handlers` for
|
|
|
|
|
possible values.
|
2014-11-25 07:57:17 -04:00
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
The *errors* argument will be assigned to an attribute of the same name.
|
|
|
|
|
Assigning to this attribute makes it possible to switch between different error
|
|
|
|
|
handling strategies during the lifetime of the :class:`IncrementalEncoder`
|
|
|
|
|
object.
|
|
|
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
.. method:: encode(object[, final])
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
Encodes *object* (taking the current state of the encoder into account)
|
|
|
|
|
and returns the resulting encoded object. If this is the last call to
|
|
|
|
|
:meth:`encode` *final* must be true (the default is false).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
.. method:: reset()
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2011-05-30 17:56:00 -03:00
|
|
|
|
Reset the encoder to the initial state. The output is discarded: call
|
2015-01-06 10:22:00 -04:00
|
|
|
|
``.encode(object, final=True)``, passing an empty byte or text string
|
|
|
|
|
if necessary, to reset the encoder and to get the output.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
2017-09-10 03:09:55 -03:00
|
|
|
|
.. method:: getstate()
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2017-09-10 03:09:55 -03:00
|
|
|
|
Return the current state of the encoder which must be an integer. The
|
|
|
|
|
implementation should make sure that ``0`` is the most common
|
|
|
|
|
state. (States that are more complicated than integers can be converted
|
|
|
|
|
into an integer by marshaling/pickling the state and encoding the bytes
|
2019-09-12 04:41:32 -03:00
|
|
|
|
of the resulting string into an integer.)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
2017-09-10 03:09:55 -03:00
|
|
|
|
.. method:: setstate(state)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2017-09-10 03:09:55 -03:00
|
|
|
|
Set the state of the encoder to *state*. *state* must be an encoder state
|
|
|
|
|
returned by :meth:`getstate`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. _incremental-decoder-objects:
|
|
|
|
|
|
|
|
|
|
IncrementalDecoder Objects
|
2015-01-06 10:22:00 -04:00
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
The :class:`IncrementalDecoder` class is used for decoding an input in multiple
|
|
|
|
|
steps. It defines the following methods which every incremental decoder must
|
|
|
|
|
define in order to be compatible with the Python codec registry.
|
|
|
|
|
|
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
.. class:: IncrementalDecoder(errors='strict')
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
Constructor for an :class:`IncrementalDecoder` instance.
|
|
|
|
|
|
|
|
|
|
All incremental decoders must provide this constructor interface. They are free
|
|
|
|
|
to add additional keyword arguments, but only the ones defined here are used by
|
|
|
|
|
the Python codec registry.
|
|
|
|
|
|
|
|
|
|
The :class:`IncrementalDecoder` may implement different error handling schemes
|
2015-01-06 10:22:00 -04:00
|
|
|
|
by providing the *errors* keyword argument. See :ref:`error-handlers` for
|
|
|
|
|
possible values.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
The *errors* argument will be assigned to an attribute of the same name.
|
|
|
|
|
Assigning to this attribute makes it possible to switch between different error
|
Merged revisions 66045,66048-66049,66053,66060,66062-66063,66065,66067,66071-66074,66080,66082-66083,66090-66093,66097-66099,66103,66105,66110,66118 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r66045 | andrew.kuchling | 2008-08-26 19:27:18 -0500 (Tue, 26 Aug 2008) | 1 line
Trim whitespace; add a few updates
........
r66048 | andrew.kuchling | 2008-08-26 19:45:02 -0500 (Tue, 26 Aug 2008) | 1 line
Add an item and a note
........
r66049 | andrew.kuchling | 2008-08-26 21:12:18 -0500 (Tue, 26 Aug 2008) | 1 line
Add various items
........
r66053 | georg.brandl | 2008-08-28 04:40:18 -0500 (Thu, 28 Aug 2008) | 2 lines
#3711: .dll isn't a valid Python extension anymore.
........
r66060 | armin.rigo | 2008-08-29 16:21:52 -0500 (Fri, 29 Aug 2008) | 3 lines
A collection of crashers, all variants of the idea
of issue #3720.
........
r66062 | georg.brandl | 2008-08-30 04:49:36 -0500 (Sat, 30 Aug 2008) | 2 lines
#3730: mention "server" attribute explicitly.
........
r66063 | georg.brandl | 2008-08-30 04:52:44 -0500 (Sat, 30 Aug 2008) | 2 lines
#3716: fix typo.
........
r66065 | georg.brandl | 2008-08-30 05:03:09 -0500 (Sat, 30 Aug 2008) | 2 lines
#3569: eval() also accepts "exec"able code objects.
........
r66067 | georg.brandl | 2008-08-30 08:17:39 -0500 (Sat, 30 Aug 2008) | 2 lines
super() actually returns a super object.
........
r66071 | andrew.kuchling | 2008-08-30 10:19:57 -0500 (Sat, 30 Aug 2008) | 1 line
Partial edits from revision and tidying pass
........
r66072 | andrew.kuchling | 2008-08-30 10:21:23 -0500 (Sat, 30 Aug 2008) | 1 line
Tidy up some sentences
........
r66073 | andrew.kuchling | 2008-08-30 10:25:47 -0500 (Sat, 30 Aug 2008) | 1 line
Correction from Antoine Pitrou: BufferedWriter and Reader support seek()
........
r66074 | andrew.kuchling | 2008-08-30 11:44:54 -0500 (Sat, 30 Aug 2008) | 1 line
Edit four more sections
........
r66080 | georg.brandl | 2008-08-30 17:00:28 -0500 (Sat, 30 Aug 2008) | 2 lines
Fix markup.
........
r66082 | andrew.kuchling | 2008-08-30 17:56:54 -0500 (Sat, 30 Aug 2008) | 1 line
More edits; markup fixes
........
r66083 | andrew.kuchling | 2008-08-30 21:24:08 -0500 (Sat, 30 Aug 2008) | 1 line
More edits
........
r66090 | andrew.kuchling | 2008-08-31 09:29:31 -0500 (Sun, 31 Aug 2008) | 1 line
Edit the library section, rearranging items to flow better and making lots of edits
........
r66091 | andrew.kuchling | 2008-08-31 10:41:48 -0500 (Sun, 31 Aug 2008) | 1 line
Last batch of edits; remove the 'other changes' section
........
r66092 | andrew.kuchling | 2008-08-31 10:48:44 -0500 (Sun, 31 Aug 2008) | 1 line
Update patch/bug count
........
r66093 | gregory.p.smith | 2008-08-31 11:34:18 -0500 (Sun, 31 Aug 2008) | 3 lines
issue3715: docstring representation of hex escaped string needs to be double
escaped.
........
r66097 | benjamin.peterson | 2008-09-01 09:13:43 -0500 (Mon, 01 Sep 2008) | 4 lines
#3703 unhelpful _fileio.FileIO error message when trying to open a directory
Reviewer: Gregory P. Smith
........
r66098 | georg.brandl | 2008-09-01 09:15:55 -0500 (Mon, 01 Sep 2008) | 2 lines
#3749: fix c'n'p errors.
........
r66099 | benjamin.peterson | 2008-09-01 09:18:30 -0500 (Mon, 01 Sep 2008) | 4 lines
Fix compilation when --without-threads is given #3683
Reviewer: Georg Brandl, Benjamin Peterson
........
r66103 | vinay.sajip | 2008-09-01 09:30:10 -0500 (Mon, 01 Sep 2008) | 1 line
logging: fixed lack of use of encoding attribute specified on a stream.
........
r66105 | vinay.sajip | 2008-09-01 09:33:59 -0500 (Mon, 01 Sep 2008) | 1 line
logging: fixed lack of use of encoding attribute specified on a stream.
........
r66110 | vinay.sajip | 2008-09-01 10:08:07 -0500 (Mon, 01 Sep 2008) | 1 line
Added section about configuring logging in a library. Thanks to Thomas Heller for the idea.
........
r66118 | vinay.sajip | 2008-09-01 12:44:14 -0500 (Mon, 01 Sep 2008) | 1 line
Bug #3738: Documentation is now more accurate in describing handler close methods.
........
2008-09-01 21:31:15 -03:00
|
|
|
|
handling strategies during the lifetime of the :class:`IncrementalDecoder`
|
2007-08-15 11:28:22 -03:00
|
|
|
|
object.
|
|
|
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
.. method:: decode(object[, final])
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
Decodes *object* (taking the current state of the decoder into account)
|
|
|
|
|
and returns the resulting decoded object. If this is the last call to
|
|
|
|
|
:meth:`decode` *final* must be true (the default is false). If *final* is
|
|
|
|
|
true the decoder must decode the input completely and must flush all
|
|
|
|
|
buffers. If this isn't possible (e.g. because of incomplete byte sequences
|
|
|
|
|
at the end of the input) it must initiate error handling just like in the
|
|
|
|
|
stateless case (which might raise an exception).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
.. method:: reset()
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
Reset the decoder to the initial state.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
.. method:: getstate()
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
Return the current state of the decoder. This must be a tuple with two
|
|
|
|
|
items, the first must be the buffer containing the still undecoded
|
|
|
|
|
input. The second must be an integer and can be additional state
|
|
|
|
|
info. (The implementation should make sure that ``0`` is the most common
|
|
|
|
|
additional state info.) If this additional state info is ``0`` it must be
|
|
|
|
|
possible to set the decoder to the state which has no input buffered and
|
|
|
|
|
``0`` as the additional state info, so that feeding the previously
|
|
|
|
|
buffered input to the decoder returns it to the previous state without
|
|
|
|
|
producing any output. (Additional state info that is more complicated than
|
|
|
|
|
integers can be converted into an integer by marshaling/pickling the info
|
|
|
|
|
and encoding the bytes of the resulting string into an integer.)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
.. method:: setstate(state)
|
|
|
|
|
|
2019-04-11 03:09:29 -03:00
|
|
|
|
Set the state of the decoder to *state*. *state* must be a decoder state
|
2008-04-24 22:59:09 -03:00
|
|
|
|
returned by :meth:`getstate`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
Stream Encoding and Decoding
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
The :class:`StreamWriter` and :class:`StreamReader` classes provide generic
|
|
|
|
|
working interfaces which can be used to implement new encoding submodules very
|
|
|
|
|
easily. See :mod:`encodings.utf_8` for an example of how this is done.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. _stream-writer-objects:
|
|
|
|
|
|
|
|
|
|
StreamWriter Objects
|
2015-01-06 10:22:00 -04:00
|
|
|
|
~~~~~~~~~~~~~~~~~~~~
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
The :class:`StreamWriter` class is a subclass of :class:`Codec` and defines the
|
|
|
|
|
following methods which every stream writer must define in order to be
|
|
|
|
|
compatible with the Python codec registry.
|
|
|
|
|
|
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
.. class:: StreamWriter(stream, errors='strict')
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
Constructor for a :class:`StreamWriter` instance.
|
|
|
|
|
|
|
|
|
|
All stream writers must provide this constructor interface. They are free to add
|
|
|
|
|
additional keyword arguments, but only the ones defined here are used by the
|
|
|
|
|
Python codec registry.
|
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
The *stream* argument must be a file-like object open for writing
|
|
|
|
|
text or binary data, as appropriate for the specific codec.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
The :class:`StreamWriter` may implement different error handling schemes by
|
2015-01-06 10:22:00 -04:00
|
|
|
|
providing the *errors* keyword argument. See :ref:`error-handlers` for
|
|
|
|
|
the standard error handlers the underlying stream codec may support.
|
2014-11-25 07:57:17 -04:00
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
The *errors* argument will be assigned to an attribute of the same name.
|
|
|
|
|
Assigning to this attribute makes it possible to switch between different error
|
|
|
|
|
handling strategies during the lifetime of the :class:`StreamWriter` object.
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
.. method:: write(object)
|
|
|
|
|
|
|
|
|
|
Writes the object's contents encoded to the stream.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
.. method:: writelines(list)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
Writes the concatenated list of strings to the stream (possibly by reusing
|
2015-01-06 10:22:00 -04:00
|
|
|
|
the :meth:`write` method). The standard bytes-to-bytes codecs
|
|
|
|
|
do not support this method.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
.. method:: reset()
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
Flushes and resets the codec buffers used for keeping state.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
Calling this method should ensure that the data on the output is put into
|
|
|
|
|
a clean state that allows appending of new fresh data without having to
|
|
|
|
|
rescan the whole stream to recover state.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In addition to the above methods, the :class:`StreamWriter` must also inherit
|
|
|
|
|
all other methods and attributes from the underlying stream.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. _stream-reader-objects:
|
|
|
|
|
|
|
|
|
|
StreamReader Objects
|
2015-01-06 10:22:00 -04:00
|
|
|
|
~~~~~~~~~~~~~~~~~~~~
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
The :class:`StreamReader` class is a subclass of :class:`Codec` and defines the
|
|
|
|
|
following methods which every stream reader must define in order to be
|
|
|
|
|
compatible with the Python codec registry.
|
|
|
|
|
|
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
.. class:: StreamReader(stream, errors='strict')
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
Constructor for a :class:`StreamReader` instance.
|
|
|
|
|
|
|
|
|
|
All stream readers must provide this constructor interface. They are free to add
|
|
|
|
|
additional keyword arguments, but only the ones defined here are used by the
|
|
|
|
|
Python codec registry.
|
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
The *stream* argument must be a file-like object open for reading
|
|
|
|
|
text or binary data, as appropriate for the specific codec.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
The :class:`StreamReader` may implement different error handling schemes by
|
2015-01-06 10:22:00 -04:00
|
|
|
|
providing the *errors* keyword argument. See :ref:`error-handlers` for
|
|
|
|
|
the standard error handlers the underlying stream codec may support.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
The *errors* argument will be assigned to an attribute of the same name.
|
|
|
|
|
Assigning to this attribute makes it possible to switch between different error
|
|
|
|
|
handling strategies during the lifetime of the :class:`StreamReader` object.
|
|
|
|
|
|
|
|
|
|
The set of allowed values for the *errors* argument can be extended with
|
|
|
|
|
:func:`register_error`.
|
|
|
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
.. method:: read([size[, chars, [firstline]]])
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
Decodes data from the stream and returns the resulting object.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
The *chars* argument indicates the number of decoded
|
|
|
|
|
code points or bytes to return. The :func:`read` method will
|
|
|
|
|
never return more data than requested, but it might return less,
|
|
|
|
|
if there is not enough available.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
The *size* argument indicates the approximate maximum
|
|
|
|
|
number of encoded bytes or code points to read
|
|
|
|
|
for decoding. The decoder can modify this setting as
|
2008-04-24 22:59:09 -03:00
|
|
|
|
appropriate. The default value -1 indicates to read and decode as much as
|
2019-09-12 04:41:32 -03:00
|
|
|
|
possible. This parameter is intended to
|
2015-01-06 10:22:00 -04:00
|
|
|
|
prevent having to decode huge files in one step.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
The *firstline* flag indicates that
|
|
|
|
|
it would be sufficient to only return the first
|
2008-04-24 22:59:09 -03:00
|
|
|
|
line, if there are decoding errors on later lines.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
The method should use a greedy read strategy meaning that it should read
|
|
|
|
|
as much data as is allowed within the definition of the encoding and the
|
|
|
|
|
given size, e.g. if optional encoding endings or state markers are
|
|
|
|
|
available on the stream, these should be read too.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
.. method:: readline([size[, keepends]])
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
Read one line from the input stream and return the decoded data.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
*size*, if given, is passed as size argument to the stream's
|
2013-07-11 12:26:13 -03:00
|
|
|
|
:meth:`read` method.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
If *keepends* is false line-endings will be stripped from the lines
|
|
|
|
|
returned.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
.. method:: readlines([sizehint[, keepends]])
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
Read all lines available on the input stream and return them as a list of
|
|
|
|
|
lines.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2019-09-12 04:41:32 -03:00
|
|
|
|
Line-endings are implemented using the codec's :meth:`decode` method and
|
|
|
|
|
are included in the list entries if *keepends* is true.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
*sizehint*, if given, is passed as the *size* argument to the stream's
|
|
|
|
|
:meth:`read` method.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
.. method:: reset()
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
Resets the codec buffers used for keeping state.
|
|
|
|
|
|
2019-09-12 04:41:32 -03:00
|
|
|
|
Note that no stream repositioning should take place. This method is
|
2008-04-24 22:59:09 -03:00
|
|
|
|
primarily intended to be able to recover from decoding errors.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In addition to the above methods, the :class:`StreamReader` must also inherit
|
|
|
|
|
all other methods and attributes from the underlying stream.
|
|
|
|
|
|
|
|
|
|
.. _stream-reader-writer:
|
|
|
|
|
|
|
|
|
|
StreamReaderWriter Objects
|
2015-01-06 10:22:00 -04:00
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
The :class:`StreamReaderWriter` is a convenience class that allows wrapping
|
|
|
|
|
streams which work in both read and write modes.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
The design is such that one can use the factory functions returned by the
|
|
|
|
|
:func:`lookup` function to construct the instance.
|
|
|
|
|
|
|
|
|
|
|
2017-11-10 19:05:12 -04:00
|
|
|
|
.. class:: StreamReaderWriter(stream, Reader, Writer, errors='strict')
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
Creates a :class:`StreamReaderWriter` instance. *stream* must be a file-like
|
|
|
|
|
object. *Reader* and *Writer* must be factory functions or classes providing the
|
|
|
|
|
:class:`StreamReader` and :class:`StreamWriter` interface resp. Error handling
|
|
|
|
|
is done in the same way as defined for the stream readers and writers.
|
|
|
|
|
|
|
|
|
|
:class:`StreamReaderWriter` instances define the combined interfaces of
|
|
|
|
|
:class:`StreamReader` and :class:`StreamWriter` classes. They inherit all other
|
|
|
|
|
methods and attributes from the underlying stream.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. _stream-recoder-objects:
|
|
|
|
|
|
|
|
|
|
StreamRecoder Objects
|
2015-01-06 10:22:00 -04:00
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
The :class:`StreamRecoder` translates data from one encoding to another,
|
2007-08-15 11:28:22 -03:00
|
|
|
|
which is sometimes useful when dealing with different encoding environments.
|
|
|
|
|
|
|
|
|
|
The design is such that one can use the factory functions returned by the
|
|
|
|
|
:func:`lookup` function to construct the instance.
|
|
|
|
|
|
|
|
|
|
|
2017-11-10 19:05:12 -04:00
|
|
|
|
.. class:: StreamRecoder(stream, encode, decode, Reader, Writer, errors='strict')
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
Creates a :class:`StreamRecoder` instance which implements a two-way conversion:
|
2015-01-06 10:22:00 -04:00
|
|
|
|
*encode* and *decode* work on the frontend — the data visible to
|
|
|
|
|
code calling :meth:`read` and :meth:`write`, while *Reader* and *Writer*
|
|
|
|
|
work on the backend — the data in *stream*.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2019-09-12 04:41:32 -03:00
|
|
|
|
You can use these objects to do transparent transcodings, e.g., from Latin-1
|
2007-08-15 11:28:22 -03:00
|
|
|
|
to UTF-8 and back.
|
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
The *stream* argument must be a file-like object.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2015-01-06 10:22:00 -04:00
|
|
|
|
The *encode* and *decode* arguments must
|
|
|
|
|
adhere to the :class:`Codec` interface. *Reader* and
|
2007-08-15 11:28:22 -03:00
|
|
|
|
*Writer* must be factory functions or classes providing objects of the
|
|
|
|
|
:class:`StreamReader` and :class:`StreamWriter` interface respectively.
|
|
|
|
|
|
|
|
|
|
Error handling is done in the same way as defined for the stream readers and
|
|
|
|
|
writers.
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
:class:`StreamRecoder` instances define the combined interfaces of
|
|
|
|
|
:class:`StreamReader` and :class:`StreamWriter` classes. They inherit all other
|
|
|
|
|
methods and attributes from the underlying stream.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. _encodings-overview:
|
|
|
|
|
|
|
|
|
|
Encodings and Unicode
|
|
|
|
|
---------------------
|
|
|
|
|
|
2015-01-14 03:26:30 -04:00
|
|
|
|
Strings are stored internally as sequences of code points in
|
2019-09-12 04:41:32 -03:00
|
|
|
|
range ``0x0``--``0x10FFFF``. (See :pep:`393` for
|
2015-01-06 10:22:00 -04:00
|
|
|
|
more details about the implementation.)
|
|
|
|
|
Once a string object is used outside of CPU and memory, endianness
|
2019-09-12 04:41:32 -03:00
|
|
|
|
and how these arrays are stored as bytes become an issue. As with other
|
2015-01-06 10:22:00 -04:00
|
|
|
|
codecs, serialising a string into a sequence of bytes is known as *encoding*,
|
|
|
|
|
and recreating the string from the sequence of bytes is known as *decoding*.
|
|
|
|
|
There are a variety of different text serialisation codecs, which are
|
|
|
|
|
collectivity referred to as :term:`text encodings <text encoding>`.
|
|
|
|
|
|
|
|
|
|
The simplest text encoding (called ``'latin-1'`` or ``'iso-8859-1'``) maps
|
2016-11-26 07:43:28 -04:00
|
|
|
|
the code points 0--255 to the bytes ``0x0``--``0xff``, which means that a string
|
2015-01-14 03:26:30 -04:00
|
|
|
|
object that contains code points above ``U+00FF`` can't be encoded with this
|
2015-01-06 10:22:00 -04:00
|
|
|
|
codec. Doing so will raise a :exc:`UnicodeEncodeError` that looks
|
|
|
|
|
like the following (although the details of the error message may differ):
|
|
|
|
|
``UnicodeEncodeError: 'latin-1' codec can't encode character '\u1234' in
|
|
|
|
|
position 3: ordinal not in range(256)``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
There's another group of encodings (the so called charmap encodings) that choose
|
2015-01-14 03:26:30 -04:00
|
|
|
|
a different subset of all Unicode code points and how these code points are
|
2016-11-26 07:43:28 -04:00
|
|
|
|
mapped to the bytes ``0x0``--``0xff``. To see how this is done simply open
|
2007-08-15 11:28:22 -03:00
|
|
|
|
e.g. :file:`encodings/cp1252.py` (which is an encoding that is used primarily on
|
|
|
|
|
Windows). There's a string constant with 256 characters that shows you which
|
|
|
|
|
character is mapped to which byte value.
|
|
|
|
|
|
2015-01-14 03:26:30 -04:00
|
|
|
|
All of these encodings can only encode 256 of the 1114112 code points
|
2008-05-11 11:52:00 -03:00
|
|
|
|
defined in Unicode. A simple and straightforward way that can store each Unicode
|
2015-01-14 03:26:30 -04:00
|
|
|
|
code point, is to store each code point as four consecutive bytes. There are two
|
2011-10-25 04:40:38 -03:00
|
|
|
|
possibilities: store the bytes in big endian or in little endian order. These
|
|
|
|
|
two encodings are called ``UTF-32-BE`` and ``UTF-32-LE`` respectively. Their
|
|
|
|
|
disadvantage is that if e.g. you use ``UTF-32-BE`` on a little endian machine you
|
|
|
|
|
will always have to swap bytes on encoding and decoding. ``UTF-32`` avoids this
|
|
|
|
|
problem: bytes will always be in natural endianness. When these bytes are read
|
2007-08-15 11:28:22 -03:00
|
|
|
|
by a CPU with a different endianness, then bytes have to be swapped though. To
|
2011-10-25 04:40:38 -03:00
|
|
|
|
be able to detect the endianness of a ``UTF-16`` or ``UTF-32`` byte sequence,
|
|
|
|
|
there's the so called BOM ("Byte Order Mark"). This is the Unicode character
|
|
|
|
|
``U+FEFF``. This character can be prepended to every ``UTF-16`` or ``UTF-32``
|
|
|
|
|
byte sequence. The byte swapped version of this character (``0xFFFE``) is an
|
|
|
|
|
illegal character that may not appear in a Unicode text. So when the
|
|
|
|
|
first character in an ``UTF-16`` or ``UTF-32`` byte sequence
|
2007-08-15 11:28:22 -03:00
|
|
|
|
appears to be a ``U+FFFE`` the bytes have to be swapped on decoding.
|
2011-10-25 04:40:38 -03:00
|
|
|
|
Unfortunately the character ``U+FEFF`` had a second purpose as
|
|
|
|
|
a ``ZERO WIDTH NO-BREAK SPACE``: a character that has no width and doesn't allow
|
2007-08-15 11:28:22 -03:00
|
|
|
|
a word to be split. It can e.g. be used to give hints to a ligature algorithm.
|
|
|
|
|
With Unicode 4.0 using ``U+FEFF`` as a ``ZERO WIDTH NO-BREAK SPACE`` has been
|
|
|
|
|
deprecated (with ``U+2060`` (``WORD JOINER``) assuming this role). Nevertheless
|
2011-10-25 04:40:38 -03:00
|
|
|
|
Unicode software still must be able to handle ``U+FEFF`` in both roles: as a BOM
|
2007-08-15 11:28:22 -03:00
|
|
|
|
it's a device to determine the storage layout of the encoded bytes, and vanishes
|
2008-05-11 11:52:00 -03:00
|
|
|
|
once the byte sequence has been decoded into a string; as a ``ZERO WIDTH
|
2007-08-15 11:28:22 -03:00
|
|
|
|
NO-BREAK SPACE`` it's a normal character that will be decoded like any other.
|
|
|
|
|
|
|
|
|
|
There's another encoding that is able to encoding the full range of Unicode
|
|
|
|
|
characters: UTF-8. UTF-8 is an 8-bit encoding, which means there are no issues
|
|
|
|
|
with byte order in UTF-8. Each byte in a UTF-8 byte sequence consists of two
|
2011-10-25 04:40:38 -03:00
|
|
|
|
parts: marker bits (the most significant bits) and payload bits. The marker bits
|
2011-09-01 02:11:28 -03:00
|
|
|
|
are a sequence of zero to four ``1`` bits followed by a ``0`` bit. Unicode characters are
|
2007-08-15 11:28:22 -03:00
|
|
|
|
encoded like this (with x being payload bits, which when concatenated give the
|
|
|
|
|
Unicode character):
|
|
|
|
|
|
|
|
|
|
+-----------------------------------+----------------------------------------------+
|
|
|
|
|
| Range | Encoding |
|
|
|
|
|
+===================================+==============================================+
|
|
|
|
|
| ``U-00000000`` ... ``U-0000007F`` | 0xxxxxxx |
|
|
|
|
|
+-----------------------------------+----------------------------------------------+
|
|
|
|
|
| ``U-00000080`` ... ``U-000007FF`` | 110xxxxx 10xxxxxx |
|
|
|
|
|
+-----------------------------------+----------------------------------------------+
|
|
|
|
|
| ``U-00000800`` ... ``U-0000FFFF`` | 1110xxxx 10xxxxxx 10xxxxxx |
|
|
|
|
|
+-----------------------------------+----------------------------------------------+
|
2011-09-01 02:11:28 -03:00
|
|
|
|
| ``U-00010000`` ... ``U-0010FFFF`` | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx |
|
2007-08-15 11:28:22 -03:00
|
|
|
|
+-----------------------------------+----------------------------------------------+
|
|
|
|
|
|
|
|
|
|
The least significant bit of the Unicode character is the rightmost x bit.
|
|
|
|
|
|
|
|
|
|
As UTF-8 is an 8-bit encoding no BOM is required and any ``U+FEFF`` character in
|
2008-05-11 11:52:00 -03:00
|
|
|
|
the decoded string (even if it's the first character) is treated as a ``ZERO
|
|
|
|
|
WIDTH NO-BREAK SPACE``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
Without external information it's impossible to reliably determine which
|
2008-05-11 11:52:00 -03:00
|
|
|
|
encoding was used for encoding a string. Each charmap encoding can
|
2007-08-15 11:28:22 -03:00
|
|
|
|
decode any random byte sequence. However that's not possible with UTF-8, as
|
|
|
|
|
UTF-8 byte sequences have a structure that doesn't allow arbitrary byte
|
Merged revisions 57778-58052 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r57820 | georg.brandl | 2007-08-31 08:59:27 +0200 (Fri, 31 Aug 2007) | 2 lines
Document new shorthand notation for index entries.
........
r57827 | georg.brandl | 2007-08-31 10:47:51 +0200 (Fri, 31 Aug 2007) | 2 lines
Fix subitem markup.
........
r57833 | martin.v.loewis | 2007-08-31 12:01:07 +0200 (Fri, 31 Aug 2007) | 1 line
Mark registry components as 64-bit on Win64.
........
r57854 | bill.janssen | 2007-08-31 21:02:23 +0200 (Fri, 31 Aug 2007) | 1 line
deprecate use of FakeSocket
........
r57855 | bill.janssen | 2007-08-31 21:02:46 +0200 (Fri, 31 Aug 2007) | 1 line
remove mentions of socket.ssl in comments
........
r57856 | bill.janssen | 2007-08-31 21:03:31 +0200 (Fri, 31 Aug 2007) | 1 line
remove use of non-existent SSLFakeSocket in apparently untested code
........
r57859 | martin.v.loewis | 2007-09-01 08:36:03 +0200 (Sat, 01 Sep 2007) | 3 lines
Bug #1737210: Change Manufacturer of Windows installer to PSF.
Will backport to 2.5.
........
r57865 | georg.brandl | 2007-09-01 09:51:24 +0200 (Sat, 01 Sep 2007) | 2 lines
Fix RST link (backport from Py3k).
........
r57876 | georg.brandl | 2007-09-01 17:49:49 +0200 (Sat, 01 Sep 2007) | 2 lines
Document sets' ">" and "<" operations (backport from py3k).
........
r57878 | skip.montanaro | 2007-09-01 19:40:03 +0200 (Sat, 01 Sep 2007) | 4 lines
Added a note and examples to explain that re.split does not split on an
empty pattern match. (issue 852532).
........
r57879 | walter.doerwald | 2007-09-01 20:18:09 +0200 (Sat, 01 Sep 2007) | 2 lines
Fix wrong function names.
........
r57880 | walter.doerwald | 2007-09-01 20:34:05 +0200 (Sat, 01 Sep 2007) | 2 lines
Fix typo.
........
r57889 | andrew.kuchling | 2007-09-01 22:31:59 +0200 (Sat, 01 Sep 2007) | 1 line
Markup fix
........
r57892 | andrew.kuchling | 2007-09-01 22:43:36 +0200 (Sat, 01 Sep 2007) | 1 line
Add various items
........
r57895 | andrew.kuchling | 2007-09-01 23:17:58 +0200 (Sat, 01 Sep 2007) | 1 line
Wording change
........
r57896 | andrew.kuchling | 2007-09-01 23:18:31 +0200 (Sat, 01 Sep 2007) | 1 line
Add more items
........
r57904 | ronald.oussoren | 2007-09-02 11:46:07 +0200 (Sun, 02 Sep 2007) | 3 lines
Macosx: this patch ensures that the value of MACOSX_DEPLOYMENT_TARGET used
by the Makefile is also used at configure-time.
........
r57925 | georg.brandl | 2007-09-03 09:16:46 +0200 (Mon, 03 Sep 2007) | 2 lines
Fix #883466: don't allow Unicode as arguments to quopri and uu codecs.
........
r57936 | matthias.klose | 2007-09-04 01:33:04 +0200 (Tue, 04 Sep 2007) | 2 lines
- Added support for linking the bsddb module against BerkeleyDB 4.6.x.
........
r57954 | mark.summerfield | 2007-09-04 10:16:15 +0200 (Tue, 04 Sep 2007) | 3 lines
Added cross-references plus a note about dict & list shallow copying.
........
r57958 | martin.v.loewis | 2007-09-04 11:51:57 +0200 (Tue, 04 Sep 2007) | 3 lines
Document that we rely on the OS to release the crypto
context. Fixes #1626801.
........
r57960 | martin.v.loewis | 2007-09-04 15:13:14 +0200 (Tue, 04 Sep 2007) | 3 lines
Patch #1388440: Add set_completion_display_matches_hook and
get_completion_type to readline.
........
r57961 | martin.v.loewis | 2007-09-04 16:19:28 +0200 (Tue, 04 Sep 2007) | 3 lines
Patch #1031213: Decode source line in SyntaxErrors back to its original
source encoding. Will backport to 2.5.
........
r57972 | matthias.klose | 2007-09-04 20:17:36 +0200 (Tue, 04 Sep 2007) | 3 lines
- Makefile.pre.in(buildbottest): Run an optional script pybuildbot.identify
to include some information about the build environment.
........
r57973 | matthias.klose | 2007-09-04 21:05:38 +0200 (Tue, 04 Sep 2007) | 2 lines
- Makefile.pre.in(buildbottest): Remove whitespace at eol.
........
r57975 | matthias.klose | 2007-09-04 22:46:02 +0200 (Tue, 04 Sep 2007) | 2 lines
- Fix libffi configure for hppa*-*-linux* | parisc*-*-linux*.
........
r57980 | bill.janssen | 2007-09-05 02:46:27 +0200 (Wed, 05 Sep 2007) | 1 line
SSL certificate distinguished names should be represented by tuples
........
r57985 | martin.v.loewis | 2007-09-05 08:39:17 +0200 (Wed, 05 Sep 2007) | 3 lines
Patch #1105: Explain that one needs to build the solution
to get dependencies right.
........
r57987 | armin.rigo | 2007-09-05 09:51:21 +0200 (Wed, 05 Sep 2007) | 4 lines
PyDict_GetItem() returns a borrowed reference.
There are probably a number of places that are open to attacks
such as the following one, in bltinmodule.c:min_max().
........
r57991 | martin.v.loewis | 2007-09-05 13:47:34 +0200 (Wed, 05 Sep 2007) | 3 lines
Patch #786737: Allow building in a tree of symlinks pointing to
a readonly source.
........
r57993 | georg.brandl | 2007-09-05 15:36:44 +0200 (Wed, 05 Sep 2007) | 2 lines
Backport from Py3k: Bug #1684991: explain lookup semantics for __special__ methods (new-style classes only).
........
r58004 | armin.rigo | 2007-09-06 10:30:51 +0200 (Thu, 06 Sep 2007) | 4 lines
Patch #1733973 by peaker:
ptrace_enter_call() assumes no exception is currently set.
This assumption is broken when throwing into a generator.
........
r58006 | armin.rigo | 2007-09-06 11:30:38 +0200 (Thu, 06 Sep 2007) | 4 lines
PyDict_GetItem() returns a borrowed reference.
This attack is against ceval.c:IMPORT_NAME, which calls an
object (__builtin__.__import__) without holding a reference to it.
........
r58013 | georg.brandl | 2007-09-06 16:49:56 +0200 (Thu, 06 Sep 2007) | 2 lines
Backport from 3k: #1116: fix reference to old filename.
........
r58021 | thomas.heller | 2007-09-06 22:26:20 +0200 (Thu, 06 Sep 2007) | 1 line
Fix typo: c_float represents to C float type.
........
r58022 | skip.montanaro | 2007-09-07 00:29:06 +0200 (Fri, 07 Sep 2007) | 3 lines
If this is correct for py3k branch and it's already in the release25-maint
branch, seems like it ought to be on the trunk as well.
........
r58023 | gregory.p.smith | 2007-09-07 00:59:59 +0200 (Fri, 07 Sep 2007) | 4 lines
Apply the fix from Issue1112 to make this test more robust and keep
windows happy.
........
r58031 | brett.cannon | 2007-09-07 05:17:50 +0200 (Fri, 07 Sep 2007) | 4 lines
Make uuid1 and uuid4 tests conditional on whether ctypes can be imported;
implementation of either function depends on ctypes but uuid as a whole does
not.
........
r58032 | brett.cannon | 2007-09-07 06:18:30 +0200 (Fri, 07 Sep 2007) | 6 lines
Fix a crasher where Python code managed to infinitely recurse in C code without
ever going back out to Python code in PyObject_Call(). Required introducing a
static RuntimeError instance so that normalizing an exception there is no
reliance on a recursive call that would put the exception system over the
recursion check itself.
........
r58034 | thomas.heller | 2007-09-07 08:32:17 +0200 (Fri, 07 Sep 2007) | 1 line
Add a 'c_longdouble' type to the ctypes module.
........
r58035 | thomas.heller | 2007-09-07 11:30:40 +0200 (Fri, 07 Sep 2007) | 1 line
Remove unneeded #include.
........
r58036 | thomas.heller | 2007-09-07 11:33:24 +0200 (Fri, 07 Sep 2007) | 6 lines
Backport from py3k branch:
Add a workaround for a strange bug on win64, when _ctypes is compiled
with the SDK compiler. This should fix the failing
Lib\ctypes\test\test_as_parameter.py test.
........
r58037 | georg.brandl | 2007-09-07 16:14:40 +0200 (Fri, 07 Sep 2007) | 2 lines
Fix a wrong indentation for sublists.
........
r58043 | georg.brandl | 2007-09-07 22:10:49 +0200 (Fri, 07 Sep 2007) | 2 lines
#1095: ln -f doesn't work portably, fix in Makefile.
........
r58049 | skip.montanaro | 2007-09-08 02:34:17 +0200 (Sat, 08 Sep 2007) | 1 line
be explicit about the actual location of the missing file
........
2007-09-08 14:39:28 -03:00
|
|
|
|
sequences. To increase the reliability with which a UTF-8 encoding can be
|
2007-08-15 11:28:22 -03:00
|
|
|
|
detected, Microsoft invented a variant of UTF-8 (that Python 2.5 calls
|
|
|
|
|
``"utf-8-sig"``) for its Notepad program: Before any of the Unicode characters
|
|
|
|
|
is written to the file, a UTF-8 encoded BOM (which looks like this as a byte
|
|
|
|
|
sequence: ``0xef``, ``0xbb``, ``0xbf``) is written. As it's rather improbable
|
|
|
|
|
that any charmap encoded file starts with these byte values (which would e.g.
|
|
|
|
|
map to
|
|
|
|
|
|
|
|
|
|
| LATIN SMALL LETTER I WITH DIAERESIS
|
|
|
|
|
| RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
|
|
|
|
|
| INVERTED QUESTION MARK
|
|
|
|
|
|
2011-10-25 04:40:38 -03:00
|
|
|
|
in iso-8859-1), this increases the probability that a ``utf-8-sig`` encoding can be
|
2007-08-15 11:28:22 -03:00
|
|
|
|
correctly guessed from the byte sequence. So here the BOM is not used to be able
|
|
|
|
|
to determine the byte order used for generating the byte sequence, but as a
|
|
|
|
|
signature that helps in guessing the encoding. On encoding the utf-8-sig codec
|
|
|
|
|
will write ``0xef``, ``0xbb``, ``0xbf`` as the first three bytes to the file. On
|
2011-10-25 04:40:38 -03:00
|
|
|
|
decoding ``utf-8-sig`` will skip those three bytes if they appear as the first
|
2019-09-12 04:41:32 -03:00
|
|
|
|
three bytes in the file. In UTF-8, the use of the BOM is discouraged and
|
2011-10-25 04:40:38 -03:00
|
|
|
|
should generally be avoided.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. _standard-encodings:
|
|
|
|
|
|
|
|
|
|
Standard Encodings
|
|
|
|
|
------------------
|
|
|
|
|
|
|
|
|
|
Python comes with a number of codecs built-in, either implemented as C functions
|
|
|
|
|
or with dictionaries as mapping tables. The following table lists the codecs by
|
|
|
|
|
name, together with a few common aliases, and the languages for which the
|
|
|
|
|
encoding is likely used. Neither the list of aliases nor the list of languages
|
|
|
|
|
is meant to be exhaustive. Notice that spelling alternatives that only differ in
|
Merged revisions 74542,74544-74548,74550,74554-74555,74578,74588,74590,74603,74616-74618,74621 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74542 | georg.brandl | 2009-08-23 23:28:56 +0200 (So, 23 Aug 2009) | 1 line
Restore alphabetic order.
........
r74544 | georg.brandl | 2009-08-24 19:12:30 +0200 (Mo, 24 Aug 2009) | 1 line
#6775: fix python.org URLs in README.
........
r74545 | georg.brandl | 2009-08-24 19:14:29 +0200 (Mo, 24 Aug 2009) | 1 line
#6772: mention utf-8 as utf8 alias.
........
r74546 | georg.brandl | 2009-08-24 19:20:40 +0200 (Mo, 24 Aug 2009) | 1 line
#6725: spell "namespace" consistently.
........
r74547 | georg.brandl | 2009-08-24 19:22:05 +0200 (Mo, 24 Aug 2009) | 1 line
#6718: fix example.
........
r74548 | georg.brandl | 2009-08-24 19:24:27 +0200 (Mo, 24 Aug 2009) | 1 line
#6677: mention "deleting" as an alias for removing files.
........
r74550 | georg.brandl | 2009-08-24 19:48:40 +0200 (Mo, 24 Aug 2009) | 1 line
#6677: note that rmdir only removes empty directories.
........
r74554 | georg.brandl | 2009-08-27 20:59:02 +0200 (Do, 27 Aug 2009) | 1 line
Typo fix.
........
r74555 | georg.brandl | 2009-08-27 21:02:43 +0200 (Do, 27 Aug 2009) | 1 line
#6787: reference fix.
........
r74578 | tarek.ziade | 2009-08-29 15:33:21 +0200 (Sa, 29 Aug 2009) | 1 line
fixed #6801: symmetric_difference_update also accepts pipe
........
r74588 | georg.brandl | 2009-08-30 10:35:01 +0200 (So, 30 Aug 2009) | 1 line
#6803: fix old name.
........
r74590 | georg.brandl | 2009-08-30 13:51:53 +0200 (So, 30 Aug 2009) | 1 line
#6801: fix copy-paste oversight.
........
r74603 | georg.brandl | 2009-08-31 08:38:29 +0200 (Mo, 31 Aug 2009) | 1 line
other -> others where multiple arguments are accepted.
........
r74616 | georg.brandl | 2009-09-01 09:46:26 +0200 (Di, 01 Sep 2009) | 1 line
#6808: clarification.
........
r74617 | georg.brandl | 2009-09-01 09:53:37 +0200 (Di, 01 Sep 2009) | 1 line
#6765: hint that log(x, base) is not very sophisticated.
........
r74618 | georg.brandl | 2009-09-01 10:00:47 +0200 (Di, 01 Sep 2009) | 1 line
#6810: add a link to the section about frame objects instead of just a description where to find it.
........
r74621 | georg.brandl | 2009-09-01 10:06:03 +0200 (Di, 01 Sep 2009) | 1 line
#6638: fix wrong parameter name and markup a class.
........
2009-09-01 05:11:14 -03:00
|
|
|
|
case or use a hyphen instead of an underscore are also valid aliases; therefore,
|
|
|
|
|
e.g. ``'utf-8'`` is a valid alias for the ``'utf_8'`` codec.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2011-02-25 15:19:57 -04:00
|
|
|
|
.. impl-detail::
|
|
|
|
|
|
|
|
|
|
Some common encodings can bypass the codecs lookup machinery to
|
2019-09-12 04:41:32 -03:00
|
|
|
|
improve performance. These optimization opportunities are only
|
2017-12-15 06:19:23 -04:00
|
|
|
|
recognized by CPython for a limited set of (case insensitive)
|
|
|
|
|
aliases: utf-8, utf8, latin-1, latin1, iso-8859-1, iso8859-1, mbcs
|
|
|
|
|
(Windows only), ascii, us-ascii, utf-16, utf16, utf-32, utf32, and
|
|
|
|
|
the same using underscores instead of dashes. Using alternative
|
|
|
|
|
aliases for these encodings may result in slower execution.
|
|
|
|
|
|
|
|
|
|
.. versionchanged:: 3.6
|
|
|
|
|
Optimization opportunity recognized for us-ascii.
|
2011-02-25 15:19:57 -04:00
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
Many of the character sets support the same languages. They vary in individual
|
|
|
|
|
characters (e.g. whether the EURO SIGN is supported or not), and in the
|
|
|
|
|
assignment of characters to code positions. For the European languages in
|
|
|
|
|
particular, the following variants typically exist:
|
|
|
|
|
|
|
|
|
|
* an ISO 8859 codeset
|
|
|
|
|
|
2016-05-08 10:53:41 -03:00
|
|
|
|
* a Microsoft Windows code page, which is typically derived from an 8859 codeset,
|
2007-08-15 11:28:22 -03:00
|
|
|
|
but replaces control characters with additional graphic characters
|
|
|
|
|
|
|
|
|
|
* an IBM EBCDIC code page
|
|
|
|
|
|
|
|
|
|
* an IBM PC code page, which is ASCII compatible
|
|
|
|
|
|
2013-03-28 09:28:44 -03:00
|
|
|
|
.. tabularcolumns:: |l|p{0.3\linewidth}|p{0.3\linewidth}|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| Codec | Aliases | Languages |
|
|
|
|
|
+=================+================================+================================+
|
|
|
|
|
| ascii | 646, us-ascii | English |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| big5 | big5-tw, csbig5 | Traditional Chinese |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| big5hkscs | big5-hkscs, hkscs | Traditional Chinese |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp037 | IBM037, IBM039 | English |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2014-03-07 22:00:34 -04:00
|
|
|
|
| cp273 | 273, IBM273, csIBM273 | German |
|
|
|
|
|
| | | |
|
|
|
|
|
| | | .. versionadded:: 3.4 |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2007-08-15 11:28:22 -03:00
|
|
|
|
| cp424 | EBCDIC-CP-HE, IBM424 | Hebrew |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp437 | 437, IBM437 | English |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp500 | EBCDIC-CP-BE, EBCDIC-CP-CH, | Western Europe |
|
|
|
|
|
| | IBM500 | |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2009-07-15 16:21:18 -03:00
|
|
|
|
| cp720 | | Arabic |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2007-08-15 11:28:22 -03:00
|
|
|
|
| cp737 | | Greek |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp775 | IBM775 | Baltic languages |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp850 | 850, IBM850 | Western Europe |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp852 | 852, IBM852 | Central and Eastern Europe |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp855 | 855, IBM855 | Bulgarian, Byelorussian, |
|
|
|
|
|
| | | Macedonian, Russian, Serbian |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp856 | | Hebrew |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp857 | 857, IBM857 | Turkish |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2010-06-27 19:41:29 -03:00
|
|
|
|
| cp858 | 858, IBM858 | Western Europe |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2007-08-15 11:28:22 -03:00
|
|
|
|
| cp860 | 860, IBM860 | Portuguese |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp861 | 861, CP-IS, IBM861 | Icelandic |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp862 | 862, IBM862 | Hebrew |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp863 | 863, IBM863 | Canadian |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp864 | IBM864 | Arabic |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp865 | 865, IBM865 | Danish, Norwegian |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp866 | 866, IBM866 | Russian |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp869 | 869, CP-GR, IBM869 | Greek |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp874 | | Thai |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp875 | | Greek |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp932 | 932, ms932, mskanji, ms-kanji | Japanese |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp949 | 949, ms949, uhc | Korean |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp950 | 950, ms950 | Traditional Chinese |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp1006 | | Urdu |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp1026 | ibm1026 | Turkish |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2013-11-23 12:52:23 -04:00
|
|
|
|
| cp1125 | 1125, ibm1125, cp866u, ruscii | Ukrainian |
|
|
|
|
|
| | | |
|
|
|
|
|
| | | .. versionadded:: 3.4 |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2007-08-15 11:28:22 -03:00
|
|
|
|
| cp1140 | ibm1140 | Western Europe |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp1250 | windows-1250 | Central and Eastern Europe |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp1251 | windows-1251 | Bulgarian, Byelorussian, |
|
|
|
|
|
| | | Macedonian, Russian, Serbian |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp1252 | windows-1252 | Western Europe |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp1253 | windows-1253 | Greek |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp1254 | windows-1254 | Turkish |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp1255 | windows-1255 | Hebrew |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
Merged revisions 74779-74786,74793,74795,74811,74860-74861,74863,74876,74886,74896,74901,74903,74908,74912,74930,74933,74943,74946,74952-74955,75015,75019,75032,75068,75076,75095,75098,75102,75129,75139,75230 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74779 | michael.foord | 2009-09-13 11:13:36 -0500 (Sun, 13 Sep 2009) | 1 line
Change to tutorial wording for reading text / binary files on Windows. Issue #6301.
........
r74780 | michael.foord | 2009-09-13 11:40:02 -0500 (Sun, 13 Sep 2009) | 1 line
Objects that compare equal automatically pass or fail assertAlmostEqual and assertNotAlmostEqual tests on unittest.TestCase. Issue 6567.
........
r74781 | michael.foord | 2009-09-13 11:46:19 -0500 (Sun, 13 Sep 2009) | 1 line
Note that sys._getframe is not guaranteed to exist in all implementations of Python, and a corresponding note in inspect.currentframe. Issue 6712.
........
r74782 | michael.foord | 2009-09-13 12:07:46 -0500 (Sun, 13 Sep 2009) | 1 line
Tutorial tweaks. Issue 6849.
........
r74783 | michael.foord | 2009-09-13 12:28:35 -0500 (Sun, 13 Sep 2009) | 1 line
unittest.TestLoader.loadTestsFromName honors the loader suiteClass attribute. Issue 6866.
........
r74784 | georg.brandl | 2009-09-13 13:15:07 -0500 (Sun, 13 Sep 2009) | 1 line
Typo fix.
........
r74785 | michael.foord | 2009-09-13 14:07:03 -0500 (Sun, 13 Sep 2009) | 1 line
Test discovery in unittest will only attempt to import modules that are importable; i.e. their names are valid Python identifiers. If an import fails during discovery this will be recorded as an error and test discovery will continue. Issue 6568.
........
r74786 | michael.foord | 2009-09-13 14:08:18 -0500 (Sun, 13 Sep 2009) | 1 line
Remove an extraneous space in unittest documentation.
........
r74793 | georg.brandl | 2009-09-14 09:50:47 -0500 (Mon, 14 Sep 2009) | 1 line
#6908: fix association of hashlib hash attributes.
........
r74795 | benjamin.peterson | 2009-09-14 22:36:26 -0500 (Mon, 14 Sep 2009) | 1 line
Py_SetPythonHome uses static storage #6913
........
r74811 | georg.brandl | 2009-09-15 15:26:59 -0500 (Tue, 15 Sep 2009) | 1 line
Add Armin Ronacher.
........
r74860 | benjamin.peterson | 2009-09-16 21:46:54 -0500 (Wed, 16 Sep 2009) | 1 line
kill bare except
........
r74861 | benjamin.peterson | 2009-09-16 22:18:28 -0500 (Wed, 16 Sep 2009) | 1 line
pep 8 defaults
........
r74863 | benjamin.peterson | 2009-09-16 22:27:33 -0500 (Wed, 16 Sep 2009) | 1 line
rationalize a bit
........
r74876 | georg.brandl | 2009-09-17 11:15:53 -0500 (Thu, 17 Sep 2009) | 1 line
#6932: remove paragraph that advises relying on __del__ being called.
........
r74886 | benjamin.peterson | 2009-09-17 16:33:46 -0500 (Thu, 17 Sep 2009) | 1 line
use macros
........
r74896 | georg.brandl | 2009-09-18 02:22:41 -0500 (Fri, 18 Sep 2009) | 1 line
#6936: for interactive use, quit() is just fine.
........
r74901 | georg.brandl | 2009-09-18 04:14:52 -0500 (Fri, 18 Sep 2009) | 1 line
#6905: use better exception messages in inspect when the argument is of the wrong type.
........
r74903 | georg.brandl | 2009-09-18 04:18:27 -0500 (Fri, 18 Sep 2009) | 1 line
#6938: "ident" is always a string, so use a format code which works.
........
r74908 | georg.brandl | 2009-09-18 08:57:11 -0500 (Fri, 18 Sep 2009) | 1 line
Use str.format() to fix beginner's mistake with %-style string formatting.
........
r74912 | georg.brandl | 2009-09-18 11:19:56 -0500 (Fri, 18 Sep 2009) | 1 line
Optimize optimization and fix method name in docstring.
........
r74930 | georg.brandl | 2009-09-18 16:21:41 -0500 (Fri, 18 Sep 2009) | 1 line
#6925: rewrite docs for locals() and vars() a bit.
........
r74933 | georg.brandl | 2009-09-18 16:35:59 -0500 (Fri, 18 Sep 2009) | 1 line
#6930: clarify description about byteorder handling in UTF decoder routines.
........
r74943 | georg.brandl | 2009-09-19 02:35:07 -0500 (Sat, 19 Sep 2009) | 1 line
#6944: the argument to PyArg_ParseTuple should be a tuple, otherwise a SystemError is set. Also clean up another usage of PyArg_ParseTuple.
........
r74946 | georg.brandl | 2009-09-19 03:43:16 -0500 (Sat, 19 Sep 2009) | 1 line
Update bug tracker reference.
........
r74952 | georg.brandl | 2009-09-19 05:42:34 -0500 (Sat, 19 Sep 2009) | 1 line
#6946: fix duplicate index entries for datetime classes.
........
r74953 | georg.brandl | 2009-09-19 07:04:16 -0500 (Sat, 19 Sep 2009) | 1 line
Fix references to threading.enumerate().
........
r74954 | georg.brandl | 2009-09-19 08:13:56 -0500 (Sat, 19 Sep 2009) | 1 line
Add Doug.
........
r74955 | georg.brandl | 2009-09-19 08:20:49 -0500 (Sat, 19 Sep 2009) | 1 line
Add Mark Summerfield.
........
r75015 | georg.brandl | 2009-09-22 05:55:08 -0500 (Tue, 22 Sep 2009) | 1 line
Fix encoding name.
........
r75019 | vinay.sajip | 2009-09-22 12:23:41 -0500 (Tue, 22 Sep 2009) | 1 line
Fixed a typo, and added sections on optimization and using arbitrary objects as messages.
........
r75032 | benjamin.peterson | 2009-09-22 17:15:28 -0500 (Tue, 22 Sep 2009) | 1 line
fix typos/rephrase
........
r75068 | benjamin.peterson | 2009-09-25 21:57:59 -0500 (Fri, 25 Sep 2009) | 1 line
comment out ugly xxx
........
r75076 | vinay.sajip | 2009-09-26 09:53:32 -0500 (Sat, 26 Sep 2009) | 1 line
Tidied up name of parameter in StreamHandler
........
r75095 | michael.foord | 2009-09-27 14:15:41 -0500 (Sun, 27 Sep 2009) | 1 line
Test creation moved from TestProgram.parseArgs to TestProgram.createTests exclusively. Issue 6956.
........
r75098 | michael.foord | 2009-09-27 15:08:23 -0500 (Sun, 27 Sep 2009) | 1 line
Documentation improvement for load_tests protocol in unittest. Issue 6515.
........
r75102 | skip.montanaro | 2009-09-27 21:12:27 -0500 (Sun, 27 Sep 2009) | 3 lines
Patch from Thomas Barr so that csv.Sniffer will set doublequote property.
Closes issue 6606.
........
r75129 | vinay.sajip | 2009-09-29 02:08:54 -0500 (Tue, 29 Sep 2009) | 1 line
Issue #7014: logging: Improved IronPython 2.6 compatibility.
........
r75139 | raymond.hettinger | 2009-09-29 13:53:24 -0500 (Tue, 29 Sep 2009) | 3 lines
Issue 7008: Better document str.title and show how to work around the apostrophe problem.
........
r75230 | benjamin.peterson | 2009-10-04 08:38:38 -0500 (Sun, 04 Oct 2009) | 1 line
test logging
........
2009-10-04 11:49:41 -03:00
|
|
|
|
| cp1256 | windows-1256 | Arabic |
|
2007-08-15 11:28:22 -03:00
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp1257 | windows-1257 | Baltic languages |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| cp1258 | windows-1258 | Vietnamese |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| euc_jp | eucjp, ujis, u-jis | Japanese |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| euc_jis_2004 | jisx0213, eucjis2004 | Japanese |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| euc_jisx0213 | eucjisx0213 | Japanese |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| euc_kr | euckr, korean, ksc5601, | Korean |
|
|
|
|
|
| | ks_c-5601, ks_c-5601-1987, | |
|
|
|
|
|
| | ksx1001, ks_x-1001 | |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2018-10-30 21:26:06 -03:00
|
|
|
|
| gb2312 | chinese, csiso58gb231280, | Simplified Chinese |
|
|
|
|
|
| | euc-cn, euccn, eucgb2312-cn, | |
|
|
|
|
|
| | gb2312-1980, gb2312-80, | |
|
|
|
|
|
| | iso-ir-58 | |
|
2007-08-15 11:28:22 -03:00
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| gbk | 936, cp936, ms936 | Unified Chinese |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| gb18030 | gb18030-2000 | Unified Chinese |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| hz | hzgb, hz-gb, hz-gb-2312 | Simplified Chinese |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| iso2022_jp | csiso2022jp, iso2022jp, | Japanese |
|
|
|
|
|
| | iso-2022-jp | |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| iso2022_jp_1 | iso2022jp-1, iso-2022-jp-1 | Japanese |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| iso2022_jp_2 | iso2022jp-2, iso-2022-jp-2 | Japanese, Korean, Simplified |
|
|
|
|
|
| | | Chinese, Western Europe, Greek |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| iso2022_jp_2004 | iso2022jp-2004, | Japanese |
|
|
|
|
|
| | iso-2022-jp-2004 | |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| iso2022_jp_3 | iso2022jp-3, iso-2022-jp-3 | Japanese |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| iso2022_jp_ext | iso2022jp-ext, iso-2022-jp-ext | Japanese |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| iso2022_kr | csiso2022kr, iso2022kr, | Korean |
|
|
|
|
|
| | iso-2022-kr | |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| latin_1 | iso-8859-1, iso8859-1, 8859, | Western Europe |
|
2007-08-15 11:28:22 -03:00
|
|
|
|
| | cp819, latin, latin1, L1 | |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| iso8859_2 | iso-8859-2, latin2, L2 | Central and Eastern Europe |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| iso8859_3 | iso-8859-3, latin3, L3 | Esperanto, Maltese |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900-60931,60933-60958 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60901 | eric.smith | 2008-02-19 14:21:56 +0100 (Tue, 19 Feb 2008) | 1 line
Added PEP 3101.
........
r60907 | georg.brandl | 2008-02-20 20:12:36 +0100 (Wed, 20 Feb 2008) | 2 lines
Fixes contributed by Ori Avtalion.
........
r60909 | eric.smith | 2008-02-21 00:34:22 +0100 (Thu, 21 Feb 2008) | 1 line
Trim leading zeros from a floating point exponent, per C99. See issue 1600. As far as I know, this only affects Windows. Add float type 'n' to PyOS_ascii_formatd (see PEP 3101 for 'n' description).
........
r60910 | eric.smith | 2008-02-21 00:39:28 +0100 (Thu, 21 Feb 2008) | 1 line
Now that PyOS_ascii_formatd supports the 'n' format, simplify the float formatting code to just call it.
........
r60918 | andrew.kuchling | 2008-02-21 15:23:38 +0100 (Thu, 21 Feb 2008) | 2 lines
Close manifest file.
This change doesn't make any difference to CPython, but is a necessary fix for Jython.
........
r60921 | guido.van.rossum | 2008-02-21 18:46:16 +0100 (Thu, 21 Feb 2008) | 2 lines
Remove news about float repr() -- issue 1580 is still in limbo.
........
r60923 | guido.van.rossum | 2008-02-21 19:18:37 +0100 (Thu, 21 Feb 2008) | 5 lines
Removed uses of dict.has_key() from distutils, and uses of
callable() from copy_reg.py, so the interpreter now starts up
without warnings when '-3' is given. More work like this needs to
be done in the rest of the stdlib.
........
r60924 | thomas.heller | 2008-02-21 19:28:48 +0100 (Thu, 21 Feb 2008) | 4 lines
configure.ac: Remove the configure check for _Bool, it is already done in the
top-level Python configure script.
configure, fficonfig.h.in: regenerated.
........
r60925 | thomas.heller | 2008-02-21 19:52:20 +0100 (Thu, 21 Feb 2008) | 3 lines
Replace 'has_key()' with 'in'.
Replace 'raise Error, stuff' with 'raise Error(stuff)'.
........
r60927 | raymond.hettinger | 2008-02-21 20:24:53 +0100 (Thu, 21 Feb 2008) | 1 line
Update more instances of has_key().
........
r60928 | guido.van.rossum | 2008-02-21 20:46:35 +0100 (Thu, 21 Feb 2008) | 3 lines
Fix a few typos and layout glitches (more work is needed).
Move 2.5 news to Misc/HISTORY.
........
r60936 | georg.brandl | 2008-02-21 21:33:38 +0100 (Thu, 21 Feb 2008) | 2 lines
#2079: typo in userdict docs.
........
r60938 | georg.brandl | 2008-02-21 21:38:13 +0100 (Thu, 21 Feb 2008) | 2 lines
Part of #2154: minimal syntax fixes in doc example snippets.
........
r60942 | raymond.hettinger | 2008-02-22 04:16:42 +0100 (Fri, 22 Feb 2008) | 1 line
First draft for itertools.product(). Docs and other updates forthcoming.
........
r60955 | nick.coghlan | 2008-02-22 11:54:06 +0100 (Fri, 22 Feb 2008) | 1 line
Try to make command line error messages from runpy easier to understand (and suppress traceback cruft from the implicitly invoked runpy machinery)
........
r60956 | georg.brandl | 2008-02-22 13:31:45 +0100 (Fri, 22 Feb 2008) | 2 lines
A lot more typo fixes by Ori Avtalion.
........
r60957 | georg.brandl | 2008-02-22 13:56:34 +0100 (Fri, 22 Feb 2008) | 2 lines
Don't reference pyshell.
........
r60958 | georg.brandl | 2008-02-22 13:57:05 +0100 (Fri, 22 Feb 2008) | 2 lines
Another fix.
........
2008-02-22 12:37:40 -04:00
|
|
|
|
| iso8859_4 | iso-8859-4, latin4, L4 | Baltic languages |
|
2007-08-15 11:28:22 -03:00
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| iso8859_5 | iso-8859-5, cyrillic | Bulgarian, Byelorussian, |
|
|
|
|
|
| | | Macedonian, Russian, Serbian |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| iso8859_6 | iso-8859-6, arabic | Arabic |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| iso8859_7 | iso-8859-7, greek, greek8 | Greek |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| iso8859_8 | iso-8859-8, hebrew | Hebrew |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| iso8859_9 | iso-8859-9, latin5, L5 | Turkish |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| iso8859_10 | iso-8859-10, latin6, L6 | Nordic languages |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2015-09-24 04:04:05 -03:00
|
|
|
|
| iso8859_11 | iso-8859-11, thai | Thai languages |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
Merged revisions 78760,78771-78773,78802,78922,78952 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78760 | georg.brandl | 2010-03-07 16:23:59 +0100 (So, 07 Mär 2010) | 1 line
#5341: more built-in vs builtin fixes.
........
r78771 | georg.brandl | 2010-03-07 21:58:31 +0100 (So, 07 Mär 2010) | 1 line
#8085: The function is called PyObject_NewVar, not PyObject_VarNew.
........
r78772 | georg.brandl | 2010-03-07 22:12:28 +0100 (So, 07 Mär 2010) | 1 line
#8039: document conditional expressions better, giving them their own section.
........
r78773 | georg.brandl | 2010-03-07 22:32:06 +0100 (So, 07 Mär 2010) | 1 line
#8044: document Py_{Enter,Leave}RecursiveCall functions.
........
r78802 | georg.brandl | 2010-03-08 17:28:40 +0100 (Mo, 08 Mär 2010) | 1 line
Fix typo.
........
r78922 | georg.brandl | 2010-03-13 14:41:58 +0100 (Sa, 13 Mär 2010) | 1 line
Update for new download location.
........
r78952 | georg.brandl | 2010-03-14 10:55:08 +0100 (So, 14 Mär 2010) | 1 line
#8137: add iso-8859-16 to the standard encodings table.
........
2010-03-14 07:56:14 -03:00
|
|
|
|
| iso8859_13 | iso-8859-13, latin7, L7 | Baltic languages |
|
2007-08-15 11:28:22 -03:00
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| iso8859_14 | iso-8859-14, latin8, L8 | Celtic languages |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
Merged revisions 78760,78771-78773,78802,78922,78952 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78760 | georg.brandl | 2010-03-07 16:23:59 +0100 (So, 07 Mär 2010) | 1 line
#5341: more built-in vs builtin fixes.
........
r78771 | georg.brandl | 2010-03-07 21:58:31 +0100 (So, 07 Mär 2010) | 1 line
#8085: The function is called PyObject_NewVar, not PyObject_VarNew.
........
r78772 | georg.brandl | 2010-03-07 22:12:28 +0100 (So, 07 Mär 2010) | 1 line
#8039: document conditional expressions better, giving them their own section.
........
r78773 | georg.brandl | 2010-03-07 22:32:06 +0100 (So, 07 Mär 2010) | 1 line
#8044: document Py_{Enter,Leave}RecursiveCall functions.
........
r78802 | georg.brandl | 2010-03-08 17:28:40 +0100 (Mo, 08 Mär 2010) | 1 line
Fix typo.
........
r78922 | georg.brandl | 2010-03-13 14:41:58 +0100 (Sa, 13 Mär 2010) | 1 line
Update for new download location.
........
r78952 | georg.brandl | 2010-03-14 10:55:08 +0100 (So, 14 Mär 2010) | 1 line
#8137: add iso-8859-16 to the standard encodings table.
........
2010-03-14 07:56:14 -03:00
|
|
|
|
| iso8859_15 | iso-8859-15, latin9, L9 | Western Europe |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| iso8859_16 | iso-8859-16, latin10, L10 | South-Eastern Europe |
|
2007-08-15 11:28:22 -03:00
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| johab | cp1361, ms1361 | Korean |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| koi8_r | | Russian |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2015-05-12 17:24:19 -03:00
|
|
|
|
| koi8_t | | Tajik |
|
|
|
|
|
| | | |
|
|
|
|
|
| | | .. versionadded:: 3.5 |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2007-08-15 11:28:22 -03:00
|
|
|
|
| koi8_u | | Ukrainian |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2015-05-12 17:16:55 -03:00
|
|
|
|
| kz1048 | kz_1048, strk1048_2002, rk1048 | Kazakh |
|
|
|
|
|
| | | |
|
|
|
|
|
| | | .. versionadded:: 3.5 |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2007-08-15 11:28:22 -03:00
|
|
|
|
| mac_cyrillic | maccyrillic | Bulgarian, Byelorussian, |
|
|
|
|
|
| | | Macedonian, Russian, Serbian |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| mac_greek | macgreek | Greek |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| mac_iceland | maciceland | Icelandic |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2019-06-05 19:18:07 -03:00
|
|
|
|
| mac_latin2 | maclatin2, maccentraleurope, | Central and Eastern Europe |
|
|
|
|
|
| | mac_centeuro | |
|
2007-08-15 11:28:22 -03:00
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2010-08-20 23:54:44 -03:00
|
|
|
|
| mac_roman | macroman, macintosh | Western Europe |
|
2007-08-15 11:28:22 -03:00
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| mac_turkish | macturkish | Turkish |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| ptcp154 | csptcp154, pt154, cp154, | Kazakh |
|
|
|
|
|
| | cyrillic-asian | |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| shift_jis | csshiftjis, shiftjis, sjis, | Japanese |
|
|
|
|
|
| | s_jis | |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| shift_jis_2004 | shiftjis2004, sjis_2004, | Japanese |
|
|
|
|
|
| | sjis2004 | |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| shift_jisx0213 | shiftjisx0213, sjisx0213, | Japanese |
|
|
|
|
|
| | s_jisx0213 | |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2007-08-16 18:55:45 -03:00
|
|
|
|
| utf_32 | U32, utf32 | all languages |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| utf_32_be | UTF-32BE | all languages |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| utf_32_le | UTF-32LE | all languages |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2007-08-15 11:28:22 -03:00
|
|
|
|
| utf_16 | U16, utf16 | all languages |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2010-12-08 18:25:45 -04:00
|
|
|
|
| utf_16_be | UTF-16BE | all languages |
|
2007-08-15 11:28:22 -03:00
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2010-12-08 18:25:45 -04:00
|
|
|
|
| utf_16_le | UTF-16LE | all languages |
|
2007-08-15 11:28:22 -03:00
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| utf_7 | U7, unicode-1-1-utf-7 | all languages |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
2019-05-13 05:42:31 -03:00
|
|
|
|
| utf_8 | U8, UTF, utf8, cp65001 | all languages |
|
2007-08-15 11:28:22 -03:00
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
| utf_8_sig | | all languages |
|
|
|
|
|
+-----------------+--------------------------------+--------------------------------+
|
|
|
|
|
|
2013-11-19 05:32:41 -04:00
|
|
|
|
.. versionchanged:: 3.4
|
|
|
|
|
The utf-16\* and utf-32\* encoders no longer allow surrogate code points
|
2015-01-06 10:22:00 -04:00
|
|
|
|
(``U+D800``--``U+DFFF``) to be encoded.
|
|
|
|
|
The utf-32\* decoders no longer decode
|
2013-11-19 05:32:41 -04:00
|
|
|
|
byte sequences that correspond to surrogate code points.
|
|
|
|
|
|
2019-05-13 05:42:31 -03:00
|
|
|
|
.. versionchanged:: 3.8
|
|
|
|
|
``cp65001`` is now an alias to ``utf_8``.
|
|
|
|
|
|
2013-11-19 05:32:41 -04:00
|
|
|
|
|
2013-05-23 07:24:02 -03:00
|
|
|
|
Python Specific Encodings
|
|
|
|
|
-------------------------
|
|
|
|
|
|
|
|
|
|
A number of predefined codecs are specific to Python, so their codec names have
|
2019-09-12 04:41:32 -03:00
|
|
|
|
no meaning outside Python. These are listed in the tables below based on the
|
2013-05-23 07:24:02 -03:00
|
|
|
|
expected input and output types (note that while text encodings are the most
|
|
|
|
|
common use case for codecs, the underlying codec infrastructure supports
|
2019-09-12 04:41:32 -03:00
|
|
|
|
arbitrary data transforms rather than just text encodings). For asymmetric
|
|
|
|
|
codecs, the stated meaning describes the encoding direction.
|
2013-05-23 07:24:02 -03:00
|
|
|
|
|
2013-11-22 21:13:36 -04:00
|
|
|
|
Text Encodings
|
|
|
|
|
^^^^^^^^^^^^^^
|
|
|
|
|
|
2013-05-23 07:24:02 -03:00
|
|
|
|
The following codecs provide :class:`str` to :class:`bytes` encoding and
|
|
|
|
|
:term:`bytes-like object` to :class:`str` decoding, similar to the Unicode text
|
|
|
|
|
encodings.
|
2007-08-31 07:15:37 -03:00
|
|
|
|
|
2013-03-28 09:28:44 -03:00
|
|
|
|
.. tabularcolumns:: |l|p{0.3\linewidth}|p{0.3\linewidth}|
|
|
|
|
|
|
2008-05-11 11:52:00 -03:00
|
|
|
|
+--------------------+---------+---------------------------+
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| Codec | Aliases | Meaning |
|
2008-05-11 11:52:00 -03:00
|
|
|
|
+====================+=========+===========================+
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| idna | | Implement :rfc:`3490`, |
|
2008-05-11 11:52:00 -03:00
|
|
|
|
| | | see also |
|
2015-01-06 10:22:00 -04:00
|
|
|
|
| | | :mod:`encodings.idna`. |
|
|
|
|
|
| | | Only ``errors='strict'`` |
|
|
|
|
|
| | | is supported. |
|
2008-05-11 11:52:00 -03:00
|
|
|
|
+--------------------+---------+---------------------------+
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| mbcs | ansi, | Windows only: Encode the |
|
2016-09-06 23:46:42 -03:00
|
|
|
|
| | dbcs | operand according to the |
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| | | ANSI codepage (CP_ACP). |
|
2008-05-11 11:52:00 -03:00
|
|
|
|
+--------------------+---------+---------------------------+
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| oem | | Windows only: Encode the |
|
2016-09-06 23:46:42 -03:00
|
|
|
|
| | | operand according to the |
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| | | OEM codepage (CP_OEMCP). |
|
2016-09-06 23:46:42 -03:00
|
|
|
|
| | | |
|
|
|
|
|
| | | .. versionadded:: 3.6 |
|
|
|
|
|
+--------------------+---------+---------------------------+
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| palmos | | Encoding of PalmOS 3.5. |
|
2008-05-11 11:52:00 -03:00
|
|
|
|
+--------------------+---------+---------------------------+
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| punycode | | Implement :rfc:`3492`. |
|
2015-01-06 10:22:00 -04:00
|
|
|
|
| | | Stateful codecs are not |
|
|
|
|
|
| | | supported. |
|
2008-05-11 11:52:00 -03:00
|
|
|
|
+--------------------+---------+---------------------------+
|
2015-01-06 10:22:00 -04:00
|
|
|
|
| raw_unicode_escape | | Latin-1 encoding with |
|
|
|
|
|
| | | ``\uXXXX`` and |
|
|
|
|
|
| | | ``\UXXXXXXXX`` for other |
|
|
|
|
|
| | | code points. Existing |
|
|
|
|
|
| | | backslashes are not |
|
|
|
|
|
| | | escaped in any way. |
|
|
|
|
|
| | | It is used in the Python |
|
|
|
|
|
| | | pickle protocol. |
|
2008-05-11 11:52:00 -03:00
|
|
|
|
+--------------------+---------+---------------------------+
|
|
|
|
|
| undefined | | Raise an exception for |
|
2015-01-06 10:22:00 -04:00
|
|
|
|
| | | all conversions, even |
|
|
|
|
|
| | | empty strings. The error |
|
|
|
|
|
| | | handler is ignored. |
|
2008-05-11 11:52:00 -03:00
|
|
|
|
+--------------------+---------+---------------------------+
|
2015-01-06 10:22:00 -04:00
|
|
|
|
| unicode_escape | | Encoding suitable as the |
|
|
|
|
|
| | | contents of a Unicode |
|
|
|
|
|
| | | literal in ASCII-encoded |
|
|
|
|
|
| | | Python source code, |
|
|
|
|
|
| | | except that quotes are |
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| | | not escaped. Decode |
|
|
|
|
|
| | | from Latin-1 source code. |
|
2015-01-06 10:22:00 -04:00
|
|
|
|
| | | Beware that Python source |
|
|
|
|
|
| | | code actually uses UTF-8 |
|
|
|
|
|
| | | by default. |
|
2008-05-11 11:52:00 -03:00
|
|
|
|
+--------------------+---------+---------------------------+
|
2019-03-18 03:44:11 -03:00
|
|
|
|
|
|
|
|
|
.. versionchanged:: 3.8
|
|
|
|
|
"unicode_internal" codec is removed.
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
2013-11-22 21:13:36 -04:00
|
|
|
|
.. _binary-transforms:
|
|
|
|
|
|
|
|
|
|
Binary Transforms
|
|
|
|
|
^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
The following codecs provide binary transforms: :term:`bytes-like object`
|
2019-09-12 04:41:32 -03:00
|
|
|
|
to :class:`bytes` mappings. They are not supported by :meth:`bytes.decode`
|
2015-01-06 10:22:00 -04:00
|
|
|
|
(which only produces :class:`str` output).
|
2013-11-22 21:13:36 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. tabularcolumns:: |l|L|L|L|
|
|
|
|
|
|
|
|
|
|
+----------------------+------------------+------------------------------+------------------------------+
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| Codec | Aliases | Meaning | Encoder / decoder |
|
2013-11-22 21:13:36 -04:00
|
|
|
|
+======================+==================+==============================+==============================+
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| base64_codec [#b64]_ | base64, base_64 | Convert the operand to | :meth:`base64.encodebytes` / |
|
|
|
|
|
| | | multiline MIME base64 (the | :meth:`base64.decodebytes` |
|
|
|
|
|
| | | result always includes a | |
|
|
|
|
|
| | | trailing ``'\n'``). | |
|
2013-11-22 21:13:36 -04:00
|
|
|
|
| | | | |
|
|
|
|
|
| | | .. versionchanged:: 3.4 | |
|
|
|
|
|
| | | accepts any | |
|
|
|
|
|
| | | :term:`bytes-like object` | |
|
|
|
|
|
| | | as input for encoding and | |
|
|
|
|
|
| | | decoding | |
|
|
|
|
|
+----------------------+------------------+------------------------------+------------------------------+
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| bz2_codec | bz2 | Compress the operand using | :meth:`bz2.compress` / |
|
|
|
|
|
| | | bz2. | :meth:`bz2.decompress` |
|
2013-11-22 21:13:36 -04:00
|
|
|
|
+----------------------+------------------+------------------------------+------------------------------+
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| hex_codec | hex | Convert the operand to | :meth:`binascii.b2a_hex` / |
|
2015-09-11 21:34:28 -03:00
|
|
|
|
| | | hexadecimal | :meth:`binascii.a2b_hex` |
|
2013-11-22 21:13:36 -04:00
|
|
|
|
| | | representation, with two | |
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| | | digits per byte. | |
|
2013-11-22 21:13:36 -04:00
|
|
|
|
+----------------------+------------------+------------------------------+------------------------------+
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| quopri_codec | quopri, | Convert the operand to MIME | :meth:`quopri.encode` with |
|
|
|
|
|
| | quotedprintable, | quoted printable. | ``quotetabs=True`` / |
|
2015-09-11 21:34:28 -03:00
|
|
|
|
| | quoted_printable | | :meth:`quopri.decode` |
|
2013-11-22 21:13:36 -04:00
|
|
|
|
+----------------------+------------------+------------------------------+------------------------------+
|
|
|
|
|
| uu_codec | uu | Convert the operand using | :meth:`uu.encode` / |
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| | | uuencode. | :meth:`uu.decode` |
|
2013-11-22 21:13:36 -04:00
|
|
|
|
+----------------------+------------------+------------------------------+------------------------------+
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| zlib_codec | zip, zlib | Compress the operand using | :meth:`zlib.compress` / |
|
|
|
|
|
| | | gzip. | :meth:`zlib.decompress` |
|
2013-11-22 21:13:36 -04:00
|
|
|
|
+----------------------+------------------+------------------------------+------------------------------+
|
2013-10-02 11:43:22 -03:00
|
|
|
|
|
|
|
|
|
.. [#b64] In addition to :term:`bytes-like objects <bytes-like object>`,
|
|
|
|
|
``'base64_codec'`` also accepts ASCII-only instances of :class:`str` for
|
|
|
|
|
decoding
|
2013-05-23 07:24:02 -03:00
|
|
|
|
|
2013-11-22 21:13:36 -04:00
|
|
|
|
.. versionadded:: 3.2
|
|
|
|
|
Restoration of the binary transforms.
|
2013-05-23 07:24:02 -03:00
|
|
|
|
|
2013-11-22 21:13:36 -04:00
|
|
|
|
.. versionchanged:: 3.4
|
|
|
|
|
Restoration of the aliases for the binary transforms.
|
2010-12-02 14:06:51 -04:00
|
|
|
|
|
2013-03-28 09:28:44 -03:00
|
|
|
|
|
2013-11-22 21:13:36 -04:00
|
|
|
|
.. _text-transforms:
|
|
|
|
|
|
|
|
|
|
Text Transforms
|
|
|
|
|
^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
The following codec provides a text transform: a :class:`str` to :class:`str`
|
2019-09-12 04:41:32 -03:00
|
|
|
|
mapping. It is not supported by :meth:`str.encode` (which only produces
|
2015-01-06 10:22:00 -04:00
|
|
|
|
:class:`bytes` output).
|
2013-11-22 21:13:36 -04:00
|
|
|
|
|
|
|
|
|
.. tabularcolumns:: |l|l|L|
|
|
|
|
|
|
|
|
|
|
+--------------------+---------+---------------------------+
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| Codec | Aliases | Meaning |
|
2013-11-22 21:13:36 -04:00
|
|
|
|
+====================+=========+===========================+
|
2019-09-12 04:41:32 -03:00
|
|
|
|
| rot_13 | rot13 | Return the Caesar-cypher |
|
|
|
|
|
| | | encryption of the |
|
|
|
|
|
| | | operand. |
|
2013-11-22 21:13:36 -04:00
|
|
|
|
+--------------------+---------+---------------------------+
|
2010-12-02 14:06:51 -04:00
|
|
|
|
|
|
|
|
|
.. versionadded:: 3.2
|
2013-11-22 21:13:36 -04:00
|
|
|
|
Restoration of the ``rot_13`` text transform.
|
|
|
|
|
|
|
|
|
|
.. versionchanged:: 3.4
|
|
|
|
|
Restoration of the ``rot13`` alias.
|
2010-12-02 14:06:51 -04:00
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
:mod:`encodings.idna` --- Internationalized Domain Names in Applications
|
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
.. module:: encodings.idna
|
|
|
|
|
:synopsis: Internationalized Domain Names implementation
|
|
|
|
|
.. moduleauthor:: Martin v. Löwis
|
|
|
|
|
|
|
|
|
|
This module implements :rfc:`3490` (Internationalized Domain Names in
|
|
|
|
|
Applications) and :rfc:`3492` (Nameprep: A Stringprep Profile for
|
|
|
|
|
Internationalized Domain Names (IDN)). It builds upon the ``punycode`` encoding
|
|
|
|
|
and :mod:`stringprep`.
|
|
|
|
|
|
|
|
|
|
These RFCs together define a protocol to support non-ASCII characters in domain
|
|
|
|
|
names. A domain name containing non-ASCII characters (such as
|
|
|
|
|
``www.Alliancefrançaise.nu``) is converted into an ASCII-compatible encoding
|
|
|
|
|
(ACE, such as ``www.xn--alliancefranaise-npb.nu``). The ACE form of the domain
|
|
|
|
|
name is then used in all places where arbitrary characters are not allowed by
|
|
|
|
|
the protocol, such as DNS queries, HTTP :mailheader:`Host` fields, and so
|
|
|
|
|
on. This conversion is carried out in the application; if possible invisible to
|
|
|
|
|
the user: The application should transparently convert Unicode domain labels to
|
|
|
|
|
IDNA on the wire, and convert back ACE labels to Unicode before presenting them
|
|
|
|
|
to the user.
|
|
|
|
|
|
2011-04-13 15:12:18 -03:00
|
|
|
|
Python supports this conversion in several ways: the ``idna`` codec performs
|
|
|
|
|
conversion between Unicode and ACE, separating an input string into labels
|
2018-05-31 01:39:00 -03:00
|
|
|
|
based on the separator characters defined in :rfc:`section 3.1 of RFC 3490 <3490#section-3.1>`
|
2011-04-13 15:12:18 -03:00
|
|
|
|
and converting each label to ACE as required, and conversely separating an input
|
|
|
|
|
byte string into labels based on the ``.`` separator and converting any ACE
|
2019-09-12 04:41:32 -03:00
|
|
|
|
labels found into unicode. Furthermore, the :mod:`socket` module
|
2007-08-15 11:28:22 -03:00
|
|
|
|
transparently converts Unicode host names to ACE, so that applications need not
|
|
|
|
|
be concerned about converting host names themselves when they pass them to the
|
|
|
|
|
socket module. On top of that, modules that have host names as function
|
2008-05-26 13:32:26 -03:00
|
|
|
|
parameters, such as :mod:`http.client` and :mod:`ftplib`, accept Unicode host
|
|
|
|
|
names (:mod:`http.client` then also transparently sends an IDNA hostname in the
|
2007-08-15 11:28:22 -03:00
|
|
|
|
:mailheader:`Host` field if it sends that field at all).
|
|
|
|
|
|
|
|
|
|
When receiving host names from the wire (such as in reverse name lookup), no
|
2019-09-12 04:41:32 -03:00
|
|
|
|
automatic conversion to Unicode is performed: applications wishing to present
|
2007-08-15 11:28:22 -03:00
|
|
|
|
such host names to the user should decode them to Unicode.
|
|
|
|
|
|
|
|
|
|
The module :mod:`encodings.idna` also implements the nameprep procedure, which
|
|
|
|
|
performs certain normalizations on host names, to achieve case-insensitivity of
|
|
|
|
|
international domain names, and to unify similar characters. The nameprep
|
|
|
|
|
functions can be used directly if desired.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: nameprep(label)
|
|
|
|
|
|
|
|
|
|
Return the nameprepped version of *label*. The implementation currently assumes
|
|
|
|
|
query strings, so ``AllowUnassigned`` is true.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: ToASCII(label)
|
|
|
|
|
|
|
|
|
|
Convert a label to ASCII, as specified in :rfc:`3490`. ``UseSTD3ASCIIRules`` is
|
|
|
|
|
assumed to be false.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: ToUnicode(label)
|
|
|
|
|
|
|
|
|
|
Convert a label to Unicode, as specified in :rfc:`3490`.
|
|
|
|
|
|
|
|
|
|
|
2010-06-16 20:33:54 -03:00
|
|
|
|
:mod:`encodings.mbcs` --- Windows ANSI codepage
|
|
|
|
|
-----------------------------------------------
|
|
|
|
|
|
|
|
|
|
.. module:: encodings.mbcs
|
|
|
|
|
:synopsis: Windows ANSI codepage
|
|
|
|
|
|
2019-09-12 04:41:32 -03:00
|
|
|
|
This module implements the ANSI codepage (CP_ACP).
|
2010-06-16 20:33:54 -03:00
|
|
|
|
|
2018-10-12 11:55:20 -03:00
|
|
|
|
.. availability:: Windows only.
|
2010-06-16 20:33:54 -03:00
|
|
|
|
|
2011-10-18 16:21:00 -03:00
|
|
|
|
.. versionchanged:: 3.3
|
|
|
|
|
Support any error handler.
|
|
|
|
|
|
2010-06-16 20:33:54 -03:00
|
|
|
|
.. versionchanged:: 3.2
|
|
|
|
|
Before 3.2, the *errors* argument was ignored; ``'replace'`` was always used
|
|
|
|
|
to encode, and ``'ignore'`` to decode.
|
|
|
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
:mod:`encodings.utf_8_sig` --- UTF-8 codec with BOM signature
|
|
|
|
|
-------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
.. module:: encodings.utf_8_sig
|
|
|
|
|
:synopsis: UTF-8 codec with BOM signature
|
|
|
|
|
.. moduleauthor:: Walter Dörwald
|
|
|
|
|
|
2019-09-12 04:41:32 -03:00
|
|
|
|
This module implements a variant of the UTF-8 codec. On encoding, a UTF-8 encoded
|
2007-08-15 11:28:22 -03:00
|
|
|
|
BOM will be prepended to the UTF-8 encoded bytes. For the stateful encoder this
|
2019-09-12 04:41:32 -03:00
|
|
|
|
is only done once (on the first write to the byte stream). On decoding, an
|
2007-08-15 11:28:22 -03:00
|
|
|
|
optional UTF-8 encoded BOM at the start of the data will be skipped.
|