Skip to content

Commit

Permalink
More clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
LilSpazJoekp committed Nov 27, 2023
1 parent ab27e6a commit 023e457
Show file tree
Hide file tree
Showing 67 changed files with 8,054 additions and 4,175 deletions.
4 changes: 2 additions & 2 deletions AUTHORS.rst
Expand Up @@ -2,8 +2,6 @@ Maintainers
===========

- Joel Payne <lilspazjoekp@gmail.com> `@LilSpazJoekp <https://github.com/LilSpazJoekp>`_
- Vikramaditya Gaonkar <vikramaditya91@gmail.com> `@vikramaditya91
<https://github.com/vikramaditya91>`_

Contributors
============
Expand All @@ -13,6 +11,8 @@ Contributors
- Zeerak Waseem <zeerak.w@gmail.com> `@ZeerakW <https://github.com/ZeerakW>`_
- jarhill0 `@jarhill0 <https://github.com/jarhill0>`_
- Watchful1 `@Watchful1 <https://github.com/Watchful1>`_
- Vikramaditya Gaonkar <vikramaditya91@gmail.com> `@vikramaditya91
<https://github.com/vikramaditya91>`_
- PythonCoderAS `@PythonCoderAS <https://github.com/PythonCoderAS>`_
- MaybeNetwork `@MaybeNetwork <https://github.com/MaybeNetwork>`_
- Add "Name <email (optional)> and github profile link" above this line.
15 changes: 7 additions & 8 deletions README.rst
Expand Up @@ -39,7 +39,7 @@ asyncprawcore
:alt: Black code style
:target: https://github.com/psf/black

asyncprawcore is a low-level communication layer for PRAW 4+.
asyncprawcore is a low-level communication layer used by Async PRAW 7+.

Installation
------------
Expand All @@ -55,8 +55,8 @@ Execution Example

The following example demonstrates how to use asyncprawcore to obtain the list of
trophies for a given user using the script-app type. This example assumes you have the
environment variables ``asyncprawcore_CLIENT_ID`` and ``asyncprawcore_CLIENT_SECRET``
set to the appropriate values for your application.
environment variables ``PRAWCORE_CLIENT_ID`` and ``PRAWCORE_CLIENT_SECRET`` set to the
appropriate values for your application.

.. code-block:: python
Expand All @@ -69,8 +69,8 @@ set to the appropriate values for your application.
async def main():
authenticator = asyncprawcore.TrustedAuthenticator(
asyncprawcore.Requestor("YOUR_VALID_USER_AGENT"),
os.environ["asyncprawcore_CLIENT_ID"],
os.environ["asyncprawcore_CLIENT_SECRET"],
os.environ["PRAWCORE_CLIENT_ID"],
os.environ["PRAWCORE_CLIENT_SECRET"],
)
authorizer = asyncprawcore.ReadOnlyAuthorizer(authenticator)
await authorizer.refresh()
Expand All @@ -80,8 +80,7 @@ set to the appropriate values for your application.
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
asyncio.run(main())
Save the above as ``trophies.py`` and then execute via:

Expand All @@ -95,7 +94,7 @@ https://github.com/praw-dev/asyncprawcore/tree/main/examples
Depending on asyncprawcore
--------------------------

asyncprawcore follows `semantic versioning <http://semver.org/>`_ with the exception
asyncprawcore follows `semantic versioning <https://semver.org/>`_ with the exception
that deprecations will not be preceded by a minor release. In essence, expect only major
versions to introduce breaking changes to asyncprawcore's public interface. As a result,
if you depend on asyncprawcore then it is a good idea to specify not only the minimum
Expand Down
5 changes: 3 additions & 2 deletions asyncprawcore/exceptions.py
Expand Up @@ -114,10 +114,11 @@ class Redirect(ResponseException):
def __init__(self, response: ClientResponse):
"""Initialize a Redirect exception instance.
:param response: A ``aiohttp.ClientResponse`` instance.
:param response: A ``aiohttp.ClientResponse`` instance containing a location
header.
"""
path: str = urlparse(response.headers.get("location")).path
path = urlparse(response.headers.get("location")).path
self.path = path[:-5] if path.endswith(".json") else path
self.response = response
msg = f"Redirect to {self.path}"
Expand Down
9 changes: 5 additions & 4 deletions examples/caching_requestor.py
Expand Up @@ -52,8 +52,8 @@ async def main():
try:
authenticator = asyncprawcore.TrustedAuthenticator(
caching_requestor,
os.environ["asyncprawcore_CLIENT_ID"],
os.environ["asyncprawcore_CLIENT_SECRET"],
os.environ["PRAWCORE_CLIENT_ID"],
os.environ["PRAWCORE_CLIENT_SECRET"],
)
authorizer = asyncprawcore.ReadOnlyAuthorizer(authenticator)
await authorizer.refresh()
Expand Down Expand Up @@ -86,7 +86,8 @@ async def main():
finally:
await caching_requestor.close()

return 0


if __name__ == "__main__":
loop = asyncio.get_event_loop()
sys.exit(loop.run_until_complete(main()))
sys.exit(asyncio.run(main()))
5 changes: 2 additions & 3 deletions examples/device_id_auth_trophies.py
Expand Up @@ -21,7 +21,7 @@ async def main():

authenticator = asyncprawcore.UntrustedAuthenticator(
asyncprawcore.Requestor("asyncprawcore_device_id_auth_example"),
os.environ["asyncprawcore_CLIENT_ID"],
os.environ["PRAWCORE_CLIENT_ID"],
)
authorizer = asyncprawcore.DeviceIDAuthorizer(authenticator)
await authorizer.refresh()
Expand All @@ -38,5 +38,4 @@ async def main():


if __name__ == "__main__":
loop = asyncio.get_event_loop()
sys.exit(loop.run_until_complete(main()))
sys.exit(asyncio.run(main()))
11 changes: 5 additions & 6 deletions examples/obtain_refresh_token.py
Expand Up @@ -50,9 +50,9 @@ async def main():
try:
authenticator = asyncprawcore.TrustedAuthenticator(
requestor,
os.environ["ASYNCPRAWCORE_CLIENT_ID"],
os.environ["ASYNCPRAWCORE_CLIENT_SECRET"],
os.environ["ASYNCPRAWCORE_REDIRECT_URI"],
os.environ["PRAWCORE_CLIENT_ID"],
os.environ["PRAWCORE_CLIENT_SECRET"],
"http://localhost:8080",
)

state = str(random.randint(0, 65000))
Expand Down Expand Up @@ -80,11 +80,10 @@ async def main():
await authorizer.authorize(params["code"])

send_message(client, f"Refresh token: {authorizer.refresh_token}")
return 0
finally:
await requestor.close()
return 0


if __name__ == "__main__":
loop = asyncio.get_event_loop()
sys.exit(loop.run_until_complete(main()))
sys.exit(asyncio.run(main()))
11 changes: 5 additions & 6 deletions examples/read_only_auth_trophies.py
Expand Up @@ -23,8 +23,8 @@ async def main():
try:
authenticator = asyncprawcore.TrustedAuthenticator(
requestor,
os.environ["asyncprawcore_CLIENT_ID"],
os.environ["asyncprawcore_CLIENT_SECRET"],
os.environ["PRAWCORE_CLIENT_ID"],
os.environ["PRAWCORE_CLIENT_SECRET"],
)
authorizer = asyncprawcore.ReadOnlyAuthorizer(authenticator)
await authorizer.refresh()
Expand All @@ -38,12 +38,11 @@ async def main():
print(
f"{trophy['data']['name']}{(f' ({description})' if description else '')}"
)

return 0
finally:
await requestor.close()

return 0


if __name__ == "__main__":
loop = asyncio.get_event_loop()
sys.exit(loop.run_until_complete(main()))
sys.exit(asyncio.run(main()))
15 changes: 7 additions & 8 deletions examples/script_auth_friend_list.py
Expand Up @@ -21,13 +21,13 @@ async def main():
try:
authenticator = asyncprawcore.TrustedAuthenticator(
requestor,
os.environ["asyncprawcore_CLIENT_ID"],
os.environ["asyncprawcore_CLIENT_SECRET"],
os.environ["PRAWCORE_CLIENT_ID"],
os.environ["PRAWCORE_CLIENT_SECRET"],
)
authorizer = asyncprawcore.ScriptAuthorizer(
authenticator,
os.environ["asyncprawcore_USERNAME"],
os.environ["asyncprawcore_PASSWORD"],
os.environ["PRAWCORE_USERNAME"],
os.environ["PRAWCORE_PASSWORD"],
)
await authorizer.refresh()

Expand All @@ -36,12 +36,11 @@ async def main():

for friend in data["data"]["children"]:
print(friend["name"])

return 0
finally:
await requestor.close()

return 0


if __name__ == "__main__":
loop = asyncio.get_event_loop()
sys.exit(loop.run_until_complete(main()))
sys.exit(asyncio.run(main()))
14 changes: 11 additions & 3 deletions tests/conftest.py
Expand Up @@ -100,6 +100,14 @@ def __init__(self, _dict):
).split()
}

placeholders["basic_auth"] = b64encode(
f"{placeholders['client_id']}:{placeholders['client_secret']}".encode("utf-8")
).decode("utf-8")
if (
placeholders["client_id"] != "fake_client_id"
and placeholders["client_secret"] == "fake_client_secret"
):
placeholders["basic_auth"] = b64encode(
f"{placeholders['client_id']}:".encode("utf-8")
).decode("utf-8")
else:
placeholders["basic_auth"] = b64encode(
f"{placeholders['client_id']}:{placeholders['client_secret']}".encode("utf-8")
).decode("utf-8")
3 changes: 0 additions & 3 deletions tests/integration/__init__.py
Expand Up @@ -7,7 +7,6 @@
from ..utils import (
CustomPersister,
CustomSerializer,
ensure_environment_variables,
ensure_integration_test,
filter_access_token,
)
Expand Down Expand Up @@ -46,8 +45,6 @@ def cassette(self, request, recorder, cassette_name):
# before class markers.
kwargs.setdefault(key, value)
with recorder.use_cassette(cassette_name, **kwargs) as cassette:
if not cassette.write_protected:
ensure_environment_variables()
yield cassette
ensure_integration_test(cassette)
used_cassettes.add(cassette_name)
Expand Down

0 comments on commit 023e457

Please sign in to comment.