Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions domaintools_async/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@

from domaintools.base_results import Results

from domaintools.exceptions import ServiceUnavailableException
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I apologize, I lost this comment from my initial review: I may be missing something, but I don't currently see this import used. I just want to ensure this doesn't allude to any additional work you would like to include in this pull request

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 52.


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

def __init__(self, iterator):
self.iterator = iterator
def __init__(self, results):
self.results = results
self.iterator = None

def __aiter__(self):
return self

async def __anext__(self):
if self.iterator is None:
await self.results
self.iterator = self.results._items().__iter__()

try:
return self.iterator.__next__()
except StopIteration:
Expand All @@ -38,7 +44,7 @@ async def _make_async_request(self, session):

async def __awaitable__(self):
if self._data is None:
with aiohttp.ClientSession(connector=aiohttp.TCPConnector(verify_ssl=self.api.verify_ssl)) as session:
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(verify_ssl=self.api.verify_ssl)) as session:
wait_time = self._wait_time()
if wait_time is None and self.api:
try:
Expand All @@ -53,9 +59,8 @@ async def __awaitable__(self):

return self

async def __aiter__(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this change was made alluded to in 3.6 and made permanent in 3.7: https://bugs.python.org/issue27243, as annoying as it is we'll need to maintain backward compatibility for the time being.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, this is the backwards compatible approach, since this will work on 3.5.3, 3.6 and 3.7 (I just verified). Whereas, the current master is not compatible with 3.7.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like I was wrong and they actually made the change in 3.5.2, that does mean that backward compatibility would be lost for the 3.5.0 and 3.5.1, however as 3.5.6 is now out I think it's safe to simply update the minimal version to 3.5.2. Thanks for verifying!

await self
return AIter(self._items().__iter__())
def __aiter__(self):
return _AIter(self)

async def __aenter__(self):
return await self
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
packages = ['domaintools']
if sys.version_info[0] >= 3 and sys.version_info[1] >= 5:
packages.append('domaintools_async')
requires.append('aiohttp==2.3.6')
requires.append('aiohttp==3.4.4')
elif sys.version_info[0] == 2 and sys.version_info[1] <= 6:
requires.extend(['ordereddict', 'argparse'])

Expand Down