Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rdos
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien David
rdos
Merge requests
!5
Adding json functions
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Adding json functions
Adding-Json-FUNCTIONS
into
master
Overview
19
Commits
36
Pipelines
34
Changes
6
Merged
Ismail Moumni
requested to merge
Adding-Json-FUNCTIONS
into
master
4 years ago
Overview
15
Commits
36
Pipelines
34
Changes
1
Expand
0
0
Merge request reports
Compare
version 5
version 33
9341f38a
4 years ago
version 32
69c31724
4 years ago
version 31
982c9b38
4 years ago
version 30
1f2b01e8
4 years ago
version 29
1ee3ca19
4 years ago
version 28
53eb5fd3
4 years ago
version 27
fc74fe39
4 years ago
version 26
0ca5d143
4 years ago
version 25
d4ea05c7
4 years ago
version 24
4427d873
4 years ago
version 23
3c921e5f
4 years ago
version 22
3d1c11a9
4 years ago
version 21
eac68f6d
4 years ago
version 20
e2fc5a18
4 years ago
version 19
1c55cd4d
4 years ago
version 18
0788ddd8
4 years ago
version 17
322bf12d
4 years ago
version 16
b4b323ab
4 years ago
version 15
852c156a
4 years ago
version 14
22afc38d
4 years ago
version 13
701a3615
4 years ago
version 12
9e0f66c2
4 years ago
version 11
d82b41ee
4 years ago
version 10
fb4297dd
4 years ago
version 9
1523c90f
4 years ago
version 8
d330df5d
4 years ago
version 7
103f9d43
4 years ago
version 6
268f39cc
4 years ago
version 5
1f9f00f1
4 years ago
version 4
2bb9fba6
4 years ago
version 3
8a9bd677
4 years ago
version 2
a85102c7
4 years ago
version 1
dbc772b5
4 years ago
master (base)
and
version 6
latest version
246939d0
36 commits,
4 years ago
version 33
9341f38a
35 commits,
4 years ago
version 32
69c31724
34 commits,
4 years ago
version 31
982c9b38
33 commits,
4 years ago
version 30
1f2b01e8
32 commits,
4 years ago
version 29
1ee3ca19
31 commits,
4 years ago
version 28
53eb5fd3
30 commits,
4 years ago
version 27
fc74fe39
29 commits,
4 years ago
version 26
0ca5d143
28 commits,
4 years ago
version 25
d4ea05c7
27 commits,
4 years ago
version 24
4427d873
26 commits,
4 years ago
version 23
3c921e5f
25 commits,
4 years ago
version 22
3d1c11a9
24 commits,
4 years ago
version 21
eac68f6d
23 commits,
4 years ago
version 20
e2fc5a18
22 commits,
4 years ago
version 19
1c55cd4d
21 commits,
4 years ago
version 18
0788ddd8
20 commits,
4 years ago
version 17
322bf12d
19 commits,
4 years ago
version 16
b4b323ab
18 commits,
4 years ago
version 15
852c156a
17 commits,
4 years ago
version 14
22afc38d
16 commits,
4 years ago
version 13
701a3615
15 commits,
4 years ago
version 12
9e0f66c2
14 commits,
4 years ago
version 11
d82b41ee
13 commits,
4 years ago
version 10
fb4297dd
12 commits,
4 years ago
version 9
1523c90f
11 commits,
4 years ago
version 8
d330df5d
10 commits,
4 years ago
version 7
103f9d43
9 commits,
4 years ago
version 6
268f39cc
8 commits,
4 years ago
version 5
1f9f00f1
7 commits,
4 years ago
version 4
2bb9fba6
6 commits,
4 years ago
version 3
8a9bd677
5 commits,
4 years ago
version 2
a85102c7
4 commits,
4 years ago
version 1
dbc772b5
3 commits,
4 years ago
Show latest version
1 file
+
118
−
41
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
softwares/server/server.py
+
118
−
41
Options
# authors: Julien DAVID & Ismail MOUMNI
import
socket
import
json
import
sys
import
os
import
sys
# import database as db
sys
.
path
.
append
(
os
.
path
.
realpath
(
'
../softwares/
'
))
# from database.database import getParameters
# SERVER PORT
__RDOS_Port__
=
9393
# Dictionnary
# Need to connect to MYSQL DB
__RDOS_Dict__
=
{
"
ismail
"
:
"
moumni
"
}
# tools List
__RDOS_Tool__
=
[
"
name
"
]
__RDOS_Dict__
=
{
"
ismail
"
:
"
moumni
"
}
# tools List
__RDOS_Tool__
=
[]
class
server
:
# Creating Socket IP4 TCP
class
RdosServer
:
# Function server_conn creates a socket and listens on port 9393
# Function input address : SERVER IP ADRESS & Port server Port
# Function output query send from client to server
def
server_conn
(
address
,
PORT
):
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
serv
:
serv
.
bind
((
address
,
PORT
))
@@ -25,7 +26,7 @@ class server:
serv
.
listen
(
5
)
print
(
"
ok
"
)
# accepting the connection from client and getting client IP
conn
,
addr
=
serv
.
accept
()
conn
,
addr
=
serv
.
accept
()
print
(
"
connexion accepted
"
)
with
conn
:
print
(
'
Connexion acceptée depuis l IP :
'
,
addr
)
@@ -34,34 +35,110 @@ class server:
query
=
(
json
.
loads
(
data
.
decode
(
'
utf-8
'
)))
print
(
query
)
if
query_valid
(
query
):
dt_js
=
json
.
dumps
(
send_param_client
(
__RDOS_Dict__
,
__RDOS_Tool__
))
Tool
=
__RDOS_Tool__
dt_js
=
json
.
dumps
(
send_param_client
(
__RDOS_Dict__
,
Tool
))
print
(
dt_js
)
conn
.
send
(
bytes
((
dt_js
),
"
utf-8
"
))
serv
.
close
()
# Function query_valid matches the query send from client side
# with the the parameter dict
# Function input dictionnary from client
# Function output boolean true if match else False
def
query_valid
(
data
:
dict
):
if
'
parameters
'
in
data
:
if
(
data
[
'
parameters
'
]
==
'
request
'
)
&
(
len
(
data
)
<
2
):
return
True
return
False
# Function send_param_client send a dictionnary containing parameters
# needed to add a query to db
# Function exmaple s = {"ARGUMENTS","Tools":"List of Tools" }
# Function input takes dictionnary and a list of tools
# Function output returns a new dictionnary containing arguments
# # for db query and list of tools
def
send_param_client
(
__RDOS_Dict__
:
dict
,
__RDOS_Tools__
:
list
):
dict_cl
=
{}
if
len
(
__RDOS_Dict__
)
>
0
:
dict_cl
[
"
outils
"
]
=
(
__RDOS_Tools__
)
s
=
{
**
__RDOS_Dict__
,
**
dict_cl
}
return
s
conn
.
send
(
bytes
((
dt_js
),
"
utf-8
"
))
# Function query_valid matches the query send from client side
# with the the parameter dict
# Function input dictionnary from client
# Function output boolean true if match else False
def
query_valid
(
data
:
dict
):
if
'
parameters
'
in
data
:
if
(
data
[
'
parameters
'
]
==
'
request
'
)
&
(
len
(
data
)
<
2
):
return
True
return
False
# Function send_param_client send a dictionnary containing parameters
# needed to add a query to db
# Function exmaple s = {"ARGUMENTS","Tools":"List of Tools" }
# Function input takes dictionnary and a list of tools
# Function output returns a new dictionnary containing arguments
# # for db query and list of tools
def
send_param_client
(
__RDOS_Dict__
:
dict
,
__RDOS_Tools__
:
list
):
dict_cl
=
{}
if
len
(
__RDOS_Dict__
)
>
0
:
dict_cl
[
"
outils
"
]
=
(
__RDOS_Tools__
)
s
=
{
**
__RDOS_Dict__
,
**
dict_cl
}
return
s
# Function json_loads changes a json file into a Dict
# Function json_loads returns a Dictinnary
def
json_to_dict
(
js
):
data
=
json
.
loads
(
js
)
return
data
def
db_req
(
tool
:
str
):
tool_dict
=
db
.
getParameters
(
tool
)
return
tool_dict
def
verif_param
(
data
:
dict
):
# Tuple
# s = db.getParameters(data['tool'])
s
=
({
"
id
"
:
""
,
"
name
"
:
""
},
{})
if
s
is
not
None
:
try
:
gen
=
s
[
0
]
gen_default
=
s
[
1
]
if
match_query_dict
(
gen
,
data
):
for
a
in
data
:
if
data
[
a
]
==
""
:
data
[
a
]
=
gen_default
[
a
]
return
data
except
Exception
as
msg
:
print
(
"
Error :
"
%
msg
)
else
:
raise
Exception
(
"
Error from DB
"
)
def
match_query_dict
(
biblio
:
dict
,
data
:
dict
):
if
biblio
is
not
None
and
data
is
not
None
:
return
biblio
.
keys
()
==
data
.
keys
()
else
:
raise
ValueError
(
"
Error Dict Value
"
)
# Function match_generator_dict Matches Dictionnary with a list
# Function input 2 arguments Dictionnary and query from Server
# Function output true if dictionnary keys match list elements else false
def
match_generator_dict
(
biblio
:
dict
,
Genereator
:
list
):
for
a
in
Genereator
:
for
b
in
biblio
.
keys
():
if
a
!=
b
:
return
False
return
True
if
__name__
==
'
__main__
'
:
data
=
{
"
internet
"
:
"
internet
"
,
"
glossary
"
:
{
"
title
"
:
"
example glossary
"
,
"
GlossDiv
"
:
{
"
title
"
:
"
S
"
,
"
GlossList
"
:
{
"
GlossEntry
"
:
{
"
ID
"
:
"
SGML
"
,
"
SortAs
"
:
"
SGML
"
,
"
GlossTerm
"
:
"
Standard Generalized Markup Language
"
,
"
Acronym
"
:
"
SGML
"
,
"
Abbrev
"
:
"
ISO 8879:1986
"
,
"
GlossDef
"
:
{
"
para
"
:
"
A meta-markup language.
"
,
"
GlossSeeAlso
"
:
[
"
GML
"
,
"
XML
"
]
},
"
GlossSee
"
:
"
markup
"
}
}
}
}
}
data1
=
{
"
ll
"
:
"
s
"
,
"
ismail
"
:
"
ss
"
}
print
(
match_query_dict
(
data
,
data
))
print
(
verif_param
({
"
name
"
:
""
}))
Loading