kollagen/tgbot/kollagen-bot/parser.py

16 lines
351 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):
if re.findall(r'[^\w]', val):
raise RuntimeError("No special characters in arguments allowed!")
return val