Static typization
This commit is contained in:
parent
bf1bc9c553
commit
aeb8f58f6e
3 changed files with 21 additions and 11 deletions
|
@ -1,5 +1,6 @@
|
||||||
import hashlib
|
import hashlib
|
||||||
import lxml.html
|
import lxml.html
|
||||||
|
from typing import Optional, List
|
||||||
|
|
||||||
from . import atserver
|
from . import atserver
|
||||||
from . import atconnect
|
from . import atconnect
|
||||||
|
@ -7,7 +8,10 @@ from . import aterrors
|
||||||
|
|
||||||
class Client:
|
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):
|
if (password == None) and (md5 == None):
|
||||||
raise AttributeError('Password was not specified')
|
raise AttributeError('Password was not specified')
|
||||||
|
@ -42,7 +46,7 @@ class Client:
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def servers(self):
|
def servers(self) -> List[atserver.AternosServer]:
|
||||||
serverspage = self.atconn.request_cloudflare(
|
serverspage = self.atconn.request_cloudflare(
|
||||||
'https://aternos.org/servers/',
|
'https://aternos.org/servers/',
|
||||||
atconnect.REQGET
|
atconnect.REQGET
|
||||||
|
|
|
@ -9,14 +9,17 @@ FTYPE_DIR = 1
|
||||||
|
|
||||||
class AternosFile:
|
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.atserv = atserv
|
||||||
self._name = name
|
self._name = name
|
||||||
self._ftype = ftype
|
self._ftype = ftype
|
||||||
self._size = size
|
self._size = float(size)
|
||||||
|
|
||||||
def delete(self):
|
def delete(self) -> None:
|
||||||
|
|
||||||
self.atserv.atserver_request(
|
self.atserv.atserver_request(
|
||||||
'https://aternos.org/panel/ajax/delete.php',
|
'https://aternos.org/panel/ajax/delete.php',
|
||||||
|
@ -25,7 +28,7 @@ class AternosFile:
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def text(self):
|
def text(self) -> str:
|
||||||
editor = self.atserv.atserver_request(
|
editor = self.atserv.atserver_request(
|
||||||
f'https://aternos.org/files/{self._name}',
|
f'https://aternos.org/files/{self._name}',
|
||||||
atconnect.REQGET
|
atconnect.REQGET
|
||||||
|
@ -41,7 +44,7 @@ class AternosFile:
|
||||||
return rawlines
|
return rawlines
|
||||||
|
|
||||||
@text.setter
|
@text.setter
|
||||||
def text(self, value):
|
def text(self, value:Union[str,bytes]) -> None:
|
||||||
self.atserv.atserver_request(
|
self.atserv.atserver_request(
|
||||||
f'https://aternos.org/panel/ajax/save.php',
|
f'https://aternos.org/panel/ajax/save.php',
|
||||||
atconnect.REQPOST, data={'content': value},
|
atconnect.REQPOST, data={'content': value},
|
||||||
|
@ -49,13 +52,13 @@ class AternosFile:
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self) -> str:
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ftype(self):
|
def ftype(self) -> int:
|
||||||
return self._ftype
|
return self._ftype
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def size(self):
|
def size(self) -> float:
|
||||||
return self._size
|
return self._size
|
||||||
|
|
|
@ -39,7 +39,10 @@ class AternosFileManager:
|
||||||
fsize_num = fsize_text[:fsize_text.rfind(' ')]
|
fsize_num = fsize_text[:fsize_text.rfind(' ')]
|
||||||
fsize_msr = fsize_text[fsize_text.rfind(' ')+1:]
|
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]
|
fullpath = f.xpath('/@data-path')[0]
|
||||||
filepath = fullpath[:fullpath.rfind('/')]
|
filepath = fullpath[:fullpath.rfind('/')]
|
||||||
|
|
Reference in a new issue