-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from MarzaElise/main
Added context manager support and fixed bugs
- Loading branch information
Showing
8 changed files
with
332 additions
and
162 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*__pycache__ | ||
venv/ | ||
**/__pycache__ | ||
venv/ | ||
test.md |
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .quran import * | ||
from .bible import * | ||
from .torah import * | ||
from .errors import * |
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
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,67 @@ | ||
from typing import TYPE_CHECKING | ||
from typing import Optional, Union | ||
|
||
__all__ = ( | ||
"ApiError", | ||
"ContentTypeError", | ||
"NumberError", | ||
"WrongLang", | ||
"NotFound", | ||
"BibleOnly", | ||
) | ||
|
||
|
||
class ApiError(Exception): | ||
def __init__(self, status: int, msg: str) -> None: | ||
super().__init__(f"Api has an error, return code: {status}.\n{msg}") | ||
|
||
|
||
class ContentTypeError(Exception): | ||
def __init__( | ||
self, | ||
class_: str, | ||
mode: str, | ||
first_query: Optional[Union[str, int]], | ||
second_query: Optional[Union[str, int]], | ||
) -> None: | ||
super().__init__( | ||
f"Attempt to decode JSON with unexpected mimetype: Return code: None\nlink: http://api.alquran.cloud/v1/{mode}/{first_query}:{second_query}/en.asad" | ||
if class_ == "Ayah" | ||
else f"Attempt to decode JSON with unexpected mimetype: Return code: None\nlink: http://api.alquran.cloud/v1/{mode}/{first_query}/{second_query}/en.asad" | ||
) | ||
|
||
|
||
class NumberError(Exception): | ||
def __init__( | ||
self, | ||
mode: int, | ||
obj: str, | ||
first_query: int, | ||
second_query: Optional[Union[str, int]], | ||
) -> None: | ||
super().__init__( | ||
f"{obj} must above {first_query}" | ||
if mode == 0 | ||
else f"{obj} must be between {first_query} to {second_query}" | ||
) | ||
|
||
|
||
class WrongLang(Exception): | ||
def __init__(self, lang: str) -> None: | ||
super().__init__( | ||
f"The lang '{lang}' is not supported, it only support arabic(ar) and english(eng)" | ||
) | ||
|
||
|
||
class NotFound(Exception): | ||
def __init__(self, book: str, chapter: int, verse: str) -> None: | ||
super().__init__( | ||
f"Book {book}, Chapter {chapter}, Verse(s) {verse} Wasn't Found." | ||
) | ||
|
||
|
||
class BibleOnly(Exception): | ||
def __init__(self, book: str) -> None: | ||
super().__init__( | ||
f"The book {book} wasn't found because its available only in Bible" | ||
) |
Oops, something went wrong.