コード例 #1
0
ファイル: System.py プロジェクト: 3he11/Spirit
def write(line, end="\n"):
    try:
        if mswindows:
            readline.GetOutputFile().write_color(colorize(line) + end)
        else:
            sys.stdout.write(colorize(line) + end)
    except LookupError:
        # We failed to print in color.  This is a problem looking up the encoding
        # Permanently disable color and continue
        print(line)
コード例 #2
0
 def pre_input(self, completefn):
     if self.raw_input:
         if HAVE_READLINE:
             import atexit
             self.old_completer = readline.get_completer()
             # Fix Bug #3129: Limit the history size to consume less memory
             readline.set_history_length(self.historysize)   
             readline.set_completer(completefn)
             readline.parse_and_bind(self.completekey+": complete")
             try:
                 readline.read_history_file()
             except IOError:
                 pass
             atexit.register(readline.write_history_file)
             self.havecolor = True
             if mswindows and self.enablecolor:
                 self.cwrite = readline.GetOutputFile().write_color
             else:
                 self.cwrite = self.stdout.write
コード例 #3
0
                if not end and result != "":
                    line = readline.rl.readline("... ")
                else:
                    line = readline.rl.readline(prompt)
                if line.strip().endswith(":"):
                    end = False
                elif result == "":
                    end = True
                if line.strip() == "":
                    end = True
                result = result + "\n" + line
            return six.text_type(result)

        try:
            import readline
            console = readline.GetOutputFile()
        except (ImportError, AttributeError):
            log_loading.info(
                "Could not get readline console. Will not interpret ANSI color codes."
            )
        else:
            conf.readfunc = readLineScapy
            orig_stdout = sys.stdout
            sys.stdout = console


def get_working_if():
    try:
        # return the interface associated with the route with smallest
        # mask (route by default if it exists)
        return min(read_routes(), key=lambda x: x[1])[3]
コード例 #4
0
    # patch add_history to allow for strings in pyreadline <= 1.5:
    # fix copied from pyreadline 1.6
    import pyreadline
    if pyreadline.release.version <= '1.5':

        def add_history(line):
            """add a line to the history buffer."""
            from pyreadline import lineobj
            if not isinstance(line, lineobj.TextLine):
                line = lineobj.TextLine(line)
            return _rl.add_history(line)


if (sys.platform == 'win32' or sys.platform == 'cli') and have_readline:
    try:
        _outputfile = _rl.GetOutputFile()
    except AttributeError:
        warnings.warn("Failed GetOutputFile")
        have_readline = False

# Test to see if libedit is being used instead of GNU readline.
# Thanks to Boyd Waters for the original patch.
uses_libedit = False

if have_readline:
    # Official Python docs state that 'libedit' is in the docstring for libedit readline:
    uses_libedit = _rl.__doc__ and 'libedit' in _rl.__doc__
    # Note that many non-System Pythons also do not use proper readline,
    # but do not report libedit at all, nor are they linked dynamically against libedit.
    # known culprits of this include: EPD, Fink
    # There is not much we can do to detect this, until we find a specific failure
コード例 #5
0
_readline = None

try:
    from readline import *
    import readline as _readline
except ImportError:
    try:
        from pyreadline import *
        import pyreadline as _readline
    except ImportError:
        pass

if IS_WIN and _readline:
    try:
        _outputfile = _readline.GetOutputFile()
    except AttributeError:
        debugMsg = "Failed GetOutputFile when using platform's "
        debugMsg += "readline library"
        logger.debug(debugMsg)

        _readline = None

# 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:
    import commands

    (status, result) = commands.getstatusoutput("otool -L %s | grep libedit" %
コード例 #6
0
ファイル: fuzzbunch.py プロジェクト: wrfly/shadowbroker-auto
 def do_resizeconsole(self, line):
     try:
         import readline
         readline.GetOutputFile().size(width=90, height=65)
     except:
         pass