remove other instances of the six meta path importer if six is reloaded (fixes #71)
diff --git a/CHANGES b/CHANGES
index 7b026ac..b5fabfa 100644
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,12 @@
 
 This file lists the changes in each six version.
 
+1.7.1
+-----
+
+- Issue #71: Make the six.moves meta path importer handle reloading of the six
+  module gracefully.
+
 1.7.0
 -----
 
diff --git a/six.py b/six.py
index 78e065a..416fee0 100644
--- a/six.py
+++ b/six.py
@@ -731,12 +731,25 @@
 
 # Complete the moves implementation.
 # This code is at the end of this module to speed up module loading.
-# 1. turn this module into a package.
+# Turn this module into a package.
 __path__ = []  # required for PEP 302 and PEP 451
 __package__ = __name__  # see PEP 366 @ReservedAssignment
 try:
     __spec__.submodule_search_locations = []  # PEP 451 @UndefinedVariable
 except NameError:
     pass
-# 2. add the importer to the meta path import hook.
+# Remove other six meta path importers, since they cause problems. This can
+# happen if six is removed from sys.modules and then reloaded. (Setuptools does
+# this for some reason.)
+for i, importer in enumerate(sys.meta_path):
+    # Here's some real nastiness: Another "instance" of the six module might be
+    # floating around. Therefore, we can't use isinstance() to check for the six
+    # meta path importer, since the other six instance will have inserted an
+    # importer with different class.
+    if (type(importer).__name__ == "_SixMetaPathImporter" and
+        importer.name == __name__):
+        del sys.meta_path[i]
+        break
+del i, importer
+# Finally, add the importer to the meta path import hook.
 sys.meta_path.append(_importer)