<s> from __future__ import print_function , unicode_literals , absolute_import <EOL> import os <EOL> import pyreadline . logger as logger <EOL> from pyreadline . logger import log <EOL> import pyreadline . lineeditor . lineobj as lineobj <EOL> import pyreadline . lineeditor . history as history <EOL> from . import basemode <EOL> class NotEmacsMode ( basemode . BaseMode ) : <EOL> mode = "<STR_LIT>" <EOL> def __init__ ( self , rlobj ) : <EOL> super ( NotEmacsMode , self ) . __init__ ( rlobj ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" <EOL> def _readline_from_keyboard ( self ) : <EOL> c = self . console <EOL> while <NUM_LIT:1> : <EOL> self . _update_line ( ) <EOL> event = c . getkeypress ( ) <EOL> if self . next_meta : <EOL> self . next_meta = False <EOL> control , meta , shift , code = event . keyinfo <EOL> event . keyinfo = ( control , True , shift , code ) <EOL> if event . keyinfo in self . exit_dispatch : <EOL> if lineobj . EndOfLine ( self . l_buffer ) == <NUM_LIT:0> : <EOL> raise EOFError <EOL> dispatch_func = self . key_dispatch . get ( event . keyinfo , self . self_insert ) <EOL> log ( "<STR_LIT>" % ( event . keyinfo , ) ) <EOL> r = None <EOL> if dispatch_func : <EOL> r = dispatch_func ( event ) <EOL> self . l_buffer . push_undo ( ) <EOL> self . previous_func = dispatch_func <EOL> if r : <EOL> self . _update_line ( ) <EOL> break <EOL> def readline ( self , prompt = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> if self . first_prompt : <EOL> self . first_prompt = False <EOL> if self . startup_hook : <EOL> try : <EOL> self . startup_hook ( ) <EOL> except : <EOL> print ( '<STR_LIT>' ) <EOL> traceback . print_exc ( ) <EOL> c = self . console <EOL> self . l_buffer . reset_line ( ) <EOL> self . prompt = prompt <EOL> self . _print_prompt ( ) <EOL> if self . pre_input_hook : <EOL> try : <EOL> self . pre_input_hook ( ) <EOL> except : <EOL> print ( '<STR_LIT>' ) <EOL> traceback . print_exc ( ) <EOL> self . pre_input_hook = None <EOL> log ( "<STR_LIT>" % self . paste_line_buffer ) <EOL> if len ( self . paste_line_buffer ) > <NUM_LIT:0> : <EOL> self . l_buffer = lineobj . ReadlineTextBuffer ( self . paste_line_buffer [ <NUM_LIT:0> ] ) <EOL> self . _update_line ( ) <EOL> self . paste_line_buffer = self . paste_line_buffer [ <NUM_LIT:1> : ] <EOL> c . write ( '<STR_LIT:\r\n>' ) <EOL> else : <EOL> self . _readline_from_keyboard ( ) <EOL> c . write ( '<STR_LIT:\r\n>' ) <EOL> self . add_history ( self . l_buffer . copy ( ) ) <EOL> log ( '<STR_LIT>' % self . l_buffer . get_line_text ( ) ) <EOL> return self . l_buffer . get_line_text ( ) + '<STR_LIT:\n>' <EOL> def beginning_of_line ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . beginning_of_line ( ) <EOL> def end_of_line ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . end_of_line ( ) <EOL> def forward_char ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . forward_char ( ) <EOL> def backward_char ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . backward_char ( ) <EOL> def forward_word ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . forward_word ( ) <EOL> def backward_word ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . backward_word ( ) <EOL> def clear_screen ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . console . page ( ) <EOL> def redraw_current_line ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def accept_line ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> return True <EOL> def previous_history ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . _history . previous_history ( self . l_buffer ) <EOL> def next_history ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . _history . next_history ( self . l_buffer ) <EOL> def beginning_of_history ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . _history . beginning_of_history ( ) <EOL> def end_of_history ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . _history . end_of_history ( self . l_buffer ) <EOL> def _i_search ( self , searchfun , direction , init_event ) : <EOL> c = self . console <EOL> line = self . get_line_buffer ( ) <EOL> query = '<STR_LIT>' <EOL> hc_start = self . _history . history_cursor <EOL> while <NUM_LIT:1> : <EOL> x , y = self . prompt_end_pos <EOL> c . pos ( <NUM_LIT:0> , y ) <EOL> if direction < <NUM_LIT:0> : <EOL> prompt = '<STR_LIT>' <EOL> else : <EOL> prompt = '<STR_LIT>' <EOL> scroll = c . write_scrolling ( "<STR_LIT>" % ( prompt , query , line ) ) <EOL> self . _update_prompt_pos ( scroll ) <EOL> self . _clear_after ( ) <EOL> event = c . getkeypress ( ) <EOL> if event . keysym == '<STR_LIT>' : <EOL> if len ( query ) > <NUM_LIT:0> : <EOL> query = query [ : - <NUM_LIT:1> ] <EOL> self . _history . history_cursor = hc_start <EOL> else : <EOL> self . _bell ( ) <EOL> elif event . char in string . letters + string . digits + string . punctuation + '<STR_LIT:U+0020>' : <EOL> self . _history . history_cursor = hc_start <EOL> query += event . char <EOL> elif event . keyinfo == init_event . keyinfo : <EOL> self . _history . history_cursor += direction <EOL> line = searchfun ( query ) <EOL> pass <EOL> else : <EOL> if event . keysym != '<STR_LIT>' : <EOL> self . _bell ( ) <EOL> break <EOL> line = searchfun ( query ) <EOL> px , py = self . prompt_begin_pos <EOL> c . pos ( <NUM_LIT:0> , py ) <EOL> self . l_buffer . set_line ( line ) <EOL> self . _print_prompt ( ) <EOL> self . _history . history_cursor = len ( self . _history . history ) <EOL> def reverse_search_history ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . _i_search ( self . _history . reverse_search_history , - <NUM_LIT:1> , e ) <EOL> def forward_search_history ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . _i_search ( self . _history . forward_search_history , <NUM_LIT:1> , e ) <EOL> def non_incremental_reverse_search_history ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . _history . non_incremental_reverse_search_history ( self . l_buffer ) <EOL> def non_incremental_forward_search_history ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . _history . non_incremental_reverse_search_history ( self . l_buffer ) <EOL> def history_search_forward ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer = self . _history . history_search_forward ( self . l_buffer ) <EOL> def history_search_backward ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer = self . _history . history_search_backward ( self . l_buffer ) <EOL> def yank_nth_arg ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def yank_last_arg ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def delete_char ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . delete_char ( ) <EOL> def backward_delete_char ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . backward_delete_char ( ) <EOL> def forward_backward_delete_char ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def quoted_insert ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> e = self . console . getkeypress ( ) <EOL> self . insert_text ( e . char ) <EOL> def tab_insert ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> cursor = min ( self . l_buffer . point , len ( self . l_buffer . line_buffer ) ) <EOL> ws = '<STR_LIT:U+0020>' * ( self . tabstop - ( cursor % self . tabstop ) ) <EOL> self . insert_text ( ws ) <EOL> def self_insert ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> if ord ( e . char ) != <NUM_LIT:0> : <EOL> self . insert_text ( e . char ) <EOL> def transpose_chars ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . transpose_chars ( ) <EOL> def transpose_words ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . transpose_words ( ) <EOL> def upcase_word ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . upcase_word ( ) <EOL> def downcase_word ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . downcase_word ( ) <EOL> def capitalize_word ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . capitalize_word ( ) <EOL> def overwrite_mode ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def kill_line ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . kill_line ( ) <EOL> def backward_kill_line ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . backward_kill_line ( ) <EOL> def unix_line_discard ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . unix_line_discard ( ) <EOL> def kill_whole_line ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . kill_whole_line ( ) <EOL> def kill_word ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . kill_word ( ) <EOL> def backward_kill_word ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . backward_kill_word ( ) <EOL> def unix_word_rubout ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . unix_word_rubout ( ) <EOL> def delete_horizontal_space ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def kill_region ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def copy_region_as_kill ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def copy_region_to_clipboard ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> if self . enable_win32_clipboard : <EOL> mark = min ( self . l_buffer . mark , len ( self . l_buffer . line_buffer ) ) <EOL> cursor = min ( self . l_buffer . point , len ( self . l_buffer . line_buffer ) ) <EOL> if self . l_buffer . mark == - <NUM_LIT:1> : <EOL> return <EOL> begin = min ( cursor , mark ) <EOL> end = max ( cursor , mark ) <EOL> toclipboard = "<STR_LIT>" . join ( self . l_buffer . line_buffer [ begin : end ] ) <EOL> clipboard . SetClipboardText ( str ( toclipboard ) ) <EOL> def copy_backward_word ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def copy_forward_word ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def paste ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> if self . enable_win32_clipboard : <EOL> txt = clipboard . get_clipboard_text_and_convert ( False ) <EOL> self . insert_text ( txt ) <EOL> def paste_mulitline_code ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> reg = re . compile ( "<STR_LIT>" ) <EOL> if self . enable_win32_clipboard : <EOL> txt = clipboard . get_clipboard_text_and_convert ( False ) <EOL> t = reg . split ( txt ) <EOL> t = [ row for row in t if row . strip ( ) != "<STR_LIT>" ] <EOL> if t != [ "<STR_LIT>" ] : <EOL> self . insert_text ( t [ <NUM_LIT:0> ] ) <EOL> self . add_history ( self . l_buffer . copy ( ) ) <EOL> self . paste_line_buffer = t [ <NUM_LIT:1> : ] <EOL> log ( "<STR_LIT>" % self . paste_line_buffer ) <EOL> return True <EOL> else : <EOL> return False <EOL> def ipython_paste ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> if self . enable_win32_clipboard : <EOL> txt = clipboard . get_clipboard_text_and_convert ( <EOL> self . enable_ipython_paste_list_of_lists ) <EOL> if self . enable_ipython_paste_for_paths : <EOL> if len ( txt ) < <NUM_LIT> and ( "<STR_LIT:\t>" not in txt ) and ( "<STR_LIT:\n>" not in txt ) : <EOL> txt = txt . replace ( "<STR_LIT:\\>" , "<STR_LIT:/>" ) . replace ( "<STR_LIT:U+0020>" , r"<STR_LIT>" ) <EOL> self . insert_text ( txt ) <EOL> def yank ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def yank_pop ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def digit_argument ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def universal_argument ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def delete_char_or_list ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def start_kbd_macro ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def end_kbd_macro ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def call_last_kbd_macro ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def re_read_init_file ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def abort ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . _bell ( ) <EOL> def do_uppercase_version ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def prefix_meta ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . next_meta = True <EOL> def undo ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . pop_undo ( ) <EOL> def revert_line ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def tilde_expand ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def set_mark ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . l_buffer . set_mark ( ) <EOL> def exchange_point_and_mark ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def character_search ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def character_search_backward ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def insert_comment ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def dump_functions ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def dump_variables ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def dump_macros ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def init_editing_mode ( self , e ) : <EOL> '''<STR_LIT>''' <EOL> self . _bind_exit_key ( '<STR_LIT>' ) <EOL> self . _bind_exit_key ( '<STR_LIT>' ) <EOL> self . _bind_key ( '<STR_LIT>' , self . self_insert ) <EOL> self . _bind_key ( '<STR_LIT>' , self . self_insert ) <EOL> self . _bind_key ( '<STR_LIT>' , self . accept_line ) <EOL> self . _bind_key ( '<STR_LIT>' , self . backward_char ) <EOL> self . _bind_key ( '<STR_LIT>' , self . backward_char ) <EOL> self . _bind_key ( '<STR_LIT>' , self . forward_char ) <EOL> self . _bind_key ( '<STR_LIT>' , self . forward_char ) <EOL> self . _bind_key ( '<STR_LIT>' , self . backward_delete_char ) <EOL> self . _bind_key ( '<STR_LIT>' , self . beginning_of_line ) <EOL> self . _bind_key ( '<STR_LIT>' , self . end_of_line ) <EOL> self . _bind_key ( '<STR_LIT>' , self . delete_char ) <EOL> self . _bind_key ( '<STR_LIT>' , self . delete_char ) <EOL> self . _bind_key ( '<STR_LIT>' , self . clear_screen ) <EOL> def commonprefix ( m ) : <EOL> "<STR_LIT>" <EOL> if not m : return '<STR_LIT>' <EOL> prefix = m [ <NUM_LIT:0> ] <EOL> for item in m : <EOL> for i in range ( len ( prefix ) ) : <EOL> if prefix [ : i + <NUM_LIT:1> ] . lower ( ) != item [ : i + <NUM_LIT:1> ] . lower ( ) : <EOL> prefix = prefix [ : i ] <EOL> if i == <NUM_LIT:0> : return '<STR_LIT>' <EOL> break <EOL> return prefix </s>
