Arrow exprs parser!
This commit is contained in:
parent
08743f69bd
commit
bb5978f8f5
7 changed files with 29 additions and 172 deletions
|
@ -1,11 +1,9 @@
|
|||
import hashlib
|
||||
import lxml.html
|
||||
from typing import Optional, Union, List
|
||||
|
||||
from . import atserver
|
||||
from . import atconnect
|
||||
from . import aterrors
|
||||
from typing import List
|
||||
|
||||
from .atserver import AternosServer
|
||||
from .atconnect import AternosConnect
|
||||
from .aterrors import AternosCredentialsError
|
||||
|
||||
class Client:
|
||||
|
@ -17,7 +15,7 @@ class Client:
|
|||
@classmethod
|
||||
def from_hashed(cls, username:str, md5:str):
|
||||
|
||||
atconn = atconnect.AternosConnect()
|
||||
atconn = AternosConnect()
|
||||
atconn.parse_token()
|
||||
atconn.generate_sec()
|
||||
|
||||
|
@ -50,7 +48,7 @@ class Client:
|
|||
@classmethod
|
||||
def from_session(cls, session:str):
|
||||
|
||||
atconn = atconnect.AternosConnect()
|
||||
atconn = AternosConnect()
|
||||
atconn.session.cookies.set('ATERNOS_SESSION', session)
|
||||
atconn.parse_token()
|
||||
atconn.generate_sec()
|
||||
|
@ -60,7 +58,7 @@ class Client:
|
|||
@staticmethod
|
||||
def google() -> str:
|
||||
|
||||
atconn = atconnect.AternosConnect()
|
||||
atconn = AternosConnect()
|
||||
auth = atconn.request_cloudflare(
|
||||
'https://aternos.org/auth/google-login',
|
||||
atconnect.REQGET, redirect=False
|
||||
|
@ -79,6 +77,6 @@ class Client:
|
|||
servers = []
|
||||
for server in serverslist:
|
||||
servid = server.xpath('./div[@class="server-body"]/@data-id')[0]
|
||||
servers.append(atserver.AternosServer(servid, self.atconn))
|
||||
servers.append(AternosServer(servid, self.atconn))
|
||||
|
||||
return servers
|
||||
|
|
|
@ -1,57 +1,21 @@
|
|||
import re
|
||||
import regex
|
||||
import base64
|
||||
import js2py
|
||||
from typing import Optional, Union, List, Any
|
||||
|
||||
# regexr.com/6el10
|
||||
arrowexp = re.compile(r'(\(?(\w+(?:,\s*\w+)*)\)?|\(\))\s*=>\s*(({\s*.+\s*})|(.+;|.+$))')
|
||||
|
||||
# Thanks to https://stackoverflow.com/a/1651562/17901968
|
||||
def brackets(s:str, search:Optional[str]=None) -> List[Union[int]]:
|
||||
result = []
|
||||
content = [s]
|
||||
repeated = False
|
||||
for expr in content:
|
||||
if expr.find('(') == -1: continue
|
||||
count = -1
|
||||
indexes = []
|
||||
cont = False
|
||||
for i, ch in enumerate(expr):
|
||||
if ch == '(':
|
||||
indexes.append(i)
|
||||
if count == -1:
|
||||
count = 1
|
||||
else:
|
||||
count += 1
|
||||
if ch == ')':
|
||||
if len(indexes) > 1:
|
||||
indexes.pop()
|
||||
else:
|
||||
indexes.append(i)
|
||||
if expr.find('(', i) != -1:
|
||||
cont = True
|
||||
count -= 1
|
||||
if count == 0: break
|
||||
if count != 0:
|
||||
raise ValueError('Unmatched parenthesis')
|
||||
else:
|
||||
inner = expr[indexes[0]+1:indexes[1]]
|
||||
if repeated:
|
||||
content.pop()
|
||||
repeated = False
|
||||
content.append(inner)
|
||||
if search == None \
|
||||
or search in inner:
|
||||
result.append(indexes)
|
||||
if cont:
|
||||
content.append(content[len(content)-2])
|
||||
repeated = True
|
||||
return result
|
||||
# Thanks to http://regex.inginf.units.it/
|
||||
arrowexp = regex.compile(r'\w[^\}]*+')
|
||||
|
||||
def to_ecma5_function(f:str) -> str:
|
||||
pass
|
||||
match = arrowexp.search(f)
|
||||
conv = '(function(){' + match.group(0) + '})()'
|
||||
return regex.sub(
|
||||
r'(?:s|\(s\)) => s.split\([\'"]{2}\).reverse\(\).join\([\'"]{2}\)',
|
||||
'function(s){return s.split(\'\').reverse().join(\'\')}',
|
||||
conv
|
||||
)
|
||||
|
||||
def atob(s):
|
||||
def atob(s:str) -> str:
|
||||
return base64.standard_b64decode(str(s)).decode('utf-8')
|
||||
|
||||
def exec(f:str) -> Any:
|
||||
|
|
Reference in a new issue