From d8f21d97baaef3ab68ac9f39dd1c29d4f6b0c958 Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Thu, 9 Dec 2021 23:32:14 +1000 Subject: [PATCH] Coding style. - Avoid using eval. - Use more lru_caches. --- eris/eris/tools.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eris/eris/tools.py b/eris/eris/tools.py index 2d3b2a4..d9424df 100755 --- a/eris/eris/tools.py +++ b/eris/eris/tools.py @@ -114,11 +114,13 @@ def deps(**kwargs): def _syntax_highlight(text, lexer, style): + @functools.lru_cache(maxsize=500) def _parse_rgb(hex_rgb): if hex_rgb.startswith("#"): hex_rgb = hex_rgb[1:] - return tuple(eval("0x"+hex_rgb[index:index+2]) for index in [0, 2, 4]) + return tuple(int("0x" + hex_rgb[index:index+2], base=16) for index in [0, 2, 4]) + @functools.lru_cache(maxsize=500) def _char_style_for_token_type(token_type, default_bg_color, default_style): try: token_style = style.style_for_token(token_type)