Skip to content

Commit

Permalink
fix: provide ability to close requestor
Browse files Browse the repository at this point in the history
Co-authored-by: LilSpazJoekp <15524072+lilspazjoekp@users.noreply.github.com>
Co-authored-by: PythonCoderAS <13932583+PythonCoderAS@users.noreply.github.com>
Signed-off-by: LilSpazJoekp <15524072+LilSpazJoekp@users.noreply.github.com>
  • Loading branch information
3 people committed Dec 28, 2020
1 parent e0884d1 commit 11d6298
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ Source Contributors
- Todd Roberts `@toddrob99 <https://github.com/toddrob99>`_
- MaybeNetwork `@MaybeNetwork <https://github.com/MaybeNetwork>`_
- Nick Kelly `@nickatnight <https://github.com/nickatnight>`_
- Gerard Rodes <GerardRodesVidal@gmail.com> `@GerardRodes <https://github.com/GerardRodes>`_
<!-- - Add "Name <email (optional)> and github profile link" above this line. -->
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Unreleased
* Ability to submit image galleries with :meth:`.submit_gallery`.
* Ability to pass a gallery url to :meth:`.Reddit.submission`.
* Ability to specify modmail mute duration.
* Added :meth:`.Reddit.close` to close the requestor session.

**Changed**

Expand Down
8 changes: 7 additions & 1 deletion asyncpraw/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ def __enter__(self):
def __exit__(self, *_args):
"""Handle the context manager close."""

async def close(self):
"""Close the requestor."""
await self.requestor.close()

def __init__(
self,
site_name: str = None,
Expand Down Expand Up @@ -221,7 +225,7 @@ async def request(self, *args, **kwargs):
)

self._prepare_objector()
self._prepare_asyncprawcore(requestor_class, requestor_kwargs)
self.requestor = self._prepare_asyncprawcore(requestor_class, requestor_kwargs)

self.auth = models.Auth(self, None)
"""An instance of :class:`.Auth`.
Expand Down Expand Up @@ -418,6 +422,8 @@ def _prepare_asyncprawcore(self, requestor_class=None, requestor_kwargs=None):
else:
self._prepare_untrusted_asyncprawcore(requestor)

return requestor

def _prepare_trusted_asyncprawcore(self, requestor):
authenticator = TrustedAuthenticator(
requestor,
Expand Down

0 comments on commit 11d6298

Please sign in to comment.