Backported PyCogent commit fec2a29