3333import time
3434import types
3535import urllib
36- import urllib2
37- import urlparse
3836import unicodedata
3937
4038from ConfigParser import DEFAULTSECT
178176from thirdparty .colorama .initialise import init as coloramainit
179177from thirdparty .magic import magic
180178from thirdparty .odict import OrderedDict
179+ from thirdparty .six .moves import urllib as _urllib
181180from thirdparty .termcolor .termcolor import colored
182181
183182class UnicodeRawConfigParser (RawConfigParser ):
@@ -1467,7 +1466,7 @@ def parseTargetUrl():
14671466 conf .url = conf .url .replace ('?' , URI_QUESTION_MARKER )
14681467
14691468 try :
1470- urlSplit = urlparse .urlsplit (conf .url )
1469+ urlSplit = _urllib . parse .urlsplit (conf .url )
14711470 except ValueError as ex :
14721471 errMsg = "invalid URL '%s' has been given ('%s'). " % (conf .url , getSafeExString (ex ))
14731472 errMsg += "Please be sure that you don't have any leftover characters (e.g. '[' or ']') "
@@ -2653,15 +2652,15 @@ def urldecode(value, encoding=None, unsafe="%%&=;+%s" % CUSTOM_INJECTION_MARK_CH
26532652 pass
26542653 finally :
26552654 if convall :
2656- result = urllib . unquote_plus (value ) if spaceplus else urllib .unquote (value )
2655+ result = _urllib . parse . unquote_plus (value ) if spaceplus else _urllib . parse .unquote (value )
26572656 else :
26582657 def _ (match ):
26592658 charset = reduce (lambda x , y : x .replace (y , "" ), unsafe , string .printable )
26602659 char = chr (ord (match .group (1 ).decode ("hex" )))
26612660 return char if char in charset else match .group (0 )
26622661 result = value
26632662 if spaceplus :
2664- result = result .replace ('+' , ' ' ) # plus sign has a special meaning in URL encoded data (hence the usage of urllib .unquote_plus in convall case)
2663+ result = result .replace ('+' , ' ' ) # plus sign has a special meaning in URL encoded data (hence the usage of _urllib.parse .unquote_plus in convall case)
26652664 result = re .sub (r"%([0-9a-fA-F]{2})" , _ , result )
26662665
26672666 if isinstance (result , str ):
@@ -2700,7 +2699,7 @@ def urlencode(value, safe="%&=-_", convall=False, limit=False, spaceplus=False):
27002699 value = re .sub (r"%(?![0-9a-fA-F]{2})" , "%25" , value )
27012700
27022701 while True :
2703- result = urllib .quote (utf8encode (value ), safe )
2702+ result = _urllib . parse .quote (utf8encode (value ), safe )
27042703
27052704 if limit and len (result ) > URLENCODE_CHAR_LIMIT :
27062705 if count >= len (URLENCODE_FAILSAFE_CHARS ):
@@ -2715,7 +2714,7 @@ def urlencode(value, safe="%&=-_", convall=False, limit=False, spaceplus=False):
27152714 break
27162715
27172716 if spaceplus :
2718- result = result .replace (urllib .quote (' ' ), '+' )
2717+ result = result .replace (_urllib . parse .quote (' ' ), '+' )
27192718
27202719 return result
27212720
@@ -3442,10 +3441,10 @@ def getLatestRevision():
34423441 """
34433442
34443443 retVal = None
3445- req = urllib2 .Request (url = "https://raw.githubusercontent.com/sqlmapproject/sqlmap/master/lib/core/settings.py" )
3444+ req = _urllib . request .Request (url = "https://raw.githubusercontent.com/sqlmapproject/sqlmap/master/lib/core/settings.py" )
34463445
34473446 try :
3448- content = urllib2 .urlopen (req ).read ()
3447+ content = _urllib . request .urlopen (req ).read ()
34493448 retVal = extractRegexResult (r"VERSION\s*=\s*[\"'](?P<result>[\d.]+)" , content )
34503449 except :
34513450 pass
@@ -3485,10 +3484,10 @@ def createGithubIssue(errMsg, excMsg):
34853484 ex = None
34863485 errMsg = errMsg [errMsg .find ("\n " ):]
34873486
3488- req = urllib2 . Request (url = "https://api.github.com/search/issues?q=%s" % urllib .quote ("repo:sqlmapproject/sqlmap Unhandled exception (#%s)" % key ))
3487+ req = _urllib . request . Request (url = "https://api.github.com/search/issues?q=%s" % _urllib . parse .quote ("repo:sqlmapproject/sqlmap Unhandled exception (#%s)" % key ))
34893488
34903489 try :
3491- content = urllib2 .urlopen (req ).read ()
3490+ content = _urllib . request .urlopen (req ).read ()
34923491 _ = json .loads (content )
34933492 duplicate = _ ["total_count" ] > 0
34943493 closed = duplicate and _ ["items" ][0 ]["state" ] == "closed"
@@ -3503,10 +3502,10 @@ def createGithubIssue(errMsg, excMsg):
35033502 pass
35043503
35053504 data = {"title" : "Unhandled exception (#%s)" % key , "body" : "```%s\n ```\n ```\n %s```" % (errMsg , excMsg )}
3506- req = urllib2 .Request (url = "https://api.github.com/repos/sqlmapproject/sqlmap/issues" , data = json .dumps (data ), headers = {"Authorization" : "token %s" % GITHUB_REPORT_OAUTH_TOKEN .decode ("base64" )})
3505+ req = _urllib . request .Request (url = "https://api.github.com/repos/sqlmapproject/sqlmap/issues" , data = json .dumps (data ), headers = {"Authorization" : "token %s" % GITHUB_REPORT_OAUTH_TOKEN .decode ("base64" )})
35073506
35083507 try :
3509- content = urllib2 .urlopen (req ).read ()
3508+ content = _urllib . request .urlopen (req ).read ()
35103509 except Exception as ex :
35113510 content = None
35123511
@@ -4018,7 +4017,7 @@ def asciifyUrl(url, forceQuote=False):
40184017 u'http://www.xn--uuraj-gxa24d.com'
40194018 """
40204019
4021- parts = urlparse .urlsplit (url )
4020+ parts = _urllib . parse .urlsplit (url )
40224021 if not parts .scheme or not parts .netloc :
40234022 # apparently not an url
40244023 return url
@@ -4039,10 +4038,10 @@ def asciifyUrl(url, forceQuote=False):
40394038 def quote (s , safe ):
40404039 s = s or ''
40414040 # Triggers on non-ascii characters - another option would be:
4042- # urllib .quote(s.replace('%', '')) != s.replace('%', '')
4041+ # _urllib.parse .quote(s.replace('%', '')) != s.replace('%', '')
40434042 # which would trigger on all %-characters, e.g. "&".
40444043 if getUnicode (s ).encode ("ascii" , "replace" ) != s or forceQuote :
4045- return urllib .quote (s .encode (UNICODE_ENCODING ) if isinstance (s , unicode ) else s , safe = safe )
4044+ return _urllib . parse .quote (s .encode (UNICODE_ENCODING ) if isinstance (s , unicode ) else s , safe = safe )
40464045 return s
40474046
40484047 username = quote (parts .username , '' )
@@ -4066,7 +4065,7 @@ def quote(s, safe):
40664065 if port :
40674066 netloc += ':' + str (port )
40684067
4069- return urlparse .urlunsplit ([parts .scheme , netloc , path , query , parts .fragment ]) or url
4068+ return _urllib . parse .urlunsplit ([parts .scheme , netloc , path , query , parts .fragment ]) or url
40704069
40714070def isAdminFromPrivileges (privileges ):
40724071 """
@@ -4224,7 +4223,7 @@ def _(value):
42244223 value = "http://%s" % value
42254224 return value
42264225
4227- return all (re .sub (r"(?i)\Awww\." , "" , urlparse . urlparse (_ (url ) or "" ).netloc .split (':' )[0 ]) == re .sub (r"(?i)\Awww\." , "" , urlparse .urlparse (_ (urls [0 ]) or "" ).netloc .split (':' )[0 ]) for url in urls [1 :])
4226+ return all (re .sub (r"(?i)\Awww\." , "" , _urllib . parse . urlparse (_ (url ) or "" ).netloc .split (':' )[0 ]) == re .sub (r"(?i)\Awww\." , "" , _urllib . parse .urlparse (_ (urls [0 ]) or "" ).netloc .split (':' )[0 ]) for url in urls [1 :])
42284227
42294228def getHostHeader (url ):
42304229 """
@@ -4237,7 +4236,7 @@ def getHostHeader(url):
42374236 retVal = url
42384237
42394238 if url :
4240- retVal = urlparse .urlparse (url ).netloc
4239+ retVal = _urllib . parse .urlparse (url ).netloc
42414240
42424241 if re .search (r"http(s)?://\[.+\]" , url , re .I ):
42434242 retVal = extractRegexResult (r"http(s)?://\[(?P<result>.+)\]" , url )
0 commit comments