diff options
author | Dirk Mueller <dirk@dmllr.de> | 2013-08-04 23:32:21 +0200 |
---|---|---|
committer | Dirk Mueller <dirk@dmllr.de> | 2013-08-04 23:32:21 +0200 |
commit | 706caf96fc19255a52a3565e3a5ecc7290245ebe (patch) | |
tree | 283d4b91c3bbe919f0e9580f9f76fb777db026eb | |
parent | 9d858db885db1ff9ed1a2556aac4cb9348c2e75e (diff) | |
download | oslo-serialization-706caf96fc19255a52a3565e3a5ecc7290245ebe.tar.gz |
Make dependency on netaddr optional
https://review.openstack.org/#/c/38023/ pointed out that
the dependency on netaddr is unnecessary and can be avoided.
Use try_import to avoid a hard dependency on netaddr.
Change-Id: I8b246f20f9001379fcb5ca3a84aabee3847cb945
-rw-r--r-- | openstack/common/jsonutils.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/openstack/common/jsonutils.py b/openstack/common/jsonutils.py index 9c72376..5a0235d 100644 --- a/openstack/common/jsonutils.py +++ b/openstack/common/jsonutils.py @@ -41,11 +41,12 @@ import json import types import xmlrpclib -import netaddr import six +from openstack.common import importutils from openstack.common import timeutils +netaddr = importutils.try_import("netaddr") _nasty_type_tests = [inspect.ismodule, inspect.isclass, inspect.ismethod, inspect.isfunction, inspect.isgeneratorfunction, @@ -138,7 +139,7 @@ def to_primitive(value, convert_instances=False, convert_datetime=True, # Likely an instance of something. Watch for cycles. # Ignore class member vars. return recursive(value.__dict__, level=level + 1) - elif isinstance(value, netaddr.IPAddress): + elif netaddr and isinstance(value, netaddr.IPAddress): return six.text_type(value) else: if any(test(value) for test in _nasty_type_tests): |