sqlmap/lib/core/readlineng.py

63 lines
1.8 KiB
Python
Raw Permalink Normal View History

2019-05-08 13:47:52 +03:00
#!/usr/bin/env python
2008-10-15 19:38:22 +04:00
"""
2024-01-04 01:11:52 +03:00
Copyright (c) 2006-2024 sqlmap developers (https://sqlmap.org/)
2017-10-11 15:50:46 +03:00
See the file 'LICENSE' for copying permission
2008-10-15 19:38:22 +04:00
"""
_readline = None
try:
from readline import *
import readline as _readline
2018-04-05 13:25:41 +03:00
except:
2008-10-15 19:38:22 +04:00
try:
from pyreadline import *
import pyreadline as _readline
2018-04-05 13:25:41 +03:00
except:
pass
2008-10-15 19:38:22 +04:00
2022-05-13 18:56:45 +03:00
from lib.core.data import logger
from lib.core.settings import IS_WIN
from lib.core.settings import PLATFORM
if IS_WIN and _readline:
2008-10-15 19:38:22 +04:00
try:
_outputfile = _readline.GetOutputFile()
2008-10-15 19:38:22 +04:00
except AttributeError:
debugMsg = "Failed GetOutputFile when using platform's "
2008-10-15 19:38:22 +04:00
debugMsg += "readline library"
logger.debug(debugMsg)
_readline = None
2008-10-15 19:38:22 +04:00
# Test to see if libedit is being used instead of GNU readline.
# Thanks to Boyd Waters for this patch.
uses_libedit = False
2019-05-06 15:41:35 +03:00
if PLATFORM == "mac" and _readline:
2008-10-15 19:38:22 +04:00
import commands
(status, result) = commands.getstatusoutput("otool -L %s | grep libedit" % _readline.__file__)
2008-10-15 19:38:22 +04:00
if status == 0 and len(result) > 0:
# We are bound to libedit - new in Leopard
_readline.parse_and_bind("bind ^I rl_complete")
2008-10-15 19:38:22 +04:00
debugMsg = "Leopard libedit detected when using platform's "
2008-10-15 19:38:22 +04:00
debugMsg += "readline library"
logger.debug(debugMsg)
uses_libedit = True
# the clear_history() function was only introduced in Python 2.4 and is
# actually optional in the readline API, so we must explicitly check for its
# existence. Some known platforms actually don't have it. This thread:
# http://mail.python.org/pipermail/python-dev/2003-August/037845.html
# has the original discussion.
if _readline:
if not hasattr(_readline, "clear_history"):
2008-10-15 19:38:22 +04:00
def clear_history():
pass
_readline.clear_history = clear_history