Skip to content

Commit e390ae2

Browse files
jnwatsontimothycrosley
authored andcommitted
Make 3.7 compatible, fix missing import, update to aiohttp 3 compatibility (#26)
* Make 3.7 compatible, fix missing import, update to aiohttp 3 compat * Fix setup.py aiohttp version
1 parent 89ce2f8 commit e390ae2

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

domaintools_async/__init__.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@
44

55
from domaintools.base_results import Results
66

7+
from domaintools.exceptions import ServiceUnavailableException
78

8-
class AIter(object):
9-
"""A wrapper to turn non async-iterators into async compatible iterators"""
10-
__slots__ = ('iterator', )
9+
class _AIter(object):
10+
"""A wrapper to wrap an AsyncResults as an async iterable"""
11+
__slots__ = ('results', 'iterator', )
1112

12-
def __init__(self, iterator):
13-
self.iterator = iterator
13+
def __init__(self, results):
14+
self.results = results
15+
self.iterator = None
1416

1517
def __aiter__(self):
1618
return self
1719

1820
async def __anext__(self):
21+
if self.iterator is None:
22+
await self.results
23+
self.iterator = self.results._items().__iter__()
24+
1925
try:
2026
return self.iterator.__next__()
2127
except StopIteration:
@@ -38,7 +44,7 @@ async def _make_async_request(self, session):
3844

3945
async def __awaitable__(self):
4046
if self._data is None:
41-
with aiohttp.ClientSession(connector=aiohttp.TCPConnector(verify_ssl=self.api.verify_ssl)) as session:
47+
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(verify_ssl=self.api.verify_ssl)) as session:
4248
wait_time = self._wait_time()
4349
if wait_time is None and self.api:
4450
try:
@@ -53,9 +59,8 @@ async def __awaitable__(self):
5359

5460
return self
5561

56-
async def __aiter__(self):
57-
await self
58-
return AIter(self._items().__iter__())
62+
def __aiter__(self):
63+
return _AIter(self)
5964

6065
async def __aenter__(self):
6166
return await self

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
packages = ['domaintools']
1414
if sys.version_info[0] >= 3 and sys.version_info[1] >= 5:
1515
packages.append('domaintools_async')
16-
requires.append('aiohttp==2.3.6')
16+
requires.append('aiohttp==3.4.4')
1717
elif sys.version_info[0] == 2 and sys.version_info[1] <= 6:
1818
requires.extend(['ordereddict', 'argparse'])
1919

0 commit comments

Comments
 (0)