<s> '''<STR_LIT>''' <EOL> import os <EOL> import json <EOL> from . basicfile import BasicFile <EOL> from . errors import SeedFileError <EOL> from . . fuzztools . rangefinder import RangeFinder <EOL> from . . fuzztools import filetools <EOL> from . . scoring . scorable_thing import ScorableThing <EOL> def print_dict ( d , indent = <NUM_LIT:0> ) : <EOL> for ( k , v ) in d . iteritems ( ) : <EOL> indent_str = '<STR_LIT:U+0020>' * indent <EOL> if isinstance ( v , dict ) : <EOL> print indent_str + k <EOL> print_dict ( v , indent + <NUM_LIT:1> ) <EOL> else : <EOL> print indent_str + "<STR_LIT>" % ( k , type ( v ) . __name__ , v ) <EOL> class SeedFile ( BasicFile , ScorableThing ) : <EOL> '''<STR_LIT:U+0020>''' <EOL> def __init__ ( self , output_base_dir , path ) : <EOL> '''<STR_LIT>''' <EOL> BasicFile . __init__ ( self , path ) <EOL> ScorableThing . __init__ ( self , key = self . md5 ) <EOL> if not self . len > <NUM_LIT:0> : <EOL> raise SeedFileError ( '<STR_LIT>' % self . path ) <EOL> self . output_dir = os . path . join ( output_base_dir , self . md5 ) <EOL> if self . len > <NUM_LIT:1> : <EOL> self . range_min = <NUM_LIT:1.0> / self . len <EOL> self . range_max = <NUM_LIT:1.0> - self . range_min <EOL> else : <EOL> self . range_min = <NUM_LIT:0> <EOL> self . range_max = <NUM_LIT:1> <EOL> if not os . path . exists ( self . output_dir ) : <EOL> filetools . make_directories ( self . output_dir ) <EOL> self . rangefinder = self . _get_rangefinder ( ) <EOL> def _get_rangefinder ( self ) : <EOL> rf_log = os . path . join ( self . output_dir , '<STR_LIT>' ) <EOL> return RangeFinder ( self . range_min , self . range_max , rf_log ) <EOL> def __getstate__ ( self ) : <EOL> '''<STR_LIT>''' <EOL> state = self . __dict__ . copy ( ) <EOL> state [ '<STR_LIT>' ] = self . rangefinder . __getstate__ ( ) <EOL> return state <EOL> def __setstate__ ( self , state ) : <EOL> old_rf = state . pop ( '<STR_LIT>' ) <EOL> self . a = state [ '<STR_LIT:a>' ] <EOL> self . b = state [ '<STR_LIT:b>' ] <EOL> self . seen = state [ '<STR_LIT>' ] <EOL> self . successes = state [ '<STR_LIT>' ] <EOL> self . tries = state [ '<STR_LIT>' ] <EOL> self . uniques_only = state [ '<STR_LIT>' ] <EOL> new_rf = self . _get_rangefinder ( ) <EOL> old_ranges = old_rf [ '<STR_LIT>' ] <EOL> for k , old_range in old_ranges . iteritems ( ) : <EOL> if k in new_rf . things : <EOL> new_range = new_rf . things [ k ] <EOL> for attr in [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> setattr ( new_range , attr , old_range [ attr ] ) <EOL> self . rangefinder = new_rf <EOL> def cache_key ( self ) : <EOL> return '<STR_LIT>' % self . md5 <EOL> def pkl_file ( self ) : <EOL> return '<STR_LIT>' % self . md5 <EOL> def to_json ( self , sort_keys = True , indent = None ) : <EOL> state = self . __dict__ . copy ( ) <EOL> state [ '<STR_LIT>' ] = state [ '<STR_LIT>' ] . to_json ( sort_keys = sort_keys , indent = indent ) <EOL> return json . dumps ( state , sort_keys = sort_keys , indent = indent ) </s>
