Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_formatter_json():
result = Formatter().format("{foo!j}", **{u'foo': {u'bar': u'Räuber Hotzenplotz'}}).encode('utf-8')
assert result == b'{"bar": "R\\u00e4uber Hotzenplotz"}'
def test_formatter_basic():
result = Formatter().format("{foo}", **{u'foo': u'Räuber Hotzenplotz'}).encode('utf-8')
assert result == b'R\xc3\xa4uber Hotzenplotz'
if orig_value is None:
return None
res = orig_value
if function is not None:
function_name = sanitize_function_name(function)
if function_name is not None:
try:
res = context.invoker.datamap(function_name, transform_data)
return res
except Exception as e:
logger.warning("Cannot invoke %s(): %s" % (function_name, e))
try:
res = Formatter().format(function, **transform_data)
except Exception as e:
logger.exception("Formatting message failed")
if isinstance(res, str):
res = res.replace("\\n", "\n")
return res