Skip to content

Commit 8d89389

Browse files
committed
StringIO is bad m'kay (python3 this and that)
1 parent 4b75ca1 commit 8d89389

File tree

9 files changed

+23
-26
lines changed

9 files changed

+23
-26
lines changed

lib/core/common.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import hashlib
1616
import httplib
1717
import inspect
18+
import io
1819
import json
1920
import keyword
2021
import locale
@@ -40,7 +41,6 @@
4041

4142
from ConfigParser import DEFAULTSECT
4243
from ConfigParser import RawConfigParser
43-
from StringIO import StringIO
4444
from difflib import SequenceMatcher
4545
from math import sqrt
4646
from optparse import OptionValueError
@@ -158,7 +158,6 @@
158158
from lib.core.settings import REFLECTED_REPLACEMENT_TIMEOUT
159159
from lib.core.settings import REFLECTED_VALUE_MARKER
160160
from lib.core.settings import REFLECTIVE_MISS_THRESHOLD
161-
from lib.core.settings import SAFE_VARIABLE_MARKER
162161
from lib.core.settings import SENSITIVE_DATA_REGEX
163162
from lib.core.settings import SENSITIVE_OPTIONS
164163
from lib.core.settings import STDIN_PIPE_DASH
@@ -2079,7 +2078,7 @@ def parseXmlFile(xmlFile, handler):
20792078
"""
20802079

20812080
try:
2082-
with contextlib.closing(StringIO(readCachedFileContent(xmlFile))) as stream:
2081+
with contextlib.closing(io.StringIO(readCachedFileContent(xmlFile))) as stream:
20832082
parse(stream, handler)
20842083
except (SAXParseException, UnicodeError) as ex:
20852084
errMsg = "something appears to be wrong with "
@@ -3322,7 +3321,7 @@ def openFile(filename, mode='r', encoding=UNICODE_ENCODING, errors="replace", bu
33223321
if filename not in kb.cache.content:
33233322
kb.cache.content[filename] = sys.stdin.read()
33243323

3325-
return contextlib.closing(StringIO(readCachedFileContent(filename)))
3324+
return contextlib.closing(io.StringIO(readCachedFileContent(filename)))
33263325
else:
33273326
try:
33283327
return codecs.open(filename, mode, encoding, errors, buffering)
@@ -4107,9 +4106,9 @@ def findPageForms(content, url, raise_=False, addToTargets=False):
41074106
set([(u'/input.php', 'POST', u'id=1', None, None)])
41084107
"""
41094108

4110-
class _(StringIO):
4109+
class _(io.BytesIO):
41114110
def __init__(self, content, url):
4112-
StringIO.__init__(self, unicodeencode(content, kb.pageEncoding) if isinstance(content, unicode) else content)
4111+
io.BytesIO.__init__(self, unicodeencode(content, kb.pageEncoding) if isinstance(content, unicode) else content)
41134112
self._url = url
41144113

41154114
def geturl(self):

lib/core/convert.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
import pickle as picklePy
1414

1515
import base64
16+
import io
1617
import json
1718
import re
18-
import StringIO
1919
import sys
2020

2121
from lib.core.settings import IS_WIN
@@ -84,7 +84,7 @@ def _(self):
8484
self.load_reduce()
8585

8686
def loads(str):
87-
f = StringIO.StringIO(str)
87+
f = io.BytesIO(str)
8888
if unsafe:
8989
unpickler = picklePy.Unpickler(f)
9090
unpickler.dispatch[picklePy.REDUCE] = _

lib/core/option.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@
125125
from lib.core.settings import SUPPORTED_DBMS
126126
from lib.core.settings import SUPPORTED_OS
127127
from lib.core.settings import TIME_DELAY_CANDIDATES
128-
from lib.core.settings import UNICODE_ENCODING
129128
from lib.core.settings import UNION_CHAR_REGEX
130129
from lib.core.settings import UNKNOWN_DBMS_VERSION
131130
from lib.core.settings import URI_INJECTABLE_REGEX

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from lib.core.enums import OS
2020

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.3.3.49"
22+
VERSION = "1.3.3.50"
2323
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2424
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2525
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

lib/request/basic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
import codecs
99
import gzip
10+
import io
1011
import logging
1112
import re
12-
import StringIO
1313
import struct
1414
import zlib
1515

@@ -273,9 +273,9 @@ def decodePage(page, contentEncoding, contentType):
273273

274274
try:
275275
if contentEncoding == "deflate":
276-
data = StringIO.StringIO(zlib.decompress(page, -15)) # Reference: http://stackoverflow.com/questions/1089662/python-inflate-and-deflate-implementations
276+
data = io.BytesIO(zlib.decompress(page, -15)) # Reference: http://stackoverflow.com/questions/1089662/python-inflate-and-deflate-implementations
277277
else:
278-
data = gzip.GzipFile("", "rb", 9, StringIO.StringIO(page))
278+
data = gzip.GzipFile("", "rb", 9, io.BytesIO(page))
279279
size = struct.unpack("<l", page[-4:])[0] # Reference: http://pydoc.org/get.cgi/usr/local/lib/python2.5/gzip.py
280280
if size > MAX_CONNECTION_TOTAL_SIZE:
281281
raise Exception("size too large")

lib/request/redirecthandler.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
See the file 'LICENSE' for copying permission
66
"""
77

8+
import io
89
import time
910
import types
1011
import urllib2
1112
import urlparse
1213

13-
from StringIO import StringIO
14-
1514
from lib.core.data import conf
1615
from lib.core.data import kb
1716
from lib.core.data import logger
@@ -165,7 +164,7 @@ def _(self, length=None):
165164
except:
166165
redurl = None
167166
result = fp
168-
fp.read = StringIO("").read
167+
fp.read = io.BytesIO("").read
169168
else:
170169
result = fp
171170

lib/takeover/web.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
See the file 'LICENSE' for copying permission
66
"""
77

8+
import io
89
import os
910
import posixpath
1011
import re
11-
import StringIO
1212
import tempfile
1313
import urlparse
1414

@@ -97,7 +97,7 @@ def webUpload(self, destFileName, directory, stream=None, content=None, filepath
9797
content = f.read()
9898

9999
if content is not None:
100-
stream = StringIO.StringIO(content) # string content
100+
stream = io.BytesIO(content) # string content
101101

102102
return self._webFileStreamUpload(stream, destFileName, directory)
103103

lib/utils/har.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import BaseHTTPServer
1010
import datetime
1111
import httplib
12+
import io
1213
import re
13-
import StringIO
1414
import time
1515

1616
from lib.core.bigarray import BigArray
@@ -149,11 +149,11 @@ def parse(cls, raw):
149149
comment = ""
150150

151151
if altered.startswith("HTTP response [") or altered.startswith("HTTP redirect ["):
152-
io = StringIO.StringIO(raw)
153-
first_line = io.readline()
152+
stream = io.StringIO(raw)
153+
first_line = stream.readline()
154154
parts = cls.extract_status.search(first_line)
155155
status_line = "HTTP/1.0 %s %s" % (parts.group(1), parts.group(2))
156-
remain = io.read()
156+
remain = stream.read()
157157
altered = status_line + "\r\n" + remain
158158
comment = first_line
159159

@@ -203,7 +203,7 @@ class FakeSocket:
203203
# https://stackoverflow.com/questions/24728088/python-parse-http-response-string
204204

205205
def __init__(self, response_text):
206-
self._file = StringIO.StringIO(response_text)
206+
self._file = io.StringIO(response_text)
207207

208208
def makefile(self, *args, **kwargs):
209209
return self._file
@@ -214,7 +214,7 @@ class HTTPRequest(BaseHTTPServer.BaseHTTPRequestHandler):
214214

215215
def __init__(self, request_text):
216216
self.comment = None
217-
self.rfile = StringIO.StringIO(request_text)
217+
self.rfile = io.StringIO(request_text)
218218
self.raw_requestline = self.rfile.readline()
219219

220220
if self.raw_requestline.startswith("HTTP request ["):

thirdparty/multipart/multipartpost.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2121
"""
2222

23+
import io
2324
import mimetools
2425
import mimetypes
2526
import os
2627
import stat
27-
import StringIO
2828
import sys
2929
import urllib
3030
import urllib2
@@ -53,7 +53,7 @@ def http_request(self, request):
5353

5454
try:
5555
for(key, value) in data.items():
56-
if isinstance(value, file) or hasattr(value, "file") or isinstance(value, StringIO.StringIO):
56+
if isinstance(value, file) or hasattr(value, "file") or isinstance(value, io.IOBase):
5757
v_files.append((key, value))
5858
else:
5959
v_vars.append((key, value))

0 commit comments

Comments
 (0)