It's already been rewritten and optimized in scikit-bio:

http://scikit-bio.org/math.stats.distance.html