Skip to content

Commit 70d7381

Browse files
authored
fix: resolve regex escape sequence warnings (#151)
Use raw string and repr() for safe URL pattern embedding in f-strings.
1 parent f372b99 commit 70d7381

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/bedrock_agentcore_starter_toolkit/services/import_agent/scripts/base_bedrock_translate.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,10 @@ def remove_files(file_paths: List[str]):
10311031

10321032
return code_1p
10331033

1034+
def _get_url_regex_pattern(self) -> str:
1035+
"""Get the URL regex pattern for source extraction."""
1036+
return r'(?:https?://|www\.)(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(?:/[^/\s]*)*'
1037+
10341038
def generate_entrypoint_code(self, platform: str) -> str:
10351039
"""Generate entrypoint code for the agent."""
10361040
entrypoint_code = ""
@@ -1059,6 +1063,7 @@ def generate_entrypoint_code(self, platform: str) -> str:
10591063
else "tools_used.update([msg.name for msg in agent_result if isinstance(msg, ToolMessage)])"
10601064
)
10611065
response_content_code = "str(agent_result)" if platform == "strands" else "agent_result[-1].content"
1066+
url_pattern = self._get_url_regex_pattern()
10621067

10631068
entrypoint_code += f"""
10641069
def endpoint(payload, context):
@@ -1079,7 +1084,7 @@ def endpoint(payload, context):
10791084
10801085
# Gathering sources from the response
10811086
sources = []
1082-
urls = re.findall(r'(?:https?://|www\.)(?:[a-zA-Z0-9\-]+\.)+[a-zA-Z]{{2,}}(?:/[^/\s]*)*', response_content)
1087+
urls = re.findall({repr(url_pattern)}, response_content)
10831088
source_tags = re.findall(r"<source>(.*?)</source>", response_content)
10841089
sources.extend(urls)
10851090
sources.extend(source_tags)

0 commit comments

Comments
 (0)