From 1f53e7abf35fc0fd12f6da905d46f1638a0f8a46 Mon Sep 17 00:00:00 2001 From: Sun Austin Date: Thu, 22 Nov 2018 09:24:25 +0800 Subject: [PATCH] Fix: "has_key" issue for Python 2/3 compatible code remove temporary_mutation function which contains 'has_key' code since temporary_mutation is not used anywhere. Change-Id: I88d8894f4ac55973408f583680c228dbe78abaeb Story: 2003433 Task:25737 Signed-off-by: Sun Austin --- sysinv/sysinv/sysinv/sysinv/common/utils.py | 49 --------------------- 1 file changed, 49 deletions(-) diff --git a/sysinv/sysinv/sysinv/sysinv/common/utils.py b/sysinv/sysinv/sysinv/sysinv/common/utils.py index a4e71bbe6c..f216eaca07 100644 --- a/sysinv/sysinv/sysinv/sysinv/common/utils.py +++ b/sysinv/sysinv/sysinv/sysinv/common/utils.py @@ -588,55 +588,6 @@ def hash_file(file_like_object): return checksum.hexdigest() -@contextlib.contextmanager -def temporary_mutation(obj, **kwargs): - """Temporarily set the attr on a particular object to a given value then - revert when finished. - - One use of this is to temporarily set the read_deleted flag on a context - object: - - with temporary_mutation(context, read_deleted="yes"): - do_something_that_needed_deleted_objects() - """ - def is_dict_like(thing): - return hasattr(thing, 'has_key') - - def get(thing, attr, default): - if is_dict_like(thing): - return thing.get(attr, default) - else: - return getattr(thing, attr, default) - - def set_value(thing, attr, val): - if is_dict_like(thing): - thing[attr] = val - else: - setattr(thing, attr, val) - - def delete(thing, attr): - if is_dict_like(thing): - del thing[attr] - else: - delattr(thing, attr) - - NOT_PRESENT = object() - - old_values = {} - for attr, new_value in kwargs.items(): - old_values[attr] = get(obj, attr, NOT_PRESENT) - set_value(obj, attr, new_value) - - try: - yield - finally: - for attr, old_value in old_values.items(): - if old_value is NOT_PRESENT: - delete(obj, attr) - else: - set_value(obj, attr, old_value) - - @contextlib.contextmanager def tempdir(**kwargs): tempfile.tempdir = CONF.tempdir