Resubmit

This is just a resubmission of https://github.com/networkx/networkx/pull/1074, so Travis can test it.