3838
3939from bpython .keys import cli_key_dispatch as key_dispatch
4040
41+ logger = logging .getLogger (__name__ )
42+
4143class FakeStdin (object ):
4244 """Stdin object user code references so sys.stdin.read() asked user for interactive input"""
4345 def __init__ (self , coderunner , repl ):
@@ -82,7 +84,7 @@ def process_event(self, e):
8284
8385 def add_input_character (self , e ):
8486 assert len (e ) == 1 , 'added multiple characters: %r' % e
85- logging .debug ('adding normal char %r to current line' , e )
87+ logger .debug ('adding normal char %r to current line' , e )
8688 c = e if py3 else e .encode ('utf8' )
8789 self .current_line = (self .current_line [:self .cursor_offset_in_line ] +
8890 c +
@@ -114,6 +116,10 @@ def write(self, value):
114116 # others, so here's a hack to keep them happy
115117 raise IOError (errno .EBADF , "sys.stdin is read-only" )
116118
119+ @property
120+ def encoding (self ):
121+ return 'UTF8'
122+
117123 #TODO write a read() method
118124
119125class ReevaluateFakeStdin (object ):
@@ -160,7 +166,7 @@ def __init__(self, locals_=None, config=None, request_refresh=lambda: None, bann
160166 interp is an interpreter to use
161167 """
162168
163- logging .debug ("starting init" )
169+ logger .debug ("starting init" )
164170
165171 if config is None :
166172 config = Struct ()
@@ -192,7 +198,7 @@ def smarter_request_refresh():
192198 refresh_request = self .request_refresh
193199 )
194200 self .rl_char_sequences = get_updated_char_sequences (key_dispatch , config )
195- logging .debug ("starting parent init" )
201+ logger .debug ("starting parent init" )
196202 super (Repl , self ).__init__ (interp , config )
197203 self .formatter = BPythonFormatter (config .color_scheme )
198204 self .interact = self .status_bar # overwriting what bpython.Repl put there
@@ -242,7 +248,7 @@ def __exit__(self, *args):
242248
243249 def clean_up_current_line_for_exit (self ):
244250 """Called when trying to exit to prep for final paint"""
245- logging .debug ('unhighlighting paren for exit' )
251+ logger .debug ('unhighlighting paren for exit' )
246252 self .cursor_offset_in_line = - 1
247253 self .unhighlight_paren ()
248254
@@ -257,15 +263,15 @@ def process_event(self, e):
257263 self .last_events .append (e )
258264 self .last_events .pop (0 )
259265
260- logging .debug ("processing event %r" , e )
266+ logger .debug ("processing event %r" , e )
261267 if isinstance (e , events .RefreshRequestEvent ):
262268 if self .status_bar .has_focus :
263269 self .status_bar .process_event (e )
264270 else :
265271 assert self .coderunner .code_is_waiting
266272 self .run_code_and_maybe_finish ()
267273 elif isinstance (e , events .WindowChangeEvent ):
268- logging .debug ('window change to %d %d' , e .width , e .height )
274+ logger .debug ('window change to %d %d' , e .width , e .height )
269275 self .scroll_offset -= e .cursor_dy
270276 self .width , self .height = e .width , e .height
271277
@@ -289,7 +295,7 @@ def process_event(self, e):
289295 return self .stdin .process_event (e )
290296
291297 elif isinstance (e , events .SigIntEvent ):
292- logging .debug ('received sigint event' )
298+ logger .debug ('received sigint event' )
293299 self .keyboard_interrupt ()
294300 self .update_completion ()
295301 return
@@ -386,7 +392,7 @@ def only_whitespace_left_of_cursor():
386392 """returns true if all characters on current line before cursor are whitespace"""
387393 return self ._current_line [:self .cursor_offset_in_line ].strip ()
388394
389- logging .debug ('self.matches: %r' , self .matches )
395+ logger .debug ('self.matches: %r' , self .matches )
390396 if not only_whitespace_left_of_cursor ():
391397 front_white = (len (self ._current_line [:self .cursor_offset_in_line ]) -
392398 len (self ._current_line [:self .cursor_offset_in_line ].lstrip ()))
@@ -404,8 +410,8 @@ def only_whitespace_left_of_cursor():
404410 if not self .config .auto_display_list and not self .list_win_visible :
405411 return True #TODO why?
406412 cw = self .current_string () or self .current_word
407- logging .debug ('current string: %r' , self .current_string ())
408- logging .debug ('current word: %r' , self .current_word )
413+ logger .debug ('current string: %r' , self .current_string ())
414+ logger .debug ('current word: %r' , self .current_word )
409415 if not cw :
410416 return
411417
@@ -501,7 +507,7 @@ def push(self, line, insert_into_history=True):
501507 display_line = bpythonparse (format (self .tokenize (line ), self .formatter ))
502508 # careful: self.tokenize requires that the line not be in self.buffer yet!
503509
504- logging .debug ('display line being pushed to buffer: %r -> %r' , line , display_line )
510+ logger .debug ('display line being pushed to buffer: %r -> %r' , line , display_line )
505511 self .display_buffer .append (display_line )
506512 else :
507513 self .display_buffer .append (fmtstr (line ))
@@ -512,14 +518,14 @@ def push(self, line, insert_into_history=True):
512518
513519 code_to_run = '\n ' .join (self .buffer )
514520
515- logging .debug ('running %r in interpreter' , self .buffer )
521+ logger .debug ('running %r in interpreter' , self .buffer )
516522 try :
517523 c = bool (code .compile_command ('\n ' .join (self .buffer )))
518524 self .saved_predicted_parse_error = False
519525 except (ValueError , SyntaxError , OverflowError ):
520526 c = self .saved_predicted_parse_error = True
521527 if c :
522- logging .debug ('finished - buffer cleared' )
528+ logger .debug ('finished - buffer cleared' )
523529 self .display_lines .extend (self .display_buffer_lines )
524530 self .display_buffer = []
525531 self .buffer = []
@@ -531,8 +537,8 @@ def push(self, line, insert_into_history=True):
531537 def run_code_and_maybe_finish (self , for_code = None ):
532538 r = self .coderunner .run_code (for_code = for_code )
533539 if r :
534- logging .debug ("----- Running finish command stuff -----" )
535- logging .debug ("saved_indent: %r" , self .saved_indent )
540+ logger .debug ("----- Running finish command stuff -----" )
541+ logger .debug ("saved_indent: %r" , self .saved_indent )
536542 err = self .saved_predicted_parse_error
537543 self .saved_predicted_parse_error = False
538544
@@ -569,8 +575,8 @@ def unhighlight_paren(self):
569575 # then this is the current line, so don't worry about it
570576 return
571577 self .highlighted_paren = None
572- logging .debug ('trying to unhighlight a paren on line %r' , lineno )
573- logging .debug ('with these tokens: %r' , saved_tokens )
578+ logger .debug ('trying to unhighlight a paren on line %r' , lineno )
579+ logger .debug ('with these tokens: %r' , saved_tokens )
574580 new = bpythonparse (format (saved_tokens , self .formatter ))
575581 self .display_buffer [lineno ] = self .display_buffer [lineno ].setslice_with_length (0 , len (new ), new , len (self .display_buffer [lineno ]))
576582
@@ -589,13 +595,13 @@ def get_current_block(self):
589595
590596 def send_to_stdout (self , output ):
591597 lines = output .split ('\n ' )
592- logging .debug ('display_lines: %r' , self .display_lines )
598+ logger .debug ('display_lines: %r' , self .display_lines )
593599 self .current_stdouterr_line += lines [0 ]
594600 if len (lines ) > 1 :
595601 self .display_lines .extend (paint .display_linize (self .current_stdouterr_line , self .width , blank_line = True ))
596602 self .display_lines .extend (sum ([paint .display_linize (line , self .width , blank_line = True ) for line in lines [1 :- 1 ]], []))
597603 self .current_stdouterr_line = lines [- 1 ]
598- logging .debug ('display_lines: %r' , self .display_lines )
604+ logger .debug ('display_lines: %r' , self .display_lines )
599605
600606 def send_to_stderr (self , error ):
601607 #self.send_to_stdout(error)
@@ -625,12 +631,11 @@ def current_line_formatted(self):
625631 """The colored current line (no prompt, not wrapped)"""
626632 if self .config .syntax :
627633 fs = bpythonparse (format (self .tokenize (self ._current_line ), self .formatter ))
628- logging .debug ('Display line %r -> %r' , self ._current_line , fs )
634+ logger .debug ('Display line %r -> %r' , self ._current_line , fs )
629635 else :
630636 fs = fmtstr (self ._current_line )
631637 if hasattr (self , 'old_fs' ) and str (fs ) != str (self .old_fs ):
632638 pass
633- #logging.debug('calculating current formatted line: %r', repr(fs))
634639 self .old_fs = fs
635640 return fs
636641
@@ -655,7 +660,7 @@ def current_word(self):
655660 def _get_current_word (self ):
656661 pos = self .cursor_offset_in_line
657662
658- matches = list (re .finditer (r''' [\w_][\w0-9._\[\]'] *[(]?'' ' , self ._current_line ))
663+ matches = list (re .finditer (r'[\w_][\w0-9._] *[(]?' , self ._current_line ))
659664 start = pos
660665 end = pos
661666 word = None
@@ -698,7 +703,7 @@ def current_cursor_line(self):
698703 """Current line, either output/input or Python prompt + code"""
699704 value = (self .current_output_line +
700705 ('' if self .coderunner .running else self .display_line_with_prompt ))
701- logging .debug ('current cursor line: %r' , value )
706+ logger .debug ('current cursor line: %r' , value )
702707 return value
703708
704709 @property
@@ -741,7 +746,7 @@ def paint(self, about_to_exit=False, user_quit=False):
741746 #TODO test case of current line filling up the whole screen (there aren't enough rows to show it)
742747
743748 if current_line_start_row < 0 : #if current line trying to be drawn off the top of the screen
744- logging .debug ('#<---History contiguity broken by rewind--->' )
749+ logger .debug ('#<---History contiguity broken by rewind--->' )
745750 msg = "#<---History contiguity broken by rewind--->"
746751 arr [0 , 0 :min (len (msg ), width )] = [msg [:width ]]
747752
@@ -762,8 +767,8 @@ def paint(self, about_to_exit=False, user_quit=False):
762767 current_line = paint .paint_current_line (min_height , width , self .current_cursor_line )
763768 if user_quit : # quit() or exit() in interp
764769 current_line_start_row = current_line_start_row - current_line .height
765- logging .debug ("---current line row slice %r, %r" , current_line_start_row , current_line_start_row + current_line .height )
766- logging .debug ("---current line col slice %r, %r" , 0 , current_line .width )
770+ logger .debug ("---current line row slice %r, %r" , current_line_start_row , current_line_start_row + current_line .height )
771+ logger .debug ("---current line col slice %r, %r" , 0 , current_line .width )
767772 arr [current_line_start_row :current_line_start_row + current_line .height ,
768773 0 :current_line .width ] = current_line
769774
@@ -786,7 +791,7 @@ def paint(self, about_to_exit=False, user_quit=False):
786791 cursor_row += current_line_start_row
787792
788793 if self .list_win_visible :
789- logging .debug ('infobox display code running' )
794+ logger .debug ('infobox display code running' )
790795 visible_space_above = history .height
791796 visible_space_below = min_height - current_line_end_row - 1
792797
@@ -797,9 +802,9 @@ def paint(self, about_to_exit=False, user_quit=False):
797802 arr [current_line_start_row - infobox .height :current_line_start_row , 0 :infobox .width ] = infobox
798803 else :
799804 arr [current_line_end_row + 1 :current_line_end_row + 1 + infobox .height , 0 :infobox .width ] = infobox
800- logging .debug ('slamming infobox of shape %r into arr of shape %r' , infobox .shape , arr .shape )
805+ logger .debug ('slamming infobox of shape %r into arr of shape %r' , infobox .shape , arr .shape )
801806
802- logging .debug ('about to exit: %r' , about_to_exit )
807+ logger .debug ('about to exit: %r' , about_to_exit )
803808 if show_status_bar :
804809 if self .config .curtsies_fill_terminal :
805810 if about_to_exit :
@@ -822,8 +827,8 @@ def paint(self, about_to_exit=False, user_quit=False):
822827 if self .config .color_scheme ['background' ] not in ('d' , 'D' ):
823828 for r in range (arr .height ):
824829 arr [r ] = fmtstr (arr [r ], bg = color_for_letter (self .config .color_scheme ['background' ]))
825- logging .debug ('returning arr of size %r' , arr .shape )
826- logging .debug ('cursor pos: %r' , (cursor_row , cursor_column ))
830+ logger .debug ('returning arr of size %r' , arr .shape )
831+ logger .debug ('cursor pos: %r' , (cursor_row , cursor_column ))
827832 return arr , (cursor_row , cursor_column )
828833
829834 @contextlib .contextmanager
@@ -849,8 +854,8 @@ def my_print(msg):
849854 my_print ('X``' + ('`' * (self .width + 2 ))+ '``X' )
850855 for line in arr :
851856 my_print ('X```' + line .ljust (self .width )+ '```X' )
852- logging .debug ('line:' )
853- logging .debug (repr (line ))
857+ logger .debug ('line:' )
858+ logger .debug (repr (line ))
854859 my_print ('X``' + ('`' * (self .width + 2 ))+ '``X' )
855860 my_print ('X' * (self .width + 8 ))
856861 return max (len (arr ) - self .height , 0 )
@@ -897,7 +902,7 @@ def echo(self, msg, redraw=True):
897902 Supposed to parse and echo a formatted string with appropriate attributes.
898903 It's not supposed to update the screen if it's reevaluating the code (as it
899904 does with undo)."""
900- logging .debug ("echo called with %r" % msg )
905+ logger .debug ("echo called with %r" % msg )
901906 def cw (self ):
902907 """Returns the "current word", based on what's directly left of the cursor.
903908 examples inclue "socket.socket.metho" or "self.reco" or "yiel" """
@@ -907,7 +912,7 @@ def cpos(self):
907912 "many WATs were had - it's the pos from the end of the line back" ""
908913 return len (self ._current_line ) - self .cursor_offset_in_line
909914 def reprint_line (self , lineno , tokens ):
910- logging .debug ("calling reprint line with %r %r" , lineno , tokens )
915+ logger .debug ("calling reprint line with %r %r" , lineno , tokens )
911916 if self .config .syntax :
912917 self .display_buffer [lineno ] = bpythonparse (format (tokens , self .formatter ))
913918 def reevaluate (self , insert_into_history = False ):
0 commit comments