Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
G
gracedb-client
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tanner Prestegard
gracedb-client
Commits
00032476
Verified
Commit
00032476
authored
Aug 23, 2019
by
Tanner Prestegard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rest: improve arg validation in gracedb.createSuperevent
parent
4fc8ddb6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
10 deletions
+22
-10
ligo/gracedb/rest.py
ligo/gracedb/rest.py
+22
-10
No files found.
ligo/gracedb/rest.py
View file @
00032476
...
@@ -1157,7 +1157,7 @@ class GraceDb(GsiRest):
...
@@ -1157,7 +1157,7 @@ class GraceDb(GsiRest):
return
self
.
get
(
uri
).
json
()[
'numRows'
]
return
self
.
get
(
uri
).
json
()[
'numRows'
]
def
createSuperevent
(
self
,
t_start
,
t_0
,
t_end
,
preferred_event
,
def
createSuperevent
(
self
,
t_start
,
t_0
,
t_end
,
preferred_event
,
category
=
'production'
,
events
=
[]
,
labels
=
None
):
category
=
'production'
,
events
=
None
,
labels
=
None
):
"""Create a superevent.
"""Create a superevent.
All LIGO-Virgo users can create test superevents, but special
All LIGO-Virgo users can create test superevents, but special
...
@@ -1201,28 +1201,40 @@ class GraceDb(GsiRest):
...
@@ -1201,28 +1201,40 @@ class GraceDb(GsiRest):
if
labels
:
if
labels
:
if
isinstance
(
labels
,
six
.
string_types
):
if
isinstance
(
labels
,
six
.
string_types
):
labels
=
[
labels
]
labels
=
[
labels
]
elif
isinstance
(
labels
,
list
):
elif
isinstance
(
labels
,
(
list
,
tuple
)):
pass
# Validate each entry
if
any
([
not
isinstance
(
l
,
six
.
string_types
)
for
l
in
labels
]):
err_msg
=
"One of the provided labels is not a string"
raise
TypeError
(
err_msg
)
else
:
else
:
raise
TypeError
(
"labels arg is {0}, should be str or list"
raise
TypeError
(
"labels arg is {0}, should be str or list"
.
format
(
type
(
labels
)))
.
format
(
type
(
labels
)))
# Check labels against those in database
# Check labels against those in database
for
l
in
labels
:
for
l
in
labels
:
if
l
not
in
self
.
allowed_labels
:
if
l
not
in
self
.
allowed_labels
:
raise
Nam
eError
((
"Label '{0}' does not exist in the "
raise
Valu
eError
((
"Label '{0}' does not exist in the "
"database"
).
format
(
l
))
"database"
).
format
(
l
))
if
events
:
if
events
:
if
isinstance
(
events
,
six
.
string_types
):
if
isinstance
(
events
,
six
.
string_types
):
events
=
[
events
]
events
=
[
events
]
elif
isinstance
(
events
,
list
):
elif
isinstance
(
events
,
(
list
,
tuple
)):
pass
if
any
([
not
isinstance
(
e
,
six
.
string_types
)
for
e
in
events
]):
err_msg
=
\
"One of the provided event graceids is not a string"
raise
TypeError
(
err_msg
)
else
:
else
:
raise
TypeError
(
"events arg is {0}, should be str or list"
raise
TypeError
(
"events arg is {0}, should be str or list"
.
format
(
type
(
events
)))
.
format
(
type
(
events
)))
# validate category, convert to short form if necessary
# Validate category, convert to short form if necessary
category
=
self
.
_getCode
(
category
.
lower
(),
if
not
isinstance
(
category
,
six
.
string_types
):
self
.
superevent_categories
)
err_msg
=
"category arg is {0}, should be a string"
.
format
(
type
(
category
))
raise
TypeError
(
err_msg
)
category
=
self
.
_getCode
(
category
,
self
.
superevent_categories
)
# Note: category can be None here as a result of processing
# by _getCode, which indicates failure to match the provided
# superevent category
if
not
category
:
if
not
category
:
raise
ValueError
(
"category must be one of: {0}"
.
format
(
raise
ValueError
(
"category must be one of: {0}"
.
format
(
list
(
six
.
itervalues
(
self
.
superevent_categories
))))
list
(
six
.
itervalues
(
self
.
superevent_categories
))))
...
...
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