Skip to content

Commit

Permalink
Fix race-condition
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenning committed Oct 20, 2023
1 parent 3a2e943 commit 3076b53
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions ciscoconfparse/ccp_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3695,6 +3695,16 @@ def sort_list(self, value):
raise ValueError(error)

class CiscoRange(MutableSequence):
# Set up default attributes on the object...
text = None
result_type = None
default_iter_attr = None
reverse = None
begin_obj = None
this_obj = None
iterate_attribute = None
_list = None
range_str = None
"""Explode Cisco ranges into a list of explicit items... examples below...
Examples
Expand Down Expand Up @@ -3970,11 +3980,17 @@ def parse_text_list(self, text, debug=False):
# De-deplicate _expanded_interfaces...
_expanded_interfaces = expanded_interfaces
_expanded_interfaces = list(set(_expanded_interfaces))
retval = sorted(_expanded_interfaces, key=lambda x: x.sort_list, reverse=self.reverse)
if False:
retval = sorted(_expanded_interfaces, key=lambda x: x.sort_list, reverse=self.reverse)
retval = self.attribute_sort(_expanded_interfaces, attribute="sort_list", reverse=False)
if debug is True:
logger.info(f"CiscoRange(text='{self.text}', debug=True) [begin_obj: {type(self.begin_obj)}] returning: {retval}")
return retval

def attribute_sort(self, target_list, attribute="sort_list", reverse=False):
new_list = sorted(self._list, key=lambda x: getattr(x, attribute), reverse=reverse)
return target_list

# This method is on CiscoRange()
@logger.catch(reraise=True)
def __repr__(self):
Expand Down Expand Up @@ -4020,12 +4036,17 @@ def __setitem__(self, ii, val):

# This method is on CiscoRange()
@logger.catch(reraise=True)
def insert(self, ii, val):
def insert(self, idx, val, sort=True):
# Insert at the end of the list with new_last_list_idx = len(self._list)
new_last_list_idx = len(self._list)
#pragma warning disable S2190
self._list.insert(new_last_list_idx, val)
new_list = copy.deepcopy(self._list)
new_list = new_list.insert(int(idx), val)
#pragma warning restore S2190
if sort is True:
retval = self.attribute_sort(new_list, attribute="sort_list", reverse=False)
else:
retval = new_list
self._list = retval
return self

# This method is on CiscoRange()
Expand Down

0 comments on commit 3076b53

Please sign in to comment.