<s> import json <EOL> from nativeconfig . exceptions import DeserializationError <EOL> from nativeconfig . options . base_option import BaseOption <EOL> class BooleanOption ( BaseOption ) : <EOL> """<STR_LIT>""" <EOL> TRUE_RAW_VALUES = ( '<STR_LIT:1>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> FALSE_RAW_VALUES = ( '<STR_LIT:0>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> ALLOWED_RAW_VALUES = TRUE_RAW_VALUES + FALSE_RAW_VALUES <EOL> def __init__ ( self , name , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( ) . __init__ ( name , choices = [ True , False ] , ** kwargs ) <EOL> def serialize ( self , python_value ) : <EOL> return '<STR_LIT:1>' if python_value else '<STR_LIT:0>' <EOL> def deserialize ( self , raw_value ) : <EOL> if raw_value . upper ( ) in self . TRUE_RAW_VALUES : <EOL> return True <EOL> elif raw_value . upper ( ) in self . FALSE_RAW_VALUES : <EOL> return False <EOL> else : <EOL> raise DeserializationError ( "<STR_LIT>" . format ( raw_value , self . ALLOWED_RAW_VALUES , self . name ) , raw_value , self . name ) <EOL> def deserialize_json ( self , json_value ) : <EOL> try : <EOL> value = json . loads ( json_value ) <EOL> except ValueError : <EOL> raise DeserializationError ( "<STR_LIT>" . format ( self . name , json_value ) , json_value , self . name ) <EOL> else : <EOL> if value is not None : <EOL> if not isinstance ( value , bool ) : <EOL> raise DeserializationError ( "<STR_LIT>" . format ( json_value ) , json_value , self . name ) <EOL> else : <EOL> return bool ( value ) <EOL> else : <EOL> return None </s>
