sqlmap/lib/core/readlineng.py

66 lines
1.8 KiB
Python
Raw Normal View History

#!/usr/bin/env python2
2008-10-15 19:38:22 +04:00
"""
2013-01-18 18:07:51 +04:00
Copyright (c) 2006-2013 sqlmap developers (http://sqlmap.org/)
2010-10-15 03:18:29 +04:00
See the file 'doc/COPYING' for copying permission
2008-10-15 19:38:22 +04:00
"""
from lib.core.data import logger
from lib.core.settings import IS_WIN
from lib.core.settings import PLATFORM
2008-10-15 19:38:22 +04:00
_readline = None
2008-10-15 19:38:22 +04:00
try:
from readline import *
import readline as _readline
2008-10-15 19:38:22 +04:00
except ImportError:
try:
from pyreadline import *
import pyreadline as _readline
except ImportError:
pass
2008-10-15 19:38:22 +04:00
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
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:
2008-10-15 19:38:22 +04:00
try:
_readline.clear_history()
2008-10-15 19:38:22 +04:00
except AttributeError:
def clear_history():
pass
_readline.clear_history = clear_history