From f54082111dbd48027034811bfaae9c4954fa2a0f Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Sat, 13 Jul 2013 19:25:49 +0200 Subject: [PATCH] Better way how to deal with required extensions --- lib/request/basic.py | 16 ++-------------- lib/utils/versioncheck.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/request/basic.py b/lib/request/basic.py index b25a77c95..7ccb0c926 100755 --- a/lib/request/basic.py +++ b/lib/request/basic.py @@ -6,24 +6,12 @@ See the file 'doc/COPYING' for copying permission """ import codecs +import gzip import logging import re import StringIO import struct - -try: - import bz2 - import gzip - import sqlite3 - import zlib -except ImportError, ex: - from lib.core.data import logger - - errMsg = "missing one of core extensions (bz2, gzip, sqlite3, zlib) " - errMsg += "probably because current version of Python has been " - errMsg += "built without appropriate dev packages (e.g. libsqlite3-dev)" - logger.critical(errMsg) - raise SystemExit +import zlib from lib.core.common import extractErrorMessage from lib.core.common import extractRegexResult diff --git a/lib/utils/versioncheck.py b/lib/utils/versioncheck.py index 9a3d5f5e6..3d882171e 100644 --- a/lib/utils/versioncheck.py +++ b/lib/utils/versioncheck.py @@ -11,3 +11,13 @@ PYVERSION = sys.version.split()[0] if PYVERSION >= "3" or PYVERSION < "2.6": exit("[CRITICAL] incompatible Python version detected ('%s'). For successfully running sqlmap you'll have to use version 2.6 or 2.7 (visit 'http://www.python.org/download/')" % PYVERSION) + +extensions = ("bz2", "gzip", "ssl", "sqlite3", "zlib") +try: + for _ in extensions: + __import__(_) +except ImportError, ex: + errMsg = "missing one or more core extensions (%s) " % (", ".join("'%s'" % _ for _ in extensions)) + errMsg += "most probably because current version of Python has been " + errMsg += "built without appropriate dev packages (e.g. 'libsqlite3-dev')" + exit(errMsg) \ No newline at end of file