CleverSwarm API invocation example
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user