Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Julien David
rdos
Commits
7c5cfc3b
Commit
7c5cfc3b
authored
Oct 02, 2020
by
Ismail Moumni
Browse files
Editing server_conn
parent
256f9993
Pipeline
#1062
failed with stage
in 14 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
softwares/server/server.py
View file @
7c5cfc3b
...
...
@@ -6,7 +6,6 @@ import sys
import
database.database
as
db
sys
.
path
.
append
(
os
.
path
.
realpath
(
'../softwares/'
))
__RDOS_Dict__
=
{}
# tools List
...
...
@@ -34,18 +33,12 @@ class RdosServer:
print
(
"Requete reçu : "
,
query
)
if
(
query
is
not
None
):
# Sending GENERATORS
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
)
print
(
ins
)
else
:
raise
Exception
(
"Query doesn't match!"
)
conn
.
send
(
bytes
(
json
.
dumps
(
match
),
"utf-8"
))
else
:
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
_param
eters
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
_param
eters
(
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
else
:
raise
Exception
(
"
Error Database
"
)
raise
Exception
(
"
Dictionnaire non Valid
"
)
else
:
raise
Exception
(
"Dictionnaire Vide!!"
)
...
...
@@ -156,13 +149,11 @@ 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"
)
else
:
raise
Exception
(
"Query Doesn't match"
)
raise
Exception
(
"Invalid Query"
)
ins
=
db
.
insert_query
(
req
)
s
.
send
(
bytes
(
json
.
dumps
(
ins
),
"utf-8"
))
print
(
"Query send"
)
else
:
raise
Exception
(
"Invalid Query"
)
if
__name__
==
'__main__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment