#NEWLINE# @ app . route ( '/stream-bytes/<int:n>' ) #NEWLINE# def stream_random_bytes( request , n ) : #NEWLINE# #INDENT# 'Streams n random bytes generated with given seed,\n    at given chunk size per packet.\n    ' #NEWLINE# n = int ( n ) #NEWLINE# n = min ( n , ( 100 * 1024 ) ) #NEWLINE# params = CaseInsensitiveDict ( request . args . items ( ) ) #NEWLINE# if ( 'seed' in params ) : #NEWLINE# #INDENT# random . seed ( int ( params [ 'seed' ] ) ) #NEWLINE# #UNINDENT# if ( 'chunk_size' in params ) : #NEWLINE# #INDENT# chunk_size = max ( 1 , int ( params [ 'chunk_size' ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# chunk_size = ( 10 * 1024 ) #NEWLINE# #UNINDENT# def generate_bytes( ) : #NEWLINE# #INDENT# chunks = bytearray ( ) #NEWLINE# for i in xrange ( n ) : #NEWLINE# #INDENT# chunks . append ( random . randint ( 0 , 255 ) ) #NEWLINE# if ( len ( chunks ) == chunk_size ) : #NEWLINE# #INDENT# ( yield bytes ( chunks ) ) #NEWLINE# chunks = bytearray ( ) #NEWLINE# #UNINDENT# #UNINDENT# if chunks : #NEWLINE# #INDENT# ( yield bytes ( chunks ) ) #NEWLINE# #UNINDENT# #UNINDENT# headers = { #NEWLINE# #INDENT# 'Content-Type' : 'application/octet-stream' , #NEWLINE# #UNINDENT# } #NEWLINE# return Response ( generate_bytes ( ) , headers = headers )