Update docs w.r.t. PEP 3100 changes -- patch for GHOP by Dan Finnie.
diff --git a/Doc/library/array.rst b/Doc/library/array.rst
index ec68f65..efe80b7 100644
--- a/Doc/library/array.rst
+++ b/Doc/library/array.rst
@@ -183,18 +183,6 @@
returned.
-.. method:: array.read(f, n)
-
- .. deprecated:: 1.5.1
- Use the :meth:`fromfile` method.
-
- Read *n* items (as machine values) from the file object *f* and append them to
- the end of the array. If less than *n* items are available, :exc:`EOFError` is
- raised, but the items that were available are still inserted into the array.
- *f* must be a real built-in file object; something else with a :meth:`read`
- method won't do.
-
-
.. method:: array.remove(x)
Remove the first occurrence of *x* from the array.
@@ -229,13 +217,6 @@
obtain a unicode string from an array of some other type.
-.. method:: array.write(f)
-
- .. deprecated:: 1.5.1
- Use the :meth:`tofile` method.
-
- Write all items (as machine values) to the file object *f*.
-
When an array object is printed or converted to a string, it is represented as
``array(typecode, initializer)``. The *initializer* is omitted if the array is
empty, otherwise it is a string if the *typecode* is ``'c'``, otherwise it is a
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
index e13e32b..0be8d07 100644
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -403,7 +403,7 @@
Any valid Python identifier may be used for a fieldname except for names
starting with an underscore. Valid identifiers consist of letters, digits,
and underscores but do not start with a digit or underscore and cannot be
- a :mod:`keyword` such as *class*, *for*, *return*, *global*, *pass*, *print*,
+ a :mod:`keyword` such as *class*, *for*, *return*, *global*, *pass*,
or *raise*.
If *verbose* is true, the class definition is printed just before being built.
diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst
index 28f2e59..89bd441 100644
--- a/Doc/library/configparser.rst
+++ b/Doc/library/configparser.rst
@@ -199,7 +199,7 @@
.. method:: RawConfigParser.read(filenames)
Attempt to read and parse a list of filenames, returning a list of filenames
- which were successfully parsed. If *filenames* is a string or Unicode string,
+ which were successfully parsed. If *filenames* is a string,
it is treated as a single filename. If a file named in *filenames* cannot be
opened, that file will be ignored. This is designed so that you can specify a
list of potential configuration file locations (for example, the current
@@ -330,8 +330,8 @@
.. method:: SafeConfigParser.set(section, option, value)
If the given section exists, set the given option to the specified value;
- otherwise raise :exc:`NoSectionError`. *value* must be a string (:class:`str`
- or :class:`unicode`); if not, :exc:`TypeError` is raised.
+ otherwise raise :exc:`NoSectionError`. *value* must be a string; if it is
+ not, :exc:`TypeError` is raised.
Examples
@@ -373,12 +373,12 @@
# getint() and getboolean() also do this for their respective types
float = config.getfloat('Section1', 'float')
int = config.getint('Section1', 'int')
- print float + int
+ print(float + int)
# Notice that the next output does not interpolate '%(bar)s' or '%(baz)s'.
# This is because we are using a RawConfigParser().
if config.getboolean('Section1', 'bool'):
- print config.get('Section1', 'foo')
+ print(config.get('Section1', 'foo'))
To get interpolation, you will need to use a :class:`ConfigParser` or
:class:`SafeConfigParser`::
@@ -389,13 +389,13 @@
config.read('example.cfg')
# Set the third, optional argument of get to 1 if you wish to use raw mode.
- print config.get('Section1', 'foo', 0) # -> "Python is fun!"
- print config.get('Section1', 'foo', 1) # -> "%(bar)s is %(baz)s!"
+ print(config.get('Section1', 'foo', 0)) # -> "Python is fun!"
+ print(config.get('Section1', 'foo', 1)) # -> "%(bar)s is %(baz)s!"
# The optional fourth argument is a dict with members that will take
# precedence in interpolation.
- print config.get('Section1', 'foo', 0, {'bar': 'Documentation',
- 'baz': 'evil'})
+ print(config.get('Section1', 'foo', 0, {'bar': 'Documentation',
+ 'baz': 'evil'}))
Defaults are available in all three types of ConfigParsers. They are used in
interpolation if an option used is not defined elsewhere. ::
@@ -406,10 +406,10 @@
config = ConfigParser.SafeConfigParser({'bar': 'Life', 'baz': 'hard'})
config.read('example.cfg')
- print config.get('Section1', 'foo') # -> "Python is fun!"
+ print(config.get('Section1', 'foo')) # -> "Python is fun!"
config.remove_option('Section1', 'bar')
config.remove_option('Section1', 'baz')
- print config.get('Section1', 'foo') # -> "Life is hard!"
+ print(config.get('Section1', 'foo')) # -> "Life is hard!"
The function ``opt_move`` below can be used to move options between sections::
diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst
index 56972f4..ffdb3cb 100644
--- a/Doc/library/csv.rst
+++ b/Doc/library/csv.rst
@@ -86,7 +86,7 @@
>>> import csv
>>> spamReader = csv.reader(open('eggs.csv'), delimiter=' ', quotechar='|')
>>> for row in spamReader:
- ... print ', '.join(row)
+ ... print(', '.join(row))
Spam, Spam, Spam, Spam, Spam, Baked Beans
Spam, Lovely Spam, Wonderful Spam
@@ -121,7 +121,7 @@
.. function:: register_dialect(name[, dialect][, fmtparam])
- Associate *dialect* with *name*. *name* must be a string or Unicode object. The
+ Associate *dialect* with *name*. *name* must be a string. The
dialect can be specified either by passing a sub-class of :class:`Dialect`, or
by *fmtparam* keyword arguments, or both, with keyword arguments overriding
parameters of the dialect. For full details about the dialect and formatting
diff --git a/Doc/library/datatypes.rst b/Doc/library/datatypes.rst
index 858af96..558c201 100644
--- a/Doc/library/datatypes.rst
+++ b/Doc/library/datatypes.rst
@@ -11,8 +11,8 @@
Python also provides some built-in data types, in particular,
:class:`dict`, :class:`list`, :class:`set` and :class:`frozenset`, and
-:class:`tuple`. The :class:`str` class can be used to handle binary data
-and 8-bit text, and the :class:`unicode` class to handle Unicode text.
+:class:`tuple`. The :class:`str` class can be used to strings, including
+Unicode strings, and the :class:`bytes` class to handle binary data.
The following modules are documented in this chapter:
diff --git a/Doc/library/easydialogs.rst b/Doc/library/easydialogs.rst
index 2a3b66b..5aa5e5b 100644
--- a/Doc/library/easydialogs.rst
+++ b/Doc/library/easydialogs.rst
@@ -107,7 +107,7 @@
*actionButtonLabel* is a string to show instead of "Open" in the OK button,
*cancelButtonLabel* is a string to show instead of "Cancel" in the cancel
button, *wanted* is the type of value wanted as a return: :class:`str`,
- :class:`unicode`, :class:`FSSpec`, :class:`FSRef` and subtypes thereof are
+ :class:`FSSpec`, :class:`FSRef` and subtypes thereof are
acceptable.
.. index:: single: Navigation Services
diff --git a/Doc/library/email.charset.rst b/Doc/library/email.charset.rst
index a943fc2..3a18220 100644
--- a/Doc/library/email.charset.rst
+++ b/Doc/library/email.charset.rst
@@ -242,6 +242,6 @@
Add a codec that map characters in the given character set to and from Unicode.
*charset* is the canonical name of a character set. *codecname* is the name of a
- Python codec, as appropriate for the second argument to the :func:`unicode`
- built-in, or to the :meth:`encode` method of a Unicode string.
+ Python codec, as appropriate for the second argument to the :class:`str`'s
+ :func:`decode` method
diff --git a/Doc/library/email.header.rst b/Doc/library/email.header.rst
index c426c95..ecd9f1f 100644
--- a/Doc/library/email.header.rst
+++ b/Doc/library/email.header.rst
@@ -53,8 +53,8 @@
Optional *s* is the initial header value. If ``None`` (the default), the
initial header value is not set. You can later append to the header with
- :meth:`append` method calls. *s* may be a byte string or a Unicode string, but
- see the :meth:`append` documentation for semantics.
+ :meth:`append` method calls. *s* may be an instance of :class:`bytes` or
+ :class:`str`, but see the :meth:`append` documentation for semantics.
Optional *charset* serves two purposes: it has the same meaning as the *charset*
argument to the :meth:`append` method. It also sets the default character set
@@ -86,19 +86,19 @@
a :class:`Charset` instance. A value of ``None`` (the default) means that the
*charset* given in the constructor is used.
- *s* may be a byte string or a Unicode string. If it is a byte string (i.e.
- ``isinstance(s, str)`` is true), then *charset* is the encoding of that byte
- string, and a :exc:`UnicodeError` will be raised if the string cannot be decoded
- with that character set.
+ *s* may be an instance of :class:`bytes` or :class:`str`. If it is an instance
+ of :class:`bytes`, then *charset* is the encoding of that byte string, and a
+ :exc:`UnicodeError` will be raised if the string cannot be decoded with that
+ character set.
- If *s* is a Unicode string, then *charset* is a hint specifying the character
- set of the characters in the string. In this case, when producing an
+ If *s* is an instance of :class:`str`, then *charset* is a hint specifying the
+ character set of the characters in the string. In this case, when producing an
:rfc:`2822`\ -compliant header using :rfc:`2047` rules, the Unicode string will
be encoded using the following charsets in order: ``us-ascii``, the *charset*
hint, ``utf-8``. The first character set to not provoke a :exc:`UnicodeError`
is used.
- Optional *errors* is passed through to any :func:`unicode` or
+ Optional *errors* is passed through to any :func:`encode` or
:func:`ustr.encode` call, and defaults to "strict".
@@ -121,7 +121,7 @@
.. method:: Header.__unicode__()
- A helper for the built-in :func:`unicode` function. Returns the header as a
+ A helper for :class:`str`'s :func:`encode` method. Returns the header as a
Unicode string.
diff --git a/Doc/library/email.util.rst b/Doc/library/email.util.rst
index 2396fb7..49428f4 100644
--- a/Doc/library/email.util.rst
+++ b/Doc/library/email.util.rst
@@ -130,10 +130,10 @@
When a header parameter is encoded in :rfc:`2231` format,
:meth:`Message.get_param` may return a 3-tuple containing the character set,
language, and value. :func:`collapse_rfc2231_value` turns this into a unicode
- string. Optional *errors* is passed to the *errors* argument of the built-in
- :func:`unicode` function; it defaults to ``replace``. Optional
+ string. Optional *errors* is passed to the *errors* argument of :class:`str`'s
+ :func:`encode` method; it defaults to ``'replace'``. Optional
*fallback_charset* specifies the character set to use if the one in the
- :rfc:`2231` header is not known by Python; it defaults to ``us-ascii``.
+ :rfc:`2231` header is not known by Python; it defaults to ``'us-ascii'``.
For convenience, if the *value* passed to :func:`collapse_rfc2231_value` is not
a tuple, it should be a string and it is returned unquoted.
diff --git a/Doc/library/fcntl.rst b/Doc/library/fcntl.rst
index 5050a7f..4ae18fa 100644
--- a/Doc/library/fcntl.rst
+++ b/Doc/library/fcntl.rst
@@ -47,7 +47,6 @@
.. function:: ioctl(fd, op[, arg[, mutate_flag]])
This function is identical to the :func:`fcntl` function, except that the
- operations are typically defined in the library module :mod:`termios` and the
argument handling is even more complicated.
The parameter *arg* can be one of an integer, absent (treated identically to the
diff --git a/Doc/library/fileinput.rst b/Doc/library/fileinput.rst
index a14e05b..8e70380 100644
--- a/Doc/library/fileinput.rst
+++ b/Doc/library/fileinput.rst
@@ -168,9 +168,3 @@
Usage example: ``fi =
fileinput.FileInput(openhook=fileinput.hook_encoded("iso-8859-1"))``
-
- .. note::
-
- With this hook, :class:`FileInput` might return Unicode strings depending on the
- specified *encoding*.
-
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index 596e8a0..df3e16c 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -129,7 +129,7 @@
different ways:
* If it is a *string*, you must also give the *encoding* (and optionally,
- *errors*) parameters; :func:`bytearray` then converts the Unicode string to
+ *errors*) parameters; :func:`bytearray` then converts the string to
bytes using :meth:`str.encode`.
* If it is an *integer*, the array will have that size and will be
@@ -415,10 +415,9 @@
.. warning::
The default *locals* act as described for function :func:`locals` below:
- modifications to the default *locals* dictionary should not be attempted. Pass
- an explicit *locals* dictionary if you need to see effects of the code on
- *locals* after function :func:`execfile` returns. :func:`exec` cannot be
- used reliably to modify a function's locals.
+ modifications to the default *locals* dictionary should not be attempted.
+ Pass an explicit *locals* dictionary if you need to see effects of the
+ code on *locals* after function :func:`exec` returns.
.. function:: filter(function, iterable)
@@ -805,16 +804,17 @@
:mod:`fileinput`, :mod:`os`, :mod:`os.path`, :mod:`tempfile`, and
:mod:`shutil`.
+
+.. XXX works for bytes too, but should it?
.. function:: ord(c)
Given a string of length one, return an integer representing the Unicode code
- point of the character when the argument is a unicode object, or the value of
- the byte when the argument is an 8-bit string. For example, ``ord('a')`` returns
- the integer ``97``, ``ord(u'\u2020')`` returns ``8224``. This is the inverse of
- :func:`chr` for 8-bit strings and of :func:`unichr` for unicode objects. If a
- unicode argument is given and Python was built with UCS2 Unicode, then the
- character's code point must be in the range [0..65535] inclusive; otherwise the
- string length is two, and a :exc:`TypeError` will be raised.
+ point of the character. For example, ``ord('a')`` returns the integer ``97``
+ and ``ord('\u2020')`` returns ``8224``. This is the inverse of :func:`chr`.
+
+ If the argument length is not one, a :exc:`TypeError` will be raised. (If
+ Python was built with UCS2 Unicode, then the character's code point must be
+ in the range [0..65535] inclusive; otherwise the string length is two!)
.. function:: pow(x, y[, z])
@@ -838,6 +838,22 @@
accidents.)
+.. function:: print([object, ...][, sep=' '][, end='\n'][, file=sys.stdout])
+
+ Print *object*\(s) to the stream *file*, separated by *sep* and followed by
+ *end*. *sep*, *end* and *file*, if present, must be given as keyword
+ arguments.
+
+ All non-keyword arguments are converted to strings like :func:`str` does and
+ written to the stream, separated by *sep* and followed by *end*. Both *sep*
+ and *end* must be strings; they can also be ``None``, which means to use the
+ default values. If no *object* is given, :func:`print` will just write
+ *end*.
+
+ The *file* argument must be an object with a ``write(string)`` method; if it
+ is not present or ``None``, :data:`sys.stdout` will be used.
+
+
.. function:: property([fget[, fset[, fdel[, doc]]]])
Return a property attribute.
diff --git a/Doc/library/gettext.rst b/Doc/library/gettext.rst
index 1940ec9..da8f4f1 100644
--- a/Doc/library/gettext.rst
+++ b/Doc/library/gettext.rst
@@ -136,9 +136,9 @@
greater convenience than the GNU :program:`gettext` API. It is the recommended
way of localizing your Python applications and modules. :mod:`gettext` defines
a "translations" class which implements the parsing of GNU :file:`.mo` format
-files, and has methods for returning either standard 8-bit strings or Unicode
-strings. Instances of this "translations" class can also install themselves in
-the built-in namespace as the function :func:`_`.
+files, and has methods for returning strings. Instances of this "translations"
+class can also install themselves in the built-in namespace as the function
+:func:`_`.
.. function:: find(domain[, localedir[, languages[, all]]])
@@ -257,8 +257,7 @@
.. method:: NullTranslations.ugettext(message)
If a fallback has been set, forward :meth:`ugettext` to the fallback. Otherwise,
- return the translated message as a Unicode string. Overridden in derived
- classes.
+ return the translated message as a string. Overridden in derived classes.
.. method:: NullTranslations.ngettext(singular, plural, n)
@@ -276,7 +275,7 @@
.. method:: NullTranslations.ungettext(singular, plural, n)
If a fallback has been set, forward :meth:`ungettext` to the fallback.
- Otherwise, return the translated message as a Unicode string. Overridden in
+ Otherwise, return the translated message as a string. Overridden in
derived classes.
@@ -347,8 +346,8 @@
``None`` if not found. If the charset encoding is specified, then all message
ids and message strings read from the catalog are converted to Unicode using
this encoding. The :meth:`ugettext` method always returns a Unicode, while the
-:meth:`gettext` returns an encoded 8-bit string. For the message id arguments
-of both methods, either Unicode strings or 8-bit strings containing only
+:meth:`gettext` returns an encoded bytestring. For the message id arguments
+of both methods, either Unicode strings or bytestrings containing only
US-ASCII characters are acceptable. Note that the Unicode version of the
methods (i.e. :meth:`ugettext` and :meth:`ungettext`) are the recommended
interface to use for internationalized Python programs.
@@ -366,7 +365,7 @@
.. method:: GNUTranslations.gettext(message)
Look up the *message* id in the catalog and return the corresponding message
- string, as an 8-bit string encoded with the catalog's charset encoding, if
+ string, as a bytestring encoded with the catalog's charset encoding, if
known. If there is no entry in the catalog for the *message* id, and a fallback
has been set, the look up is forwarded to the fallback's :meth:`gettext` method.
Otherwise, the *message* id is returned.
@@ -382,7 +381,7 @@
.. method:: GNUTranslations.ugettext(message)
Look up the *message* id in the catalog and return the corresponding message
- string, as a Unicode string. If there is no entry in the catalog for the
+ string, as a string. If there is no entry in the catalog for the
*message* id, and a fallback has been set, the look up is forwarded to the
fallback's :meth:`ugettext` method. Otherwise, the *message* id is returned.
@@ -391,7 +390,7 @@
Do a plural-forms lookup of a message id. *singular* is used as the message id
for purposes of lookup in the catalog, while *n* is used to determine which
- plural form to use. The returned message string is an 8-bit string encoded with
+ plural form to use. The returned message string is a bytestring encoded with
the catalog's charset encoding, if known.
If the message id is not found in the catalog, and a fallback is specified, the
@@ -410,7 +409,7 @@
Do a plural-forms lookup of a message id. *singular* is used as the message id
for purposes of lookup in the catalog, while *n* is used to determine which
- plural form to use. The returned message string is a Unicode string.
+ plural form to use. The returned message string is a string.
If the message id is not found in the catalog, and a fallback is specified, the
request is forwarded to the fallback's :meth:`ungettext` method. Otherwise,
diff --git a/Doc/library/imp.rst b/Doc/library/imp.rst
index 831d1a7..ac1b14b 100644
--- a/Doc/library/imp.rst
+++ b/Doc/library/imp.rst
@@ -185,6 +185,19 @@
continue to use the old class definition. The same is true for derived classes.
+.. function:: acquire_lock()
+
+ Acquires the interpreter's import lock for the current thread. This lock should
+ be used by import hooks to ensure thread-safety when importing modules. On
+ platforms without threads, this function does nothing.
+
+
+.. function:: release_lock()
+
+ Release the interpreter's import lock. On platforms without threads, this
+ function does nothing.
+
+
The following constants with integer values, defined in this module, are used to
indicate the search result of :func:`find_module`.
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index 58ed4fa..013ed38 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -177,7 +177,8 @@
Make an iterator that filters elements from iterable returning only those for
which the predicate is ``True``. If *predicate* is ``None``, return the items
- that are true. Equivalent to::
+ that are true. This function is the same as the built-in :func:`filter`
+ function. Equivalent to::
def ifilter(predicate, iterable):
if predicate is None:
@@ -204,7 +205,8 @@
.. function:: imap(function, *iterables)
Make an iterator that computes the function using arguments from each of the
- iterables. Equivalent to::
+ iterables. This function is the same as the built-in :func:`map` function.
+ Equivalent to::
def imap(function, *iterables):
iterables = [iter(it) for it in iterables)
@@ -230,7 +232,7 @@
def islice(iterable, *args):
s = slice(*args)
- it = iter(range(s.start or 0, s.stop or sys.maxsize, s.step or 1))
+ it = range(s.start or 0, s.stop or sys.maxsize, s.step or 1)
nexti = next(it)
for i, element in enumerate(iterable):
if i == nexti:
diff --git a/Doc/library/logging.rst b/Doc/library/logging.rst
index 98e2862..f466df1 100644
--- a/Doc/library/logging.rst
+++ b/Doc/library/logging.rst
@@ -95,7 +95,7 @@
logfiles = glob.glob('%s*' % LOG_FILENAME)
for filename in logfiles:
- print filename
+ print(filename)
The result should be 6 separate files, each with part of the log history for the
application::
@@ -2428,13 +2428,13 @@
HOST = 'localhost'
PORT = 9999
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- print "connecting..."
+ print("connecting...")
s.connect((HOST, PORT))
- print "sending config..."
+ print("sending config...")
s.send(struct.pack(">L", len(data_to_send)))
s.send(data_to_send)
s.close()
- print "complete"
+ print("complete")
More examples
diff --git a/Doc/library/mailbox.rst b/Doc/library/mailbox.rst
index 5bff408..d81897c 100644
--- a/Doc/library/mailbox.rst
+++ b/Doc/library/mailbox.rst
@@ -1643,7 +1643,7 @@
list_names = ('python-list', 'python-dev', 'python-bugs')
- boxes = dict((name, mailbox.mbox('~/email/%s' % name)) for name in list_names)
+ boxes = {name: mailbox.mbox('~/email/%s' % name) for name in list_names}
inbox = mailbox.Maildir('~/Maildir', factory=None)
for key in inbox.iterkeys():
diff --git a/Doc/library/marshal.rst b/Doc/library/marshal.rst
index 8f669b2..fbe3e45 100644
--- a/Doc/library/marshal.rst
+++ b/Doc/library/marshal.rst
@@ -38,7 +38,7 @@
Not all Python object types are supported; in general, only objects whose value
is independent from a particular invocation of Python can be written and read by
this module. The following types are supported: ``None``, integers,
-floating point numbers, strings, Unicode objects, tuples, lists, sets,
+floating point numbers, strings, bytes, bytearrays, tuples, lists, sets,
dictionaries, and code objects, where it should be understood that tuples, lists
and dictionaries are only supported as long as the values contained therein are
themselves supported; and recursive lists and dictionaries should not be written
diff --git a/Doc/library/operator.rst b/Doc/library/operator.rst
index 15f46eb..9a613ab 100644
--- a/Doc/library/operator.rst
+++ b/Doc/library/operator.rst
@@ -93,13 +93,6 @@
Return the bitwise and of *a* and *b*.
-.. function:: div(a, b)
- __div__(a, b)
-
- Return ``a / b`` when ``__future__.division`` is not in effect. This is
- also known as "classic" division.
-
-
.. function:: floordiv(a, b)
__floordiv__(a, b)
@@ -171,8 +164,8 @@
.. function:: truediv(a, b)
__truediv__(a, b)
- Return ``a / b`` when ``__future__.division`` is in effect. This is also
- known as "true" division.
+ Return ``a / b`` where 2/3 is .66 rather than 0. This is also known as
+ "true" division.
.. function:: xor(a, b)
@@ -211,7 +204,7 @@
Remove the value of *a* at index *b*.
-
+
.. function:: delslice(a, b, c)
__delslice__(a, b, c)
@@ -241,14 +234,6 @@
Return ``a * b`` where *a* is a sequence and *b* is an integer.
-.. function:: sequenceIncludes(...)
-
- .. deprecated:: 2.0
- Use :func:`contains` instead.
-
- Alias for :func:`contains`.
-
-
.. function:: setitem(a, b, c)
__setitem__(a, b, c)
@@ -260,6 +245,7 @@
Set the slice of *a* from index *b* to index *c-1* to the sequence *v*.
+
Many operations have an "in-place" version. The following functions provide a
more primitive access to in-place operators than the usual syntax does; for
example, the :term:`statement` ``x += y`` is equivalent to
@@ -285,13 +271,6 @@
``a = iconcat(a, b)`` is equivalent to ``a += b`` for *a* and *b* sequences.
-.. function:: idiv(a, b)
- __idiv__(a, b)
-
- ``a = idiv(a, b)`` is equivalent to ``a /= b`` when ``__future__.division`` is
- not in effect.
-
-
.. function:: ifloordiv(a, b)
__ifloordiv__(a, b)
@@ -350,8 +329,7 @@
.. function:: itruediv(a, b)
__itruediv__(a, b)
- ``a = itruediv(a, b)`` is equivalent to ``a /= b`` when ``__future__.division``
- is in effect.
+ ``a = itruediv(a, b)`` is equivalent to ``a /= b``.
.. function:: ixor(a, b)
@@ -363,10 +341,11 @@
The :mod:`operator` module also defines a few predicates to test the type of
objects.
+.. XXX just remove them?
.. note::
- Be careful not to misinterpret the results of these functions; only
- :func:`isCallable` has any measure of reliability with instance objects.
+ Be careful not to misinterpret the results of these functions; none have any
+ measure of reliability with instance objects.
For example::
>>> class C:
@@ -379,21 +358,10 @@
.. note::
- Python 3 is expected to introduce abstract base classes for
- collection types, so it should be possible to write, for example,
- ``isinstance(obj, collections.Mapping)`` and ``isinstance(obj,
+ Since there are now abstract classes for collection types, you should write,
+ for example, ``isinstance(obj, collections.Mapping)`` and ``isinstance(obj,
collections.Sequence)``.
-.. function:: isCallable(obj)
-
- .. deprecated:: 2.0
- Use the :func:`callable` built-in function instead.
-
- Returns true if the object *obj* can be called like a function, otherwise it
- returns false. True is returned for functions, instance methods, class
- objects, and instance objects which support the :meth:`__call__` method.
-
-
.. function:: isMappingType(obj)
Returns true if the object *obj* supports the mapping interface. This is true for
@@ -492,11 +460,7 @@
+-----------------------+-------------------------+---------------------------------+
| Containment Test | ``obj in seq`` | ``contains(seq, obj)`` |
+-----------------------+-------------------------+---------------------------------+
-| Division | ``a / b`` | ``div(a, b)`` (without |
-| | | ``__future__.division``) |
-+-----------------------+-------------------------+---------------------------------+
-| Division | ``a / b`` | ``truediv(a, b)`` (with |
-| | | ``__future__.division``) |
+| Division | ``a / b`` | ``truediv(a, b)`` |
+-----------------------+-------------------------+---------------------------------+
| Division | ``a // b`` | ``floordiv(a, b)`` |
+-----------------------+-------------------------+---------------------------------+
diff --git a/Doc/library/os.path.rst b/Doc/library/os.path.rst
index 4d7f0a4..c3c56be 100644
--- a/Doc/library/os.path.rst
+++ b/Doc/library/os.path.rst
@@ -288,5 +288,5 @@
.. data:: supports_unicode_filenames
True if arbitrary Unicode strings can be used as file names (within limitations
- imposed by the file system), and if :func:`os.listdir` returns Unicode strings
- for a Unicode argument.
+ imposed by the file system), and if :func:`os.listdir` returns strings that
+ contain characters that cannot be represented by ASCII.
diff --git a/Doc/library/os.rst b/Doc/library/os.rst
index 294da5e..6dc4a63 100644
--- a/Doc/library/os.rst
+++ b/Doc/library/os.rst
@@ -701,13 +701,13 @@
.. function:: getcwd()
- Return a string representing the current working directory. Availability:
- Macintosh, Unix, Windows.
+ Return a bytestring representing the current working directory.
+ Availability: Macintosh, Unix, Windows.
.. function:: getcwdu()
- Return a Unicode object representing the current working directory.
+ Return a string representing the current working directory.
Availability: Macintosh, Unix, Windows.
diff --git a/Doc/library/pickle.rst b/Doc/library/pickle.rst
index 7e04f5b..a9288e6 100644
--- a/Doc/library/pickle.rst
+++ b/Doc/library/pickle.rst
@@ -327,7 +327,7 @@
* integers, floating point numbers, complex numbers
-* normal and Unicode strings
+* strings, bytes, bytearrays
* tuples, lists, sets, and dictionaries containing only picklable objects
@@ -659,7 +659,7 @@
import pickle
data1 = {'a': [1, 2.0, 3, 4+6j],
- 'b': ('string', u'Unicode string'),
+ 'b': ("string", "string using Unicode features \u0394"),
'c': None}
selfref_list = [1, 2, 3]
diff --git a/Doc/library/pkgutil.rst b/Doc/library/pkgutil.rst
index 3ef1354..1a84338 100644
--- a/Doc/library/pkgutil.rst
+++ b/Doc/library/pkgutil.rst
@@ -34,8 +34,7 @@
returned. Items are only appended to the copy at the end.
It is assumed that ``sys.path`` is a sequence. Items of ``sys.path`` that are
- not (Unicode or 8-bit) strings referring to existing directories are ignored.
- Unicode items on ``sys.path`` that cause errors when used as filenames may cause
- this function to raise an exception (in line with :func:`os.path.isdir`
- behavior).
+ not strings referring to existing directories are ignored. Unicode items on
+ ``sys.path`` that cause errors when used as filenames may cause this function
+ to raise an exception (in line with :func:`os.path.isdir` behavior).
diff --git a/Doc/library/re.rst b/Doc/library/re.rst
index 7de088a..5c2935b 100644
--- a/Doc/library/re.rst
+++ b/Doc/library/re.rst
@@ -1153,7 +1153,7 @@
>>> text = "He was carefully disguised but captured quickly by police."
>>> for m in re.finditer(r"\w+ly", text):
- print '%02d-%02d: %s' % (m.start(), m.end(), m.group(0))
+ print('%02d-%02d: %s' % (m.start(), m.end(), m.group(0)))
07-16: carefully
40-47: quickly
diff --git a/Doc/library/simplexmlrpcserver.rst b/Doc/library/simplexmlrpcserver.rst
index ab20ad0..557b525 100644
--- a/Doc/library/simplexmlrpcserver.rst
+++ b/Doc/library/simplexmlrpcserver.rst
@@ -149,7 +149,7 @@
s = xmlrpclib.ServerProxy('http://localhost:8000')
print(s.pow(2,3)) # Returns 2**3 = 8
print(s.add(2,3)) # Returns 5
- print(s.div(5,2)) # Returns 5//2 = 2
+ print(s.mul(5,2)) # Returns 5*2 = 10
# Print list of available methods
print(s.system.listMethods())
diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst
index 02c2fa4..5585934 100644
--- a/Doc/library/sqlite3.rst
+++ b/Doc/library/sqlite3.rst
@@ -184,7 +184,7 @@
Registers a callable to convert the custom Python type *type* into one of
SQLite's supported types. The callable *callable* accepts as single parameter
the Python value, and must return a value of the following types: int,
- float, str (UTF-8 encoded), unicode or buffer.
+ float, str, bytes (UTF-8 encoded) or buffer.
.. function:: complete_statement(sql)
@@ -258,7 +258,7 @@
parameters the function accepts, and *func* is a Python callable that is called
as the SQL function.
- The function can return any of the types supported by SQLite: unicode, str, int,
+ The function can return any of the types supported by SQLite: bytes, str, int,
float, buffer and None.
Example:
@@ -275,7 +275,7 @@
final result of the aggregate.
The ``finalize`` method can return any of the types supported by SQLite:
- unicode, str, int, float, buffer and None.
+ bytes, str, int, float, buffer and None.
Example:
@@ -354,13 +354,13 @@
.. attribute:: Connection.text_factory
Using this attribute you can control what objects are returned for the TEXT data
- type. By default, this attribute is set to :class:`unicode` and the
- :mod:`sqlite3` module will return Unicode objects for TEXT. If you want to
- return bytestrings instead, you can set it to :class:`str`.
+ type. By default, this attribute is set to :class:`str` and the
+ :mod:`sqlite3` module will return strings for TEXT. If you want to
+ return bytestrings instead, you can set it to :class:`bytes`.
- For efficiency reasons, there's also a way to return Unicode objects only for
- non-ASCII data, and bytestrings otherwise. To activate it, set this attribute to
- :const:`sqlite3.OptimizedUnicode`.
+ For efficiency reasons, there's also a way to return :class:`str` objects
+ only for non-ASCII data, and :class:`bytes` otherwise. To activate it, set
+ this attribute to :const:`sqlite3.OptimizedUnicode`.
You can also set it to any other callable that accepts a single bytestring
parameter and returns the resulting object.
@@ -424,7 +424,7 @@
at once. It issues a COMMIT statement first, then executes the SQL script it
gets as a parameter.
- *sql_script* can be a bytestring or a Unicode string.
+ *sql_script* can be an instance of :class:`str` or :class:`bytes`.
Example:
@@ -493,21 +493,21 @@
The following Python types can thus be sent to SQLite without any problem:
-+------------------------+-------------+
-| Python type | SQLite type |
-+========================+=============+
-| ``None`` | NULL |
-+------------------------+-------------+
-| ``int`` | INTEGER |
-+------------------------+-------------+
-| ``float`` | REAL |
-+------------------------+-------------+
-| ``str (UTF8-encoded)`` | TEXT |
-+------------------------+-------------+
-| ``unicode`` | TEXT |
-+------------------------+-------------+
-| ``buffer`` | BLOB |
-+------------------------+-------------+
++-------------------------------+-------------+
+| Python type | SQLite type |
++===============================+=============+
+| ``None`` | NULL |
++-------------------------------+-------------+
+| :class:`int` | INTEGER |
++-------------------------------+-------------+
+| :class:`float` | REAL |
++-------------------------------+-------------+
+| :class:`bytes` (UTF8-encoded) | TEXT |
++-------------------------------+-------------+
+| :class:`str` | TEXT |
++-------------------------------+-------------+
+| :class:`buffer` | BLOB |
++-------------------------------+-------------+
This is how SQLite types are converted to Python types by default:
@@ -520,7 +520,7 @@
+-------------+---------------------------------------------+
| ``REAL`` | float |
+-------------+---------------------------------------------+
-| ``TEXT`` | depends on text_factory, unicode by default |
+| ``TEXT`` | depends on text_factory, str by default |
+-------------+---------------------------------------------+
| ``BLOB`` | buffer |
+-------------+---------------------------------------------+
@@ -537,7 +537,7 @@
As described before, SQLite supports only a limited set of types natively. To
use other Python types with SQLite, you must **adapt** them to one of the
sqlite3 module's supported types for SQLite: one of NoneType, int, float,
-str, unicode, buffer.
+str, bytes, buffer.
The :mod:`sqlite3` module uses Python object adaptation, as described in
:pep:`246` for this. The protocol to use is :class:`PrepareProtocol`.
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst
index 6a2be28..c976007 100644
--- a/Doc/library/stdtypes.rst
+++ b/Doc/library/stdtypes.rst
@@ -2070,13 +2070,13 @@
.. XXX does this still apply?
.. attribute:: file.encoding
- The encoding that this file uses. When Unicode strings are written to a file,
+ The encoding that this file uses. When strings are written to a file,
they will be converted to byte strings using this encoding. In addition, when
the file is connected to a terminal, the attribute gives the encoding that the
terminal is likely to use (that information might be incorrect if the user has
misconfigured the terminal). The attribute is read-only and may not be present
on all file-like objects. It may also be ``None``, in which case the file uses
- the system default encoding for converting Unicode strings.
+ the system default encoding for converting strings.
.. attribute:: file.mode
diff --git a/Doc/library/string.rst b/Doc/library/string.rst
index 7cd28b0..ce5129d 100644
--- a/Doc/library/string.rst
+++ b/Doc/library/string.rst
@@ -538,7 +538,7 @@
String functions
----------------
-The following functions are available to operate on string and Unicode objects.
+The following functions are available to operate on string objects.
They are not available as string methods.
diff --git a/Doc/library/stringio.rst b/Doc/library/stringio.rst
index 192e310..15edfba 100644
--- a/Doc/library/stringio.rst
+++ b/Doc/library/stringio.rst
@@ -1,3 +1,4 @@
+.. XXX this whole file is outdated
:mod:`StringIO` --- Read and write strings as files
===================================================
@@ -9,7 +10,7 @@
This module implements a file-like class, :class:`StringIO`, that reads and
writes a string buffer (also known as *memory files*). See the description of
file objects for operations (section :ref:`bltin-file-objects`). (For
-standard strings, see :class:`str` and :class:`unicode`.)
+standard strings, see :class:`str`.)
.. class:: StringIO([buffer])
@@ -19,20 +20,13 @@
:class:`StringIO` will start empty. In both cases, the initial file position
starts at zero.
- The :class:`StringIO` object can accept either Unicode or 8-bit strings, but
- mixing the two may take some care. If both are used, 8-bit strings that cannot
- be interpreted as 7-bit ASCII (that use the 8th bit) will cause a
- :exc:`UnicodeError` to be raised when :meth:`getvalue` is called.
-
The following methods of :class:`StringIO` objects require special mention:
.. method:: StringIO.getvalue()
Retrieve the entire contents of the "file" at any time before the
- :class:`StringIO` object's :meth:`close` method is called. See the note above
- for information about mixing Unicode and 8-bit strings; such mixing can cause
- this method to raise :exc:`UnicodeError`.
+ :class:`StringIO` object's :meth:`close` method is called.
.. method:: StringIO.close()
@@ -75,11 +69,11 @@
original :mod:`StringIO` module in that case.
Unlike the memory files implemented by the :mod:`StringIO` module, those
-provided by this module are not able to accept Unicode strings that cannot be
-encoded as plain ASCII strings.
+provided by this module are not able to accept strings that cannot be
+encoded in plain ASCII.
-Calling :func:`StringIO` with a Unicode string parameter populates
-the object with the buffer representation of the Unicode string, instead of
+Calling :func:`StringIO` with a string parameter populates
+the object with the buffer representation of the string, instead of
encoding the string.
Another difference from the :mod:`StringIO` module is that calling
diff --git a/Doc/library/traceback.rst b/Doc/library/traceback.rst
index 179e04e..2f29aae 100644
--- a/Doc/library/traceback.rst
+++ b/Doc/library/traceback.rst
@@ -42,7 +42,7 @@
.. function:: print_exc([limit[, file]])
- This is a shorthand for ``print_exception(*sys.exc_info()``.
+ This is a shorthand for ``print_exception(*sys.exc_info())``.
.. function:: format_exc([limit])
@@ -172,26 +172,26 @@
lumberjack()
except:
exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
- print "*** print_tb:"
+ print("*** print_tb:")
traceback.print_tb(exceptionTraceback, limit=1, file=sys.stdout)
- print "*** print_exception:"
+ print("*** print_exception:")
traceback.print_exception(exceptionType, exceptionValue, exceptionTraceback,
limit=2, file=sys.stdout)
- print "*** print_exc:"
+ print("*** print_exc:")
traceback.print_exc()
- print "*** format_exc, first and last line:"
+ print("*** format_exc, first and last line:")
formatted_lines = traceback.format_exc().splitlines()
- print formatted_lines[0]
- print formatted_lines[-1]
- print "*** format_exception:"
- print repr(traceback.format_exception(exceptionType, exceptionValue,
- exceptionTraceback))
- print "*** extract_tb:"
- print repr(traceback.extract_tb(exceptionTraceback))
- print "*** format_tb:"
- print repr(traceback.format_tb(exceptionTraceback))
- print "*** tb_lineno:", traceback.tb_lineno(exceptionTraceback)
- print "*** print_last:"
+ print(formatted_lines[0])
+ print(formatted_lines[-1])
+ print("*** format_exception:")
+ print(repr(traceback.format_exception(exceptionType, exceptionValue,
+ exceptionTraceback)))
+ print("*** extract_tb:")
+ print(repr(traceback.extract_tb(exceptionTraceback)))
+ print("*** format_tb:")
+ print(repr(traceback.format_tb(exceptionTraceback)))
+ print("*** tb_lineno:", traceback.tb_lineno(exceptionTraceback))
+ print("*** print_last:")
traceback.print_last()
@@ -249,8 +249,8 @@
...
>>> def lumberstack():
... traceback.print_stack()
- ... print repr(traceback.extract_stack())
- ... print repr(traceback.format_stack())
+ ... print(repr(traceback.extract_stack()))
+ ... print(repr(traceback.format_stack()))
...
>>> another_function()
File "<doctest>", line 10, in <module>
@@ -261,10 +261,10 @@
traceback.print_stack()
[('<doctest>', 10, '<module>', 'another_function()'),
('<doctest>', 3, 'another_function', 'lumberstack()'),
- ('<doctest>', 7, 'lumberstack', 'print repr(traceback.extract_stack())')]
+ ('<doctest>', 7, 'lumberstack', 'print(repr(traceback.extract_stack()))')]
[' File "<doctest>", line 10, in <module>\n another_function()\n',
' File "<doctest>", line 3, in another_function\n lumberstack()\n',
- ' File "<doctest>", line 8, in lumberstack\n print repr(traceback.format_stack())\n']
+ ' File "<doctest>", line 8, in lumberstack\n print(repr(traceback.format_stack()))\n']
This last example demonstrates the final few formatting functions::
diff --git a/Doc/library/undoc.rst b/Doc/library/undoc.rst
index ae8fae7..78098b0 100644
--- a/Doc/library/undoc.rst
+++ b/Doc/library/undoc.rst
@@ -61,18 +61,6 @@
:synopsis: Rudimentary decoder for AppleSingle format files.
-
-:mod:`buildtools` --- Helper module for BuildApplet and Friends
----------------------------------------------------------------
-
-.. module:: buildtools
- :platform: Mac
- :synopsis: Helper module for BuildApplet, BuildApplication and macfreeze.
-
-
-.. deprecated:: 2.4
-
-
:mod:`icopen` --- Internet Config replacement for :meth:`open`
--------------------------------------------------------------
diff --git a/Doc/library/unicodedata.rst b/Doc/library/unicodedata.rst
index 9a238f1..7a779f6 100644
--- a/Doc/library/unicodedata.rst
+++ b/Doc/library/unicodedata.rst
@@ -27,72 +27,72 @@
.. function:: lookup(name)
Look up character by name. If a character with the given name is found, return
- the corresponding Unicode character. If not found, :exc:`KeyError` is raised.
+ the corresponding character. If not found, :exc:`KeyError` is raised.
-.. function:: name(unichr[, default])
+.. function:: name(chr[, default])
- Returns the name assigned to the Unicode character *unichr* as a string. If no
+ Returns the name assigned to the character *chr* as a string. If no
name is defined, *default* is returned, or, if not given, :exc:`ValueError` is
raised.
-.. function:: decimal(unichr[, default])
+.. function:: decimal(chr[, default])
- Returns the decimal value assigned to the Unicode character *unichr* as integer.
+ Returns the decimal value assigned to the character *chr* as integer.
If no such value is defined, *default* is returned, or, if not given,
:exc:`ValueError` is raised.
-.. function:: digit(unichr[, default])
+.. function:: digit(chr[, default])
- Returns the digit value assigned to the Unicode character *unichr* as integer.
+ Returns the digit value assigned to the character *chr* as integer.
If no such value is defined, *default* is returned, or, if not given,
:exc:`ValueError` is raised.
-.. function:: numeric(unichr[, default])
+.. function:: numeric(chr[, default])
- Returns the numeric value assigned to the Unicode character *unichr* as float.
+ Returns the numeric value assigned to the character *chr* as float.
If no such value is defined, *default* is returned, or, if not given,
:exc:`ValueError` is raised.
-.. function:: category(unichr)
+.. function:: category(chr)
- Returns the general category assigned to the Unicode character *unichr* as
+ Returns the general category assigned to the character *chr* as
string.
-.. function:: bidirectional(unichr)
+.. function:: bidirectional(chr)
- Returns the bidirectional category assigned to the Unicode character *unichr* as
+ Returns the bidirectional category assigned to the character *chr* as
string. If no such value is defined, an empty string is returned.
-.. function:: combining(unichr)
+.. function:: combining(chr)
- Returns the canonical combining class assigned to the Unicode character *unichr*
+ Returns the canonical combining class assigned to the character *chr*
as integer. Returns ``0`` if no combining class is defined.
-.. function:: east_asian_width(unichr)
+.. function:: east_asian_width(chr)
- Returns the east asian width assigned to the Unicode character *unichr* as
+ Returns the east asian width assigned to the character *chr* as
string.
-.. function:: mirrored(unichr)
+.. function:: mirrored(chr)
- Returns the mirrored property assigned to the Unicode character *unichr* as
+ Returns the mirrored property assigned to the character *chr* as
integer. Returns ``1`` if the character has been identified as a "mirrored"
character in bidirectional text, ``0`` otherwise.
-.. function:: decomposition(unichr)
+.. function:: decomposition(chr)
- Returns the character decomposition mapping assigned to the Unicode character
- *unichr* as string. An empty string is returned in case no such mapping is
+ Returns the character decomposition mapping assigned to the character
+ *chr* as string. An empty string is returned in case no such mapping is
defined.
@@ -146,16 +146,16 @@
>>> unicodedata.lookup('LEFT CURLY BRACKET')
u'{'
- >>> unicodedata.name(u'/')
+ >>> unicodedata.name('/')
'SOLIDUS'
- >>> unicodedata.decimal(u'9')
+ >>> unicodedata.decimal('9')
9
- >>> unicodedata.decimal(u'a')
+ >>> unicodedata.decimal('a')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: not a decimal
- >>> unicodedata.category(u'A') # 'L'etter, 'u'ppercase
+ >>> unicodedata.category('A') # 'L'etter, 'u'ppercase
'Lu'
- >>> unicodedata.bidirectional(u'\u0660') # 'A'rabic, 'N'umber
+ >>> unicodedata.bidirectional('\u0660') # 'A'rabic, 'N'umber
'AN'
diff --git a/Doc/library/userdict.rst b/Doc/library/userdict.rst
index 0490118..2d66270 100644
--- a/Doc/library/userdict.rst
+++ b/Doc/library/userdict.rst
@@ -146,7 +146,7 @@
behaviors to strings.
It should be noted that these classes are highly inefficient compared to real
-string or Unicode objects; this is especially the case for
+string or bytes objects; this is especially the case for
:class:`MutableString`.
The :mod:`UserString` module defines the following classes:
@@ -158,9 +158,9 @@
content is kept in a regular string or Unicode string object, which is
accessible via the :attr:`data` attribute of :class:`UserString` instances. The
instance's contents are initially set to a copy of *sequence*. *sequence* can
- be either a regular Python string or Unicode string, an instance of
- :class:`UserString` (or a subclass) or an arbitrary sequence which can be
- converted into a string using the built-in :func:`str` function.
+ be an instance of :class:`bytes`, :class:`str`, :class:`UserString` (or a
+ subclass) or an arbitrary sequence which can be converted into a string using
+ the built-in :func:`str` function.
.. class:: MutableString([sequence])
@@ -173,13 +173,13 @@
mutable object as dictionary key, which would be otherwise very error prone and
hard to track down.
-In addition to supporting the methods and operations of string and Unicode
+In addition to supporting the methods and operations of bytes and string
objects (see section :ref:`string-methods`), :class:`UserString` instances
provide the following attribute:
.. attribute:: MutableString.data
- A real Python string or Unicode object used to store the content of the
+ A real Python string or bytes object used to store the content of the
:class:`UserString` class.
diff --git a/Doc/library/wsgiref.rst b/Doc/library/wsgiref.rst
index e43d850..55d780f 100644
--- a/Doc/library/wsgiref.rst
+++ b/Doc/library/wsgiref.rst
@@ -169,7 +169,7 @@
wrapper = FileWrapper(filelike, blksize=5)
for chunk in wrapper:
- print chunk
+ print(chunk)
@@ -428,7 +428,7 @@
validator_app = validator(simple_app)
httpd = make_server('', 8000, validator_app)
- print "Listening on port 8000...."
+ print("Listening on port 8000....")
httpd.serve_forever()
@@ -720,7 +720,7 @@
return ["Hello World"]
httpd = make_server('', 8000, hello_world_app)
- print "Serving on port 8000..."
+ print("Serving on port 8000...")
# Serve until process is killed
httpd.serve_forever()
diff --git a/Doc/library/xml.dom.minidom.rst b/Doc/library/xml.dom.minidom.rst
index 84a95f1..75f381e 100644
--- a/Doc/library/xml.dom.minidom.rst
+++ b/Doc/library/xml.dom.minidom.rst
@@ -147,10 +147,10 @@
document. Encoding this string in an encoding other than UTF-8 is likely
incorrect, since UTF-8 is the default encoding of XML.
- With an explicit *encoding* argument, the result is a byte string in the
- specified encoding. It is recommended that this argument is always specified. To
- avoid :exc:`UnicodeError` exceptions in case of unrepresentable text data, the
- encoding argument should be specified as "utf-8".
+ With an explicit *encoding* argument, the result is a :class:`bytes` object
+ in the specified encoding. It is recommended that this argument is always
+ specified. To avoid :exc:`UnicodeError` exceptions in case of unrepresentable
+ text data, the encoding argument should be specified as "utf-8".
.. method:: Node.toprettyxml([indent[, newl[, encoding]]])
@@ -212,7 +212,7 @@
``boolean`` all map to Python integer objects.
* The type ``DOMString`` maps to Python strings. :mod:`xml.dom.minidom` supports
- either byte or Unicode strings, but will normally produce Unicode strings.
+ either bytes or strings, but will normally produce strings.
Values of type ``DOMString`` may also be ``None`` where allowed to have the IDL
``null`` value by the DOM specification from the W3C.
diff --git a/Doc/library/xml.dom.rst b/Doc/library/xml.dom.rst
index 76edd43..5ddd6a8 100644
--- a/Doc/library/xml.dom.rst
+++ b/Doc/library/xml.dom.rst
@@ -985,7 +985,7 @@
+------------------+-------------------------------------------+
Additionally, the :class:`DOMString` defined in the recommendation is mapped to
-a Python string or Unicode string. Applications should be able to handle
+a bytes or string object. Applications should be able to handle
Unicode whenever a string is returned from the DOM.
The IDL ``null`` value is mapped to ``None``, which may be accepted or
diff --git a/Doc/library/xml.etree.elementtree.rst b/Doc/library/xml.etree.elementtree.rst
index 172a2a0..44c82e0 100644
--- a/Doc/library/xml.etree.elementtree.rst
+++ b/Doc/library/xml.etree.elementtree.rst
@@ -43,10 +43,11 @@
.. function:: Comment([text])
- Comment element factory. This factory function creates a special element that
- will be serialized as an XML comment. The comment string can be either an 8-bit
- ASCII string or a Unicode string. *text* is a string containing the comment
- string. Returns an element instance representing a comment.
+ Comment element factory. This factory function creates a special element
+ that will be serialized as an XML comment. The comment string can be either
+ an ASCII-only :class:`bytes` object or a :class:`str` object. *text* is a
+ string containing the comment string. Returns an element instance
+ representing a comment.
.. function:: dump(elem)
@@ -67,10 +68,11 @@
dependent, but it will always be compatible with the _ElementInterface class in
this module.
- The element name, attribute names, and attribute values can be either 8-bit
- ASCII strings or Unicode strings. *tag* is the element name. *attrib* is an
- optional dictionary, containing element attributes. *extra* contains additional
- attributes, given as keyword arguments. Returns an element instance.
+ The element name, attribute names, and attribute values can be either an
+ ASCII-only :class:`bytes` object or a :class:`str` object. *tag* is the
+ element name. *attrib* is an optional dictionary, containing element
+ attributes. *extra* contains additional attributes, given as keyword
+ arguments. Returns an element instance.
.. function:: fromstring(text)
@@ -114,11 +116,11 @@
Subelement factory. This function creates an element instance, and appends it
to an existing element.
- The element name, attribute names, and attribute values can be either 8-bit
- ASCII strings or Unicode strings. *parent* is the parent element. *tag* is the
- subelement name. *attrib* is an optional dictionary, containing element
- attributes. *extra* contains additional attributes, given as keyword arguments.
- Returns an element instance.
+ The element name, attribute names, and attribute values can be an ASCII-only
+ :class:`bytes` object or a :class:`str` object. *parent* is the parent
+ element. *tag* is the subelement name. *attrib* is an optional dictionary,
+ containing element attributes. *extra* contains additional attributes, given
+ as keyword arguments. Returns an element instance.
.. function:: tostring(element[, encoding])
@@ -275,7 +277,7 @@
with subelements: :meth:`__delitem__`, :meth:`__getitem__`, :meth:`__setitem__`,
:meth:`__len__`.
-Caution: Because Element objects do not define a :meth:`__nonzero__` method,
+Caution: Because Element objects do not define a :meth:`__bool__` method,
elements with no subelements will test as ``False``. ::
element = root.find('foo')
@@ -426,7 +428,7 @@
.. method:: TreeBuilder.data(data)
Adds text to the current element. *data* is a string. This should be either an
- 8-bit string containing ASCII text, or a Unicode string.
+ ASCII-only :class:`bytes` object or a :class:`str` object.
.. method:: TreeBuilder.end(tag)
diff --git a/Doc/library/xml.sax.handler.rst b/Doc/library/xml.sax.handler.rst
index c31efd8..c7dbdb5 100644
--- a/Doc/library/xml.sax.handler.rst
+++ b/Doc/library/xml.sax.handler.rst
@@ -281,8 +281,8 @@
must come from the same external entity so that the Locator provides useful
information.
- *content* may be a Unicode string or a byte string; the ``expat`` reader module
- produces always Unicode strings.
+ *content* may be a string or bytes instance; the ``expat`` reader module
+ always produces strings.
.. note::
diff --git a/Doc/library/xml.sax.reader.rst b/Doc/library/xml.sax.reader.rst
index 5994371..5d0b0dd 100644
--- a/Doc/library/xml.sax.reader.rst
+++ b/Doc/library/xml.sax.reader.rst
@@ -307,7 +307,7 @@
.. method:: InputSource.setCharacterStream(charfile)
Set the character stream for this input source. (The stream must be a Python 1.6
- Unicode-wrapped file-like that performs conversion to Unicode strings.)
+ Unicode-wrapped file-like that performs conversion to strings.)
If there is a character stream specified, the SAX parser will ignore any byte
stream and will not attempt to open a URI connection to the system identifier.
diff --git a/Doc/library/xmlrpclib.rst b/Doc/library/xmlrpclib.rst
index 82ce1da..dd06c0a 100644
--- a/Doc/library/xmlrpclib.rst
+++ b/Doc/library/xmlrpclib.rst
@@ -194,7 +194,7 @@
return n%2 == 0
server = SimpleXMLRPCServer(("localhost", 8000))
- print "Listening on port 8000..."
+ print("Listening on port 8000...")
server.register_function(is_even, "is_even")
server.serve_forever()
@@ -203,8 +203,8 @@
import xmlrpclib
proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
- print "3 is even: %s" % str(proxy.is_even(3))
- print "100 is even: %s" % str(proxy.is_even(100))
+ print("3 is even: %s" % str(proxy.is_even(3)))
+ print("100 is even: %s" % str(proxy.is_even(100)))
.. _datetime-objects:
@@ -241,7 +241,7 @@
return xmlrpclib.DateTime(today)
server = SimpleXMLRPCServer(("localhost", 8000))
- print "Listening on port 8000..."
+ print("Listening on port 8000...")
server.register_function(today, "today")
server.serve_forever()
@@ -255,7 +255,7 @@
today = proxy.today()
# convert the ISO8601 string to a datetime object
converted = datetime.datetime.strptime(today.value, "%Y%m%dT%H:%M:%S")
- print "Today: %s" % converted.strftime("%d.%m.%Y, %H:%M")
+ print("Today: %s" % converted.strftime("%d.%m.%Y, %H:%M"))
.. _binary-objects:
@@ -300,7 +300,7 @@
handle.close()
server = SimpleXMLRPCServer(("localhost", 8000))
- print "Listening on port 8000..."
+ print("Listening on port 8000...")
server.register_function(python_logo, 'python_logo')
server.serve_forever()
@@ -343,7 +343,7 @@
return x+y+0j
server = SimpleXMLRPCServer(("localhost", 8000))
- print "Listening on port 8000..."
+ print("Listening on port 8000...")
server.register_function(add, 'add')
server.serve_forever()
@@ -356,9 +356,9 @@
try:
proxy.add(2, 5)
except xmlrpclib.Fault, err:
- print "A fault occured"
- print "Fault code: %d" % err.faultCode
- print "Fault string: %s" % err.faultString
+ print("A fault occured")
+ print("Fault code: %d" % err.faultCode)
+ print("Fault string: %s" % err.faultString)
@@ -403,11 +403,11 @@
try:
proxy.some_method()
except xmlrpclib.ProtocolError, err:
- print "A protocol error occured"
- print "URL: %s" % err.url
- print "HTTP/HTTPS headers: %s" % err.headers
- print "Error code: %d" % err.errcode
- print "Error message: %s" % err.errmsg
+ print("A protocol error occured")
+ print("URL: %s" % err.url)
+ print("HTTP/HTTPS headers: %s" % err.headers)
+ print("Error code: %d" % err.errcode)
+ print("Error message: %s" % err.errmsg)
MultiCall Objects
-----------------
@@ -444,7 +444,7 @@
# A simple server with simple arithmetic functions
server = SimpleXMLRPCServer(("localhost", 8000))
- print "Listening on port 8000..."
+ print("Listening on port 8000...")
server.register_multicall_functions()
server.register_function(add, 'add')
server.register_function(subtract, 'subtract')
@@ -464,7 +464,7 @@
multicall.divide(7,3)
result = multicall()
- print "7+3=%d, 7-3=%d, 7*3=%d, 7/3=%d" % tuple(result)
+ print("7+3=%d, 7-3=%d, 7*3=%d, 7/3=%d" % tuple(result))
Convenience Functions