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 +
@@ -160,7 +162,7 @@ def __init__(self, locals_=None, config=None, request_refresh=lambda: None, bann
160162 interp is an interpreter to use
161163 """
162164
163- logging .debug ("starting init" )
165+ logger .debug ("starting init" )
164166
165167 if config is None :
166168 config = Struct ()
@@ -192,7 +194,7 @@ def smarter_request_refresh():
192194 refresh_request = self .request_refresh
193195 )
194196 self .rl_char_sequences = get_updated_char_sequences (key_dispatch , config )
195- logging .debug ("starting parent init" )
197+ logger .debug ("starting parent init" )
196198 super (Repl , self ).__init__ (interp , config )
197199 self .formatter = BPythonFormatter (config .color_scheme )
198200 self .interact = self .status_bar # overwriting what bpython.Repl put there
@@ -242,7 +244,7 @@ def __exit__(self, *args):
242244
243245 def clean_up_current_line_for_exit (self ):
244246 """Called when trying to exit to prep for final paint"""
245- logging .debug ('unhighlighting paren for exit' )
247+ logger .debug ('unhighlighting paren for exit' )
246248 self .cursor_offset_in_line = - 1
247249 self .unhighlight_paren ()
248250
@@ -257,15 +259,15 @@ def process_event(self, e):
257259 self .last_events .append (e )
258260 self .last_events .pop (0 )
259261
260- logging .debug ("processing event %r" , e )
262+ logger .debug ("processing event %r" , e )
261263 if isinstance (e , events .RefreshRequestEvent ):
262264 if self .status_bar .has_focus :
263265 self .status_bar .process_event (e )
264266 else :
265267 assert self .coderunner .code_is_waiting
266268 self .run_code_and_maybe_finish ()
267269 elif isinstance (e , events .WindowChangeEvent ):
268- logging .debug ('window change to %d %d' , e .width , e .height )
270+ logger .debug ('window change to %d %d' , e .width , e .height )
269271 self .scroll_offset -= e .cursor_dy
270272 self .width , self .height = e .width , e .height
271273
@@ -289,7 +291,7 @@ def process_event(self, e):
289291 return self .stdin .process_event (e )
290292
291293 elif isinstance (e , events .SigIntEvent ):
292- logging .debug ('received sigint event' )
294+ logger .debug ('received sigint event' )
293295 self .keyboard_interrupt ()
294296 self .update_completion ()
295297 return
@@ -386,7 +388,7 @@ def only_whitespace_left_of_cursor():
386388 """returns true if all characters on current line before cursor are whitespace"""
387389 return self ._current_line [:self .cursor_offset_in_line ].strip ()
388390
389- logging .debug ('self.matches: %r' , self .matches )
391+ logger .debug ('self.matches: %r' , self .matches )
390392 if not only_whitespace_left_of_cursor ():
391393 front_white = (len (self ._current_line [:self .cursor_offset_in_line ]) -
392394 len (self ._current_line [:self .cursor_offset_in_line ].lstrip ()))
@@ -404,8 +406,8 @@ def only_whitespace_left_of_cursor():
404406 if not self .config .auto_display_list and not self .list_win_visible :
405407 return True #TODO why?
406408 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 )
409+ logger .debug ('current string: %r' , self .current_string ())
410+ logger .debug ('current word: %r' , self .current_word )
409411 if not cw :
410412 return
411413
@@ -501,7 +503,7 @@ def push(self, line, insert_into_history=True):
501503 display_line = bpythonparse (format (self .tokenize (line ), self .formatter ))
502504 # careful: self.tokenize requires that the line not be in self.buffer yet!
503505
504- logging .debug ('display line being pushed to buffer: %r -> %r' , line , display_line )
506+ logger .debug ('display line being pushed to buffer: %r -> %r' , line , display_line )
505507 self .display_buffer .append (display_line )
506508 else :
507509 self .display_buffer .append (fmtstr (line ))
@@ -512,14 +514,14 @@ def push(self, line, insert_into_history=True):
512514
513515 code_to_run = '\n ' .join (self .buffer )
514516
515- logging .debug ('running %r in interpreter' , self .buffer )
517+ logger .debug ('running %r in interpreter' , self .buffer )
516518 try :
517519 c = bool (code .compile_command ('\n ' .join (self .buffer )))
518520 self .saved_predicted_parse_error = False
519521 except (ValueError , SyntaxError , OverflowError ):
520522 c = self .saved_predicted_parse_error = True
521523 if c :
522- logging .debug ('finished - buffer cleared' )
524+ logger .debug ('finished - buffer cleared' )
523525 self .display_lines .extend (self .display_buffer_lines )
524526 self .display_buffer = []
525527 self .buffer = []
@@ -531,8 +533,8 @@ def push(self, line, insert_into_history=True):
531533 def run_code_and_maybe_finish (self , for_code = None ):
532534 r = self .coderunner .run_code (for_code = for_code )
533535 if r :
534- logging .debug ("----- Running finish command stuff -----" )
535- logging .debug ("saved_indent: %r" , self .saved_indent )
536+ logger .debug ("----- Running finish command stuff -----" )
537+ logger .debug ("saved_indent: %r" , self .saved_indent )
536538 err = self .saved_predicted_parse_error
537539 self .saved_predicted_parse_error = False
538540
@@ -569,8 +571,8 @@ def unhighlight_paren(self):
569571 # then this is the current line, so don't worry about it
570572 return
571573 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 )
574+ logger .debug ('trying to unhighlight a paren on line %r' , lineno )
575+ logger .debug ('with these tokens: %r' , saved_tokens )
574576 new = bpythonparse (format (saved_tokens , self .formatter ))
575577 self .display_buffer [lineno ] = self .display_buffer [lineno ].setslice_with_length (0 , len (new ), new , len (self .display_buffer [lineno ]))
576578
@@ -589,13 +591,13 @@ def get_current_block(self):
589591
590592 def send_to_stdout (self , output ):
591593 lines = output .split ('\n ' )
592- logging .debug ('display_lines: %r' , self .display_lines )
594+ logger .debug ('display_lines: %r' , self .display_lines )
593595 self .current_stdouterr_line += lines [0 ]
594596 if len (lines ) > 1 :
595597 self .display_lines .extend (paint .display_linize (self .current_stdouterr_line , self .width , blank_line = True ))
596598 self .display_lines .extend (sum ([paint .display_linize (line , self .width , blank_line = True ) for line in lines [1 :- 1 ]], []))
597599 self .current_stdouterr_line = lines [- 1 ]
598- logging .debug ('display_lines: %r' , self .display_lines )
600+ logger .debug ('display_lines: %r' , self .display_lines )
599601
600602 def send_to_stderr (self , error ):
601603 #self.send_to_stdout(error)
@@ -625,12 +627,11 @@ def current_line_formatted(self):
625627 """The colored current line (no prompt, not wrapped)"""
626628 if self .config .syntax :
627629 fs = bpythonparse (format (self .tokenize (self ._current_line ), self .formatter ))
628- logging .debug ('Display line %r -> %r' , self ._current_line , fs )
630+ logger .debug ('Display line %r -> %r' , self ._current_line , fs )
629631 else :
630632 fs = fmtstr (self ._current_line )
631633 if hasattr (self , 'old_fs' ) and str (fs ) != str (self .old_fs ):
632634 pass
633- #logging.debug('calculating current formatted line: %r', repr(fs))
634635 self .old_fs = fs
635636 return fs
636637
@@ -698,7 +699,7 @@ def current_cursor_line(self):
698699 """Current line, either output/input or Python prompt + code"""
699700 value = (self .current_output_line +
700701 ('' if self .coderunner .running else self .display_line_with_prompt ))
701- logging .debug ('current cursor line: %r' , value )
702+ logger .debug ('current cursor line: %r' , value )
702703 return value
703704
704705 @property
@@ -741,7 +742,7 @@ def paint(self, about_to_exit=False, user_quit=False):
741742 #TODO test case of current line filling up the whole screen (there aren't enough rows to show it)
742743
743744 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--->' )
745+ logger .debug ('#<---History contiguity broken by rewind--->' )
745746 msg = "#<---History contiguity broken by rewind--->"
746747 arr [0 , 0 :min (len (msg ), width )] = [msg [:width ]]
747748
@@ -762,8 +763,8 @@ def paint(self, about_to_exit=False, user_quit=False):
762763 current_line = paint .paint_current_line (min_height , width , self .current_cursor_line )
763764 if user_quit : # quit() or exit() in interp
764765 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 )
766+ logger .debug ("---current line row slice %r, %r" , current_line_start_row , current_line_start_row + current_line .height )
767+ logger .debug ("---current line col slice %r, %r" , 0 , current_line .width )
767768 arr [current_line_start_row :current_line_start_row + current_line .height ,
768769 0 :current_line .width ] = current_line
769770
@@ -786,7 +787,7 @@ def paint(self, about_to_exit=False, user_quit=False):
786787 cursor_row += current_line_start_row
787788
788789 if self .list_win_visible :
789- logging .debug ('infobox display code running' )
790+ logger .debug ('infobox display code running' )
790791 visible_space_above = history .height
791792 visible_space_below = min_height - current_line_end_row - 1
792793
@@ -797,9 +798,9 @@ def paint(self, about_to_exit=False, user_quit=False):
797798 arr [current_line_start_row - infobox .height :current_line_start_row , 0 :infobox .width ] = infobox
798799 else :
799800 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 )
801+ logger .debug ('slamming infobox of shape %r into arr of shape %r' , infobox .shape , arr .shape )
801802
802- logging .debug ('about to exit: %r' , about_to_exit )
803+ logger .debug ('about to exit: %r' , about_to_exit )
803804 if show_status_bar :
804805 if self .config .curtsies_fill_terminal :
805806 if about_to_exit :
@@ -822,8 +823,8 @@ def paint(self, about_to_exit=False, user_quit=False):
822823 if self .config .color_scheme ['background' ] not in ('d' , 'D' ):
823824 for r in range (arr .height ):
824825 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 ))
826+ logger .debug ('returning arr of size %r' , arr .shape )
827+ logger .debug ('cursor pos: %r' , (cursor_row , cursor_column ))
827828 return arr , (cursor_row , cursor_column )
828829
829830 @contextlib .contextmanager
@@ -849,8 +850,8 @@ def my_print(msg):
849850 my_print ('X``' + ('`' * (self .width + 2 ))+ '``X' )
850851 for line in arr :
851852 my_print ('X```' + line .ljust (self .width )+ '```X' )
852- logging .debug ('line:' )
853- logging .debug (repr (line ))
853+ logger .debug ('line:' )
854+ logger .debug (repr (line ))
854855 my_print ('X``' + ('`' * (self .width + 2 ))+ '``X' )
855856 my_print ('X' * (self .width + 8 ))
856857 return max (len (arr ) - self .height , 0 )
@@ -897,7 +898,7 @@ def echo(self, msg, redraw=True):
897898 Supposed to parse and echo a formatted string with appropriate attributes.
898899 It's not supposed to update the screen if it's reevaluating the code (as it
899900 does with undo)."""
900- logging .debug ("echo called with %r" % msg )
901+ logger .debug ("echo called with %r" % msg )
901902 def cw (self ):
902903 """Returns the "current word", based on what's directly left of the cursor.
903904 examples inclue "socket.socket.metho" or "self.reco" or "yiel" """
@@ -907,7 +908,7 @@ def cpos(self):
907908 "many WATs were had - it's the pos from the end of the line back" ""
908909 return len (self ._current_line ) - self .cursor_offset_in_line
909910 def reprint_line (self , lineno , tokens ):
910- logging .debug ("calling reprint line with %r %r" , lineno , tokens )
911+ logger .debug ("calling reprint line with %r %r" , lineno , tokens )
911912 if self .config .syntax :
912913 self .display_buffer [lineno ] = bpythonparse (format (tokens , self .formatter ))
913914 def reevaluate (self , insert_into_history = False ):
0 commit comments