Document that API returns native strings.

This commit is contained in:
Itamar Turner-Trauring 2020-07-28 11:11:05 -04:00
parent 4dae5d867c
commit cc494e3d39

View File

@ -102,13 +102,18 @@ except ImportError:
increase_rlimits = _increase_rlimits increase_rlimits = _increase_rlimits
def get_local_addresses_sync(): def get_local_addresses_sync():
"""
Return a list of IPv4 addresses (as dotted-quad native strings) that are
currently configured on this host, sorted in descending order of how likely
we think they are to work.
"""
return [native_str(a) for a in _synchronously_find_addresses_via_config()] return [native_str(a) for a in _synchronously_find_addresses_via_config()]
def get_local_addresses_async(target="198.41.0.4"): # A.ROOT-SERVERS.NET def get_local_addresses_async(target="198.41.0.4"): # A.ROOT-SERVERS.NET
""" """
Return a Deferred that fires with a list of IPv4 addresses (as dotted-quad Return a Deferred that fires with a list of IPv4 addresses (as dotted-quad
strings) that are currently configured on this host, sorted in descending native strings) that are currently configured on this host, sorted in
order of how likely we think they are to work. descending order of how likely we think they are to work.
@param target: we want to learn an IP address they could try using to @param target: we want to learn an IP address they could try using to
connect to us; The default value is fine, but it might help if you connect to us; The default value is fine, but it might help if you
@ -137,7 +142,7 @@ def get_local_addresses_async(target="198.41.0.4"): # A.ROOT-SERVERS.NET
def get_local_ip_for(target): def get_local_ip_for(target):
"""Find out what our IP address is for use by a given target. """Find out what our IP address is for use by a given target.
@return: the IP address as a dotted-quad string which could be used by @return: the IP address as a dotted-quad native string which could be used
to connect to us. It might work for them, it might not. If to connect to us. It might work for them, it might not. If
there is no suitable address (perhaps we don't currently have an there is no suitable address (perhaps we don't currently have an
externally-visible interface), this will return None. externally-visible interface), this will return None.
@ -172,7 +177,7 @@ def get_local_ip_for(target):
return localip return localip
finally: finally:
d = port.stopListening() d = port.stopListening()
d.addErrback(log.err) 3 d.addErrback(log.err)
except (socket.error, CannotListenError): except (socket.error, CannotListenError):
# no route to that host # no route to that host
localip = None localip = None