mirror of
https://github.com/RGBCube/GitHubWrapper
synced 2025-05-31 04:58:12 +00:00
Rewrote the library
- Only HTTPClient, File and Object exists currently
This commit is contained in:
parent
7bd3d48eab
commit
b23d5b78eb
16 changed files with 1048 additions and 1534 deletions
2
github/objects/__init__.py
Normal file
2
github/objects/__init__.py
Normal file
|
@ -0,0 +1,2 @@
|
|||
from .file import *
|
||||
from .object import *
|
26
github/objects/file.py
Normal file
26
github/objects/file.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
__all__ = ("File",)
|
||||
|
||||
import os
|
||||
from io import BytesIO, StringIO
|
||||
from pathlib import Path
|
||||
from typing import Union
|
||||
|
||||
|
||||
class File:
|
||||
def __init__(self, file: Union[str, StringIO, BytesIO], /, *, filename: str) -> None:
|
||||
self._file = file
|
||||
self.name = filename
|
||||
|
||||
def read(self) -> str:
|
||||
f = self._file
|
||||
|
||||
if isinstance(f, BytesIO):
|
||||
return f.read().decode("utf-8")
|
||||
|
||||
if isinstance(f, StringIO):
|
||||
return f.getvalue()
|
||||
|
||||
if os.path.exists(f):
|
||||
return Path(f).read_text()
|
||||
|
||||
return f
|
18
github/objects/object.py
Normal file
18
github/objects/object.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from __future__ import annotations
|
||||
|
||||
__all__ = ("Object",)
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..internals import HTTPClient
|
||||
|
||||
|
||||
class Object:
|
||||
__slots__ = ("__http",)
|
||||
|
||||
def __init__(self, *, http: HTTPClient) -> None:
|
||||
self.__http = http
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<{self.__class__.__name__}>"
|
Loading…
Add table
Add a link
Reference in a new issue