Files
amq-adapter-python/amqp/router/utils.py
T

10 lines
306 B
Python

import re
def sanitize_as_rabbitmq_name(input_str: str) -> str:
pattern = re.compile(r"[^a-zA-Z0-9.#/\-]")
matcher = pattern.search(input_str)
token = input_str[:matcher.start()] if matcher else input_str
step1 = re.sub(r"[^A-Za-z0-9#]", ".", token)
return re.sub(r"\.+", ".", step1)