Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OSUG
RESIF
ws-sacpz-resp
Commits
808e602d
Commit
808e602d
authored
Jul 09, 2020
by
Jerome Touvier
Browse files
code refactoring
parent
eef664fc
Changes
4
Hide whitespace changes
Inline
Side-by-side
apps/constants.py
View file @
808e602d
VERSION
=
"1.0.0"
parameters
=
{
"network"
:
None
,
"station"
:
None
,
"location"
:
None
,
"channel"
:
None
,
"starttime"
:
None
,
"endtime"
:
None
,
"net"
:
"*"
,
"sta"
:
"*"
,
"loc"
:
"*"
,
"cha"
:
"*"
,
"start"
:
None
,
"end"
:
None
,
"time"
:
None
,
"nodata"
:
"204"
,
}
class
Parameters
:
def
__init__
(
self
):
self
.
network
=
None
self
.
station
=
None
self
.
location
=
None
self
.
channel
=
None
self
.
starttime
=
None
self
.
endtime
=
None
self
.
net
=
"*"
self
.
sta
=
"*"
self
.
loc
=
"*"
self
.
cha
=
"*"
self
.
start
=
None
self
.
end
=
None
self
.
time
=
None
self
.
nodata
=
"204"
self
.
constraints
=
{
"booleans"
:
[],
"floats"
:
[],
"not_none"
:
[],
}
def
todict
(
self
):
return
self
.
__dict__
ALIAS
=
[
...
...
apps/root.py
View file @
808e602d
...
...
@@ -5,7 +5,7 @@ from copy import copy
from
multiprocessing
import
Process
,
Queue
from
apps.constants
import
ALIAS
from
apps.constants
import
p
arameters
from
apps.constants
import
P
arameters
from
apps.globals
import
Error
from
apps.globals
import
HTTP
from
apps.globals
import
TIMEOUT
...
...
@@ -64,7 +64,7 @@ def check_parameters(params):
def
checks_get
(
request
):
# get default parameters
params
=
copy
(
p
arameters
)
params
=
P
arameters
().
todict
(
)
# check if the parameters are unknown
(
p
,
result
)
=
check_request
(
request
,
params
,
ALIAS
)
...
...
apps/utils.py
View file @
808e602d
...
...
@@ -136,32 +136,27 @@ def check_request(request, params, alias):
return
(
keys
,
{
"msg"
:
HTTP
.
_200_
,
"details"
:
Error
.
VALID_PARAM
,
"code"
:
200
})
def
check_base_parameters
(
params
,
max_days
=
None
,
not_none
=
None
,
booleans
=
None
,
floats
=
None
):
def
check_base_parameters
(
params
,
max_days
=
None
):
# Search for missing mandatory parameters
if
not_none
is
not
None
:
for
key
in
not_none
:
if
params
[
key
]
is
None
:
return
error_param
(
params
,
Error
.
MISSING
+
key
)
for
key
in
params
[
"constraints"
][
"not_none"
]:
if
params
[
key
]
is
None
:
return
error_param
(
params
,
Error
.
MISSING
+
key
)
# Boolean parameter validations
if
booleans
is
not
None
:
for
key
in
booleans
:
val
=
params
[
key
]
if
not
is_valid_bool_string
(
val
):
return
error_param
(
params
,
f
"Invalid
{
key
}
value:
{
val
}
{
Error
.
BOOL
}
."
)
params
[
key
]
=
True
if
val
.
lower
()
in
STRING_TRUE
else
False
for
key
in
params
[
"constraints"
][
"booleans"
]:
val
=
params
[
key
]
if
not
is_valid_bool_string
(
val
):
return
error_param
(
params
,
f
"Invalid
{
key
}
value:
{
val
}
{
Error
.
BOOL
}
."
)
params
[
key
]
=
True
if
val
.
lower
()
in
STRING_TRUE
else
False
# Float parameter validations
if
floats
is
not
None
:
for
key
in
floats
:
val
=
params
[
key
]
if
is_valid_float
(
val
):
params
[
key
]
=
float
(
val
)
elif
val
is
not
None
:
return
error_param
(
params
,
f
"Invalid
{
key
}
value:
{
val
}
"
)
for
key
in
params
[
"constraints"
][
"floats"
]:
val
=
params
[
key
]
if
is_valid_float
(
val
):
params
[
key
]
=
float
(
val
)
elif
val
is
not
None
:
return
error_param
(
params
,
f
"Invalid
{
key
}
value:
{
val
}
"
)
# Station validations
network
=
params
[
"network"
].
split
(
","
)
...
...
tests/test.py
View file @
808e602d
...
...
@@ -113,6 +113,11 @@ class MyTest(unittest.TestCase):
p1
[
"end"
]
=
None
p1
[
"time"
]
=
"2018-02-12T04:08:02"
p1
[
"nodata"
]
=
"204"
p1
[
"constraints"
]
=
{
"booleans"
:
[],
"floats"
:
[],
"not_none"
:
[],
}
valid_param
=
{
"msg"
:
HTTP
.
_200_
,
"details"
:
Error
.
VALID_PARAM
,
"code"
:
200
}
...
...
Write
Preview
Supports
Markdown
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