summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorSebastian Pedersen <31063917+SebastianGPedersen@users.noreply.github.com>2020-04-13 23:07:56 (GMT)
committerGitHub <noreply@github.com>2020-04-13 23:07:56 (GMT)
commita1a0eb4a394a5ac7a8422616ce1ee4125a3ef74f (patch)
treedfc13bcfb05cc9bd76cae41d04f11de1785c3bf2 /Doc/library
parent258f5179f9494189e6a80311c86981d2a88ba9d6 (diff)
downloadcpython-a1a0eb4a394a5ac7a8422616ce1ee4125a3ef74f.zip
cpython-a1a0eb4a394a5ac7a8422616ce1ee4125a3ef74f.tar.gz
cpython-a1a0eb4a394a5ac7a8422616ce1ee4125a3ef74f.tar.bz2
bpo-39380: Change ftplib encoding from latin-1 to utf-8 (GH-18048)
Add the encoding in ftplib.FTP and ftplib.FTP_TLS to the constructor as keyword-only and change the default from "latin-1" to "utf-8" to follow RFC 2640.
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/ftplib.rst33
1 files changed, 20 insertions, 13 deletions
diff --git a/Doc/library/ftplib.rst b/Doc/library/ftplib.rst
index a4bb695..f4d4cdf 100644
--- a/Doc/library/ftplib.rst
+++ b/Doc/library/ftplib.rst
@@ -19,6 +19,8 @@ as mirroring other FTP servers. It is also used by the module
:mod:`urllib.request` to handle URLs that use FTP. For more information on FTP
(File Transfer Protocol), see Internet :rfc:`959`.
+The default encoding is UTF-8, following :rfc:`2640`.
+
Here's a sample session using the :mod:`ftplib` module::
>>> from ftplib import FTP
@@ -41,7 +43,7 @@ Here's a sample session using the :mod:`ftplib` module::
The module defines the following items:
-.. class:: FTP(host='', user='', passwd='', acct='', timeout=None, source_address=None)
+.. class:: FTP(host='', user='', passwd='', acct='', timeout=None, source_address=None, *, encoding='utf-8')
Return a new instance of the :class:`FTP` class. When *host* is given, the
method call ``connect(host)`` is made. When *user* is given, additionally
@@ -50,7 +52,8 @@ The module defines the following items:
parameter specifies a timeout in seconds for blocking operations like the
connection attempt (if is not specified, the global default timeout setting
will be used). *source_address* is a 2-tuple ``(host, port)`` for the socket
- to bind to as its source address before connecting.
+ to bind to as its source address before connecting. The *encoding* parameter
+ specifies the encoding for directories and filenames.
The :class:`FTP` class supports the :keyword:`with` statement, e.g.:
@@ -74,9 +77,11 @@ The module defines the following items:
.. versionchanged:: 3.9
If the *timeout* parameter is set to be zero, it will raise a
- :class:`ValueError` to prevent the creation of a non-blocking socket
+ :class:`ValueError` to prevent the creation of a non-blocking socket.
+ The *encoding* parameter was added, and the default was changed from
+ Latin-1 to UTF-8 to follow :rfc:`2640`.
-.. class:: FTP_TLS(host='', user='', passwd='', acct='', keyfile=None, certfile=None, context=None, timeout=None, source_address=None)
+.. class:: FTP_TLS(host='', user='', passwd='', acct='', keyfile=None, certfile=None, context=None, timeout=None, source_address=None, *, encoding='utf-8')
A :class:`FTP` subclass which adds TLS support to FTP as described in
:rfc:`4217`.
@@ -110,7 +115,9 @@ The module defines the following items:
.. versionchanged:: 3.9
If the *timeout* parameter is set to be zero, it will raise a
- :class:`ValueError` to prevent the creation of a non-blocking socket
+ :class:`ValueError` to prevent the creation of a non-blocking socket.
+ The *encoding* parameter was added, and the default was changed from
+ Latin-1 to UTF-8 to follow :rfc:`2640`.
Here's a sample session using the :class:`FTP_TLS` class::
@@ -259,9 +266,10 @@ followed by ``lines`` for the text version or ``binary`` for the binary version.
.. method:: FTP.retrlines(cmd, callback=None)
- Retrieve a file or directory listing in ASCII transfer mode. *cmd* should be
- an appropriate ``RETR`` command (see :meth:`retrbinary`) or a command such as
- ``LIST`` or ``NLST`` (usually just the string ``'LIST'``).
+ Retrieve a file or directory listing in the encoding specified by the
+ *encoding* parameter at initialization.
+ *cmd* should be an appropriate ``RETR`` command (see :meth:`retrbinary`) or
+ a command such as ``LIST`` or ``NLST`` (usually just the string ``'LIST'``).
``LIST`` retrieves a list of files and information about those files.
``NLST`` retrieves a list of file names.
The *callback* function is called for each line with a string argument
@@ -291,7 +299,7 @@ followed by ``lines`` for the text version or ``binary`` for the binary version.
.. method:: FTP.storlines(cmd, fp, callback=None)
- Store a file in ASCII transfer mode. *cmd* should be an appropriate
+ Store a file in line mode. *cmd* should be an appropriate
``STOR`` command (see :meth:`storbinary`). Lines are read until EOF from the
:term:`file object` *fp* (opened in binary mode) using its :meth:`~io.IOBase.readline`
method to provide the data to be stored. *callback* is an optional single
@@ -309,10 +317,9 @@ followed by ``lines`` for the text version or ``binary`` for the binary version.
If optional *rest* is given, a ``REST`` command is sent to the server, passing
*rest* as an argument. *rest* is usually a byte offset into the requested file,
telling the server to restart sending the file's bytes at the requested offset,
- skipping over the initial bytes. Note however that :rfc:`959` requires only that
- *rest* be a string containing characters in the printable range from ASCII code
- 33 to ASCII code 126. The :meth:`transfercmd` method, therefore, converts
- *rest* to a string, but no check is performed on the string's contents. If the
+ skipping over the initial bytes. Note however that the :meth:`transfercmd`
+ method converts *rest* to a string with the *encoding* parameter specified
+ at initialization, but no check is performed on the string's contents. If the
server does not recognize the ``REST`` command, an :exc:`error_reply` exception
will be raised. If this happens, simply call :meth:`transfercmd` without a
*rest* argument.