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

Skip to content

Commit 0197f8d

Browse files
committed
code refactoring regarding issue #184
1 parent e9be60e commit 0197f8d

4 files changed

Lines changed: 9 additions & 8 deletions

File tree

lib/core/common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def dataToStdout(data):
356356
sys.stdout.write(data)
357357
sys.stdout.flush()
358358
except UnicodeEncodeError:
359-
print data.encode("utf8")
359+
print data.encode(conf.dataEncoding)
360360

361361
def dataToSessionFile(data):
362362
if not conf.sessionFile:
@@ -375,7 +375,7 @@ def dataToOutFile(data):
375375

376376
rFile = filePathToString(conf.rFile)
377377
rFilePath = "%s%s%s" % (conf.filePath, os.sep, rFile)
378-
rFileFP = codecs.open(rFilePath, "wb", "utf-8")
378+
rFileFP = codecs.open(rFilePath, "wb", conf.dataEncoding)
379379

380380
rFileFP.write(data)
381381
rFileFP.flush()
@@ -416,7 +416,7 @@ def fileToStr(fileName):
416416
@rtype: C{str}
417417
"""
418418

419-
filePointer = codecs.open(fileName, "r", "utf-8")
419+
filePointer = codecs.open(fileName, "r", conf.dataEncoding)
420420
fileText = filePointer.read()
421421

422422
return fileText.replace(" ", "").replace("\t", "").replace("\r", "").replace("\n", " ")

lib/core/dump.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __write(self, data, n=True):
5555

5656
def setOutputFile(self):
5757
self.__outputFile = "%s%slog" % (conf.outputPath, os.sep)
58-
self.__outputFP = codecs.open(self.__outputFile, "a", "utf-8")
58+
self.__outputFP = codecs.open(self.__outputFile, "a", conf.dataEncoding)
5959

6060
def string(self, header, data, sort=True):
6161
if isinstance(data, (list, tuple, set)):
@@ -268,7 +268,7 @@ def dbTableValues(self, tableValues):
268268
os.makedirs(dumpDbPath, 0755)
269269

270270
dumpFileName = "%s%s%s.csv" % (dumpDbPath, os.sep, table)
271-
dumpFP = codecs.open(dumpFileName, "w", "utf-8")
271+
dumpFP = codecs.open(dumpFileName, "w", conf.dataEncoding)
272272

273273
count = int(tableValues["__infos__"]["count"])
274274
separator = ""

lib/core/option.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __urllib2Opener():
9797
urllib2.install_opener(opener)
9898

9999
def __feedTargetsDict(reqFile, addedTargetUrls):
100-
fp = codecs.open(reqFile, "r", "utf-8")
100+
fp = codecs.open(reqFile, "r", conf.dataEncoding)
101101

102102
fread = fp.read()
103103
fread = fread.replace("\r", "")
@@ -884,6 +884,7 @@ def __setConfAttributes():
884884
logger.debug(debugMsg)
885885

886886
conf.cj = None
887+
conf.dataEncoding = "utf-8"
887888
conf.dbmsConnector = None
888889
conf.dbmsHandler = None
889890
conf.dumpPath = None

lib/core/target.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def __setOutputResume():
122122

123123
if os.path.exists(conf.sessionFile):
124124
if not conf.flushSession:
125-
readSessionFP = codecs.open(conf.sessionFile, "r", "utf-8")
125+
readSessionFP = codecs.open(conf.sessionFile, "r", conf.dataEncoding)
126126
__url_cache = set()
127127
__expression_cache = {}
128128

@@ -171,7 +171,7 @@ def __setOutputResume():
171171
raise sqlmapFilePathException, errMsg
172172

173173
try:
174-
conf.sessionFP = codecs.open(conf.sessionFile, "a", "utf-8")
174+
conf.sessionFP = codecs.open(conf.sessionFile, "a", conf.dataEncoding)
175175
dataToSessionFile("\n[%s]\n" % time.strftime("%X %x"))
176176
except IOError:
177177
errMsg = "unable to write on the session file specified"

0 commit comments

Comments
 (0)