CleverSwarm API invocation example

This commit is contained in:
Stanislav Hejny
2025-02-25 20:35:20 +00:00
parent 286a4986b3
commit eb26eec767
36 changed files with 1269 additions and 126 deletions
+24 -8
View File
@@ -14,14 +14,30 @@ class RouteDatabase:
return self.routes
def pattern(self, routing_key: str) -> re.Pattern:
regex = r"\.".join(
[
r".*" if token == "" else r"#" if token == "#" else token
for token in routing_key.split(".")
]
)
if routing_key.endswith("."):
regex += r"\."
breaker = False
tokens = routing_key.split('.')
counter = len(tokens)
regex_parts = []
for token in tokens:
counter -= 1
if not breaker:
if token == "":
res = "[^\\.]*"
elif token == "#":
breaker = True
res = ".*$"
else:
res = token
if counter > 0 and not breaker:
res += "\\."
regex_parts.append(res)
else:
regex_parts.append("")
regex = "".join(filter(lambda x: x != "", regex_parts))
if not routing_key:
return re.compile(".*")
return re.compile(regex)
def matches(self, routing_key_from_route: str, routing_key_from_message: str) -> bool: