import socket
def setup():
print('setup done')
def http_server(port = 80):
with socket.create_server(('127.0.0.1',port)) as my_server:
with my_server.accept()[0] as con:
packet = con.recv(1024).decode()
con.send(b'sent mssg')
def close():
pass
import os, sys, json, threading, socket, time
import codewars_test as test
import preloaded
preloaded.make_dir()
import importlib
importlib.invalidate_caches()
time.sleep(0.01)
# prevent automated solution import
class fake_solution:
pass
sys.modules["solution"] = fake_solution
import solution
del sys.modules["solution"]
base_path = os.path.dirname(os.path.abspath(__file__))
webroot_path = f'{base_path}/server_folder/webroot'
import shutil
shutil.copy(f'{base_path}/solution.py', f'{base_path}/server_folder/solution.py')
print(os.listdir(f'{base_path}'))
print(os.listdir(f'{base_path}/server_folder'))
import server_folder.solution as solution
solution.setup()
server_thread = threading.Thread(target = solution.http_server, args = [1111])
server_thread.start()
with socket.create_connection(('127.0.0.1',1111)) as a:
a.send(b'GET / HTTP/1.1')
b = a.recv(2048).decode().replace('<', '< ')
print(b)
solution.close()
server_thread.join()