Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-dfs
csst-dfs-client
Commits
9204e31d
Commit
9204e31d
authored
Jan 06, 2026
by
Wei Shoulin
Browse files
feat: add instrument validation and improve timeout handling
parent
c379610a
Changes
6
Show whitespace changes
Inline
Side-by-side
csst_dfs_client/common/constants.py
View file @
9204e31d
DEFAULT_DATASET
=
'routine'
DEFAULT_DATASET
=
'routine'
DEFAULT_BATCH_ID
=
'auto'
DEFAULT_BATCH_ID
=
'auto'
INSTRUMENTS
=
[
'MSC'
,
'IFS'
,
'MCI'
,
'HSTDM'
,
'CPIC'
]
\ No newline at end of file
csst_dfs_client/common/request.py
View file @
9204e31d
...
@@ -38,7 +38,7 @@ def get(endpoint: str, timeout = os.getenv("CSST_DFS_REQUEST_TIMEOUT", None)) ->
...
@@ -38,7 +38,7 @@ def get(endpoint: str, timeout = os.getenv("CSST_DFS_REQUEST_TIMEOUT", None)) ->
return
requests
.
get
(
return
requests
.
get
(
url
=
get_request_url
(
endpoint
),
url
=
get_request_url
(
endpoint
),
headers
=
auth_header
(),
headers
=
auth_header
(),
timeout
=
timeout
timeout
=
float
(
timeout
)
if
timeout
else
None
)
)
@
request_error_handler_decorator
@
request_error_handler_decorator
...
@@ -47,7 +47,7 @@ def post(endpoint: str, data: dict, timeout = os.getenv("CSST_DFS_REQUEST_TIMEOU
...
@@ -47,7 +47,7 @@ def post(endpoint: str, data: dict, timeout = os.getenv("CSST_DFS_REQUEST_TIMEOU
url
=
get_request_url
(
endpoint
),
url
=
get_request_url
(
endpoint
),
headers
=
auth_header
(),
headers
=
auth_header
(),
json
=
data
,
json
=
data
,
timeout
=
timeout
timeout
=
float
(
timeout
)
if
timeout
else
None
)
)
@
request_error_handler_decorator
@
request_error_handler_decorator
...
@@ -56,7 +56,7 @@ def put(endpoint: str, data: Optional[dict] = None, timeout = os.getenv("CSST_DF
...
@@ -56,7 +56,7 @@ def put(endpoint: str, data: Optional[dict] = None, timeout = os.getenv("CSST_DF
url
=
get_request_url
(
endpoint
),
url
=
get_request_url
(
endpoint
),
headers
=
auth_header
(),
headers
=
auth_header
(),
json
=
data
,
json
=
data
,
timeout
=
timeout
timeout
=
float
(
timeout
)
if
timeout
else
None
)
)
@
request_error_handler_decorator
@
request_error_handler_decorator
...
@@ -65,7 +65,7 @@ def delete(endpoint: str, data: Optional[dict] = None, timeout = os.getenv("CSST
...
@@ -65,7 +65,7 @@ def delete(endpoint: str, data: Optional[dict] = None, timeout = os.getenv("CSST
url
=
get_request_url
(
endpoint
),
url
=
get_request_url
(
endpoint
),
headers
=
auth_header
(),
headers
=
auth_header
(),
json
=
data
,
json
=
data
,
timeout
=
timeout
timeout
=
float
(
timeout
)
if
timeout
else
None
)
)
def
post_file
(
endpoint
:
str
,
file_path
:
str
,
data
:
dict
):
def
post_file
(
endpoint
:
str
,
file_path
:
str
,
data
:
dict
):
...
@@ -80,7 +80,7 @@ def post_bytesio(endpoint: str, file_bytes: IO, data: dict, timeout = os.getenv(
...
@@ -80,7 +80,7 @@ def post_bytesio(endpoint: str, file_bytes: IO, data: dict, timeout = os.getenv(
files
=
{
files
=
{
"file"
:
file_bytes
"file"
:
file_bytes
},
},
data
=
data
,
timeout
=
timeout
data
=
data
,
timeout
=
float
(
timeout
)
if
timeout
else
None
)
)
def
download_file
(
endpoint
:
str
,
timeout
=
os
.
getenv
(
"CSST_DFS_REQUEST_TIMEOUT"
,
None
))
->
requests
.
Response
:
def
download_file
(
endpoint
:
str
,
timeout
=
os
.
getenv
(
"CSST_DFS_REQUEST_TIMEOUT"
,
None
))
->
requests
.
Response
:
...
@@ -96,5 +96,5 @@ def download_file(endpoint: str, timeout = os.getenv("CSST_DFS_REQUEST_TIMEOUT",
...
@@ -96,5 +96,5 @@ def download_file(endpoint: str, timeout = os.getenv("CSST_DFS_REQUEST_TIMEOUT",
"""
"""
return
requests
.
get
(
return
requests
.
get
(
url
=
get_request_url
(
endpoint
),
url
=
get_request_url
(
endpoint
),
headers
=
auth_header
(),
timeout
=
timeout
headers
=
auth_header
(),
timeout
=
float
(
timeout
)
if
timeout
else
None
)
)
\ No newline at end of file
csst_dfs_client/level0.py
View file @
9204e31d
...
@@ -8,7 +8,7 @@ DateTimeTuple = Tuple[str, str]
...
@@ -8,7 +8,7 @@ DateTimeTuple = Tuple[str, str]
def
find
(
def
find
(
dataset
:
str
,
dataset
:
str
,
instrument
:
Literal
[
"MSC"
,
"IFS"
,
"MCI"
,
"HSTDM"
,
"CPIC"
]
,
instrument
:
str
,
data_model
:
str
=
"raw"
,
data_model
:
str
=
"raw"
,
data_uuid
:
Optional
[
str
]
=
None
,
data_uuid
:
Optional
[
str
]
=
None
,
obs_group
:
Optional
[
str
]
=
None
,
obs_group
:
Optional
[
str
]
=
None
,
...
@@ -58,6 +58,8 @@ def find(
...
@@ -58,6 +58,8 @@ def find(
Result: 搜索结果对象.
Result: 搜索结果对象.
"""
"""
if
instrument
not
in
constants
.
INSTRUMENTS
:
raise
ValueError
(
f
"Instrument
{
instrument
}
is not supported"
)
params
=
{
params
=
{
"data_uuid"
:
data_uuid
,
"data_uuid"
:
data_uuid
,
...
...
csst_dfs_client/level1.py
View file @
9204e31d
...
@@ -5,7 +5,7 @@ import os
...
@@ -5,7 +5,7 @@ import os
DateTimeTuple
=
Tuple
[
str
,
str
]
DateTimeTuple
=
Tuple
[
str
,
str
]
def
find
(
def
find
(
instrument
:
Literal
[
'MSC'
,
'IFS'
,
'MCI'
,
'HSTDM'
,
'CPIC'
]
,
instrument
:
str
,
dataset
:
str
,
dataset
:
str
,
batch_id
:
str
,
batch_id
:
str
,
obs_group
:
Optional
[
str
]
=
None
,
obs_group
:
Optional
[
str
]
=
None
,
...
@@ -64,6 +64,8 @@ def find(
...
@@ -64,6 +64,8 @@ def find(
Result: 搜索结果对象.
Result: 搜索结果对象.
"""
"""
if
instrument
not
in
constants
.
INSTRUMENTS
:
raise
ValueError
(
f
"Instrument
{
instrument
}
is not supported"
)
params
=
{
params
=
{
'obs_group'
:
obs_group
,
'obs_group'
:
obs_group
,
...
...
csst_dfs_client/level2.py
View file @
9204e31d
...
@@ -8,7 +8,7 @@ DateTimeTuple = Tuple[str, str]
...
@@ -8,7 +8,7 @@ DateTimeTuple = Tuple[str, str]
def
find
(
def
find
(
obs_group
:
Optional
[
str
]
=
None
,
obs_group
:
Optional
[
str
]
=
None
,
obs_id
:
Optional
[
str
]
=
None
,
obs_id
:
Optional
[
str
]
=
None
,
instrument
:
Literal
[
'MSC'
,
'IFS'
,
'MCI'
,
'HSTDM'
,
'CPIC'
]
=
'MSC'
,
instrument
:
str
=
'MSC'
,
detector
:
Optional
[
str
]
=
None
,
detector
:
Optional
[
str
]
=
None
,
data_model
:
Optional
[
str
]
=
None
,
data_model
:
Optional
[
str
]
=
None
,
filter
:
Optional
[
str
]
=
None
,
filter
:
Optional
[
str
]
=
None
,
...
@@ -47,7 +47,8 @@ def find(
...
@@ -47,7 +47,8 @@ def find(
Result: 搜索结果对象.
Result: 搜索结果对象.
"""
"""
if
instrument
not
in
constants
.
INSTRUMENTS
:
raise
ValueError
(
f
"Instrument
{
instrument
}
is not supported"
)
params
=
{
params
=
{
'obs_group'
:
obs_group
,
'obs_group'
:
obs_group
,
'obs_id'
:
obs_id
,
'obs_id'
:
obs_id
,
...
...
tests/test_utils.py
0 → 100644
View file @
9204e31d
import
unittest
from
csst_dfs_client.common.utils
import
is_valid_datetime_format
class
TestIsValidDatetimeFormat
(
unittest
.
TestCase
):
def
test_valid_basic_format
(
self
):
"""测试有效的基础格式日期时间"""
self
.
assertTrue
(
is_valid_datetime_format
(
"2023-05-15 14:30:00"
))
def
test_valid_iso_format_without_timezone
(
self
):
"""测试有效的ISO格式(不带时区)日期时间"""
self
.
assertTrue
(
is_valid_datetime_format
(
"2023-05-15T14:30:00"
))
def
test_valid_iso_format_with_timezone
(
self
):
"""测试有效的ISO格式(带时区)日期时间"""
self
.
assertTrue
(
is_valid_datetime_format
(
"2023-05-15T14:30:00+08:00"
))
def
test_valid_iso_format_with_timezone2
(
self
):
"""测试有效的ISO格式(带时区)日期时间"""
self
.
assertTrue
(
is_valid_datetime_format
(
"2023-05-15T14:30:00.123"
))
def
test_invalid_date_format
(
self
):
"""测试无效的日期格式"""
with
self
.
assertRaises
(
ValueError
):
is_valid_datetime_format
(
"2023/05/15 14:30:00"
)
def
test_invalid_time_format
(
self
):
"""测试无效的时间格式"""
with
self
.
assertRaises
(
ValueError
):
is_valid_datetime_format
(
"2023-05-15 14-30-00"
)
def
test_empty_string
(
self
):
"""测试空字符串"""
with
self
.
assertRaises
(
ValueError
):
is_valid_datetime_format
(
""
)
if
__name__
==
'__main__'
:
unittest
.
main
()
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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