Skip to content

Commit

Permalink
Merge pull request #510 from knowledgejunkie/fix-invalid-escape-seque…
Browse files Browse the repository at this point in the history
…nces-in-re-match

Use raw strings in re.match
  • Loading branch information
0xc0170 authored Feb 25, 2024
2 parents b046f9d + 6b7ba7d commit a66c642
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions project_generator/tools/coide.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _export_single_project(self):
if expanded_dic['template']:
for template in expanded_dic['template']:
template = join(getcwd(), template)
if splitext(template)[1] == '.coproj' or re.match('.*\.coproj.tmpl$', template):
if splitext(template)[1] == '.coproj' or re.match(r".*\.coproj.tmpl$", template):
try:
coproj_dic = xmltodict.parse(open(template))
except IOError:
Expand All @@ -161,7 +161,7 @@ def _export_single_project(self):
# template overrides what is set in the yaml files
for template in self.env_settings.templates['coide']:
template = join(getcwd(), template)
if splitext(template)[1] == '.coproj' or re.match('.*\.coproj.tmpl$', template):
if splitext(template)[1] == '.coproj' or re.match(r".*\.coproj.tmpl$", template):
try:
coproj_dic = xmltodict.parse(open(template))
except IOError:
Expand Down
11 changes: 5 additions & 6 deletions project_generator/tools/iar.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,14 @@ def _export_single_project(self):
for template in expanded_dic['template']:
template = join(getcwd(), template)
# we support .ewp or .ewp.tmpl templates
if os.path.splitext(template)[1] == '.ewp' or re.match('.*\.ewp.tmpl$', template):
if os.path.splitext(template)[1] == '.ewp' or re.match(r".*\.ewp.tmpl$", template):
try:
ewp_dic = xmltodict.parse(open(template,'rb'), dict_constructor=dict)
template_ewp = True
except IOError:
logger.info("Template file %s not found" % template)
ewp_dic = xmltodict.parse(open(self.ewp_file,'rb').read())
if os.path.splitext(template)[1] == '.ewd' or re.match('.*\.ewd.tmpl$', template):
if os.path.splitext(template)[1] == '.ewd' or re.match(r".*\.ewd.tmpl$", template):
try:
ewd_dic = xmltodict.parse(open(template,'rb'), dict_constructor=dict)
template_ewd = True
Expand All @@ -399,14 +399,14 @@ def _export_single_project(self):
# template overrides what is set in the yaml files
for template in self.env_settings.templates['iar']:
template = join(getcwd(), template)
if os.path.splitext(template)[1] == '.ewp' or re.match('.*\.ewp.tmpl$', template):
if os.path.splitext(template)[1] == '.ewp' or re.match(r".*\.ewp.tmpl$", template):
try:
ewp_dic = xmltodict.parse(open(template,'rb'), dict_constructor=dict)
template_ewp = True
except IOError:
logger.info("Template file %s not found" % template)
ewp_dic = xmltodict.parse(open(self.ewp_file,'rb').read())
if os.path.splitext(template)[1] == '.ewd' or re.match('.*\.ewd.tmpl$', template):
if os.path.splitext(template)[1] == '.ewd' or re.match(r".*\.ewd.tmpl$", template):
# get ewd template
try:
ewd_dic = xmltodict.parse(open(template,'rb'), dict_constructor=dict)
Expand Down Expand Up @@ -518,9 +518,8 @@ def _generate_eww_file(self):
def _parse_subprocess_output(self, output):
num_errors = 0
lines = output.split("\n")
error_re = '\s*Total number of errors:\s*(\d+)\s*'
for line in lines:
m = re.match(error_re, line)
m = re.match(r"\s*Total number of errors:\s*(\d+)\s*", line)
if m is not None:
num_errors = m.group(1)
return int(num_errors)
Expand Down
4 changes: 2 additions & 2 deletions project_generator/tools/uvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def _export_single_project(self, tool_name):
for template in expanded_dic['template']:
template = join(getcwd(), template)
if os.path.splitext(template)[1] == '.uvproj' or os.path.splitext(template)[1] == '.uvprojx' or \
re.match('.*\.uvproj.tmpl$', template) or re.match('.*\.uvprojx.tmpl$', template):
re.match(r".*\.uvproj.tmpl$", template) or re.match(r".*\.uvprojx.tmpl$", template):
try:
uvproj_dic = xmltodict.parse(open(template, encoding="utf8").read())
except IOError:
Expand All @@ -417,7 +417,7 @@ def _export_single_project(self, tool_name):
for template in self.env_settings.templates['uvision']:
template = join(getcwd(), template)
if os.path.splitext(template)[1] == '.uvproj' or os.path.splitext(template)[1] == '.uvprojx' or \
re.match('.*\.uvproj.tmpl$', template) or re.match('.*\.uvprojx.tmpl$', template):
re.match(r".*\.uvproj.tmpl$", template) or re.match(r".*\.uvprojx.tmpl$", template):
try:
uvproj_dic = xmltodict.parse(open(template, encoding="utf8").read())
except IOError:
Expand Down

0 comments on commit a66c642

Please sign in to comment.