Docs: mark up FTP.connect() and FTP.login() with param lists (#114395)

Use rst substitutions to reduce raw text duplication.

Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This commit is contained in:
Erlend E. Aasland 2024-01-23 14:57:23 +01:00 committed by GitHub
parent 5277d4c7db
commit 01105c7c4f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -55,38 +55,56 @@ Reference
FTP objects FTP objects
^^^^^^^^^^^ ^^^^^^^^^^^
.. class:: FTP(host='', user='', passwd='', acct='', timeout=None, \ .. Use substitutions for some param docs so we don't need to repeat them
source_address=None, *, encoding='utf-8') in multiple places.
Return a new instance of the :class:`FTP` class. .. |param_doc_user| replace::
When *host* is given, the method call :meth:`connect(host) <connect>` The username to log in with (default: ``'anonymous'``).
is made by the constructor.
When *user* is given, additionally the method call
:meth:`login(user, passwd, acct) <connect>` is made.
:param str host: .. |param_doc_passwd| replace::
The hostname to connect to.
:param str user:
The username to log in with.
If empty string, ``"anonymous"`` is used.
:param str passwd:
The password to use when logging in. The password to use when logging in.
If not given, and if *passwd* is the empty string or ``"-"``, If not given, and if *passwd* is the empty string or ``"-"``,
a password will be automatically generated. a password will be automatically generated.
.. Ideally, we'd like to use the :rfc: directive, but Sphinx will not allow it.
.. |param_doc_acct| replace::
Account information to be used for the ``ACCT`` FTP command.
Few systems implement this.
See `RFC-959 <https://datatracker.ietf.org/doc/html/rfc959.html>`__
for more details.
.. |param_doc_source_address| replace::
A 2-tuple ``(host, port)`` for the socket to bind to as its
source address before connecting.
.. class:: FTP(host='', user='', passwd='', acct='', timeout=None, \
source_address=None, *, encoding='utf-8')
Return a new instance of the :class:`FTP` class.
:param str host:
The hostname to connect to.
If given, :code:`connect(host)` is implicitly called by the constructor.
:param str user:
|param_doc_user|
If given, :code:`login(host, passwd, acct)` is implicitly called
by the constructor.
:param str passwd:
|param_doc_passwd|
:param str acct: :param str acct:
Account information; see the ACCT FTP command. |param_doc_acct|
:param timeout: :param timeout:
A timeout in seconds for blocking operations like :meth:`connect`. A timeout in seconds for blocking operations like :meth:`connect`
If not specified, the global default timeout setting will be used. (default: the global default timeout setting).
:type timeout: int | None :type timeout: int | None
:param source_address: :param source_address:
*source_address* is a 2-tuple ``(host, port)`` for the socket |param_doc_source_address|
to bind to as its source address before connecting.
:type source_address: tuple | None :type source_address: tuple | None
:param str encoding: :param str encoding:
@ -140,17 +158,29 @@ FTP objects
.. method:: FTP.connect(host='', port=0, timeout=None, source_address=None) .. method:: FTP.connect(host='', port=0, timeout=None, source_address=None)
Connect to the given host and port. The default port number is ``21``, as Connect to the given host and port.
specified by the FTP protocol specification. It is rarely needed to specify a This function should be called only once for each instance;
different port number. This function should be called only once for each it should not be called if a *host* argument was given
instance; it should not be called at all if a host was given when the instance when the :class:`FTP` instance was created.
was created. All other methods can only be used after a connection has been All other :class:`!FTP` methods can only be called
made. after a connection has successfully been made.
The optional *timeout* parameter specifies a timeout in seconds for the
connection attempt. If no *timeout* is passed, the global default timeout :param str host:
setting will be used. The host to connect to.
*source_address* is a 2-tuple ``(host, port)`` for the socket to bind to as
its source address before connecting. :param int port:
The TCP port to connect to (default: ``21``,
as specified by the FTP protocol specification).
It is rarely needed to specify a different port number.
:param timeout:
A timeout in seconds for the connection attempt
(default: the global default timeout setting).
:type timeout: int | None
:param source_address:
|param_doc_source_address|
:type source_address: tuple | None
.. audit-event:: ftplib.connect self,host,port ftplib.FTP.connect .. audit-event:: ftplib.connect self,host,port ftplib.FTP.connect
@ -167,14 +197,21 @@ FTP objects
.. method:: FTP.login(user='anonymous', passwd='', acct='') .. method:: FTP.login(user='anonymous', passwd='', acct='')
Log in as the given *user*. The *passwd* and *acct* parameters are optional and Log on to the connected FTP server.
default to the empty string. If no *user* is specified, it defaults to This function should be called only once for each instance,
``'anonymous'``. If *user* is ``'anonymous'``, the default *passwd* is after a connection has been established;
``'anonymous@'``. This function should be called only once for each instance, it should not be called if the *host* and *user* arguments were given
after a connection has been established; it should not be called at all if a when the :class:`FTP` instance was created.
host and user were given when the instance was created. Most FTP commands are Most FTP commands are only allowed after the client has logged in.
only allowed after the client has logged in. The *acct* parameter supplies
"accounting information"; few systems implement this. :param str user:
|param_doc_user|
:param str passwd:
|param_doc_passwd|
:param str acct:
|param_doc_acct|
.. method:: FTP.abort() .. method:: FTP.abort()