From 3a26a1bfcc19b750baf734027c9c76ad791168c1 Mon Sep 17 00:00:00 2001 From: Andy Dirnberger Date: Sat, 12 Nov 2016 18:01:05 -0500 Subject: [PATCH] Make Homebrew-related modules run on Python 3 Both the `homebrew` and `homebrew_cask` modules iterate over dictionaries using `iteritems`. This is a Python 2-specific method whose behavior is similar to `items` in Python 3+. The `iteritems` function in the six library was designed to make it possible to use the correct method. --- lib/ansible/modules/extras/packaging/os/homebrew.py | 4 +++- lib/ansible/modules/extras/packaging/os/homebrew_cask.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/extras/packaging/os/homebrew.py b/lib/ansible/modules/extras/packaging/os/homebrew.py index 664f9718487..d48491d15e0 100755 --- a/lib/ansible/modules/extras/packaging/os/homebrew.py +++ b/lib/ansible/modules/extras/packaging/os/homebrew.py @@ -101,6 +101,8 @@ EXAMPLES = ''' import os.path import re +from ansible.module_utils.six import iteritems + # exceptions -------------------------------------------------------------- {{{ class HomebrewException(Exception): @@ -348,7 +350,7 @@ class Homebrew(object): self.message = '' def _setup_instance_vars(self, **kwargs): - for key, val in kwargs.iteritems(): + for key, val in iteritems(kwargs): setattr(self, key, val) def _prep(self): diff --git a/lib/ansible/modules/extras/packaging/os/homebrew_cask.py b/lib/ansible/modules/extras/packaging/os/homebrew_cask.py index debcb788ea4..2d1722398eb 100755 --- a/lib/ansible/modules/extras/packaging/os/homebrew_cask.py +++ b/lib/ansible/modules/extras/packaging/os/homebrew_cask.py @@ -75,6 +75,8 @@ EXAMPLES = ''' import os.path import re +from ansible.module_utils.six import iteritems + # exceptions -------------------------------------------------------------- {{{ class HomebrewCaskException(Exception): @@ -309,7 +311,7 @@ class HomebrewCask(object): self.message = '' def _setup_instance_vars(self, **kwargs): - for key, val in kwargs.iteritems(): + for key, val in iteritems(kwargs): setattr(self, key, val) def _prep(self):