Skip to content

Commit

Permalink
initial commit - file layout done, requests and auth handled(?)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbstractUmbra committed Jul 12, 2021
0 parents commit fa8e543
Show file tree
Hide file tree
Showing 11 changed files with 1,033 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__/
env/
build/
7 changes: 7 additions & 0 deletions LICENSE
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.
51 changes: 51 additions & 0 deletions mangadex/__init__.py
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())
77 changes: 77 additions & 0 deletions mangadex/__main__.py
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()
50 changes: 50 additions & 0 deletions mangadex/errors.py
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)
Loading

0 comments on commit fa8e543

Please sign in to comment.