#NEWLINE# def iterator( self , * types ) : #NEWLINE# #INDENT# ' Create and return a function for iterating over messages.\n\n        @param *types zero or more message types to associate with listener\n        @return function that yields messages\n        ' #NEWLINE# queue = Queue ( ) #NEWLINE# closed = [ ] #NEWLINE# def messageGenerator( block = True , timeout = 0.1 ) : #NEWLINE# #INDENT# while True : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( yield queue . get ( block = block , timeout = timeout ) ) #NEWLINE# #UNINDENT# except ( Empty , ) : #NEWLINE# #INDENT# if closed : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# self . register ( closed . append , 'ConnectionClosed' ) #NEWLINE# if types : #NEWLINE# #INDENT# self . register ( queue . put , * types ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . registerAll ( queue . put ) #NEWLINE# #UNINDENT# return messageGenerator