From 10d683a962d4e904352beae09adba30f120a86a6 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Mon, 29 Feb 2016 09:24:09 -0600 Subject: [PATCH] Look inside try/except for requests imports --- ansible_testing/modules.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ansible_testing/modules.py b/ansible_testing/modules.py index 0572576714..ee9a83f1ac 100644 --- a/ansible_testing/modules.py +++ b/ansible_testing/modules.py @@ -204,6 +204,18 @@ class ModuleValidator(Validator): 'should use ' 'ansible.module_utils.urls ' 'instead') + elif isinstance(child, ast.TryExcept): + bodies = child.body + for handler in child.handlers: + bodies.extend(handler.body) + for grandchild in bodies: + if isinstance(grandchild, ast.Import): + for name in grandchild.names: + if name.name == 'requests': + self.errors.append('requests import found, ' + 'should use ' + 'ansible.module_utils.urls ' + 'instead') def _find_module_utils(self, main): linenos = []