Skip to content

Commit

Permalink
Add type checks to ConfigList() elements
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenning committed Nov 2, 2023
1 parent 7f76e22 commit 6a0d1c7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ciscoconfparse/ciscoconfparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,29 @@ def __init__(
self.encoding = encoding or ENCODING
self.read_only = read_only

if len(config) > 0:
try:
correct_element_types = []
for ii in config:
# Check whether the elements are the correct types...
if isinstance(ii, (str, BaseCfgLine)):
correct_element_types.append(True)
else:
correct_element_types.append(False)

elements_have_len = all(correct_element_types)
except AttributeError:
elements_have_len = False
except TypeError:
elements_have_len = False
else:
elements_have_len = None

if elements_have_len is False:
error = f"All ConfigList elements must have a length()"
logger.error(error)
raise InvalidParameters(error)

# Read the configuration lines and detect invalid inputs...
# tmp_lines = self._get_ccp_lines(config=config, logger=logger)
if isinstance(config, (str, pathlib.Path,)):
Expand Down

0 comments on commit 6a0d1c7

Please sign in to comment.