Repository: timothycrosley/isort (python)

Issue:
zipimport rewritten
The built-in `from zipimport import zipimporter` is rewritten as `from zip import zipimporter` and classified as third party.

Pull request description:
Fix mangling of imports that end in "import" or "from".
Fixes #224 and #214.

Patch:
diff --git a/ACKNOWLEDGEMENTS.md b/ACKNOWLEDGEMENTS.md
index a6bba7d0..c174166a 100644
--- a/ACKNOWLEDGEMENTS.md
+++ b/ACKNOWLEDGEMENTS.md
@@ -39,6 +39,8 @@ Code Contributors
 - Kasper Jacobsen (@dinoshauer)
 - Sebastian Pipping (@hartwork)
 - Helen Sherwood-Taylor (@helenst)
+- Mocker (@Zuckonit)
+- Tim Graham (@timgraham)
 
 Documenters
 ===================
diff --git a/isort/isort.py b/isort/isort.py
index beb36bc5..8fafd9d0 100644
--- a/isort/isort.py
+++ b/isort/isort.py
@@ -594,8 +594,13 @@ class SortImports(object):
 
     def _strip_syntax(self, import_string):
         import_string = import_string.replace("_import", "[[i]]")
-        for remove_syntax in ['\\', '(', ')', ",", 'from ', 'import ']:
+        for remove_syntax in ['\\', '(', ')', ',']:
             import_string = import_string.replace(remove_syntax, " ")
+        import_list = import_string.split()
+        for key in ('from', 'import'):
+            if key in import_list:
+                import_list.remove(key)
+        import_string = ' '.join(import_list)
         import_string = import_string.replace("[[i]]", "_import")
         return import_string
 


Test patch:
diff --git a/test_isort.py b/test_isort.py
index 180c506f..7fde1b43 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -1181,3 +1181,16 @@ def test_sticky_comments():
                   "# Used for type-hinting (ref: https://github.com/davidhalter/jedi/issues/414).\n"
                   "from selenium.webdriver.remote.webdriver import WebDriver  # noqa\n")
     assert SortImports(file_contents=test_input).output == test_input
+
+
+def test_zipimport():
+    """Imports ending in "import" shouldn't be clobbered"""
+    test_input = "from zipimport import zipimport\n"
+    assert SortImports(file_contents=test_input).output == test_input
+
+
+def test_from_ending():
+    """Imports ending in "from" shouldn't be clobbered."""
+    test_input = "from foo import get_foo_from, get_foo\n"
+    expected_output = "from foo import get_foo, get_foo_from\n"
+    assert SortImports(file_contents=test_input).output == expected_output