Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
889090e
1
Parent(s): d3e7c9f
Compile URI pattern
Browse files
src/fastmcp/server/server.py
CHANGED
|
@@ -68,6 +68,9 @@ logger = get_logger(__name__)
|
|
| 68 |
|
| 69 |
DuplicateBehavior = Literal["warn", "error", "replace", "ignore"]
|
| 70 |
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
@asynccontextmanager
|
| 73 |
async def default_lifespan(server: FastMCP[LifespanResultT]) -> AsyncIterator[Any]:
|
|
@@ -1312,7 +1315,7 @@ def add_resource_prefix(uri: str, prefix: str) -> str:
|
|
| 1312 |
return uri
|
| 1313 |
|
| 1314 |
# Split the URI into protocol and path
|
| 1315 |
-
match =
|
| 1316 |
if not match:
|
| 1317 |
raise ValueError(f"Invalid URI format: {uri}. Expected protocol://path format.")
|
| 1318 |
|
|
@@ -1345,7 +1348,7 @@ def remove_resource_prefix(uri: str, prefix: str) -> str:
|
|
| 1345 |
return uri
|
| 1346 |
|
| 1347 |
# Split the URI into protocol and path
|
| 1348 |
-
match =
|
| 1349 |
if not match:
|
| 1350 |
raise ValueError(f"Invalid URI format: {uri}. Expected protocol://path format.")
|
| 1351 |
|
|
@@ -1384,7 +1387,7 @@ def has_resource_prefix(uri: str, prefix: str) -> bool:
|
|
| 1384 |
return False
|
| 1385 |
|
| 1386 |
# Split the URI into protocol and path
|
| 1387 |
-
match =
|
| 1388 |
if not match:
|
| 1389 |
raise ValueError(f"Invalid URI format: {uri}. Expected protocol://path format.")
|
| 1390 |
|
|
|
|
| 68 |
|
| 69 |
DuplicateBehavior = Literal["warn", "error", "replace", "ignore"]
|
| 70 |
|
| 71 |
+
# Compiled URI parsing regex to split a URI into protocol and path components
|
| 72 |
+
URI_PATTERN = re.compile(r"^([^:]+://)(.*?)$")
|
| 73 |
+
|
| 74 |
|
| 75 |
@asynccontextmanager
|
| 76 |
async def default_lifespan(server: FastMCP[LifespanResultT]) -> AsyncIterator[Any]:
|
|
|
|
| 1315 |
return uri
|
| 1316 |
|
| 1317 |
# Split the URI into protocol and path
|
| 1318 |
+
match = URI_PATTERN.match(uri)
|
| 1319 |
if not match:
|
| 1320 |
raise ValueError(f"Invalid URI format: {uri}. Expected protocol://path format.")
|
| 1321 |
|
|
|
|
| 1348 |
return uri
|
| 1349 |
|
| 1350 |
# Split the URI into protocol and path
|
| 1351 |
+
match = URI_PATTERN.match(uri)
|
| 1352 |
if not match:
|
| 1353 |
raise ValueError(f"Invalid URI format: {uri}. Expected protocol://path format.")
|
| 1354 |
|
|
|
|
| 1387 |
return False
|
| 1388 |
|
| 1389 |
# Split the URI into protocol and path
|
| 1390 |
+
match = URI_PATTERN.match(uri)
|
| 1391 |
if not match:
|
| 1392 |
raise ValueError(f"Invalid URI format: {uri}. Expected protocol://path format.")
|
| 1393 |
|