There are many cases in the code where you're iterating over a .keys().  This doesn't affect the Python 3 port (since it's also relevant to Python 2), but you don't need to call .keys() here if the object is a dict or mapping-like.  Python iterates over a dict's keys by default.  It's a little more critical to fix in Python 2 actually since there .keys() instantiates a new list object.  In Python 3, it's a bit more efficient, but it's still an unnecessary method call and is an anti-pattern.