<s> """<STR_LIT>""" <EOL> import time <EOL> import json <EOL> import collections <EOL> import logging <EOL> import os <EOL> import sys <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class Range ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , minimum , maximum ) : <EOL> self . min = minimum <EOL> self . max = maximum <EOL> def within_range ( self , value ) : <EOL> """<STR_LIT>""" <EOL> return value >= self . min and value <= self . max <EOL> @ property <EOL> def spread ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . max - self . min <EOL> class AgingData ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . created_at = time . time ( ) <EOL> @ property <EOL> def age ( self ) : <EOL> """<STR_LIT>""" <EOL> return time . time ( ) - self . created_at <EOL> def quacks_like_dict ( object ) : <EOL> """<STR_LIT>""" <EOL> return isinstance ( object , collections . Mapping ) <EOL> def quacks_like_list ( object ) : <EOL> """<STR_LIT>""" <EOL> return hasattr ( object , '<STR_LIT>' ) and hasattr ( object , '<STR_LIT>' ) <EOL> def merge ( a , b ) : <EOL> """<STR_LIT>""" <EOL> assert quacks_like_dict ( a ) , quacks_like_dict ( b ) <EOL> dst = a . copy ( ) <EOL> stack = [ ( dst , b ) ] <EOL> while stack : <EOL> current_dst , current_src = stack . pop ( ) <EOL> for key in current_src : <EOL> if key not in current_dst : <EOL> current_dst [ key ] = current_src [ key ] <EOL> else : <EOL> if ( quacks_like_dict ( current_src [ key ] ) and <EOL> quacks_like_dict ( current_dst [ key ] ) ) : <EOL> stack . append ( ( current_dst [ key ] , current_src [ key ] ) ) <EOL> elif ( quacks_like_list ( current_src [ key ] ) and <EOL> quacks_like_list ( current_dst [ key ] ) ) : <EOL> current_dst [ key ] . extend ( current_src [ key ] ) <EOL> else : <EOL> current_dst [ key ] = current_src [ key ] <EOL> return dst <EOL> def find_file ( filename , search_paths ) : <EOL> for search_path in search_paths : <EOL> if filename [ <NUM_LIT:0> ] != '<STR_LIT:/>' : <EOL> full_path = "<STR_LIT>" % ( search_path , filename ) <EOL> else : <EOL> full_path = filename <EOL> if os . path . exists ( full_path ) : <EOL> return full_path <EOL> fatal_error ( "<STR_LIT>" % ( <EOL> filename , search_paths ) ) <EOL> def load_json_from_search_path ( filename , search_paths ) : <EOL> with open ( find_file ( filename , search_paths ) ) as json_file : <EOL> try : <EOL> data = json . load ( json_file ) <EOL> except ValueError as e : <EOL> fatal_error ( "<STR_LIT>" % <EOL> ( filename , e ) ) <EOL> else : <EOL> return data <EOL> def fatal_error ( message ) : <EOL> LOG . error ( message ) <EOL> sys . exit ( <NUM_LIT:1> ) </s>
