pythononwheels / pow_devel

development repo for PyhtonOnWheels framework
www.pythononwheels.org
MIT License
75 stars 10 forks source link

replace all evals with getattr #17

Closed pythononwheels closed 7 years ago

pythononwheels commented 12 years ago

example: from BaseController.py (ln. 175-178):

def redirect(self, action, **kwargs):
        """ sets the given action and executes it so that all prerequisites are correct """
        self.setCurrentAction(action)
        return eval("self." + action + "(**kwargs)")

should be replaced by:

def redirect(self, action, **kwargs):
        """ sets the given action and executes it so that all prerequisites are correct """
        self.setCurrentAction(action)
        return getattr(self, action)(**kwargs)

A more secure and pythonic solution.

thanks to microkernel (user from the www.python-forum.de) see post: http://www.python-forum.de/viewtopic.php?f=9&t=29801

pythononwheels commented 7 years ago

Solved in new pow version.