@@ -1051,6 +1051,16 @@ def dataToDumpFile(dumpFile, data):
10511051 raise
10521052
10531053def dataToOutFile (filename , data ):
1054+ """
1055+ Saves data to filename
1056+
1057+ >>> pushValue(conf.get("filePath"))
1058+ >>> conf.filePath = tempfile.gettempdir()
1059+ >>> "_etc_passwd" in dataToOutFile("/etc/passwd", b":::*")
1060+ True
1061+ >>> conf.filePath = popValue()
1062+ """
1063+
10541064 retVal = None
10551065
10561066 if data :
@@ -1714,6 +1724,11 @@ def escapeJsonValue(value):
17141724 Escapes JSON value (used in payloads)
17151725
17161726 # Reference: https://stackoverflow.com/a/16652683
1727+
1728+ >>> "\\ n" in escapeJsonValue("foo\\ nbar")
1729+ False
1730+ >>> "\\ \\ t" in escapeJsonValue("foo\\ tbar")
1731+ True
17171732 """
17181733
17191734 retVal = ""
@@ -1888,6 +1903,12 @@ def getLocalIP():
18881903def getRemoteIP ():
18891904 """
18901905 Get remote/target IP address
1906+
1907+ >>> pushValue(conf.hostname)
1908+ >>> conf.hostname = "localhost"
1909+ >>> getRemoteIP() == "127.0.0.1"
1910+ True
1911+ >>> conf.hostname = popValue()
18911912 """
18921913
18931914 retVal = None
@@ -2014,6 +2035,9 @@ def normalizePath(filepath):
20142035def safeFilepathEncode (filepath ):
20152036 """
20162037 Returns filepath in (ASCII) format acceptable for OS handling (e.g. reading)
2038+
2039+ >>> 'sqlmap' in safeFilepathEncode(paths.SQLMAP_HOME_PATH)
2040+ True
20172041 """
20182042
20192043 retVal = filepath
@@ -2220,6 +2244,15 @@ def isHexEncodedString(subject):
22202244def isMultiThreadMode ():
22212245 """
22222246 Checks if running in multi-thread(ing) mode
2247+
2248+ >>> isMultiThreadMode()
2249+ False
2250+ >>> _ = lambda: time.sleep(0.1)
2251+ >>> thread = threading.Thread(target=_)
2252+ >>> thread.daemon = True
2253+ >>> thread.start()
2254+ >>> isMultiThreadMode()
2255+ True
22232256 """
22242257
22252258 return threading .activeCount () > 1
@@ -2228,6 +2261,9 @@ def isMultiThreadMode():
22282261def getConsoleWidth (default = 80 ):
22292262 """
22302263 Returns console width
2264+
2265+ >>> any((getConsoleWidth(), True))
2266+ True
22312267 """
22322268
22332269 width = None
@@ -2434,6 +2470,9 @@ def initCommonOutputs():
24342470def getFileItems (filename , commentPrefix = '#' , unicoded = True , lowercase = False , unique = False ):
24352471 """
24362472 Returns newline delimited items contained inside file
2473+
2474+ >>> "SELECT" in getFileItems(paths.SQL_KEYWORDS)
2475+ True
24372476 """
24382477
24392478 retVal = list () if not unique else OrderedDict ()
@@ -2540,8 +2579,8 @@ def goGoodSamaritan(prevValue, originalCharset):
25402579
25412580def getPartRun (alias = True ):
25422581 """
2543- Goes through call stack and finds constructs matching conf.dbmsHandler.*.
2544- Returns it or its alias used in 'txt/common-outputs.txt'
2582+ Goes through call stack and finds constructs matching
2583+ conf.dbmsHandler.*. Returns it or its alias used in 'txt/common-outputs.txt'
25452584 """
25462585
25472586 retVal = None
@@ -4997,6 +5036,12 @@ def getRequestHeader(request, name):
49975036 Solving an issue with an urllib2 Request header case sensitivity
49985037
49995038 # Reference: http://bugs.python.org/issue2275
5039+
5040+ >>> _ = lambda _: _
5041+ >>> _.headers = {"FOO": "BAR"}
5042+ >>> _.header_items = lambda: _.headers.items()
5043+ >>> getText(getRequestHeader(_, "foo"))
5044+ 'BAR'
50005045 """
50015046
50025047 retVal = None
@@ -5094,6 +5139,13 @@ def pollProcess(process, suppress_errors=False):
50945139def parseRequestFile (reqFile , checkParams = True ):
50955140 """
50965141 Parses WebScarab and Burp logs and adds results to the target URL list
5142+
5143+ >>> handle, reqFile = tempfile.mkstemp(suffix=".req")
5144+ >>> content = b"POST / HTTP/1.0\\ nUser-agent: foobar\\ nHost: www.example.com\\ n\\ nid=1\\ n"
5145+ >>> _ = os.write(handle, content)
5146+ >>> os.close(handle)
5147+ >>> next(parseRequestFile(reqFile)) == ('http://www.example.com:80/', 'POST', 'id=1', None, (('User-agent', 'foobar'), ('Host', 'www.example.com')))
5148+ True
50975149 """
50985150
50995151 def _parseWebScarabLog (content ):
0 commit comments