Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Krötenzäune-Plattform
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NABU
Krötenzäune-Projekt
Krötenzäune-Plattform
Commits
f8e2ff7d
Commit
f8e2ff7d
authored
3 years ago
by
Lars Kruse
Browse files
Options
Downloads
Patches
Plain Diff
refactor(settings): reduce code duplication in nested dict traversal
parent
0d4762e7
No related branches found
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
grouprise/settings_loader.py
+5
-7
5 additions, 7 deletions
grouprise/settings_loader.py
with
5 additions
and
7 deletions
grouprise/settings_loader.py
+
5
−
7
View file @
f8e2ff7d
...
...
@@ -679,14 +679,11 @@ class OIDCProviderEnableConfig(BooleanConfig):
def
_get_nested_dict_value
(
data
,
path
,
default
=
None
,
remove
=
False
):
if
isinstance
(
path
,
str
):
if
remove
:
return
data
.
pop
(
path
,
default
)
else
:
return
data
.
get
(
path
,
default
)
elif
not
isinstance
(
data
,
dict
):
if
not
isinstance
(
data
,
dict
):
raise
KeyError
(
f
"
Container is not a dictionary:
{
data
}
"
)
elif
len
(
path
)
==
0
:
if
remove
:
raise
ValueError
(
"
Removal of settings key is not possible, if the given path is empty
"
)
return
data
elif
len
(
path
)
==
1
:
data
.
setdefault
(
path
[
0
],
default
)
...
...
@@ -970,9 +967,10 @@ def import_settings_from_dict(settings: dict, config: dict, base_directory=None)
),
]
for
parser
in
parsers
:
value_path
=
[
parser
.
name
]
if
isinstance
(
parser
.
name
,
str
)
else
parser
.
name
try
:
value
=
_get_nested_dict_value
(
config
,
parser
.
name
,
default
=
parser
.
default
,
remove
=
True
config
,
value_path
,
default
=
parser
.
default
,
remove
=
True
)
except
KeyError
as
exc
:
raise
ConfigError
(
...
...
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