Skip to content

Commit f5b47d7

Browse files
committed
removed internal method
1 parent cfa6610 commit f5b47d7

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

packages/google-api-core/google/api_core/path_template.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def _validate_multi_segment_value(val: str) -> bool:
9898
bool: True if the value is valid and does not violate traversal boundaries,
9999
False otherwise.
100100
"""
101-
if val in ('', '.', '..'):
101+
if val in ("", ".", ".."):
102102
return False
103103

104104
segments = val.split("/")
@@ -138,34 +138,32 @@ def _build_capture_pattern(template_str: str) -> tuple[re.Pattern, tuple[str, ..
138138
- A list of wildcard type strings ('*' or '**') in matching order.
139139
"""
140140
wildcard_types = []
141+
parts = []
142+
last_idx = 0
143+
for match in _VARIABLE_RE.finditer(template_str):
144+
literal = template_str[last_idx : match.start()]
145+
parts.append(re.escape(literal))
141146

142-
def replacer(match):
143147
positional = match.group("positional")
144148
template = match.group("template")
145149

146150
if positional == "*":
147151
wildcard_types.append("*")
148-
return _SINGLE_SEGMENT_PATTERN
152+
replaced = _SINGLE_SEGMENT_PATTERN
149153
elif positional == "**":
150154
wildcard_types.append("**")
151-
return _MULTI_SEGMENT_PATTERN
155+
replaced = _MULTI_SEGMENT_PATTERN
152156
elif not template or template == "*":
153157
wildcard_types.append("*")
154-
return _SINGLE_SEGMENT_PATTERN
158+
replaced = _SINGLE_SEGMENT_PATTERN
155159
elif template == "**":
156160
wildcard_types.append("**")
157-
return _MULTI_SEGMENT_PATTERN
161+
replaced = _MULTI_SEGMENT_PATTERN
158162
else:
159163
sub_pattern, sub_types = _build_capture_pattern(template)
160164
wildcard_types.extend(sub_types)
161-
return sub_pattern.pattern
165+
replaced = sub_pattern.pattern
162166

163-
parts = []
164-
last_idx = 0
165-
for match in _VARIABLE_RE.finditer(template_str):
166-
literal = template_str[last_idx : match.start()]
167-
parts.append(re.escape(literal))
168-
replaced = replacer(match)
169167
parts.append(replaced)
170168
last_idx = match.end()
171169
literal = template_str[last_idx:]

packages/google-api-core/tests/unit/test_path_template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ def test_build_capture_pattern(template_str, expected_pattern, expected_wildcard
850850
("a/b/c/d/e/../../../..", True),
851851
("a/b/../..", False),
852852
("a/b/../../..", False),
853-
('', False),
853+
("", False),
854854
(".", False),
855855
("..", False),
856856
("", False),

0 commit comments

Comments
 (0)