##// 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 import logging
6 import logging
20 import os
7 import os
21 import re
8 import re
22 import stat
9 import stat
23 import socket
10 import socket
24 import sys
11 import sys
12 import warnings
25 from signal import signal, SIGINT, SIGABRT, SIGTERM
13 from signal import signal, SIGINT, SIGABRT, SIGTERM
26 try:
14 try:
27 from signal import SIGKILL
15 from signal import SIGKILL
@@ -36,13 +24,11 b' except:'
36 cPickle = None
24 cPickle = None
37 import pickle
25 import pickle
38
26
39 # System library imports
40 import zmq
27 import zmq
41 from zmq.log import handlers
28 from zmq.log import handlers
42
29
43 from IPython.external.decorator import decorator
30 from IPython.external.decorator import decorator
44
31
45 # IPython imports
46 from IPython.config.application import Application
32 from IPython.config.application import Application
47 from IPython.utils.localinterfaces import localhost, is_public_ip, public_ips
33 from IPython.utils.localinterfaces import localhost, is_public_ip, public_ips
48 from IPython.utils.py3compat import string_types, iteritems, itervalues
34 from IPython.utils.py3compat import string_types, iteritems, itervalues
@@ -184,18 +170,42 b' def split_url(url):'
184 assert len(lis) == 2, 'Invalid url: %r'%url
170 assert len(lis) == 2, 'Invalid url: %r'%url
185 addr,s_port = lis
171 addr,s_port = lis
186 return proto,addr,s_port
172 return proto,addr,s_port
187
173
174
188 def disambiguate_ip_address(ip, location=None):
175 def disambiguate_ip_address(ip, location=None):
189 """turn multi-ip interfaces '0.0.0.0' and '*' into connectable
176 """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)."""
177
191 if ip in ('0.0.0.0', '*'):
178 Explicit IP addresses are returned unmodified.
192 if location is None or is_public_ip(location) or not public_ips():
179
193 # If location is unspecified or cannot be determined, assume local
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 ip = localhost()
197 ip = localhost()
195 elif location:
198 elif not public_ips():
196 return location
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 return ip
206 return ip
198
207
208
199 def disambiguate_url(url, location=None):
209 def disambiguate_url(url, location=None):
200 """turn multi-ip interfaces '0.0.0.0' and '*' into connectable
210 """turn multi-ip interfaces '0.0.0.0' and '*' into connectable
201 ones, based on the location (default interpretation is localhost).
211 ones, based on the location (default interpretation is localhost).
General Comments 0
You need to be logged in to leave comments. Login now