-
Notifications
You must be signed in to change notification settings - Fork 33
Make 3.7 compatible, fix missing import, update to aiohttp 3 compatibility #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,18 +4,24 @@ | |
|
|
||
| from domaintools.base_results import Results | ||
|
|
||
| from domaintools.exceptions import ServiceUnavailableException | ||
|
|
||
| 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: | ||
|
|
@@ -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: | ||
|
|
@@ -53,9 +59,8 @@ async def __awaitable__(self): | |
|
|
||
| return self | ||
|
|
||
| async def __aiter__(self): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 52.