diff options
| author | Scott Moser <smoser@ubuntu.com> | 2016-04-04 12:07:19 -0400 |
|---|---|---|
| committer | Scott Moser <smoser@ubuntu.com> | 2016-04-04 12:07:19 -0400 |
| commit | 7d8a3194552387fa9e21216bcd9a3bfc76fa2b04 (patch) | |
| tree | c8dc45b013208a4e5e09e6ade63b3b5994f80aa3 /cloudinit/type_utils.py | |
| parent | 93f5af9f5075a416c65c1d0350c374e16f32f0d5 (diff) | |
| parent | 210b041b2fead7a57af91f60a6f89d9e5aa1ed4a (diff) | |
| download | vyos-cloud-init-7d8a3194552387fa9e21216bcd9a3bfc76fa2b04.tar.gz vyos-cloud-init-7d8a3194552387fa9e21216bcd9a3bfc76fa2b04.zip | |
merge with trunk
Diffstat (limited to 'cloudinit/type_utils.py')
| -rw-r--r-- | cloudinit/type_utils.py | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/cloudinit/type_utils.py b/cloudinit/type_utils.py index cc3d9495..b93efd6a 100644 --- a/cloudinit/type_utils.py +++ b/cloudinit/type_utils.py @@ -22,11 +22,31 @@ import types +import six + + +if six.PY3: + _NAME_TYPES = ( + types.ModuleType, + types.FunctionType, + types.LambdaType, + type, + ) +else: + _NAME_TYPES = ( + types.TypeType, + types.ModuleType, + types.FunctionType, + types.LambdaType, + types.ClassType, + ) + def obj_name(obj): - if isinstance(obj, (types.TypeType, - types.ModuleType, - types.FunctionType, - types.LambdaType)): - return str(obj.__name__) - return obj_name(obj.__class__) + if isinstance(obj, _NAME_TYPES): + return six.text_type(obj.__name__) + else: + if not hasattr(obj, '__class__'): + return repr(obj) + else: + return obj_name(obj.__class__) |
