38
38
39
39
from bpython .keys import cli_key_dispatch as key_dispatch
40
40
41
+ logger = logging .getLogger (__name__ )
42
+
41
43
class FakeStdin (object ):
42
44
"""Stdin object user code references so sys.stdin.read() asked user for interactive input"""
43
45
def __init__ (self , coderunner , repl ):
@@ -82,7 +84,7 @@ def process_event(self, e):
82
84
83
85
def add_input_character (self , e ):
84
86
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 )
86
88
c = e if py3 else e .encode ('utf8' )
87
89
self .current_line = (self .current_line [:self .cursor_offset_in_line ] +
88
90
c +
@@ -160,7 +162,7 @@ def __init__(self, locals_=None, config=None, request_refresh=lambda: None, bann
160
162
interp is an interpreter to use
161
163
"""
162
164
163
- logging .debug ("starting init" )
165
+ logger .debug ("starting init" )
164
166
165
167
if config is None :
166
168
config = Struct ()
@@ -192,7 +194,7 @@ def smarter_request_refresh():
192
194
refresh_request = self .request_refresh
193
195
)
194
196
self .rl_char_sequences = get_updated_char_sequences (key_dispatch , config )
195
- logging .debug ("starting parent init" )
197
+ logger .debug ("starting parent init" )
196
198
super (Repl , self ).__init__ (interp , config )
197
199
self .formatter = BPythonFormatter (config .color_scheme )
198
200
self .interact = self .status_bar # overwriting what bpython.Repl put there
@@ -242,7 +244,7 @@ def __exit__(self, *args):
242
244
243
245
def clean_up_current_line_for_exit (self ):
244
246
"""Called when trying to exit to prep for final paint"""
245
- logging .debug ('unhighlighting paren for exit' )
247
+ logger .debug ('unhighlighting paren for exit' )
246
248
self .cursor_offset_in_line = - 1
247
249
self .unhighlight_paren ()
248
250
@@ -257,15 +259,15 @@ def process_event(self, e):
257
259
self .last_events .append (e )
258
260
self .last_events .pop (0 )
259
261
260
- logging .debug ("processing event %r" , e )
262
+ logger .debug ("processing event %r" , e )
261
263
if isinstance (e , events .RefreshRequestEvent ):
262
264
if self .status_bar .has_focus :
263
265
self .status_bar .process_event (e )
264
266
else :
265
267
assert self .coderunner .code_is_waiting
266
268
self .run_code_and_maybe_finish ()
267
269
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 )
269
271
self .scroll_offset -= e .cursor_dy
270
272
self .width , self .height = e .width , e .height
271
273
@@ -289,7 +291,7 @@ def process_event(self, e):
289
291
return self .stdin .process_event (e )
290
292
291
293
elif isinstance (e , events .SigIntEvent ):
292
- logging .debug ('received sigint event' )
294
+ logger .debug ('received sigint event' )
293
295
self .keyboard_interrupt ()
294
296
self .update_completion ()
295
297
return
@@ -386,7 +388,7 @@ def only_whitespace_left_of_cursor():
386
388
"""returns true if all characters on current line before cursor are whitespace"""
387
389
return self ._current_line [:self .cursor_offset_in_line ].strip ()
388
390
389
- logging .debug ('self.matches: %r' , self .matches )
391
+ logger .debug ('self.matches: %r' , self .matches )
390
392
if not only_whitespace_left_of_cursor ():
391
393
front_white = (len (self ._current_line [:self .cursor_offset_in_line ]) -
392
394
len (self ._current_line [:self .cursor_offset_in_line ].lstrip ()))
@@ -404,8 +406,8 @@ def only_whitespace_left_of_cursor():
404
406
if not self .config .auto_display_list and not self .list_win_visible :
405
407
return True #TODO why?
406
408
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 )
409
411
if not cw :
410
412
return
411
413
@@ -501,7 +503,7 @@ def push(self, line, insert_into_history=True):
501
503
display_line = bpythonparse (format (self .tokenize (line ), self .formatter ))
502
504
# careful: self.tokenize requires that the line not be in self.buffer yet!
503
505
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 )
505
507
self .display_buffer .append (display_line )
506
508
else :
507
509
self .display_buffer .append (fmtstr (line ))
@@ -512,14 +514,14 @@ def push(self, line, insert_into_history=True):
512
514
513
515
code_to_run = '\n ' .join (self .buffer )
514
516
515
- logging .debug ('running %r in interpreter' , self .buffer )
517
+ logger .debug ('running %r in interpreter' , self .buffer )
516
518
try :
517
519
c = bool (code .compile_command ('\n ' .join (self .buffer )))
518
520
self .saved_predicted_parse_error = False
519
521
except (ValueError , SyntaxError , OverflowError ):
520
522
c = self .saved_predicted_parse_error = True
521
523
if c :
522
- logging .debug ('finished - buffer cleared' )
524
+ logger .debug ('finished - buffer cleared' )
523
525
self .display_lines .extend (self .display_buffer_lines )
524
526
self .display_buffer = []
525
527
self .buffer = []
@@ -531,8 +533,8 @@ def push(self, line, insert_into_history=True):
531
533
def run_code_and_maybe_finish (self , for_code = None ):
532
534
r = self .coderunner .run_code (for_code = for_code )
533
535
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 )
536
538
err = self .saved_predicted_parse_error
537
539
self .saved_predicted_parse_error = False
538
540
@@ -569,8 +571,8 @@ def unhighlight_paren(self):
569
571
# then this is the current line, so don't worry about it
570
572
return
571
573
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 )
574
576
new = bpythonparse (format (saved_tokens , self .formatter ))
575
577
self .display_buffer [lineno ] = self .display_buffer [lineno ].setslice_with_length (0 , len (new ), new , len (self .display_buffer [lineno ]))
576
578
@@ -589,13 +591,13 @@ def get_current_block(self):
589
591
590
592
def send_to_stdout (self , output ):
591
593
lines = output .split ('\n ' )
592
- logging .debug ('display_lines: %r' , self .display_lines )
594
+ logger .debug ('display_lines: %r' , self .display_lines )
593
595
self .current_stdouterr_line += lines [0 ]
594
596
if len (lines ) > 1 :
595
597
self .display_lines .extend (paint .display_linize (self .current_stdouterr_line , self .width , blank_line = True ))
596
598
self .display_lines .extend (sum ([paint .display_linize (line , self .width , blank_line = True ) for line in lines [1 :- 1 ]], []))
597
599
self .current_stdouterr_line = lines [- 1 ]
598
- logging .debug ('display_lines: %r' , self .display_lines )
600
+ logger .debug ('display_lines: %r' , self .display_lines )
599
601
600
602
def send_to_stderr (self , error ):
601
603
#self.send_to_stdout(error)
@@ -625,12 +627,11 @@ def current_line_formatted(self):
625
627
"""The colored current line (no prompt, not wrapped)"""
626
628
if self .config .syntax :
627
629
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 )
629
631
else :
630
632
fs = fmtstr (self ._current_line )
631
633
if hasattr (self , 'old_fs' ) and str (fs ) != str (self .old_fs ):
632
634
pass
633
- #logging.debug('calculating current formatted line: %r', repr(fs))
634
635
self .old_fs = fs
635
636
return fs
636
637
@@ -698,7 +699,7 @@ def current_cursor_line(self):
698
699
"""Current line, either output/input or Python prompt + code"""
699
700
value = (self .current_output_line +
700
701
('' 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 )
702
703
return value
703
704
704
705
@property
@@ -741,7 +742,7 @@ def paint(self, about_to_exit=False, user_quit=False):
741
742
#TODO test case of current line filling up the whole screen (there aren't enough rows to show it)
742
743
743
744
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--->' )
745
746
msg = "#<---History contiguity broken by rewind--->"
746
747
arr [0 , 0 :min (len (msg ), width )] = [msg [:width ]]
747
748
@@ -762,8 +763,8 @@ def paint(self, about_to_exit=False, user_quit=False):
762
763
current_line = paint .paint_current_line (min_height , width , self .current_cursor_line )
763
764
if user_quit : # quit() or exit() in interp
764
765
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 )
767
768
arr [current_line_start_row :current_line_start_row + current_line .height ,
768
769
0 :current_line .width ] = current_line
769
770
@@ -786,7 +787,7 @@ def paint(self, about_to_exit=False, user_quit=False):
786
787
cursor_row += current_line_start_row
787
788
788
789
if self .list_win_visible :
789
- logging .debug ('infobox display code running' )
790
+ logger .debug ('infobox display code running' )
790
791
visible_space_above = history .height
791
792
visible_space_below = min_height - current_line_end_row - 1
792
793
@@ -797,9 +798,9 @@ def paint(self, about_to_exit=False, user_quit=False):
797
798
arr [current_line_start_row - infobox .height :current_line_start_row , 0 :infobox .width ] = infobox
798
799
else :
799
800
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 )
801
802
802
- logging .debug ('about to exit: %r' , about_to_exit )
803
+ logger .debug ('about to exit: %r' , about_to_exit )
803
804
if show_status_bar :
804
805
if self .config .curtsies_fill_terminal :
805
806
if about_to_exit :
@@ -822,8 +823,8 @@ def paint(self, about_to_exit=False, user_quit=False):
822
823
if self .config .color_scheme ['background' ] not in ('d' , 'D' ):
823
824
for r in range (arr .height ):
824
825
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 ))
827
828
return arr , (cursor_row , cursor_column )
828
829
829
830
@contextlib .contextmanager
@@ -849,8 +850,8 @@ def my_print(msg):
849
850
my_print ('X``' + ('`' * (self .width + 2 ))+ '``X' )
850
851
for line in arr :
851
852
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 ))
854
855
my_print ('X``' + ('`' * (self .width + 2 ))+ '``X' )
855
856
my_print ('X' * (self .width + 8 ))
856
857
return max (len (arr ) - self .height , 0 )
@@ -897,7 +898,7 @@ def echo(self, msg, redraw=True):
897
898
Supposed to parse and echo a formatted string with appropriate attributes.
898
899
It's not supposed to update the screen if it's reevaluating the code (as it
899
900
does with undo)."""
900
- logging .debug ("echo called with %r" % msg )
901
+ logger .debug ("echo called with %r" % msg )
901
902
def cw (self ):
902
903
"""Returns the "current word", based on what's directly left of the cursor.
903
904
examples inclue "socket.socket.metho" or "self.reco" or "yiel" """
@@ -907,7 +908,7 @@ def cpos(self):
907
908
"many WATs were had - it's the pos from the end of the line back" ""
908
909
return len (self ._current_line ) - self .cursor_offset_in_line
909
910
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 )
911
912
if self .config .syntax :
912
913
self .display_buffer [lineno ] = bpythonparse (format (tokens , self .formatter ))
913
914
def reevaluate (self , insert_into_history = False ):
0 commit comments