Example #1
0
 def save_history(self):
     try:
         readline.write_history_file(self.history_file)
     except FileNotFoundError:
         print(
             red('Unable to write history file to '
                 '{}.'.format(self.history_file)))
Example #2
0
    def init_completer(self):
        try:
            import rlcompleter
            readline.parse_and_bind("tab: complete")

            readline.set_completer_delims("")

            readline.write_history_file(os.path.join(dxpy.config.get_user_conf_dir(), '.dx_history'))
            readline.clear_history()
            readline.set_completer()
        except:
            pass
Example #3
0
def input_loop():
    if os.path.exists(HISTORY_FILENAME):
        readline.read_history_file(HISTORY_FILENAME)
    print('Max history file length:', readline.get_history_length())
    print('Startup history:', get_history_items())
    try:
        while True:
            line = input('Prompt ("stop" to quit): ')
            if line == 'stop':
                break
            if line:
                print('Adding {!r} to the history'.format(line))
    finally:
        print('Final history:', get_history_items())
        readline.write_history_file(HISTORY_FILENAME)
def input_loop():
    if os.path.exists(HISTORY_FILENAME):
        readline.read_history_file(HISTORY_FILENAME)
    print('Lunghezza max file storico:',
          readline.get_history_length())
    print('Storico di partenza:', get_history_items())
    try:
        while True:
            line = input('Prompt ("stop" per uscire): ')
            if line == 'stop':
                break
            if line:
                print('Aggiunta di {!r} allo storico'.format(line))
    finally:
        print('Storico finale:', get_history_items())
        readline.write_history_file(HISTORY_FILENAME)
def input_loop():
    if os.path.exists(HISTORY_FILENAME):
        readline.read_history_file(HISTORY_FILENAME)
    print('Max history file length:',
          readline.get_history_length())
    print('Startup history:', get_history_items())
    try:
        while True:
            line = input('Prompt ("stop" to quit): ')
            if line == 'stop':
                break
            if line:
                print('Adding {!r} to the history'.format(line))
    finally:
        print('Final history:', get_history_items())
        readline.write_history_file(HISTORY_FILENAME)
Example #6
0
        def _process_input(self):
            if sys.version_info[0] >= 3:
                input_impl = input
            else:
                input_impl = raw_input

            self._print_startup_message()

            while True:
                self._idle.wait()
                expression = ""
                line = ""
                while len(expression) == 0 or line.endswith("\\"):
                    try:
                        if len(expression) == 0:
                            line = input_impl("[%s]" % self._prompt_string + "-> ")
                        else:
                            line = input_impl("... ")
                    except EOFError:
                        # An extra newline after EOF to exit the REPL cleanly
                        print("\nThank you for using Frida!")
                        return
                    if len(line.strip()) > 0:
                        if len(expression) > 0:
                            expression += "\n"
                        expression += line.rstrip("\\")

                if HAVE_READLINE:
                    try:
                        readline.write_history_file(HIST_FILE)
                    except IOError:
                        pass

                if expression.endswith("?"):
                    # Help feature
                    self._print_help(expression)
                elif expression.startswith("%"):
                    # "Magic" commands
                    self._do_magic(expression)
                elif expression in ("quit", "q", "exit"):
                    print("Thank you for using Frida!")
                    return
                elif expression == "help":
                    print("Frida help 1.0!")
                else:
                    self._idle.clear()
                    self._reactor.schedule(lambda: self._send_expression(expression))
Example #7
0
 def save_history(self):
     readline.write_history_file(self.history_file)
Example #8
0
                            self.parser.file_scanner.position + 1 if self.parser.file_scanner.position + 1 <= len(self.parser.file_scanner.lines) else "EOF",
                            scope))
                    else:
                        inp = raw_input( "<%s>:%s|%s:  " % (
                            "NO FILE",
                            self.position + 1,
                            scope))
                except Exception, e:
                    inp = 'quit'
                self.addline(StringIO.StringIO(inp))
                tokens = super(InteractiveVisionScanner, self).next()
            else:
                # If it's a subcommand, when we're done, we're done
                raise
        finally:
            readline.write_history_file(os.path.expanduser("~/.vision_history"))
            self.advance()
        return tokens

    @property
    def scopes(self):
        scopes = []
        try:
            command = next(com for com in reversed(self.parser.children) if com.parsed and not com.error)
            scopes.extend(command.scopes)
            if command.scopechange > 0:
                # The most recent command opened a scope,
                # include it in the list
                scopes.append(command)
            elif command.scopechange < 0:
                # The most recent command closed a scope,
Example #9
0
 def save_history(self):
     readline.write_history_file(self.history_file)
Example #10
0
 def exit(self):
     readline.write_history_file(self.history)
Example #11
0
def save_hist():
    readline.write_history_file(_HISTFILE)
Example #12
0
def save_history():
    readline.write_history_file(hfn)
Example #13
0
 def postloop(self):
     try:
         readline.write_history_file(self.HISTORY_FILE)
     except (OSError, IOError) as e:
         warn("Can't write history file: %s" % str(e))
Example #14
0
 def save_hist():
     readline.write_history_file(_HISTFILE)
Example #15
0
 def postloop(self):
     ''' Save history on exit. '''
     readline.write_history_file('.psiturk_history')
Example #16
0
 def save_history(self, histfile):
     import readline
     readline.write_history_file(histfile)
Example #17
0
        def _process_input(self):
            if sys.version_info[0] >= 3:
                input_impl = input
            else:
                input_impl = raw_input

            self._print_startup_message()
            self._ready.wait()

            while True:
                expression = ""
                line = ""
                while len(expression) == 0 or line.endswith("\\"):
                    try:
                        if len(expression) == 0:
                            line = input_impl("[%s]" % self._prompt_string + "-> ")
                        else:
                            line = input_impl("... ")
                    except EOFError:
                        # An extra newline after EOF to exit the REPL cleanly
                        print("\nThank you for using Frida!")
                        return
                    if len(line.strip()) > 0:
                        if len(expression) > 0:
                            expression += "\n"
                        expression += line.rstrip("\\")

                if HAVE_READLINE:
                    try:
                        readline.write_history_file(HIST_FILE)
                    except IOError:
                        pass

                if expression.endswith("?"):
                    try:
                        self._print_help(expression)
                    except Exception as ex:
                        error = ex.message
                        sys.stdout.write(Fore.RED + Style.BRIGHT + error['name'] + Style.RESET_ALL + ": " + error['message'] + "\n")
                        sys.stdout.flush()
                elif expression.startswith("%"):
                    self._do_magic(expression[1:].rstrip())
                elif expression in ("exit", "quit", "q"):
                    print("Thank you for using Frida!")
                    return
                elif expression == "help":
                    print("Help: #TODO :)")
                else:
                    try:
                        (t, value) = self._evaluate(expression)
                        if t in ('function', 'undefined', 'null'):
                            output = t
                        elif t == 'binary':
                            output = hexdump(value).rstrip("\n")
                        else:
                            output = json.dumps(value, sort_keys=True, indent=4, separators=(",", ": "))
                    except Exception as ex:
                        error = ex.message
                        output = Fore.RED + Style.BRIGHT + error['name'] + Style.RESET_ALL + ": " + error['message']
                    sys.stdout.write(output + "\n")
                    sys.stdout.flush()
Example #18
0
def save_history(historyPath=historyPath):
    import gnureadline
    gnureadline.write_history_file(historyPath)
Example #19
0
        def _process_input(self):
            if sys.version_info[0] >= 3:
                input_impl = input
            else:
                input_impl = raw_input

            self._print_startup_message()
            self._ready.wait()

            while True:
                expression = ""
                line = ""
                while len(expression) == 0 or line.endswith("\\"):
                    try:
                        if len(expression) == 0:
                            line = input_impl("[%s]" % self._prompt_string +
                                              "-> ")
                        else:
                            line = input_impl("... ")
                    except EOFError:
                        # An extra newline after EOF to exit the REPL cleanly
                        print("\nThank you for using Frida!")
                        return
                    if len(line.strip()) > 0:
                        if len(expression) > 0:
                            expression += "\n"
                        expression += line.rstrip("\\")

                if HAVE_READLINE:
                    try:
                        readline.write_history_file(HIST_FILE)
                    except IOError:
                        pass

                if expression.endswith("?"):
                    try:
                        self._print_help(expression)
                    except Exception as ex:
                        error = ex.message
                        sys.stdout.write(Fore.RED + Style.BRIGHT +
                                         error['name'] + Style.RESET_ALL +
                                         ": " + error['message'] + "\n")
                        sys.stdout.flush()
                elif expression.startswith("%"):
                    self._do_magic(expression[1:].rstrip())
                elif expression in ("exit", "quit", "q"):
                    print("Thank you for using Frida!")
                    return
                elif expression == "help":
                    print("Help: #TODO :)")
                else:
                    try:
                        (t, value) = self._evaluate(expression)
                        if t in ('function', 'undefined', 'null'):
                            output = t
                        elif t == 'raw':
                            output = hexdump(value).rstrip("\n")
                        else:
                            output = json.dumps(value,
                                                sort_keys=True,
                                                indent=4,
                                                separators=(",", ": "))
                    except Exception as ex:
                        error = ex.message
                        output = Fore.RED + Style.BRIGHT + error[
                            'name'] + Style.RESET_ALL + ": " + error['message']
                    sys.stdout.write(output + "\n")
                    sys.stdout.flush()
Example #20
0
 def postloop(self):
     ''' Save history on exit. '''
     readline.write_history_file('.psiturk_history')
from query.parser import DatabaseREPL
from query import davisbase_constants as dc
import gnureadline as readline
import pathlib, sys

hist_file = str(pathlib.Path.home()) + '/.davisdb_history'
open(hist_file, 'a+').close()

readline.read_history_file(hist_file)

if __name__ == '__main__':
    if not sys.stdin.isatty():
        dc.PROMPT_NAME = ''
        dc.PROMPT_MORE = ''

    prompt = DatabaseREPL()
    prompt.cmdloop_with_keyboard_interrupt()
    readline.write_history_file(hist_file)