Commit 7c5cfc3b authored by Ismail Moumni's avatar Ismail Moumni
Browse files

Editing server_conn

parent 256f9993
Pipeline #1062 failed with stage
in 14 seconds
......@@ -6,7 +6,6 @@ import sys
import database.database as db
__RDOS_Dict__ = {}
# tools List
......@@ -34,18 +33,12 @@ class RdosServer:
print("Requete reçu : ", query)
if(query is not None):
if (query["request"] == "generators"):
if (query_valid(query)):
response = db.db_generators()
conn.send(bytes(json.dumps(response), "utf-8"))
# Inserting in DATABASE
elif (query["Tool"] is not None):
match = verif_param(query)
if match != query:
ins = db_insert(conn, match)
raise Exception("Query doesn't match!")
conn.send(bytes(json.dumps(match), "utf-8"))
db_insert(conn, check_and_complete_parameters(query))
# Function query_valwid matches the query send from client side
......@@ -108,10 +101,10 @@ def match_query_dict(biblio: dict, data: dict):
raise ValueError("Error Dict Values ")
# Function verif_param verifies json send from client to server by matching it with database query
# Function check_and_complete_parameters verifies json send from client to server by matching it with database query
# Function input takes a dictionary
# Function output returns query if it matches with database query keys if not it raises an error
def verif_param(data: dict):
def check_and_complete_parameters(data: dict):
if data is not None:
tool = data.keys().strip('[]')
s = db.getParameters(data['tool'])
......@@ -146,7 +139,7 @@ def db_generators(req: dict):
s = db.get_generators()
return s
raise Exception("Error Database")
raise Exception("Dictionnaire non Valid")
raise Exception("Dictionnaire Vide!!")
......@@ -156,12 +149,10 @@ def db_generators(req: dict):
# Function db_insert returns a string if query send
def db_insert(s: socket, req: dict):
if(req is not None):
if (verif_param(req) == req):
ins = db.insert_query(req)
s.send(bytes(json.dumps(ins), "utf-8"))
print("Query send")
raise Exception("Query Doesn't match")
raise Exception("Invalid Query")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment