mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-22 21:44:18 +02:00
Compile URI pattern
This commit is contained in:
parent
e2ac996b79
commit
4ee9d3a949
1 changed files with 6 additions and 3 deletions
|
|
@ -68,6 +68,9 @@ logger = get_logger(__name__)
|
|||
|
||||
DuplicateBehavior = Literal["warn", "error", "replace", "ignore"]
|
||||
|
||||
# Compiled URI parsing regex to split a URI into protocol and path components
|
||||
URI_PATTERN = re.compile(r"^([^:]+://)(.*?)$")
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def default_lifespan(server: FastMCP[LifespanResultT]) -> AsyncIterator[Any]:
|
||||
|
|
@ -1312,7 +1315,7 @@ def add_resource_prefix(uri: str, prefix: str) -> str:
|
|||
return uri
|
||||
|
||||
# Split the URI into protocol and path
|
||||
match = re.match(r"^([^:]+://)(.*?)$", uri)
|
||||
match = URI_PATTERN.match(uri)
|
||||
if not match:
|
||||
raise ValueError(f"Invalid URI format: {uri}. Expected protocol://path format.")
|
||||
|
||||
|
|
@ -1345,7 +1348,7 @@ def remove_resource_prefix(uri: str, prefix: str) -> str:
|
|||
return uri
|
||||
|
||||
# Split the URI into protocol and path
|
||||
match = re.match(r"^([^:]+://)(.*?)$", uri)
|
||||
match = URI_PATTERN.match(uri)
|
||||
if not match:
|
||||
raise ValueError(f"Invalid URI format: {uri}. Expected protocol://path format.")
|
||||
|
||||
|
|
@ -1384,7 +1387,7 @@ def has_resource_prefix(uri: str, prefix: str) -> bool:
|
|||
return False
|
||||
|
||||
# Split the URI into protocol and path
|
||||
match = re.match(r"^([^:]+://)(.*?)$", uri)
|
||||
match = URI_PATTERN.match(uri)
|
||||
if not match:
|
||||
raise ValueError(f"Invalid URI format: {uri}. Expected protocol://path format.")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue