Show More
@@ -24,9 +24,16 b' from IPython.nbformat.v4 import (' | |||
|
24 | 24 | ) |
|
25 | 25 | from IPython.nbformat import v2 |
|
26 | 26 | from IPython.utils import py3compat |
|
27 | from IPython.utils.data import uniq_stable | |
|
28 | 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 | 38 | def notebooks_only(dir_model): |
|
32 | 39 | return [nb for nb in dir_model['content'] if nb['type']=='notebook'] |
@@ -10,9 +10,9 b' except:' | |||
|
10 | 10 | cPickle = None |
|
11 | 11 | import pickle |
|
12 | 12 | |
|
13 | # IPython imports | |
|
13 | from itertools import chain | |
|
14 | ||
|
14 | 15 | from IPython.utils.py3compat import PY3, buffer_to_bytes_py2 |
|
15 | from IPython.utils.data import flatten | |
|
16 | 16 | from ipython_kernel.pickleutil import ( |
|
17 | 17 | can, uncan, can_sequence, uncan_sequence, CannedObject, |
|
18 | 18 | istype, sequence_types, PICKLE_PROTOCOL, |
@@ -138,10 +138,12 b' def pack_apply_message(f, args, kwargs, buffer_threshold=MAX_BYTES, item_thresho' | |||
|
138 | 138 | With length at least two + len(args) + len(kwargs) |
|
139 | 139 | """ |
|
140 | 140 | |
|
141 | arg_bufs = flatten(serialize_object(arg, buffer_threshold, item_threshold) for arg in args) | |
|
141 | arg_bufs = list(chain.from_iterable( | |
|
142 | serialize_object(arg, buffer_threshold, item_threshold) for arg in args)) | |
|
142 | 143 | |
|
143 | 144 | kw_keys = sorted(kwargs.keys()) |
|
144 | kwarg_bufs = flatten(serialize_object(kwargs[key], buffer_threshold, item_threshold) for key in kw_keys) | |
|
145 | kwarg_bufs = list(chain.from_iterable( | |
|
146 | serialize_object(kwargs[key], buffer_threshold, item_threshold) for key in kw_keys)) | |
|
145 | 147 | |
|
146 | 148 | info = dict(nargs=len(args), narg_bufs=len(arg_bufs), kw_keys=kw_keys) |
|
147 | 149 |
@@ -12,10 +12,7 b' pieces to individual nodes in a cluster.' | |||
|
12 | 12 | from __future__ import division |
|
13 | 13 | |
|
14 | 14 | import sys |
|
15 | from itertools import islice | |
|
16 | ||
|
17 | from IPython.utils.data import flatten as utils_flatten | |
|
18 | ||
|
15 | from itertools import islice, chain | |
|
19 | 16 | |
|
20 | 17 | numpy = None |
|
21 | 18 | |
@@ -75,7 +72,7 b' class Map(object):' | |||
|
75 | 72 | return numpy.concatenate(listOfPartitions) |
|
76 | 73 | # Next try for Python sequence types |
|
77 | 74 | if isinstance(testObject, (list, tuple)): |
|
78 |
return |
|
|
75 | return list(chain.from_iterable(listOfPartitions)) | |
|
79 | 76 | # If we have scalars, just return listOfPartitions |
|
80 | 77 | return listOfPartitions |
|
81 | 78 | |
@@ -125,5 +122,3 b' def mappable(obj):' | |||
|
125 | 122 | |
|
126 | 123 | dists = {'b':Map,'r':RoundRobinMap} |
|
127 | 124 | |
|
128 | ||
|
129 |
@@ -1,6 +1,6 b'' | |||
|
1 | 1 | """Utilities for identifying local IP addresses.""" |
|
2 | 2 | |
|
3 |
# Copyright (c) |
|
|
3 | # Copyright (c) Jupyter Development Team. | |
|
4 | 4 | # Distributed under the terms of the Modified BSD License. |
|
5 | 5 | |
|
6 | 6 | import os |
@@ -8,7 +8,6 b' import re' | |||
|
8 | 8 | import socket |
|
9 | 9 | from subprocess import Popen, PIPE |
|
10 | 10 | |
|
11 | from IPython.utils.data import uniq_stable | |
|
12 | 11 | from warnings import warn |
|
13 | 12 | |
|
14 | 13 | |
@@ -17,6 +16,18 b' PUBLIC_IPS = []' | |||
|
17 | 16 | |
|
18 | 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 | 31 | def _get_output(cmd): |
|
21 | 32 | """Get output of a command, raising IOError if it fails""" |
|
22 | 33 | p = Popen(cmd, stdout=PIPE, stderr=PIPE) |
@@ -69,8 +80,8 b' def _populate_from_list(addrs):' | |||
|
69 | 80 | |
|
70 | 81 | local_ips.extend(['0.0.0.0', '']) |
|
71 | 82 | |
|
72 | LOCAL_IPS[:] = uniq_stable(local_ips) | |
|
73 | PUBLIC_IPS[:] = uniq_stable(public_ips) | |
|
83 | LOCAL_IPS[:] = _uniq_stable(local_ips) | |
|
84 | PUBLIC_IPS[:] = _uniq_stable(public_ips) | |
|
74 | 85 | |
|
75 | 86 | def _load_ips_ifconfig(): |
|
76 | 87 | """load ip addresses from `ifconfig` output (posix)""" |
@@ -145,8 +156,8 b' def _load_ips_netifaces():' | |||
|
145 | 156 | LOCALHOST = '127.0.0.1' |
|
146 | 157 | local_ips.insert(0, LOCALHOST) |
|
147 | 158 | local_ips.extend(['0.0.0.0', '']) |
|
148 | LOCAL_IPS[:] = uniq_stable(local_ips) | |
|
149 | PUBLIC_IPS[:] = uniq_stable(public_ips) | |
|
159 | LOCAL_IPS[:] = _uniq_stable(local_ips) | |
|
160 | PUBLIC_IPS[:] = _uniq_stable(public_ips) | |
|
150 | 161 | |
|
151 | 162 | |
|
152 | 163 | def _load_ips_gethostbyname(): |
@@ -170,13 +181,13 b' def _load_ips_gethostbyname():' | |||
|
170 | 181 | except socket.error: |
|
171 | 182 | pass |
|
172 | 183 | finally: |
|
173 | PUBLIC_IPS[:] = uniq_stable(PUBLIC_IPS) | |
|
184 | PUBLIC_IPS[:] = _uniq_stable(PUBLIC_IPS) | |
|
174 | 185 | LOCAL_IPS.extend(PUBLIC_IPS) |
|
175 | 186 | |
|
176 | 187 | # include all-interface aliases: 0.0.0.0 and '' |
|
177 | 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 | 192 | LOCALHOST = LOCAL_IPS[0] |
|
182 | 193 |
General Comments 0
You need to be logged in to leave comments.
Login now