From 6df2299719625e496f8716e35a935e429aab646f Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Thu, 26 Aug 2021 09:05:57 -0400 Subject: [PATCH 1/7] Fix getfqdn() docstring and docs --- Doc/library/socket.rst | 5 ++--- Lib/socket.py | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst index 95c7d7e0699f01..7c83cfe378c3b3 100755 --- a/Doc/library/socket.rst +++ b/Doc/library/socket.rst @@ -807,9 +807,8 @@ The :mod:`socket` module also offers various network-related services: Return a fully qualified domain name for *name*. If *name* is omitted or empty, it is interpreted as the local host. To find the fully qualified name, the hostname returned by :func:`gethostbyaddr` is checked, followed by aliases for the - host, if available. The first name which includes a period is selected. In - case no fully qualified domain name is available, the hostname as returned by - :func:`gethostname` is returned. + host, if available. The first name which includes a period is selected. If *name* is empty + or is ``'0.0.0.0'``, hostname from :func:`gethostname` is returned. .. function:: gethostbyname(hostname) diff --git a/Lib/socket.py b/Lib/socket.py index a64ae400ce9883..912ab9da16542b 100755 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -782,8 +782,8 @@ def getfqdn(name=''): An empty argument is interpreted as meaning the local host. First the hostname returned by gethostbyaddr() is checked, then - possibly existing aliases. In case no FQDN is available, hostname - from gethostname() is returned. + possibly existing aliases. If `name` is empty or is '0.0.0.0', + hostname from gethostname() is returned. """ name = name.strip() if not name or name == '0.0.0.0': From dfe540afd1a57c2fa3f1f3ed6e73a0c64e9e6ebe Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Thu, 26 Aug 2021 09:17:44 -0400 Subject: [PATCH 2/7] update for accuracy --- Doc/library/socket.rst | 5 +++-- Lib/socket.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst index 7c83cfe378c3b3..0abe643f2c39a4 100755 --- a/Doc/library/socket.rst +++ b/Doc/library/socket.rst @@ -807,8 +807,9 @@ The :mod:`socket` module also offers various network-related services: Return a fully qualified domain name for *name*. If *name* is omitted or empty, it is interpreted as the local host. To find the fully qualified name, the hostname returned by :func:`gethostbyaddr` is checked, followed by aliases for the - host, if available. The first name which includes a period is selected. If *name* is empty - or is ``'0.0.0.0'``, hostname from :func:`gethostname` is returned. + host, if available. The first name which includes a period is selected. If that logic + fails and *name* is empty or is ``'0.0.0.0'``, hostname from :func:`gethostname` is + returned. .. function:: gethostbyname(hostname) diff --git a/Lib/socket.py b/Lib/socket.py index 912ab9da16542b..8a8bbd88a20a9f 100755 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -782,8 +782,8 @@ def getfqdn(name=''): An empty argument is interpreted as meaning the local host. First the hostname returned by gethostbyaddr() is checked, then - possibly existing aliases. If `name` is empty or is '0.0.0.0', - hostname from gethostname() is returned. + possibly existing aliases. If that logic fails and `name` is empty or is + '0.0.0.0', hostname from gethostname() is returned. """ name = name.strip() if not name or name == '0.0.0.0': From 04eebb34618867ed1596eda1f4bd0986bad1a277 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Thu, 26 Aug 2021 09:38:45 -0400 Subject: [PATCH 3/7] add the note on fallback logic --- Doc/library/socket.rst | 6 +++--- Lib/socket.py | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst index 0abe643f2c39a4..e986093f3f6288 100755 --- a/Doc/library/socket.rst +++ b/Doc/library/socket.rst @@ -807,9 +807,9 @@ The :mod:`socket` module also offers various network-related services: Return a fully qualified domain name for *name*. If *name* is omitted or empty, it is interpreted as the local host. To find the fully qualified name, the hostname returned by :func:`gethostbyaddr` is checked, followed by aliases for the - host, if available. The first name which includes a period is selected. If that logic - fails and *name* is empty or is ``'0.0.0.0'``, hostname from :func:`gethostname` is - returned. + host, if available. The first name which includes a period is selected. If FQDN is not + available and *name* is empty or is ``'0.0.0.0'``, hostname from :func:`gethostname` is + returned. Otherwise, *name* is returned unchanged. .. function:: gethostbyname(hostname) diff --git a/Lib/socket.py b/Lib/socket.py index 8a8bbd88a20a9f..2a2e15ac8f073c 100755 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -783,7 +783,8 @@ def getfqdn(name=''): First the hostname returned by gethostbyaddr() is checked, then possibly existing aliases. If that logic fails and `name` is empty or is - '0.0.0.0', hostname from gethostname() is returned. + '0.0.0.0', hostname from gethostname() is returned. Otherwise, *name* is + returned unchanged. """ name = name.strip() if not name or name == '0.0.0.0': From 3730b48403ddce91989f1d276c20af58d111bc6b Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Thu, 26 Aug 2021 11:22:38 -0400 Subject: [PATCH 4/7] use consistent quoting for name in docstring --- Lib/socket.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/socket.py b/Lib/socket.py index 2a2e15ac8f073c..e5d8d8d14cec03 100755 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -783,7 +783,7 @@ def getfqdn(name=''): First the hostname returned by gethostbyaddr() is checked, then possibly existing aliases. If that logic fails and `name` is empty or is - '0.0.0.0', hostname from gethostname() is returned. Otherwise, *name* is + '0.0.0.0', hostname from gethostname() is returned. Otherwise, `name` is returned unchanged. """ name = name.strip() From a17e0761db6aa033b5f406fc304ee7371a418bc8 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Thu, 26 Aug 2021 12:32:25 -0400 Subject: [PATCH 5/7] Update Lib/socket.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ɓukasz Langa --- Lib/socket.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/socket.py b/Lib/socket.py index e5d8d8d14cec03..ef82c496cb85a4 100755 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -782,9 +782,9 @@ def getfqdn(name=''): An empty argument is interpreted as meaning the local host. First the hostname returned by gethostbyaddr() is checked, then - possibly existing aliases. If that logic fails and `name` is empty or is - '0.0.0.0', hostname from gethostname() is returned. Otherwise, `name` is - returned unchanged. + possibly existing aliases. In case no FQDN is available and `name` + was given, it is returned unchanged. If `name` was empty or '0.0.0.0', + hostname from gethostname() is returned. """ name = name.strip() if not name or name == '0.0.0.0': From 0791bd9538e39a598e4159a41587645e50e4420f Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Thu, 26 Aug 2021 13:33:54 -0400 Subject: [PATCH 6/7] updated rst paragraph per comments --- Doc/library/socket.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst index e986093f3f6288..5840741aca2e15 100755 --- a/Doc/library/socket.rst +++ b/Doc/library/socket.rst @@ -807,10 +807,10 @@ The :mod:`socket` module also offers various network-related services: Return a fully qualified domain name for *name*. If *name* is omitted or empty, it is interpreted as the local host. To find the fully qualified name, the hostname returned by :func:`gethostbyaddr` is checked, followed by aliases for the - host, if available. The first name which includes a period is selected. If FQDN is not - available and *name* is empty or is ``'0.0.0.0'``, hostname from :func:`gethostname` is - returned. Otherwise, *name* is returned unchanged. - + host, if available. The first name which includes a period is selected. In + case no fully qualified domain name is available and *name* was provided, + it is returned unchanged. If *name* was empty or equal to ``'0.0.0.0'``, + the hostname from :func:`gethostname` is returned. .. function:: gethostbyname(hostname) From 5f7485769329f42851ca5b1dda5103789f5855b5 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Thu, 26 Aug 2021 13:34:48 -0400 Subject: [PATCH 7/7] re-add newline --- Doc/library/socket.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst index 5840741aca2e15..d668c6b7972717 100755 --- a/Doc/library/socket.rst +++ b/Doc/library/socket.rst @@ -812,6 +812,7 @@ The :mod:`socket` module also offers various network-related services: it is returned unchanged. If *name* was empty or equal to ``'0.0.0.0'``, the hostname from :func:`gethostname` is returned. + .. function:: gethostbyname(hostname) Translate a host name to IPv4 address format. The IPv4 address is returned as a