From 9935fd9f8e9c18d9e78e84758ddd618e343ef823 Mon Sep 17 00:00:00 2001 From: David Kludt Date: Mon, 2 Nov 2020 08:09:35 -0600 Subject: [PATCH] Utilize deepcopy to iterate through the dictionary and update the original to avoid RuntimeError in Python 3.8 --- f5/bigip/resource.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/f5/bigip/resource.py b/f5/bigip/resource.py index c35014de4..a9a98c87f 100644 --- a/f5/bigip/resource.py +++ b/f5/bigip/resource.py @@ -488,18 +488,20 @@ def _check_keys(self, rdict): error_message = "Response contains key '_meta_data' which is "\ "incompatible with this API!!\n Response json: %r" % rdict raise DeviceProvidesIncompatibleKey(error_message) - for x in rdict: - if not re.match(tokenize.Name, x): + + copy_rdict = copy.deepcopy(rdict) + for key, value in iteritems(copy_rdict): + if not re.match(tokenize.Name, key): error_message = "Device provided %r which is disallowed"\ - " because it's not a valid Python 2.7 identifier." % x + " because it's not a valid Python 2.7 identifier." % key raise DeviceProvidesIncompatibleKey(error_message) - elif keyword.iskeyword(x): + elif keyword.iskeyword(key): # If attribute is keyword, append underscore to attribute name - rdict[x + '_'] = rdict[x] - rdict.pop(x) - elif x.startswith('__'): + rdict[key + '_'] = value + rdict.pop(key) + elif key.startswith('__'): error_message = "Device provided %r which is disallowed"\ - ", it mangles into a Python non-public attribute." % x + ", it mangles into a Python non-public attribute." % key raise DeviceProvidesIncompatibleKey(error_message) return rdict