From a77637903afaec5cd56be21d6ef7f9f3a1945512 Mon Sep 17 00:00:00 2001 From: Hassan Baker Date: Thu, 20 May 2021 12:30:09 +0100 Subject: [PATCH] python3-support support for python3 using dict.items() instead of dict.iteritems() --- automationassets/automationassets.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/automationassets/automationassets.py b/automationassets/automationassets.py index f70f3a7..6770513 100644 --- a/automationassets/automationassets.py +++ b/automationassets/automationassets.py @@ -1,5 +1,4 @@ """ Azure Automation assets module to be used with Azure Automation during offline development """ -#!/usr/bin/env python2 # ---------------------------------------------------------------------------------- # # MIT License @@ -23,6 +22,18 @@ # SOFTWARE. # ---------------------------------------------------------------------------------- +# Support for python3 +try: + dict.iteritems +except AttributeError: + # Python 3 + def iteritems(d): + return iter(d.items()) +else: + # Python 2 + def iteritems(d): + return d.iteritems() + # Constant keys for extracing items from automation assets. _KEY_NAME = "Name" _KEY_VALUE = "Value" @@ -52,7 +63,7 @@ def _get_asset_value(asset_file, asset_type, asset_name): local_assets = json.loads(json_string) return_value = None - for asset, asset_values in local_assets.iteritems(): + for asset, asset_values in iteritems(local_assets): if asset == asset_type: for value in asset_values: if value[_KEY_NAME] == asset_name: @@ -83,7 +94,7 @@ def _set_asset_value(asset_file, asset_type, asset_name, asset_value): local_assets = json.loads(json_string) item_found = False - for asset, asset_values in local_assets.iteritems(): + for asset, asset_values in iteritems(local_assets): if asset == asset_type: for value in asset_values: if value[_KEY_NAME] == asset_name: