Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
backend_common_py
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package registry
Container registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
videoag
backend_common_py
Commits
d99a61e5
Commit
d99a61e5
authored
4 months ago
by
Simon Künzel
Browse files
Options
Downloads
Patches
Plain Diff
Use new CJsonException instead of ApiClientException
parent
71a13882
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/videoag_common/miscellaneous/json.py
+11
-10
11 additions, 10 deletions
src/videoag_common/miscellaneous/json.py
with
11 additions
and
10 deletions
src/videoag_common/miscellaneous/json.py
+
11
−
10
View file @
d99a61e5
...
...
@@ -3,12 +3,13 @@ from typing import Iterable
from
videoag_common.miscellaneous.util
import
JsonTypes
from
.constants
import
*
from
.errors
import
(
ApiClientException
,
ERROR_REQUEST_INVALID_PARAMETER
,
ERROR_REQUEST_MISSING_PARAMETER
)
class
CJsonException
(
Exception
):
def
__init__
(
self
,
path
:
str
,
message
:
str
):
super
().
__init__
(
f
"
At
{
path
}
:
{
message
}
"
)
self
.
path
=
path
self
.
message
=
message
class
CJsonValue
:
...
...
@@ -18,7 +19,7 @@ class CJsonValue:
self
.
_path
=
path
def
raise_error
(
self
,
message
:
str
):
raise
ApiClient
Exception
(
ERROR_REQUEST_INVALID_PARAMETER
(
self
.
_path
,
message
)
)
raise
CJson
Exception
(
self
.
_path
,
message
)
def
equals_json
(
self
,
json
:
JsonTypes
):
return
self
.
_data
==
json
...
...
@@ -39,7 +40,7 @@ class CJsonValue:
return
self
.
_data
def
as_sint32
(
self
)
->
int
:
return
self
.
as_int
(
MIN_VALUE_SINT32
,
MAX_VALUE_SINT32
)
return
self
.
as_int
(
-
2147483648
,
2147483647
)
def
as_int
(
self
,
min_value
:
int
,
max_value
:
int
)
->
int
:
self
.
__check_value_type
(
int
,
"
int
"
)
...
...
@@ -88,7 +89,7 @@ class CJsonObject(CJsonValue):
if
optional
and
not
self
.
has
(
key
):
return
None
if
key
not
in
self
.
_data
:
raise
ApiClient
Exception
(
ERROR_REQUEST_MISSING_PARAMETER
(
f
"
{
self
.
_path
}
.
{
key
}
"
)
)
raise
CJson
Exception
(
f
"
{
self
.
_path
}
.
{
key
}
"
,
"
Is missing
"
)
return
CJsonValue
(
self
.
_data
[
key
],
f
"
{
self
.
_path
}
.
{
key
}
"
)
def
get_object
(
self
,
key
:
str
)
->
"
CJsonObject
"
:
...
...
@@ -148,7 +149,7 @@ class CJsonArray(CJsonValue, Iterable[CJsonValue]):
if
index
<
0
:
raise
ValueError
(
f
"
Negative index provided:
{
index
}
"
)
# pragma: no cover
if
index
>=
self
.
length
():
raise
ApiClient
Exception
(
ERROR_REQUEST_MISSING_PARAMETER
(
f
"
{
self
.
_path
}
[
{
index
}
]
"
)
)
raise
CJson
Exception
(
f
"
{
self
.
_path
}
[
{
index
}
]
"
,
"
Is missing
"
)
return
CJsonValue
(
self
.
_data
[
index
],
f
"
{
self
.
_path
}
[
{
index
}
]
"
)
def
get_object
(
self
,
index
:
int
)
->
"
CJsonObject
"
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment