Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6a0e0cd

Browse files
committed
code review of modules in lib/core directory
1 parent 2d9b151 commit 6a0e0cd

9 files changed

Lines changed: 70 additions & 81 deletions

File tree

lib/controller/controller.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ def start():
168168
conf.method = targetMethod
169169
conf.data = targetData
170170
conf.cookie = targetCookie
171-
injData = []
172171

173172
initTargetEnv()
174173
parseTargetUrl()

lib/core/common.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@
2020
import urlparse
2121
import ntpath
2222
import posixpath
23-
import subprocess
2423
import httplib
2524

2625
from ConfigParser import DEFAULTSECT
2726
from ConfigParser import RawConfigParser
2827
from StringIO import StringIO
2928
from difflib import SequenceMatcher
30-
from inspect import getmembers
3129
from math import sqrt
3230
from subprocess import PIPE
3331
from subprocess import Popen as execute
@@ -142,7 +140,7 @@ def paramToDict(place, parameters=None):
142140
if conf.parameters.has_key(place) and not parameters:
143141
parameters = conf.parameters[place]
144142

145-
if place is not "POSTxml":
143+
if place != "POSTxml":
146144
parameters = parameters.replace(", ", ",")
147145

148146
if place == PLACE.COOKIE:
@@ -1164,7 +1162,7 @@ def decloakToNamedTemporaryFile(filepath, name=None):
11641162
def __del__():
11651163
try:
11661164
if hasattr(retVal, 'old_name'):
1167-
retVal.name = old_name
1165+
retVal.name = retVal.old_name
11681166
retVal.close()
11691167
except OSError:
11701168
pass
@@ -1242,7 +1240,7 @@ def getConsoleWidth(default=80):
12421240
if 'COLUMNS' in os.environ and os.environ['COLUMNS'].isdigit():
12431241
width = int(os.environ['COLUMNS'])
12441242
else:
1245-
output=subprocess.Popen('stty size', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.read()
1243+
output=execute('stty size', shell=True, stdout=PIPE, stderr=PIPE).stdout.read()
12461244
items = output.split()
12471245

12481246
if len(items) == 2 and items[1].isdigit():
@@ -1694,7 +1692,7 @@ def getPublicTypeMembers(type_, onlyValues=False):
16941692

16951693
retVal = []
16961694

1697-
for name, value in getmembers(type_):
1695+
for name, value in inspect.getmembers(type_):
16981696
if not name.startswith('__'):
16991697
if not onlyValues:
17001698
retVal.append((name, value))
@@ -2094,7 +2092,7 @@ def openFile(filename, mode='r'):
20942092

20952093
try:
20962094
return codecs.open(filename, mode, conf.dataEncoding)
2097-
except IOError, e:
2095+
except IOError:
20982096
errMsg = "there has been a file opening error for filename '%s'. " % filename
20992097
errMsg += "Please check %s permissions on a file " % ("write" if mode and\
21002098
('w' in mode or 'a' in mode or '+' in mode) else "read")

lib/core/convert.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,80 +20,80 @@
2020

2121
from lib.core.data import conf
2222

23-
def base64decode(string):
24-
return string.decode("base64")
23+
def base64decode(value):
24+
return value.decode("base64")
2525

26-
def base64encode(string):
27-
return string.encode("base64")[:-1].replace("\n", "")
26+
def base64encode(value):
27+
return value.encode("base64")[:-1].replace("\n", "")
2828

29-
def base64pickle(string):
30-
return base64encode(pickle.dumps(string))
29+
def base64pickle(value):
30+
return base64encode(pickle.dumps(value))
3131

32-
def base64unpickle(string):
33-
return pickle.loads(base64decode(string))
32+
def base64unpickle(value):
33+
return pickle.loads(base64decode(value))
3434

35-
def hexdecode(string):
36-
string = string.lower()
35+
def hexdecode(value):
36+
value = value.lower()
3737

38-
if string.startswith("0x"):
39-
string = string[2:]
38+
if value.startswith("0x"):
39+
value = value[2:]
4040

41-
return string.decode("hex")
41+
return value.decode("hex")
4242

43-
def hexencode(string):
44-
return string.encode("hex")
43+
def hexencode(value):
44+
return value.encode("hex")
4545

46-
def md5hash(string):
46+
def md5hash(value):
4747
if sys.modules.has_key('hashlib'):
48-
return hashlib.md5(string).hexdigest()
48+
return hashlib.md5(value).hexdigest()
4949
else:
50-
return md5.new(string).hexdigest()
50+
return md5.new(value).hexdigest()
5151

52-
def orddecode(string):
53-
packedString = struct.pack("!"+"I" * len(string), *string)
52+
def orddecode(value):
53+
packedString = struct.pack("!"+"I" * len(value), *value)
5454
return "".join([chr(char) for char in struct.unpack("!"+"I"*(len(packedString)/4), packedString)])
5555

56-
def ordencode(string):
57-
return tuple([ord(char) for char in string])
56+
def ordencode(value):
57+
return tuple([ord(char) for char in value])
5858

59-
def sha1hash(string):
59+
def sha1hash(value):
6060
if sys.modules.has_key('hashlib'):
61-
return hashlib.sha1(string).hexdigest()
61+
return hashlib.sha1(value).hexdigest()
6262
else:
63-
return sha.new(string).hexdigest()
63+
return sha.new(value).hexdigest()
6464

65-
def urldecode(string):
65+
def urldecode(value):
6666
result = None
6767

68-
if string:
69-
result = urllib.unquote_plus(string)
68+
if value:
69+
result = urllib.unquote_plus(value)
7070

7171
return result
7272

73-
def urlencode(string, safe=":/?%&=", convall=False):
73+
def urlencode(value, safe=":/?%&=", convall=False):
7474
if conf.direct or "POSTxml" in conf.paramDict:
75-
return string
75+
return value
7676

7777
result = None
7878

79-
if string is None:
79+
if value is None:
8080
return result
8181

8282
if convall:
83-
result = urllib.quote(utf8encode(string)) # Reference: http://old.nabble.com/Re:-Problem:-neither-urllib2.quote-nor-urllib.quote-encode-the--unicode-strings-arguments-p19823144.html
83+
result = urllib.quote(utf8encode(value)) # Reference: http://old.nabble.com/Re:-Problem:-neither-urllib2.quote-nor-urllib.quote-encode-the--unicode-strings-arguments-p19823144.html
8484
else:
85-
result = urllib.quote(utf8encode(string), safe)
85+
result = urllib.quote(utf8encode(value), safe)
8686

8787
return result
8888

89-
def utf8encode(string):
90-
return string.encode("utf-8")
89+
def utf8encode(value):
90+
return value.encode("utf-8")
9191

92-
def utf8decode(string):
93-
return string.decode("utf-8")
92+
def utf8decode(value):
93+
return value.decode("utf-8")
9494

95-
def htmlescape(string):
96-
return string.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;').replace(' ', '&nbsp;')
95+
def htmlescape(value):
96+
return value.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;').replace(' ', '&nbsp;')
9797

98-
def htmlunescape(string):
99-
return string.replace('&amp;', '&').replace('&lt;', '<').replace('&gt;', '>').replace('&quot;', '"').replace('&#39;', "'").replace('&nbsp;', ' ')
98+
def htmlunescape(value):
99+
return value.replace('&amp;', '&').replace('&lt;', '<').replace('&gt;', '>').replace('&quot;', '"').replace('&#39;', "'").replace('&nbsp;', ' ')

lib/core/dump.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def dbTableValues(self, tableValues):
291291
if re.search("^[\ *]*$", value): #NULL
292292
continue
293293

294-
temp = int(value)
294+
_ = int(value)
295295
except ValueError:
296296
colType = None
297297
break
@@ -304,7 +304,7 @@ def dbTableValues(self, tableValues):
304304
if re.search("^[\ *]*$", value): #NULL
305305
continue
306306

307-
temp = float(value)
307+
_ = float(value)
308308
except ValueError:
309309
colType = None
310310
break

lib/core/readlineng.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,44 @@
77
See the file 'doc/COPYING' for copying permission
88
"""
99

10-
import sys
11-
1210
from lib.core.data import logger
1311
from lib.core.settings import IS_WIN
1412
from lib.core.settings import PLATFORM
1513

16-
try:
17-
from readline import *
18-
import readline as _rl
14+
_readline = None
1915

20-
haveReadline = True
16+
try:
17+
import readline as _readline
2118
except ImportError:
2219
try:
23-
from pyreadline import *
24-
import pyreadline as _rl
25-
26-
haveReadline = True
27-
except ImportError:
28-
haveReadline = False
20+
import pyreadline as _readline
21+
except ImportError:
22+
pass
2923

30-
if IS_WIN and haveReadline:
24+
if IS_WIN and _readline:
3125
try:
32-
_outputfile=_rl.GetOutputFile()
26+
_outputfile = _readline.GetOutputFile()
3327
except AttributeError:
34-
debugMsg = "Failed GetOutputFile when using platform's "
28+
debugMsg = "Failed GetOutputFile when using platform's "
3529
debugMsg += "readline library"
3630
logger.debug(debugMsg)
3731

38-
haveReadline = False
32+
_readline = None
3933

4034
# Test to see if libedit is being used instead of GNU readline.
4135
# Thanks to Boyd Waters for this patch.
4236
uses_libedit = False
4337

44-
if PLATFORM == 'mac' and haveReadline:
38+
if PLATFORM == 'mac' and _readline:
4539
import commands
4640

47-
(status, result) = commands.getstatusoutput( "otool -L %s | grep libedit" % _rl.__file__ )
41+
(status, result) = commands.getstatusoutput( "otool -L %s | grep libedit" % _readline.__file__ )
4842

4943
if status == 0 and len(result) > 0:
5044
# We are bound to libedit - new in Leopard
51-
_rl.parse_and_bind("bind ^I rl_complete")
45+
_readline.parse_and_bind("bind ^I rl_complete")
5246

53-
debugMsg = "Leopard libedit detected when using platform's "
47+
debugMsg = "Leopard libedit detected when using platform's "
5448
debugMsg += "readline library"
5549
logger.debug(debugMsg)
5650

@@ -61,11 +55,11 @@
6155
# existence. Some known platforms actually don't have it. This thread:
6256
# http://mail.python.org/pipermail/python-dev/2003-August/037845.html
6357
# has the original discussion.
64-
if haveReadline:
58+
if _readline:
6559
try:
66-
_rl.clear_history
60+
_readline.clear_history()
6761
except AttributeError:
6862
def clear_history():
6963
pass
7064

71-
_rl.clear_history = clear_history
65+
_readline.clear_history = clear_history

lib/core/testing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def liveTest():
141141
count += 1
142142
msg = "running live test case '%s' (%d/%d)" % (name, count, length)
143143
logger.info(msg)
144-
result = runCase(name, switches, log, session)
144+
result = runCase(switches, log, session)
145145
if result:
146146
logger.info("test passed")
147147
else:
@@ -180,7 +180,7 @@ def cleanCase():
180180
conf.verbose = 1
181181
__setVerbosity()
182182

183-
def runCase(name=None, switches=None, log=None, session=None):
183+
def runCase(switches=None, log=None, session=None):
184184
retVal = True
185185
initCase(switches)
186186

lib/core/update.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
import re
1414
import shutil
1515
import sys
16-
import tempfile
1716
import time
1817
import urlparse
19-
import zipfile
2018

2119
from distutils.dir_util import mkpath
2220
from xml.dom.minidom import Document

lib/core/xmldump.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def dbTableValues(self, tableValues):
415415

416416
logger.info("Table '%s.%s' dumped to XML file" % (db, table))
417417

418-
def dbColumns(self, dbColumns, colConsider, dbs):
418+
def dbColumns(self, dbColumns, _, dbs):
419419
'''
420420
Adds information about the columns
421421
'''
@@ -496,7 +496,7 @@ def setOutputFile(self):
496496
self.__root.setAttributeNode(self.__createAttribute(XMLNS_ATTR,NAME_SPACE_ATTR))
497497
self.__root.setAttributeNode(self.__createAttribute(SCHEME_NAME_ATTR,SCHEME_NAME))
498498
self.__doc.appendChild(self.__root)
499-
except IOError, e:
499+
except IOError:
500500
raise sqlmapFilePathException("Wrong filename provided for saving the xml file: %s" % conf.xmlFile)
501501

502502
def getOutputFile(self):

sqlmap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import psyco
2121
psyco.full()
2222
psyco.profile()
23-
except ImportError, _:
23+
except ImportError:
2424
pass
2525

2626
from lib.controller.controller import start

0 commit comments

Comments
 (0)