Remove TryImport test cause we don't hook import in debugger anymore

This commit is contained in:
Elizaveta Shashkova
2015-01-21 19:35:41 +03:00
parent 7d6be7098e
commit e9bf0844e9
2 changed files with 0 additions and 52 deletions
-31
View File
@@ -1,31 +0,0 @@
import sys
try:
# Python2
reload(sys)
except:
# Python3
import importlib
importlib.reload(sys)
def try_import(module_name):
"""
Import and return *module_name*.
Unlike the standard try/except approach to optional imports, inspect
the stack to avoid catching ImportErrors raised from **within** the
module. Only return None if *module_name* itself cannot be imported.
It is used in rapidsms, django-oscar and may be somewhere else.
"""
try:
__import__(module_name)
return sys.modules[module_name]
except ImportError:
type, info, traceback = sys.exc_info()
if traceback.tb_next:
raise
return None
result = try_import("datetime")
result = try_import("nonexistent_module")
result = None