From 07a47179a774e3d56861cee9fc231799e19f7fc9 Mon Sep 17 00:00:00 2001 From: Lee Clemens Date: Fri, 23 Jan 2015 16:00:33 -0500 Subject: [PATCH] conditionally import dnspython --- fail2ban/server/banmanager.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fail2ban/server/banmanager.py b/fail2ban/server/banmanager.py index 81ac7c4f..2b2fd39a 100644 --- a/fail2ban/server/banmanager.py +++ b/fail2ban/server/banmanager.py @@ -26,9 +26,6 @@ __license__ = "GPL" from threading import Lock -import dns.exception -import dns.resolver - from .ticket import BanTicket from .mytime import MyTime from ..helpers import getLogger @@ -139,8 +136,17 @@ class BanManager: # @return {"asn": [], "country": [], "rir": []} dict for self.__banList IPs def getBanListExtendedCymruInfo(self): - self.__lock.acquire() return_dict = {"asn": [], "country": [], "rir": []} + try: + import dns.exception + import dns.resolver + except ImportError: + logSys.error("dnspython package is required but could not be imported") + return_dict["asn"].append("error") + return_dict["country"].append("error") + return_dict["rir"].append("error") + return return_dict + self.__lock.acquire() try: for banData in self.__banList: ip = banData.getIP()