Show More
@@ -0,0 +1,15 b'' | |||||
|
1 | #----------------------------------------------------------------------------- | |||
|
2 | # Copyright (C) 2013 The IPython Development Team | |||
|
3 | # | |||
|
4 | # Distributed under the terms of the BSD License. The full license is in | |||
|
5 | # the file COPYING, distributed as part of this software. | |||
|
6 | #----------------------------------------------------------------------------- | |||
|
7 | ||||
|
8 | from .. import localinterfaces | |||
|
9 | ||||
|
10 | def test_load_ips(): | |||
|
11 | # Override the machinery that skips it if it was called before | |||
|
12 | localinterfaces._load_ips.called = False | |||
|
13 | ||||
|
14 | # Just check this doesn't error | |||
|
15 | localinterfaces._load_ips(suppress_exceptions=False) No newline at end of file |
@@ -27,7 +27,6 b' import socket' | |||||
27 |
|
27 | |||
28 | from .data import uniq_stable |
|
28 | from .data import uniq_stable | |
29 | from .process import get_output_error_code |
|
29 | from .process import get_output_error_code | |
30 | from .py3compat import bytes_to_str |
|
|||
31 | from .warn import warn |
|
30 | from .warn import warn | |
32 |
|
31 | |||
33 | #----------------------------------------------------------------------------- |
|
32 | #----------------------------------------------------------------------------- | |
@@ -42,10 +41,10 b" LOCALHOST = ''" | |||||
42 | def _only_once(f): |
|
41 | def _only_once(f): | |
43 | """decorator to only run a function once""" |
|
42 | """decorator to only run a function once""" | |
44 | f.called = False |
|
43 | f.called = False | |
45 | def wrapped(): |
|
44 | def wrapped(**kwargs): | |
46 | if f.called: |
|
45 | if f.called: | |
47 | return |
|
46 | return | |
48 | ret = f() |
|
47 | ret = f(**kwargs) | |
49 | f.called = True |
|
48 | f.called = True | |
50 | return ret |
|
49 | return ret | |
51 | return wrapped |
|
50 | return wrapped | |
@@ -96,11 +95,11 b' def _load_ips_ifconfig():' | |||||
96 | if rc: |
|
95 | if rc: | |
97 | raise IOError("no ifconfig: %s" % err) |
|
96 | raise IOError("no ifconfig: %s" % err) | |
98 |
|
97 | |||
99 |
lines = |
|
98 | lines = out.splitlines() | |
100 | addrs = [] |
|
99 | addrs = [] | |
101 | for line in lines: |
|
100 | for line in lines: | |
102 | blocks = line.lower().split() |
|
101 | blocks = line.lower().split() | |
103 | if blocks[0] == 'inet': |
|
102 | if (len(blocks) >= 2) and (blocks[0] == 'inet'): | |
104 | addrs.append(blocks[1]) |
|
103 | addrs.append(blocks[1]) | |
105 | _populate_from_list(addrs) |
|
104 | _populate_from_list(addrs) | |
106 |
|
105 | |||
@@ -111,11 +110,11 b' def _load_ips_ip():' | |||||
111 | if rc: |
|
110 | if rc: | |
112 | raise IOError("no ip: %s" % err) |
|
111 | raise IOError("no ip: %s" % err) | |
113 |
|
112 | |||
114 |
lines = |
|
113 | lines = out.splitlines() | |
115 | addrs = [] |
|
114 | addrs = [] | |
116 | for line in lines: |
|
115 | for line in lines: | |
117 | blocks = line.lower().split() |
|
116 | blocks = line.lower().split() | |
118 | if blocks[0] == 'inet': |
|
117 | if (len(blocks) >= 2) and (blocks[0] == 'inet'): | |
119 | addrs.append(blocks[1].split('/')[0]) |
|
118 | addrs.append(blocks[1].split('/')[0]) | |
120 | _populate_from_list(addrs) |
|
119 | _populate_from_list(addrs) | |
121 |
|
120 | |||
@@ -126,7 +125,7 b' def _load_ips_ipconfig():' | |||||
126 | if rc: |
|
125 | if rc: | |
127 | raise IOError("no ipconfig: %s" % err) |
|
126 | raise IOError("no ipconfig: %s" % err) | |
128 |
|
127 | |||
129 |
lines = |
|
128 | lines = out.splitlines() | |
130 | addrs = ['127.0.0.1'] |
|
129 | addrs = ['127.0.0.1'] | |
131 | for line in lines: |
|
130 | for line in lines: | |
132 | line = line.lower().split() |
|
131 | line = line.lower().split() | |
@@ -203,7 +202,7 b' def _load_ips_dumb():' | |||||
203 | PUBLIC_IPS[:] = [] |
|
202 | PUBLIC_IPS[:] = [] | |
204 |
|
203 | |||
205 | @_only_once |
|
204 | @_only_once | |
206 | def _load_ips(): |
|
205 | def _load_ips(suppress_exceptions=True): | |
207 | """load the IPs that point to this machine |
|
206 | """load the IPs that point to this machine | |
208 |
|
207 | |||
209 | This function will only ever be called once. |
|
208 | This function will only ever be called once. | |
@@ -241,6 +240,8 b' def _load_ips():' | |||||
241 |
|
240 | |||
242 | return _load_ips_gethostbyname() |
|
241 | return _load_ips_gethostbyname() | |
243 | except Exception as e: |
|
242 | except Exception as e: | |
|
243 | if not suppress_exceptions: | |||
|
244 | raise | |||
244 | # unexpected error shouldn't crash, load dumb default values instead. |
|
245 | # unexpected error shouldn't crash, load dumb default values instead. | |
245 | warn("Unexpected error discovering local network interfaces: %s" % e) |
|
246 | warn("Unexpected error discovering local network interfaces: %s" % e) | |
246 | _load_ips_dumb() |
|
247 | _load_ips_dumb() |
General Comments 0
You need to be logged in to leave comments.
Login now