modernizing Templetor SafeVisitor code using Python'