Static typization

This commit is contained in:
Andrey 2021-10-14 18:41:57 +04:00 committed by GitHub
parent bf1bc9c553
commit aeb8f58f6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 11 deletions

View file

@ -1,5 +1,6 @@
import hashlib
import lxml.html
from typing import Optional, List
from . import atserver
from . import atconnect
@ -7,7 +8,10 @@ from . import aterrors
class Client:
def __init__(self, username, md5=None, password=None):
def __init__(
self, username:str,
md5:Optional[str]=None,
password:Optional[str]=None) -> None:
if (password == None) and (md5 == None):
raise AttributeError('Password was not specified')
@ -42,7 +46,7 @@ class Client:
)
@property
def servers(self):
def servers(self) -> List[atserver.AternosServer]:
serverspage = self.atconn.request_cloudflare(
'https://aternos.org/servers/',
atconnect.REQGET

View file

@ -9,14 +9,17 @@ FTYPE_DIR = 1
class AternosFile:
def __init__(atserv:atserver.AternosServer, path:str, name:str, ftype:int=FTYPE_FILE, size:Union[]=0):
def __init__(
atserv:atserver.AternosServer,
path:str, name:str, ftype:int=FTYPE_FILE,
size:Union[]=0) -> None:
self.atserv = atserv
self._name = name
self._ftype = ftype
self._size = size
self._size = float(size)
def delete(self):
def delete(self) -> None:
self.atserv.atserver_request(
'https://aternos.org/panel/ajax/delete.php',
@ -25,7 +28,7 @@ class AternosFile:
)
@property
def text(self):
def text(self) -> str:
editor = self.atserv.atserver_request(
f'https://aternos.org/files/{self._name}',
atconnect.REQGET
@ -41,7 +44,7 @@ class AternosFile:
return rawlines
@text.setter
def text(self, value):
def text(self, value:Union[str,bytes]) -> None:
self.atserv.atserver_request(
f'https://aternos.org/panel/ajax/save.php',
atconnect.REQPOST, data={'content': value},
@ -49,13 +52,13 @@ class AternosFile:
)
@property
def name(self):
def name(self) -> str:
return self._name
@property
def ftype(self):
def ftype(self) -> int:
return self._ftype
@property
def size(self):
def size(self) -> float:
return self._size

View file

@ -39,7 +39,10 @@ class AternosFileManager:
fsize_num = fsize_text[:fsize_text.rfind(' ')]
fsize_msr = fsize_text[fsize_text.rfind(' ')+1:]
fsize = convert_size(fsize_num, fsize_msr)
try:
fsize = convert_size(float(fsize_num), fsize_msr)
except ValueError:
fsize = -1
fullpath = f.xpath('/@data-path')[0]
filepath = fullpath[:fullpath.rfind('/')]