##// END OF EJS Templates
Merge pull request #5486 from minrk/disambiguate-default...
Thomas Kluyver -
r16394:3cc040ef merge
parent child Browse files
Show More
@@ -1,27 +1,15 b''
1 """Some generic utilities for dealing with classes, urls, and serialization.
1 """Some generic utilities for dealing with classes, urls, and serialization."""
2 2
3 Authors:
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
4 5
5 * Min RK
6 """
7 #-----------------------------------------------------------------------------
8 # Copyright (C) 2010-2011 The IPython Development Team
9 #
10 # Distributed under the terms of the BSD License. The full license is in
11 # the file COPYING, distributed as part of this software.
12 #-----------------------------------------------------------------------------
13
14 #-----------------------------------------------------------------------------
15 # Imports
16 #-----------------------------------------------------------------------------
17
18 # Standard library imports.
19 6 import logging
20 7 import os
21 8 import re
22 9 import stat
23 10 import socket
24 11 import sys
12 import warnings
25 13 from signal import signal, SIGINT, SIGABRT, SIGTERM
26 14 try:
27 15 from signal import SIGKILL
@@ -36,13 +24,11 b' except:'
36 24 cPickle = None
37 25 import pickle
38 26
39 # System library imports
40 27 import zmq
41 28 from zmq.log import handlers
42 29
43 30 from IPython.external.decorator import decorator
44 31
45 # IPython imports
46 32 from IPython.config.application import Application
47 33 from IPython.utils.localinterfaces import localhost, is_public_ip, public_ips
48 34 from IPython.utils.py3compat import string_types, iteritems, itervalues
@@ -184,18 +170,42 b' def split_url(url):'
184 170 assert len(lis) == 2, 'Invalid url: %r'%url
185 171 addr,s_port = lis
186 172 return proto,addr,s_port
187
173
174
188 175 def disambiguate_ip_address(ip, location=None):
189 """turn multi-ip interfaces '0.0.0.0' and '*' into connectable
190 ones, based on the location (default interpretation of location is localhost)."""
191 if ip in ('0.0.0.0', '*'):
192 if location is None or is_public_ip(location) or not public_ips():
193 # If location is unspecified or cannot be determined, assume local
176 """turn multi-ip interfaces '0.0.0.0' and '*' into a connectable address
177
178 Explicit IP addresses are returned unmodified.
179
180 Parameters
181 ----------
182
183 ip : IP address
184 An IP address, or the special values 0.0.0.0, or *
185 location: IP address, optional
186 A public IP of the target machine.
187 If location is an IP of the current machine,
188 localhost will be returned,
189 otherwise location will be returned.
190 """
191 if ip in {'0.0.0.0', '*'}:
192 if not location:
193 # unspecified location, localhost is the only choice
194 ip = localhost()
195 elif is_public_ip(location):
196 # location is a public IP on this machine, use localhost
194 197 ip = localhost()
195 elif location:
196 return location
198 elif not public_ips():
199 # this machine's public IPs cannot be determined,
200 # assume `location` is not this machine
201 warnings.warn("IPython could not determine public IPs", RuntimeWarning)
202 ip = location
203 else:
204 # location is not this machine, do not use loopback
205 ip = location
197 206 return ip
198 207
208
199 209 def disambiguate_url(url, location=None):
200 210 """turn multi-ip interfaces '0.0.0.0' and '*' into connectable
201 211 ones, based on the location (default interpretation is localhost).
General Comments 0
You need to be logged in to leave comments. Login now