44import re
55from collections .abc import Callable
66from pathlib import Path
7+ from typing import Literal
78
89from pydantic .alias_generators import to_pascal
910from pydantic_xml import BaseXmlModel
2021LOGGER = logging .getLogger (__name__ )
2122
2223
23- def sanitize (value : str | None ) -> str | None :
24+ def sanitize (value : str | None , seperator : Literal [ "-" , "_" , "." , " " ] ) -> str | None :
2425 if not value :
2526 return value
2627 value = str (value )
27- value = re .sub (r"[^0-9a-zA-Z&! ]+" , "" , value .replace ("-" , " " ))
28+ value = re .sub (r"[^0-9a-zA-Z&! ]+" , "" , value .replace (seperator , " " ))
2829 value = " " .join (value .split ())
29- return value .replace (" " , "-" )
30+ return value .replace (" " , seperator )
3031
3132
3233class PascalModel (
@@ -61,7 +62,12 @@ def display(self) -> None:
6162
6263 CONSOLE .print (Panel .fit ("\n " .join (content_vals ), title = type (self ).__name__ ))
6364
64- def evaluate_pattern (self , pattern_map : dict [str , Callable [[Self ], str ]], pattern : str ) -> str :
65+ def evaluate_pattern (
66+ self ,
67+ pattern_map : dict [str , Callable [[Self ], str ]],
68+ pattern : str ,
69+ seperator : Literal ["-" , "_" , "." , " " ],
70+ ) -> str :
6571 def replace_match (match : re .Match ) -> str :
6672 key = match .group ("key" )
6773 padding = match .group ("padding" )
@@ -73,7 +79,7 @@ def replace_match(match: re.Match) -> str:
7379
7480 if padding and (isinstance (value , int ) or (isinstance (value , str ) and value .isdigit ())):
7581 return f"{ int (value ):0{padding }} "
76- return sanitize (value = value ) or ""
82+ return sanitize (value = value , seperator = seperator ) or ""
7783
7884 pattern_regex = re .compile (r"{(?P<key>[a-zA-Z-]+)(?::(?P<padding>\d+))?}" )
7985 return pattern_regex .sub (replace_match , pattern )
0 commit comments