mirror of https://github.com/python/cpython
updated occurences of fqdn algorithm (closes patch #101197)
This commit is contained in:
parent
77c9f50422
commit
2d2785aad1
|
@ -93,19 +93,7 @@ class HTTPServer(SocketServer.TCPServer):
|
||||||
"""Override server_bind to store the server name."""
|
"""Override server_bind to store the server name."""
|
||||||
SocketServer.TCPServer.server_bind(self)
|
SocketServer.TCPServer.server_bind(self)
|
||||||
host, port = self.socket.getsockname()
|
host, port = self.socket.getsockname()
|
||||||
if not host or host == '0.0.0.0':
|
self.server_name = socket.getfqdn(host)
|
||||||
host = socket.gethostname()
|
|
||||||
try:
|
|
||||||
hostname, hostnames, hostaddrs = socket.gethostbyaddr(host)
|
|
||||||
except socket.error:
|
|
||||||
hostname = host
|
|
||||||
else:
|
|
||||||
if '.' not in hostname:
|
|
||||||
for host in hostnames:
|
|
||||||
if '.' in host:
|
|
||||||
hostname = host
|
|
||||||
break
|
|
||||||
self.server_name = hostname
|
|
||||||
self.server_port = port
|
self.server_port = port
|
||||||
|
|
||||||
|
|
||||||
|
@ -418,16 +406,8 @@ class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
(host, port) = self.client_address
|
host, port = self.client_address
|
||||||
try:
|
return socket.getfqdn(host)
|
||||||
name, names, addresses = socket.gethostbyaddr(host)
|
|
||||||
except socket.error, msg:
|
|
||||||
return host
|
|
||||||
names.insert(0, name)
|
|
||||||
for name in names:
|
|
||||||
if '.' in name: return name
|
|
||||||
return names[0]
|
|
||||||
|
|
||||||
|
|
||||||
# Essentially static class variables
|
# Essentially static class variables
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,8 @@ import string
|
||||||
|
|
||||||
# Import SOCKS module if it exists, else standard socket module socket
|
# Import SOCKS module if it exists, else standard socket module socket
|
||||||
try:
|
try:
|
||||||
import SOCKS; socket = SOCKS
|
import SOCKS; socket = SOCKS; del SOCKS # import SOCKS as socket
|
||||||
|
from socket import getfqdn; socket.getfqdn = getfqdn; del getfqdn
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
|
@ -291,17 +292,8 @@ class FTP:
|
||||||
if not passwd: passwd = ''
|
if not passwd: passwd = ''
|
||||||
if not acct: acct = ''
|
if not acct: acct = ''
|
||||||
if user == 'anonymous' and passwd in ('', '-'):
|
if user == 'anonymous' and passwd in ('', '-'):
|
||||||
thishost = socket.gethostname()
|
# get fully qualified domain name of local host
|
||||||
# Make sure it is fully qualified
|
thishost = socket.getfqdn()
|
||||||
if not '.' in thishost:
|
|
||||||
thisaddr = socket.gethostbyname(thishost)
|
|
||||||
firstname, names, unused = \
|
|
||||||
socket.gethostbyaddr(thisaddr)
|
|
||||||
names.insert(0, firstname)
|
|
||||||
for name in names:
|
|
||||||
if '.' in name:
|
|
||||||
thishost = name
|
|
||||||
break
|
|
||||||
try:
|
try:
|
||||||
if os.environ.has_key('LOGNAME'):
|
if os.environ.has_key('LOGNAME'):
|
||||||
realuser = os.environ['LOGNAME']
|
realuser = os.environ['LOGNAME']
|
||||||
|
|
|
@ -85,7 +85,7 @@ def getfqdn(name=''):
|
||||||
is returned.
|
is returned.
|
||||||
"""
|
"""
|
||||||
name = name.strip()
|
name = name.strip()
|
||||||
if len(name) == 0:
|
if not name or name == '0.0.0.0':
|
||||||
name = gethostname()
|
name = gethostname()
|
||||||
try:
|
try:
|
||||||
hostname, aliases, ipaddrs = gethostbyaddr(name)
|
hostname, aliases, ipaddrs = gethostbyaddr(name)
|
||||||
|
|
Loading…
Reference in New Issue