1818class TemplateInformation (pydantic .BaseModel ):
1919 code : str
2020 template : type_util .TemplateType
21+ template_variable_start_end_string : tuple [str , str ]
2122
2223 @pydantic .computed_field # type: ignore[misc]
2324 @property
2425 def template_variables (self ) -> set [str ]:
2526 # From https://stackoverflow.com/a/77363330
26- template = jinja2 .Environment (autoescape = True ).parse (source = json .dumps (self .template ))
27+ template = jinja2 .Environment (
28+ autoescape = True ,
29+ variable_start_string = self .template_variable_start_end_string [0 ],
30+ variable_end_string = self .template_variable_start_end_string [1 ],
31+ ).parse (source = json .dumps (self .template , ensure_ascii = False ))
2732 return jinja2 .meta .find_undeclared_variables (ast = template )
2833
2934
@@ -32,6 +37,10 @@ def template_variables(self) -> set[str]:
3237
3338class TemplateManagerInterface (typing .Protocol [TemplateStructureType ]):
3439 template_structure_cls : type [TemplateStructureType ] | type [str ] | None = None
40+ template_variable_start_end_string : typing .ClassVar [tuple [str , str ]] = ("{{" , "}}" )
41+
42+ @property
43+ def initialized (self ) -> bool : ...
3544
3645 def check_template_valid (self , template_data : type_util .TemplateType ) -> bool :
3746 if not self .template_structure_cls or self .template_structure_cls == str :
@@ -59,21 +68,33 @@ def render(self, code: str, context: type_util.ContextType) -> type_util.Templat
5968class S3ResourceTemplateManager (template_mgr_interface .TemplateManagerInterface ):
6069 resource : typing .ClassVar [aws_resource .S3ResourcePath ]
6170
71+ @property
72+ def initialized (self ) -> bool :
73+ return True
74+
6275 def list (self ) -> list [template_mgr_interface .TemplateInformation ]:
6376 return [self .retrieve (code = f .split (sep = "." )[0 ]) for f in self .resource .list_objects (filter_by_extension = True )]
6477
6578 @functools .lru_cache # noqa: B019
6679 def retrieve (self , code : str ) -> template_mgr_interface .TemplateInformation | None :
6780 try :
6881 template_body : str = self .resource .download (code = code ).decode (encoding = "utf-8" )
69- return template_mgr_interface .TemplateInformation (code = code , template = template_body )
82+ return template_mgr_interface .TemplateInformation (
83+ code = code ,
84+ template = template_body ,
85+ template_variable_start_end_string = self .template_variable_start_end_string ,
86+ )
7087 except botocore .exceptions .ClientError :
7188 return None
7289
7390 def create (self , code : str , template_data : type_util .TemplateType ) -> template_mgr_interface .TemplateInformation :
7491 self .check_template_valid (template_data = template_data )
7592 self .resource .upload (code = code , content = template_data )
76- return template_mgr_interface .TemplateInformation (code = code , template = template_data )
93+ return template_mgr_interface .TemplateInformation (
94+ code = code ,
95+ template = template_data ,
96+ template_variable_start_end_string = self .template_variable_start_end_string ,
97+ )
7798
7899 def update (self , code : str , template_data : type_util .TemplateType ) -> template_mgr_interface .TemplateInformation :
79100 return self .create (code = code , template_data = template_data )
0 commit comments