pombreda / txt2tags

Automatically exported from code.google.com/p/txt2tags
GNU General Public License v2.0
0 stars 0 forks source link

eval is evil #159

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Get rid of all eval in the code.

$ grep -w eval txt2tags
        TARGET_NAMES[target] = eval('targets.' + target).NAME
        TARGET_TYPES[eval('targets.' + target).TYPE][1].append(target)
        ESCAPES[target] = eval('targets.' + target).ESCAPES
        HEADER_TEMPLATE[target] = eval('targets.' + target).HEADER
        HEADER_TEMPLATE[target + 'css'] = eval('targets.' + target).HEADERCSS
            alltags[target] = eval('targets.' + target).TAGS
            rules_bank[target] = eval('targets.' + target).RULES
$

Use getattr instead:

>>> getattr(targets, 'html').NAME
'HTML page'

Original issue reported on code.google.com by aureliojargas@gmail.com on 27 Jul 2012 at 5:23

GoogleCodeExporter commented 9 years ago
In think the exec() in r976 could be removed using getattr.

Original comment by aureliojargas@gmail.com on 27 Jul 2012 at 6:01

GoogleCodeExporter commented 9 years ago
Thanks for the getattr() tip, I was sure that eval()/exec was a hackish not 
really KISS way to do the job.

Original comment by fgalla...@gmail.com on 28 Jul 2012 at 1:14