Skip to content

Commit

Permalink
relax banner delimiter handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bk2zsto committed Apr 4, 2014
1 parent 5d2d95e commit bb20d76
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions ciscoconfparse/ciscoconfparse.py
Expand Up @@ -1510,25 +1510,40 @@ def _mark_banner(self, banner_str, os):
start_banner = False
end_banner = False
ii = 0

### not sure if this is a sane default but it matches assumptions below
banner_delimiter = self.comment_delimiter

if (os=="ios"):
prefix = ""
elif (os=="catos"):
prefix = "set "
else:
raise RuntimeError("FATAL: _mark_banner(): received " + \
"an invalid value for 'os'")

matchpattern = prefix + "banner\s+" + banner_str+"\s+(\^*\S)"

while (start_banner is False) & (ii < len(self._list)):
if re.search(prefix+"banner\s+"+banner_str+"\s+\^\S+", \
self._list[ii].text):
# Found the start banner at ii
start_banner = True
kk = ii + 1

matchobject = re.match(matchpattern, self._list[ii].text)
if matchobject:
### escape any leading ^
if matchobject.group(1)[0] == "^":
banner_delimiter = "\{0}".format(matchobject.group(1))
else:
banner_delimiter = matchobject.group(1)

kk = ii + 1
start_banner = True

else:
ii += 1
ii += 1

if (start_banner is True):
while (end_banner is False) & (kk < len(self._list)):
if self._list[kk].is_comment:
### .match searches from beginning so no need to ^-ify
if re.match(banner_delimiter,self._list[kk].text):
# Note: We are depending on a "!" after the banner... why
# can't a normal regex work with IOS banners!?
# Therefore the endpoint is at ( kk - 1)
Expand Down

0 comments on commit bb20d76

Please sign in to comment.