Hands down, the most repulsive Python code I’ve written in at least a quarter