##// END OF EJS Templates
copy uniq_stable out of IPython.utils.data
Min RK -
Show More
@@ -24,9 +24,16 b' from IPython.nbformat.v4 import ('
24 )
24 )
25 from IPython.nbformat import v2
25 from IPython.nbformat import v2
26 from IPython.utils import py3compat
26 from IPython.utils import py3compat
27 from IPython.utils.data import uniq_stable
28 from IPython.utils.tempdir import TemporaryDirectory
27 from IPython.utils.tempdir import TemporaryDirectory
29
28
29 def uniq_stable(elems):
30 """uniq_stable(elems) -> list
31
32 Return from an iterable, a list of all the unique elements in the input,
33 maintaining the order in which they first appear.
34 """
35 seen = set()
36 return [x for x in elems if x not in seen and not seen.add(x)]
30
37
31 def notebooks_only(dir_model):
38 def notebooks_only(dir_model):
32 return [nb for nb in dir_model['content'] if nb['type']=='notebook']
39 return [nb for nb in dir_model['content'] if nb['type']=='notebook']
@@ -1,6 +1,6 b''
1 """Utilities for identifying local IP addresses."""
1 """Utilities for identifying local IP addresses."""
2
2
3 # Copyright (c) IPython Development Team.
3 # Copyright (c) Jupyter Development Team.
4 # Distributed under the terms of the Modified BSD License.
4 # Distributed under the terms of the Modified BSD License.
5
5
6 import os
6 import os
@@ -8,7 +8,6 b' import re'
8 import socket
8 import socket
9 from subprocess import Popen, PIPE
9 from subprocess import Popen, PIPE
10
10
11 from IPython.utils.data import uniq_stable
12 from warnings import warn
11 from warnings import warn
13
12
14
13
@@ -17,6 +16,18 b' PUBLIC_IPS = []'
17
16
18 LOCALHOST = ''
17 LOCALHOST = ''
19
18
19
20 def _uniq_stable(elems):
21 """uniq_stable(elems) -> list
22
23 Return from an iterable, a list of all the unique elements in the input,
24 maintaining the order in which they first appear.
25
26 From IPython.utils.data
27 """
28 seen = set()
29 return [x for x in elems if x not in seen and not seen.add(x)]
30
20 def _get_output(cmd):
31 def _get_output(cmd):
21 """Get output of a command, raising IOError if it fails"""
32 """Get output of a command, raising IOError if it fails"""
22 p = Popen(cmd, stdout=PIPE, stderr=PIPE)
33 p = Popen(cmd, stdout=PIPE, stderr=PIPE)
@@ -69,8 +80,8 b' def _populate_from_list(addrs):'
69
80
70 local_ips.extend(['0.0.0.0', ''])
81 local_ips.extend(['0.0.0.0', ''])
71
82
72 LOCAL_IPS[:] = uniq_stable(local_ips)
83 LOCAL_IPS[:] = _uniq_stable(local_ips)
73 PUBLIC_IPS[:] = uniq_stable(public_ips)
84 PUBLIC_IPS[:] = _uniq_stable(public_ips)
74
85
75 def _load_ips_ifconfig():
86 def _load_ips_ifconfig():
76 """load ip addresses from `ifconfig` output (posix)"""
87 """load ip addresses from `ifconfig` output (posix)"""
@@ -145,8 +156,8 b' def _load_ips_netifaces():'
145 LOCALHOST = '127.0.0.1'
156 LOCALHOST = '127.0.0.1'
146 local_ips.insert(0, LOCALHOST)
157 local_ips.insert(0, LOCALHOST)
147 local_ips.extend(['0.0.0.0', ''])
158 local_ips.extend(['0.0.0.0', ''])
148 LOCAL_IPS[:] = uniq_stable(local_ips)
159 LOCAL_IPS[:] = _uniq_stable(local_ips)
149 PUBLIC_IPS[:] = uniq_stable(public_ips)
160 PUBLIC_IPS[:] = _uniq_stable(public_ips)
150
161
151
162
152 def _load_ips_gethostbyname():
163 def _load_ips_gethostbyname():
@@ -170,13 +181,13 b' def _load_ips_gethostbyname():'
170 except socket.error:
181 except socket.error:
171 pass
182 pass
172 finally:
183 finally:
173 PUBLIC_IPS[:] = uniq_stable(PUBLIC_IPS)
184 PUBLIC_IPS[:] = _uniq_stable(PUBLIC_IPS)
174 LOCAL_IPS.extend(PUBLIC_IPS)
185 LOCAL_IPS.extend(PUBLIC_IPS)
175
186
176 # include all-interface aliases: 0.0.0.0 and ''
187 # include all-interface aliases: 0.0.0.0 and ''
177 LOCAL_IPS.extend(['0.0.0.0', ''])
188 LOCAL_IPS.extend(['0.0.0.0', ''])
178
189
179 LOCAL_IPS[:] = uniq_stable(LOCAL_IPS)
190 LOCAL_IPS[:] = _uniq_stable(LOCAL_IPS)
180
191
181 LOCALHOST = LOCAL_IPS[0]
192 LOCALHOST = LOCAL_IPS[0]
182
193
General Comments 0
You need to be logged in to leave comments. Login now