Enhancement: Template.format() could use its own regex to validate the values it is given before returning a value.
Hello again,
I noticed Template.format()
can sometimes return what I'd consider erroneous output as it does not enforce the template's regex patterns to validate the given tokens dictionary. See below:
>>> import lucidity
>>> template = lucidity.Template('file', '{name}_v{version:\d\d\d}.ext')
>>> template.format({'name':'asset', 'version':'001'})
'asset_v001.ext'
>>> goodFormat = template.format({'name':'asset', 'version':'001'})
>>> goodFormat
'asset_v001.ext'
>>> template.parse(goodFormat)
{'version': '001', 'name': 'asset'}
>>> badFormat = template.format({'name':'asset', 'version':'1'})
>>> badFormat
'asset_v1.ext'
>>> template.parse(badFormat)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/softwareLocal/rez_python_envs/shared/2.7/0x60c4588c62bb0999/lib/python2.7/site-packages/lucidity/template.py", line 160, in parse
'Path {0!r} did not match template pattern.'.format(path)
lucidity.error.ParseError: Path 'asset_v1.ext' did not match template pattern.
I would have expected template.format({'name':'asset', 'version':'1'})
to raise an error because "1" is not a valid string for the "version" token as per its embedded regex, yet it accepts it blindly.