kollagen/tgbot/kollagen-bot/parser.py

16 lines
352 B
Python
Raw Normal View History

2021-09-19 13:19:00 +02:00
import argparse
import re
class ArgumentParserError(RuntimeError):
pass
class SafeArgumentParser(argparse.ArgumentParser):
def error(self, message):
raise ArgumentParserError(message)
def safe_str(val: str):
2021-09-20 23:05:24 +02:00
if re.findall(r'[^\w,]', val):
2021-09-19 13:19:00 +02:00
raise RuntimeError("No special characters in arguments allowed!")
return val