Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid regex escape sequences #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions napalm_sros/sros.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ def __init__(self, hostname, username, password, timeout=60, optional_args=None)
self.locked = False
self.terminal_stdout_re = [
re.compile(
"[\r\n]*\!?\*?(\((ex|gl|pr|ro)\))?\[.*\][\r\n]+[ABCD]\:\S+\@\S+\#\s$"
"[\r\n]*\\!?\\*?(\\((ex|gl|pr|ro)\\))?\\[.*\\][\r\n]+[ABCD]\\:\\S+\\@\\S+\\#\\s$"
),
re.compile("[\r\n]*\*?[ABCD]:[\w\-\.\,\>]+[#\$]\s"),
re.compile("[\r\n]*\\*?[ABCD]:[\\w\\-\\.\\,\\>]+[#\\$]\\s"),
]
self.terminal_stderr_re = [
re.compile("Error: .*[\r\n]+"),
Expand Down Expand Up @@ -318,7 +318,7 @@ def commit_config(self, message="", revert_in=None):
buff = self._perform_cli_commands(["commit"], True)
# If error while performing commit, return the error
error = ""
cmd_line_pattern = re.compile("\*?(.*?)(>.*)*#\s")
cmd_line_pattern = re.compile("\\*?(.*?)(>.*)*#\\s")
for item in buff.split("\n"):
if cmd_line_pattern.search(item):
continue
Expand Down Expand Up @@ -364,7 +364,7 @@ def compare_config(self):
buff = self._perform_cli_commands(
["environment more false", "compare"], True
)
cmd_line_pattern = re.compile("\*?(.*?)(>.*)*#.*?")
cmd_line_pattern = re.compile("\\*?(.*?)(>.*)*#.*?")
# buff = self._perform_cli_commands(["environment more false", "compare"])
else:
# if format is xml we convert them into dict and perform a diff on configs to return the difference
Expand Down Expand Up @@ -1125,7 +1125,7 @@ def _update_buff(buff):
else:
updated_buff = [buff]
new_buff = ""
cmd_line_pattern = re.compile("\*?(.*?)(>.*)*#.*?")
cmd_line_pattern = re.compile("\\*?(.*?)(>.*)*#.*?")
match_strings = [
cmd_candidate[0],
cmd_candidate[1],
Expand Down Expand Up @@ -1187,7 +1187,7 @@ def _update_buff(buff):
)
# remove xml declaration
config_data_running_xml = re.sub(
"<\?xml.*\?>", "", config_data_running_xml
"<\\?xml.*\\?>", "", config_data_running_xml
)
configuration["running"] = config_data_running_xml

Expand All @@ -1204,7 +1204,7 @@ def _update_buff(buff):
)[0]
)
config_data_candidate_xml = re.sub(
"<\?xml.*\?>", "", config_data_candidate_xml
"<\\?xml.*\\?>", "", config_data_candidate_xml
)
configuration["candidate"] = config_data_candidate_xml
return configuration
Expand Down Expand Up @@ -1582,7 +1582,7 @@ def get_ntp_stats(self):
# helper method
def _get_ntp_stats_data(buff):
ip_pattern = re.compile(
"(([2][5][0-5]\.)|([2][0-4][0-9]\.)|([0-1]?[0-9]?[0-9]\.)){3}"
"(([2][5][0-5]\\.)|([2][0-4][0-9]\\.)|([0-1]?[0-9]?[0-9]\\.)){3}"
+ "(([2][5][0-5])|([2][0-4][0-9])|([0-1]?[0-9]?[0-9]))"
)
dashed_row = False
Expand Down Expand Up @@ -2126,7 +2126,7 @@ def _get_ospf_protocol_attributes(router_name):
)

ip_pattern = re.compile(
"(([2][5][0-5]\.)|([2][0-4][0-9]\.)|([0-1]?[0-9]?[0-9]\.)){3}"
"(([2][5][0-5]\\.)|([2][0-4][0-9]\\.)|([0-1]?[0-9]?[0-9]\\.)){3}"
+ "(([2][5][0-5])|([2][0-4][0-9])|([0-1]?[0-9]?[0-9]))"
)

Expand Down Expand Up @@ -3857,7 +3857,7 @@ def _build_temperature_dict(instance, choice=1):
total_power_modules = total_power_modules + 1
if "Current Util." in item:
row = item.strip()
watts = re.match("^.*:\s*(\d+[.]\d+) Watts.*$", item)
watts = re.match("^.*:\\s*(\\d+[.]\\d+) Watts.*$", item)
if watts:
output = float(watts.groups()[0])

Expand Down Expand Up @@ -3992,7 +3992,7 @@ def get_ipv6_neighbors_table(self):
cmd = ["environment more false", f"show router {name} neighbor"]
buff = self._perform_cli_commands(cmd, True)
ipv6_address_regex = re.compile(
"(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))"
"(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))"
)
prev_row = ""
ip_address = ""
Expand Down Expand Up @@ -4204,7 +4204,7 @@ def cli(self, commands):
for cmd in commands:
buff = self._perform_cli_commands([cmd], True)
new_buff = ""
cmd_line_pattern = re.compile("\*?(.*?)(>.*)*#\s")
cmd_line_pattern = re.compile("\\*?(.*?)(>.*)*#\\s")
for item in buff.split("\n"):
if "[]" in item:
continue
Expand All @@ -4221,4 +4221,3 @@ def cli(self, commands):
except Exception as e:
print("Error in method cli : {}".format(e))
log.error("Error in method cli : %s" % traceback.format_exc())