MCPcopy Index your code
hub / github.com/python/cpython / _interleave_addrinfos

Function _interleave_addrinfos

Lib/asyncio/base_events.py:161–180  ·  view source on GitHub ↗

Interleave list of addrinfo tuples by family.

(addrinfos, first_address_family_count=1)

Source from the content-addressed store, hash-verified

159
160
161def _interleave_addrinfos(addrinfos, first_address_family_count=1):
162 """Interleave list of addrinfo tuples by family."""
163 # Group addresses by family
164 addrinfos_by_family = collections.OrderedDict()
165 for addr in addrinfos:
166 family = addr[0]
167 if family not in addrinfos_by_family:
168 addrinfos_by_family[family] = []
169 addrinfos_by_family[family].append(addr)
170 addrinfos_lists = list(addrinfos_by_family.values())
171
172 reordered = []
173 if first_address_family_count > 1:
174 reordered.extend(addrinfos_lists[0][:first_address_family_count - 1])
175 del addrinfos_lists[0][:first_address_family_count - 1]
176 reordered.extend(
177 a for a in itertools.chain.from_iterable(
178 itertools.zip_longest(*addrinfos_lists)
179 ) if a is not None)
180 return reordered
181
182
183def _run_until_complete_cb(fut):

Callers 1

create_connectionMethod · 0.85

Calls 4

valuesMethod · 0.95
listClass · 0.85
appendMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…