summaryrefslogtreecommitdiff
path: root/python/vyos/dicts.py
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-07-15 21:54:12 +0200
committerChristian Breunig <christian@breunig.cc>2023-07-15 21:54:20 +0200
commitea3cacea57592154a93da753e915a3d39761773d (patch)
tree33d657f4f84d3fd6139ae08634e5dea031de9324 /python/vyos/dicts.py
parent5f77ccf91eb402c548fc91b2e080a4b2b86f4181 (diff)
downloadvyos-1x-ea3cacea57592154a93da753e915a3d39761773d.tar.gz
vyos-1x-ea3cacea57592154a93da753e915a3d39761773d.zip
T5195: move individual helper functions to vyos.utils module
* FixedDict can be found in vyos.utils.dict.FixedDict * Move vyos.authutils to vyos.utils.auth
Diffstat (limited to 'python/vyos/dicts.py')
-rw-r--r--python/vyos/dicts.py53
1 files changed, 0 insertions, 53 deletions
diff --git a/python/vyos/dicts.py b/python/vyos/dicts.py
deleted file mode 100644
index b12cda40f..000000000
--- a/python/vyos/dicts.py
+++ /dev/null
@@ -1,53 +0,0 @@
-#!/usr/bin/env python3
-#
-# Copyright (C) 2019 VyOS maintainers and contributors
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 2 or later as
-# published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-
-from vyos import ConfigError
-
-
-class FixedDict(dict):
- """
- FixedDict: A dictionnary not allowing new keys to be created after initialisation.
-
- >>> f = FixedDict(**{'count':1})
- >>> f['count'] = 2
- >>> f['king'] = 3
- File "...", line ..., in __setitem__
- raise ConfigError(f'Option "{k}" has no defined default')
- """
-
- def __init__(self, **options):
- self._allowed = options.keys()
- super().__init__(**options)
-
- def __setitem__(self, k, v):
- """
- __setitem__ is a builtin which is called by python when setting dict values:
- >>> d = dict()
- >>> d['key'] = 'value'
- >>> d
- {'key': 'value'}
-
- is syntaxic sugar for
-
- >>> d = dict()
- >>> d.__setitem__('key','value')
- >>> d
- {'key': 'value'}
- """
- if k not in self._allowed:
- raise ConfigError(f'Option "{k}" has no defined default')
- super().__setitem__(k, v)