This commit is contained in:
lda committed 2025-05-01 22:42:52 +07:00
1 parent 35fc621883
commit 0c967a4f9c
1 file changed
+60 -75
+60 -75
View File
@@ -336,6 +336,10 @@ class ServerLogic(serverhttp.BaseHTTPRequestHandler):
# pass # pass
self.end_headers() self.end_headers()
def print_setup(self, code, headers, content):
self.header_setup(code, headers)
self.wfile.write(content)
def do_GET(self): def do_GET(self):
self.reallyEveryTime() self.reallyEveryTime()
pathObj: urlparse.ParseResult = urlparse.urlparse(self.path) pathObj: urlparse.ParseResult = urlparse.urlparse(self.path)
@@ -358,12 +362,13 @@ class ServerLogic(serverhttp.BaseHTTPRequestHandler):
case "/close": case "/close":
return self.close() return self.close()
case p if p != "/endp": # self.path case "/endp":
return post_endp_lda(self)
case _: # self.path
self.header_setup(rescode.FORBIDDEN) self.header_setup(rescode.FORBIDDEN)
self.wfile.write(notallowed403) self.wfile.write(notallowed403)
return return
case _:
return post_endp_lda(self)
def post_endp_lda(self): def post_endp_lda(self):
@@ -375,84 +380,44 @@ def post_endp_lda(self):
post_data_bytes = r.read(content_length) post_data_bytes = r.read(content_length)
## read how many bytes is the content length ## read how many bytes is the content length
def lmao(self, ldarescode, stupid, ldacause=None): # def lmao(self: ServerLogic, ldarescode, stupid, ldacause=None):
efg = ( efg = (
f'Ive got a POST at {self.headers.get("Origin", "_nowhere lmao_")} from {self.headers.get("Referer", "_who?_")} with the following data:\n'.encode() f'Ive got a POST at {self.headers.get("Origin", "_nowhere lmao_")} from {self.headers.get("Referer", "_who?_")} with the following data:\n'.encode()
+ ( + (
post_data_bytes post_data_bytes
or b"nothing??? what? (no fr nothing fr ALSO YOU KNOW YOUR OWN POST????????????)" or b"nothing??? what? (no fr nothing fr ALSO YOU KNOW YOUR OWN POST????????????)"
) # why so hectic ) # why so hectic
+ b"\n" + b"\n"
) )
headerWhat = {"Content-type": "text/plain;charset=utf-8"} # tf headerWhat = {"Content-type": "text/plain;charset=utf-8"} # tf
match stupid:
case 1:
print("cccc", content_type, content_length)
self.header_setup(
code=ldarescode,
headers=headerWhat,
)
self.wfile.write(efg)
self.wfile.write(b"its of the type: ")
self.wfile.write(content_type.encode() or b"fdahjklfdashkjlasdf")
case 2:
cc = ldacause
print(cc)
self.header_setup(
code=rescode.BAD_REQUEST,
headers=headerWhat,
)
self.wfile.write(efg)
self.wfile.write(
b"haha your data sucks (json.loads is not necessarily strict/bad, its just u sent bad): "
+ str(cc).encode()
)
case 3:
cc = ldacause
# print("execute err: ", cc)
q = str(cc)
for a, b in zip(severColum, clietColum):
q = q.replace(a, b)
# print("execute errd: ", q)
self.header_setup(
code=rescode.BAD_REQUEST,
headers=headerWhat,
)
self.wfile.write(efg)
self.wfile.write(
b"is it very much Invalid: "
+ q.encode()
+ b"\n funny Stuff: # replace strings found in list old to same index in list new. used for, zip, string.replace"
)
case 4:
self.header_setup(
code=rescode.CREATED,
headers=headerWhat,
)
self.wfile.write(efg)
case 5:
cc = ldacause
print("coneti eror: ", cc)
self.header_setup(
code=rescode.INTERNAL_SERVER_ERROR,
headers=headerWhat,
)
self.wfile.write(efg)
self.wfile.write(
b"the thing cant even start like what f: " + str(cc).encode()
)
if content_type != "application/json": if content_type != "application/json":
return lmao(self, rescode.OK, 1) print("cccc", content_type, content_length)
return self.print_setup(
code=rescode.OK,
headers=headerWhat,
content=efg
+ b"its of the type: "
+ (content_type.encode() or b"fdahjklfdashkjlasdf"),
)
# return lmao(self, rescode.OK, 1)
# self.wfile.write(b"its of the type: ") # self.wfile.write(b"its of the type: ")
# self.wfile.write(content_type.encode()) # self.wfile.write(content_type.encode())
try: try:
data_dict: dict = json.loads(post_data_bytes) data_dict: dict = json.loads(post_data_bytes)
## ##
except json.JSONDecodeError as e: except json.JSONDecodeError as cc:
return lmao(self, rescode.BAD_REQUEST, 2, e) print(cc)
return self.print_setup(
code=rescode.BAD_REQUEST,
headers=headerWhat,
content=efg
+ b"haha your data sucks (json.loads is not necessarily strict/bad, its just u sent bad): "
+ str(cc).encode(),
)
# return lmao(self, rescode.BAD_REQUEST, 2, e)
if data_dict.get("from") == "ldlda": if data_dict.get("from") == "ldlda":
data_dict = getnewdicttranslate( data_dict = getnewdicttranslate(
@@ -496,11 +461,31 @@ def post_endp_lda(self):
print("res of:", cur.fetchone()) print("res of:", cur.fetchone())
except sqlcon.Error as er: except sqlcon.Error as er:
return lmao(self, rescode.BAD_REQUEST, 3, er) q = str(er)
return lmao(self, rescode.CREATED, 4) for a, b in zip(severColum, clietColum):
q = q.replace(a, b)
# print("execute errd: ", q)
return self.print_setup(
code=rescode.BAD_REQUEST,
headers=headerWhat,
content=efg
+ b"is it very much Invalid: "
+ q.encode()
+ b"\n funny Stuff: # replace strings found in list old to same index in list new. used for, zip, string.replace",
)
# return lmao(self, rescode.BAD_REQUEST, 3, er)
return self.print_setup(code=rescode.CREATED, headers=headerWhat, content=efg)
except sqlcon.Error as eror: except sqlcon.Error as eror:
return lmao(self, rescode.INTERNAL_SERVER_ERROR, 5, eror) print("coneti eror: ", eror)
return self.print_setup(
code=rescode.INTERNAL_SERVER_ERROR,
headers=headerWhat,
content=efg
+ b"the thing cant even start like what f: "
+ str(eror).encode(),
)
# return lmao(self, rescode.INTERNAL_SERVER_ERROR, 5, eror)
# what the fuck is this # what the fuck is this