EnTeQuAk  committed add5d6c

added proper unicode handling for :func:`import_string`; __import__ does not accept unicode strings in the fromlist argument

  • Participants
  • Parent commits 2b3053f

Comments (0)

Files changed (2)

File tests/

 def test_import_string():
     """String based importing"""
     import cgi
+    from werkzeug.debug import DebuggedApplication
     assert import_string('cgi.escape') is cgi.escape
     assert import_string('cgi:escape') is cgi.escape
     assert import_string('XXXXXXXXXXXX', True) is None
     assert import_string('cgi.XXXXXXXXXXXX', True) is None
+    assert import_string(u'cgi.escape') is cgi.escape
+    assert import_string(u'werkzeug.debug.DebuggedApplication') is DebuggedApplication
     assert_raises(ImportError, import_string, 'XXXXXXXXXXXXXXXX')
     assert_raises(AttributeError, import_string, 'cgi.XXXXXXXXXX')

File werkzeug/

             module, obj = import_name.rsplit('.', 1)
             return __import__(import_name)
+        # __import__ is not able to handle unicode strings in the fromlist
+        # if the module is a package
+        if isinstance(obj, unicode):
+            obj = obj.encode('utf-8')
         return getattr(__import__(module, None, None, [obj]), obj)
     except (ImportError, AttributeError):
         if not silent: