1
Fork 0
mirror of https://github.com/RGBCube/GitHubWrapper synced 2025-05-16 22:15:09 +00:00

Fix files

This commit is contained in:
VarMonke 2022-04-17 02:07:17 +05:30
parent 71901dce4b
commit f75886bc92
2 changed files with 13 additions and 5 deletions

2
.gitignore vendored
View file

@ -4,7 +4,7 @@ __pycache__/
*$py.class *$py.class
#var is weird #var is weird
test.py test*.py
.vscode/ .vscode/
# C extensions # C extensions

View file

@ -8,6 +8,8 @@ if TYPE_CHECKING:
from datetime import datetime from datetime import datetime
import io import io
import os
from contextlib import nullcontext
__all__ = ( __all__ = (
'APIObject', 'APIObject',
@ -220,11 +222,17 @@ class File:
def read(self) -> str: def read(self) -> str:
if isinstance(self.fp, str): if isinstance(self.fp, str):
with open(self.fp) as fp: if os.path.exists(self.fp):
data = fp.read() with open(self.fp) as fp:
return data data = fp.read()
return data
return self.fp
elif isinstance(self.fp, io.BytesIO):
return self.fp.read().decode('utf-8')
elif isinstance(self.fp, io.StringIO):
return self.fp.getvalue()
else: else:
return self.fp.read() raise TypeError(f'Expected str, io.StringIO, or io.BytesIO, got {type(self.fp)}')
class Gist(APIObject): class Gist(APIObject):
__slots__ = ( __slots__ = (