@@ -690,6 +690,38 @@ def test_push_char(self):
690690 event = self .console .get_event (block = False )
691691 self .assertEqual (event .data , "\n " )
692692
693+ def test_bracketed_paste_two_pastes_in_one_read (self ):
694+ # Two complete pastes arrive in a single console read. The second
695+ # one is already queued, so it must be submitted without another
696+ # read, which would block on a real console.
697+ # See gh-156186.
698+
699+ self .console = WindowsConsole (encoding = 'utf-8' )
700+ self .console ._WindowsConsole__vt_support = True
701+ self .console ._WindowsConsole__original_input_mode = 0
702+ self .console .wait = MagicMock (return_value = True )
703+ self .console ._hide_cursor = MagicMock ()
704+ self .console ._show_cursor = MagicMock ()
705+ self .console .out = MagicMock ()
706+ self .console .getheightwidth = MagicMock (return_value = (25 , 80 ))
707+
708+ # start marker
709+ start_marker_records = [self .get_input_record (x ) for x in "\x1b [200~" ]
710+
711+ # body 1, end marker \x1b[201~, \r, start marker \x1b[200~, body 2, end marker, \r
712+ bulk_records = [self .get_input_record (x ) for x in "a\x1b [201~\r \x1b [200~b\x1b [201~\r " ]
713+ bulk_array = (len (bulk_records ) * wc .INPUT_RECORD )(* bulk_records )
714+ bulk_reads = [(bulk_array , len (bulk_array ))]
715+
716+ self .console ._read_input = MagicMock (side_effect = start_marker_records )
717+ self .console ._read_input_bulk = MagicMock (side_effect = bulk_reads )
718+
719+ reader = default_prepare_reader (self .console , paste_mode = False )
720+ with patch .object (wc , "SetConsoleMode" , return_value = 1 ):
721+ self .assertEqual (reader .readline (), "a" )
722+ self .assertEqual (reader .readline (), "b" )
723+ self .assertEqual (self .console ._read_input_bulk .call_count , 1 )
724+
693725
694726if __name__ == "__main__" :
695727 unittest .main ()
0 commit comments