-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit - file layout done, requests and auth handled(?)
- Loading branch information
0 parents
commit fa8e543
Showing
11 changed files
with
1,033 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
__pycache__/ | ||
env/ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2021-Present AbstractUmbra | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
The MIT License (MIT) | ||
Copyright (c) 2021-Present AbstractUmbra | ||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
""" | ||
|
||
__title__ = "mangadex" | ||
__author__ = "AbstractUmbra" | ||
__license__ = "MIT" | ||
__copyright__ = "Copyright 2021-present AbstractUmbra" | ||
__version__ = "0.1.0a" | ||
|
||
__path__ = __import__("pkgutil").extend_path(__path__, __name__) | ||
|
||
import logging | ||
from typing import NamedTuple | ||
|
||
from .http import HTTPClient as Client | ||
from .utils import * | ||
|
||
|
||
class VersionInfo(NamedTuple): | ||
major: int | ||
minor: int | ||
micro: int | ||
releaselevel: str | ||
serial: int | ||
|
||
|
||
__version__ = "0.1.0" | ||
version_info = VersionInfo(major=0, minor=1, micro=0, releaselevel="alpha", serial=0) | ||
|
||
logging.getLogger(__name__).addHandler(logging.NullHandler()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
""" | ||
The MIT License (MIT) | ||
Copyright (c) 2021-Present AbstractUmbra | ||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
""" | ||
|
||
import argparse | ||
import platform | ||
import sys | ||
|
||
import aiohttp | ||
import pkg_resources | ||
|
||
import mangadex | ||
|
||
|
||
def show_version(): | ||
entries: list[str] = [] | ||
|
||
version_info = sys.version_info | ||
entries.append(f"- Python v{version_info.major}.{version_info.minor}.{version_info.micro}-{version_info.releaselevel}") | ||
|
||
md_version_info = mangadex.version_info | ||
entries.append( | ||
f"- mangadex.py v{md_version_info.major}.{md_version_info.minor}.{md_version_info.micro}-{md_version_info.releaselevel}" | ||
) | ||
|
||
if md_version_info.releaselevel != "final": | ||
pkg = pkg_resources.get_distribution("mangadex.py") | ||
if pkg: | ||
entries.append(f" - mangadex.py pkg_resources: v{pkg.version}") | ||
|
||
entries.append(f" - aiohttp {aiohttp.__version__}") | ||
uname = platform.uname() | ||
entries.append(f"- system info: {uname.system} {uname.release} {uname.version}") | ||
|
||
print("\n".join(entries)) | ||
|
||
|
||
def parse_args() -> tuple[argparse.ArgumentParser, argparse.Namespace]: | ||
parser = argparse.ArgumentParser(prog="mangadex", description="Tools for helping with mangadex.py") | ||
parser.add_argument("-v", "--version", action="store_true", help="shows the wrapper version") | ||
|
||
parser.set_defaults(func=core) | ||
|
||
return parser, parser.parse_args() | ||
|
||
|
||
def core(parser: argparse.ArgumentParser, args: argparse.Namespace): | ||
if args.version: | ||
show_version() | ||
|
||
|
||
def main(): | ||
parser, args = parse_args() | ||
args.func(parser, args) | ||
|
||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
The MIT License (MIT) | ||
Copyright (c) 2021-Present AbstractUmbra | ||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
""" | ||
import datetime | ||
|
||
|
||
__all__ = ("APIException", "LoginError", "RefreshError") | ||
|
||
|
||
class APIException(Exception): | ||
"""Generic API error when the response code is a non 2xx error.""" | ||
|
||
def __init__(self, message: str, response_code: int) -> None: | ||
self.message = message | ||
self.response_code = response_code | ||
super().__init__() | ||
|
||
|
||
class LoginError(APIException): | ||
"""An error during the login process.""" | ||
|
||
|
||
class RefreshError(APIException): | ||
"""An error during the token refresh process.""" | ||
|
||
def __init__(self, message: str, response_code: int, last_refresh: datetime.datetime) -> None: | ||
self.message = message | ||
self.response_code = response_code | ||
self.last_refresh = last_refresh | ||
super().__init__(message, response_code) |
Oops, something went wrong.