#NEWLINE# def render( self , environ , start_response ) : #NEWLINE# #INDENT# verb = environ . get ( 'REQUEST_METHOD' , 'GET' ) . strip ( ) . upper ( ) #NEWLINE# if ( verb not in ( 'GET' , 'POST' ) ) : #NEWLINE# #INDENT# response = Response ( '405 Method Not Allowed' , status = 405 , mimetype = 'text/plain' ) #NEWLINE# response . headers [ 'Allow' ] = 'GET, POST' #NEWLINE# return response ( environ , start_response ) #NEWLINE# #UNINDENT# if ( verb == 'POST' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# clen = int ( environ . get ( 'CONTENT_LENGTH' , '0' ) ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# clen = 0 #NEWLINE# #UNINDENT# body = environ [ 'wsgi.input' ] . read ( clen ) . decode ( 'utf-8' ) #NEWLINE# body = urlparse . parse_qs ( body ) #NEWLINE# clear = body . get ( 'clear' , None ) #NEWLINE# if clear : #NEWLINE# #INDENT# del self . stats [ : ] #NEWLINE# return self . render_response ( environ , start_response ) #NEWLINE# #UNINDENT# turn = body . get ( 'turn' , ' ' ) [ 0 ] . strip ( ) . lower ( ) #NEWLINE# if ( turn not in ( 'on' , 'off' ) ) : #NEWLINE# #INDENT# response = Response ( '400 Bad Request: parameter "turn=(on|off)" required' , status = '400' , mimetype = 'text/plain' ) #NEWLINE# return response ( environ , start_response ) #NEWLINE# #UNINDENT# if ( turn == 'on' ) : #NEWLINE# #INDENT# self . start ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . stop ( ) #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# while True : #NEWLINE# #INDENT# self . stats . append ( self . collector . get ( block = False ) ) #NEWLINE# #UNINDENT# #UNINDENT# except queue . Empty : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# return self . render_response ( environ , start_response )