Skip to content

Commit 8bb867a

Browse files
committed
async and regular iter func
1 parent d4f1e4b commit 8bb867a

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

ipinfo/handler.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -346,17 +346,6 @@ def getBatchDetailsIter(
346346
else:
347347
lookup_addresses.append(ip_address)
348348

349-
# pre-populate with anything we've got in the cache, and keep around
350-
# the IPs not in the cache.
351-
for ip_address in ip_addresses:
352-
# if the supplied IP address uses the objects defined in the
353-
# built-in module ipaddress extract the appropriate string notation
354-
# before formatting the URL.
355-
if isinstance(ip_address, IPv4Address) or isinstance(
356-
ip_address, IPv6Address
357-
):
358-
ip_address = ip_address.exploded
359-
360349
try:
361350
cached_ipaddr = self.cache[cache_key(ip_address)]
362351
result[ip_address] = cached_ipaddr
@@ -365,7 +354,7 @@ def getBatchDetailsIter(
365354

366355
# all in cache - exit early.
367356
if len(lookup_addresses) == 0:
368-
yield result
357+
yield result.items()
369358

370359
url = API_URL + "/batch"
371360
headers = handler_utils.get_headers(self.access_token, self.headers)

ipinfo/handler_async.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ async def getBatchDetailsIter(
358358
batch_size = BATCH_MAX_SIZE
359359

360360
results = {}
361-
362361
lookup_addresses = []
363362
for ip_address in ip_addresses:
364363
if isinstance(ip_address, IPv4Address) or isinstance(
@@ -371,6 +370,8 @@ async def getBatchDetailsIter(
371370
details["ip"] = ip_address
372371
details["bogon"] = True
373372
yield Details(details)
373+
else:
374+
lookup_addresses.append(ip_address)
374375

375376
try:
376377
cached_ipaddr = self.cache[cache_key(ip_address)]

0 commit comments

Comments
 (0)