<s> """<STR_LIT>""" <EOL> import tempfile <EOL> import os <EOL> import subprocess <EOL> import shutil <EOL> """<STR_LIT>""" <EOL> def collect_values ( branch , valid_values , anomaly_key = None ) : <EOL> """<STR_LIT>""" <EOL> if valid_values . get ( anomaly_key ) is None : <EOL> valid_values [ anomaly_key ] = [ ] <EOL> if isinstance ( branch , dict ) : <EOL> for key , value in branch . items ( ) : <EOL> collect_values ( value , valid_values , key ) <EOL> if isinstance ( branch , list ) : <EOL> for i in range ( <NUM_LIT:0> , len ( branch ) ) : <EOL> collect_values ( branch [ i ] , valid_values , anomaly_key ) <EOL> if isinstance ( branch , ( int , str , unicode , float ) ) or branch in ( <EOL> True , False , None ) : <EOL> valid_values [ anomaly_key ] . append ( branch ) <EOL> valid_values [ None ] . append ( branch ) <EOL> return valid_values <EOL> def fuzz_values ( valuedict , no_of_fuzzcases , radamsacmd ) : <EOL> """<STR_LIT>""" <EOL> fuzzdict = { } <EOL> for key in valuedict . keys ( ) : <EOL> if valuedict [ key ] == [ ] : <EOL> fuzzdict [ key ] = get_fuzz ( valuedict [ None ] , no_of_fuzzcases , <EOL> radamsacmd ) <EOL> else : <EOL> fuzzdict [ key ] = get_fuzz ( valuedict [ key ] , no_of_fuzzcases , <EOL> radamsacmd ) <EOL> return fuzzdict <EOL> def get_fuzz ( valuelist , no_of_fuzzcases , radamsacmd ) : <EOL> """<STR_LIT>""" <EOL> valid_case_directory = tempfile . mkdtemp ( ) <EOL> fuzz_case_directory = tempfile . mkdtemp ( ) <EOL> for valid_string in valuelist : <EOL> tempfilehandle = tempfile . mkstemp ( suffix = '<STR_LIT>' , <EOL> dir = valid_case_directory ) <EOL> with os . fdopen ( tempfilehandle [ <NUM_LIT:0> ] , "<STR_LIT:w>" ) as filehandle : <EOL> if isinstance ( valid_string , ( bool , int , long , float ) ) : <EOL> valid_string = str ( valid_string ) <EOL> filehandle . write ( bytearray ( valid_string , "<STR_LIT>" ) ) <EOL> try : <EOL> subprocess . check_call ( <EOL> [ radamsacmd , "<STR_LIT>" , fuzz_case_directory + "<STR_LIT>" , "<STR_LIT>" , <EOL> str ( no_of_fuzzcases ) , "<STR_LIT>" , valid_case_directory ] ) <EOL> except subprocess . CalledProcessError as error : <EOL> assert False , "<STR_LIT>" % error <EOL> fuzzlist = [ ] <EOL> for filename in os . listdir ( fuzz_case_directory ) : <EOL> filehandle = open ( fuzz_case_directory + "<STR_LIT:/>" + filename , "<STR_LIT:r>" ) <EOL> fuzzlist . append ( filehandle . read ( ) ) <EOL> shutil . rmtree ( valid_case_directory ) <EOL> shutil . rmtree ( fuzz_case_directory ) <EOL> return fuzzlist </s>
