<s> import json <EOL> import logging <EOL> import os <EOL> logging . basicConfig ( level = logging . INFO ) <EOL> logger = logging . getLogger ( __name__ ) <EOL> class Preferences ( object ) : <EOL> """<STR_LIT>""" <EOL> PATH = os . path . expanduser ( '<STR_LIT>' ) <EOL> def __init__ ( self ) : <EOL> self . _prefs = { } <EOL> self . load ( ) ; <EOL> def load ( self ) : <EOL> logger . info ( '<STR_LIT>' ) <EOL> if not os . path . isfile ( self . PATH ) : <EOL> logger . info ( '<STR_LIT>' , self . PATH ) <EOL> return <EOL> with open ( self . PATH ) as f : <EOL> try : <EOL> self . _prefs = json . loads ( f . read ( ) ) <EOL> except ValueError as error : <EOL> logger . exception ( error ) <EOL> return <EOL> logger . info ( '<STR_LIT>' ) <EOL> @ property <EOL> def host ( self ) : <EOL> return self . _prefs . get ( '<STR_LIT:host>' ) <EOL> @ host . setter <EOL> def host ( self , host ) : <EOL> self . _prefs [ '<STR_LIT:host>' ] = host <EOL> @ property <EOL> def api_key ( self ) : <EOL> return self . _prefs . get ( '<STR_LIT>' ) <EOL> @ api_key . setter <EOL> def api_key ( self , api_key ) : <EOL> self . _prefs [ '<STR_LIT>' ] = api_key <EOL> def save ( self ) : <EOL> logger . info ( '<STR_LIT>' ) <EOL> with open ( self . PATH , '<STR_LIT:w>' ) as f : <EOL> f . write ( json . dumps ( self . _prefs , indent = <NUM_LIT:4> ) ) <EOL> logger . info ( '<STR_LIT>' ) </s>
