Skip to content

Commit

Permalink
Ensure regex strings are raw strings (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
chennin authored May 10, 2024
1 parent 3e05707 commit 22f62f2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions stellarisdashboard/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def _get_mod_data_dir(mod_descriptor_path: pathlib.Path):
try:
with open(mod_descriptor_path, "r") as f:
for line in f:
match = re.match('^\s*path\s*=\s*"(.*)"\s*$', line)
match = re.match(r'^\s*path\s*=\s*"(.*)"\s*$', line)
if match:
return pathlib.Path(match.group(1))
except Exception as e:
Expand All @@ -468,7 +468,7 @@ def _get_mod_data_dir(mod_descriptor_path: pathlib.Path):
def _localization_file_matches_language(file_path: pathlib.Path, language: str):
with open(file_path, "r") as f:
first_line = f.readline()
match = re.match(f"^\ufeff\s*{language}\s*:\s*$", first_line)
match = re.match(rf"^\ufeff\s*{language}\s*:\s*$", first_line)
return match is not None


Expand Down
2 changes: 1 addition & 1 deletion stellarisdashboard/dashboard_app/visualization_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,7 @@ def get_color_by_name(self, country_name: str):
@staticmethod
def _parse_map_colors(path: pathlib.Path):
with open(path, "r") as f:
prepared_str = re.sub("#[^\n]*", "", f.read()) # strip out comments
prepared_str = re.sub(r"#[^\n]*", "", f.read()) # strip out comments
data = rust_parser.parse_save_from_string(prepared_str)

colors = data.get("colors", {})
Expand Down
2 changes: 1 addition & 1 deletion stellarisdashboard/game_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def _handle_unresolved_variables(self, render_template):
if match == "ORD":
continue
resolved = lookup_key(match)
render_template = re.sub(f"\${match}\$", resolved, render_template)
render_template = re.sub(rf"\${match}\$", resolved, render_template)

return render_template

Expand Down

0 comments on commit 22f62f2

Please sign in to comment.