##// END OF EJS Templates
disambiguate to location when no IPs can be determined...
MinRK -
Show More
@@ -22,6 +22,7 b' import re'
22 import stat
22 import stat
23 import socket
23 import socket
24 import sys
24 import sys
25 import warnings
25 from signal import signal, SIGINT, SIGABRT, SIGTERM
26 from signal import signal, SIGINT, SIGABRT, SIGTERM
26 try:
27 try:
27 from signal import SIGKILL
28 from signal import SIGKILL
@@ -184,18 +185,42 b' def split_url(url):'
184 assert len(lis) == 2, 'Invalid url: %r'%url
185 assert len(lis) == 2, 'Invalid url: %r'%url
185 addr,s_port = lis
186 addr,s_port = lis
186 return proto,addr,s_port
187 return proto,addr,s_port
187
188
189
188 def disambiguate_ip_address(ip, location=None):
190 def disambiguate_ip_address(ip, location=None):
189 """turn multi-ip interfaces '0.0.0.0' and '*' into connectable
191 """turn multi-ip interfaces '0.0.0.0' and '*' into a connectable address
190 ones, based on the location (default interpretation of location is localhost)."""
192
191 if ip in ('0.0.0.0', '*'):
193 Explicit IP addresses are returned unmodified.
192 if location is None or is_public_ip(location) or not public_ips():
194
193 # If location is unspecified or cannot be determined, assume local
195 Parameters
196 ----------
197
198 ip : IP address
199 An IP address, or the special values 0.0.0.0, or *
200 location: IP address, optional
201 A public IP of the target machine.
202 If location is an IP of the current machine,
203 localhost will be returned,
204 otherwise location will be returned.
205 """
206 if ip in {'0.0.0.0', '*'}:
207 if not location:
208 # unspecified location, localhost is the only choice
209 ip = localhost()
210 elif is_public_ip(location):
211 # location is a public IP on this machine, use localhost
194 ip = localhost()
212 ip = localhost()
195 elif location:
213 elif not public_ips():
196 return location
214 # this machine's public IPs cannot be determined,
215 # assume `location` is not this machine
216 warnings.warn("IPython could not determine public IPs", RuntimeWarning)
217 ip = location
218 else:
219 # location is not this machine, do not use loopback
220 ip = location
197 return ip
221 return ip
198
222
223
199 def disambiguate_url(url, location=None):
224 def disambiguate_url(url, location=None):
200 """turn multi-ip interfaces '0.0.0.0' and '*' into connectable
225 """turn multi-ip interfaces '0.0.0.0' and '*' into connectable
201 ones, based on the location (default interpretation is localhost).
226 ones, based on the location (default interpretation is localhost).
General Comments 0
You need to be logged in to leave comments. Login now