#NEWLINE# def _parser_generator( self ) : #NEWLINE# #INDENT# "\n        Coroutine that processes VT100 output.\n\n        It's actually a state machine, implemented as a coroutine. So all the\n        'state' that we have is stored in local variables.\n\n        This generator is not the most beautiful, but it is as performant as\n        possible. When a process generates a lot of output (That is often much\n        more than a person would give as input), then this will be the\n        bottleneck, because it processes just one character at a time.\n\n        We did many manual optimizations to this function in order to make it\n        as efficient as possible. Don't change anything without profiling\n        first.\n        " #NEWLINE# listener = self . listener #NEWLINE# basic = self . basic #NEWLINE# escape = self . escape #NEWLINE# sharp = self . sharp #NEWLINE# percent = percent . percent #NEWLINE# csi = self . csi #NEWLINE# ESC = ctrl . ESC #NEWLINE# CSI = ctrl . CSI #NEWLINE# CTRL_SEQUENCES_ALLOWED_IN_CSI = set ( [ ctrl . BEL , ctrl . BS , ctrl . HT , ctrl . LF , ctrl . VT , ctrl . FF , ctrl . CR ] ) #NEWLINE# def create_dispatch_dictionary( source_dict ) : #NEWLINE# #INDENT# def dummy( * a , **kw ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# return defaultdict ( ( lambda : dummy ) , { event : getattr ( listener , attr ) for ( event , attr ) in source_dict . items ( ) } ) #NEWLINE# #UNINDENT# basic_dispatch = create_dispatch_dictionary ( basic ) #NEWLINE# sharp_dispatch = create_dispatch_dictionary ( sharp ) #NEWLINE# percent_dispatch = create_dispatch_dictionary ( percent ) #NEWLINE# escape_dispatch = create_dispatch_dictionary ( escape ) #NEWLINE# csi_dispatch = create_dispatch_dictionary ( csi ) #NEWLINE# while True : #NEWLINE# #INDENT# char = ( yield True ) #NEWLINE# if ( char == ESC ) : #NEWLINE# #INDENT# char = ( yield ) #NEWLINE# if ( char == '[' ) : #NEWLINE# #INDENT# char = CSI #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( char == '#' ) : #NEWLINE# #INDENT# sharp_dispatch [ ( yield ) ] ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( char == '%' ) : #NEWLINE# #INDENT# percent_dispatch [ ( yield ) ] ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( char in '()' ) : #NEWLINE# #INDENT# listener . set_charset ( ( yield ) , mode = char ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( char == ']' ) : #NEWLINE# #INDENT# data = [ ] #NEWLINE# while True : #NEWLINE# #INDENT# c = ( yield ) #NEWLINE# if ( c == '\x07' ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# data . append ( c ) #NEWLINE# #UNINDENT# #UNINDENT# listener . square_close ( '' . join ( data ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# escape_dispatch [ char ] ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# if ( char in basic ) : #NEWLINE# #INDENT# basic_dispatch [ char ] ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( char == CSI ) : #NEWLINE# #INDENT# current = '' #NEWLINE# params = [ ] #NEWLINE# private = False #NEWLINE# while True : #NEWLINE# #INDENT# char = ( yield ) #NEWLINE# if ( char == '?' ) : #NEWLINE# #INDENT# private = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( char in CTRL_SEQUENCES_ALLOWED_IN_CSI ) : #NEWLINE# #INDENT# basic_dispatch [ char ] ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( char in ( ctrl . SP , '>' ) ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if char . isdigit ( ) : #NEWLINE# #INDENT# current += char #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# params . append ( min ( int ( ( current or 0 ) ) , 9999 ) ) #NEWLINE# if ( char == ';' ) : #NEWLINE# #INDENT# current = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if private : #NEWLINE# #INDENT# csi_dispatch [ char ] ( * params , private = True ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# csi_dispatch [ char ] ( * params ) #NEWLINE# #UNINDENT# #UNINDENT# except TypeError : #NEWLINE# #INDENT# logger . warning ( 'Dispatch %s failed. params=%s, private=%s' , params , private ) #NEWLINE# #UNINDENT# break