Only reference msgpack if it imported successfully

Fixes #26850
This commit is contained in:
Colton Myers 2015-09-02 11:54:45 -06:00 committed by rallytime
parent a563af29d3
commit 5a4c8dd2f5

View File

@ -26,6 +26,7 @@ except ImportError:
log = logging.getLogger(__name__)
HAS_MSGPACK = False
try:
# Attempt to import msgpack
import msgpack
@ -33,10 +34,12 @@ try:
# for some msgpack bindings, check for it
if msgpack.loads(msgpack.dumps([1, 2, 3]), use_list=True) is None:
raise ImportError
HAS_MSGPACK = True
except ImportError:
# Fall back to msgpack_pure
try:
import msgpack_pure as msgpack
import msgpack_pure as msgpack # pylint: disable=import-error
HAS_MSGPACK = True
except ImportError:
# TODO: Come up with a sane way to get a configured logfile
# and write to the logfile when this error is hit also
@ -48,7 +51,7 @@ except ImportError:
#sys.exit(salt.defaults.exitcodes.EX_GENERIC)
if not hasattr(msgpack, 'exceptions'):
if HAS_MSGPACK and not hasattr(msgpack, 'exceptions'):
class PackValueError(Exception):
'''
older versions of msgpack do not have PackValueError