MCPcopy Index your code
hub / github.com/google/adk-python / _parse_cors_origins

Function _parse_cors_origins

src/google/adk/cli/api_server.py:99–124  ·  view source on GitHub ↗

Parse allow_origins into literal origins and a combined regex pattern. Args: allow_origins: List of origin strings. Entries prefixed with 'regex:' are treated as regex patterns; all others are treated as literal origins. Returns: A tuple of (literal_origins, combined_regex) where

(
    allow_origins: list[str],
)

Source from the content-addressed store, hash-verified

97
98
99def _parse_cors_origins(
100 allow_origins: list[str],
101) -> tuple[list[str], Optional[str]]:
102 """Parse allow_origins into literal origins and a combined regex pattern.
103
104 Args:
105 allow_origins: List of origin strings. Entries prefixed with 'regex:' are
106 treated as regex patterns; all others are treated as literal origins.
107
108 Returns:
109 A tuple of (literal_origins, combined_regex) where combined_regex is None
110 if no regex patterns were provided, or a single pattern joining all regex
111 patterns with '|'.
112 """
113 literal_origins = []
114 regex_patterns = []
115 for origin in allow_origins:
116 if origin.startswith(_REGEX_PREFIX):
117 pattern = origin[len(_REGEX_PREFIX) :]
118 if pattern:
119 regex_patterns.append(pattern)
120 else:
121 literal_origins.append(origin)
122
123 combined_regex = "|".join(regex_patterns) if regex_patterns else None
124 return literal_origins, combined_regex
125
126
127def _is_origin_allowed(

Callers 2

get_fast_api_appMethod · 0.85

Calls 2

appendMethod · 0.45
joinMethod · 0.45

Tested by 1