<s> """<STR_LIT>""" <EOL> import base64 <EOL> import json <EOL> import logging . config <EOL> import os <EOL> import sys <EOL> class ConfigException ( Exception ) : <EOL> pass <EOL> class Credentials ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , app_id , app_secret , app_token , endpoint = '<STR_LIT>' ) : <EOL> self . app_id = app_id <EOL> self . app_secret = app_secret <EOL> self . app_token = app_token <EOL> self . endpoint = endpoint <EOL> @ property <EOL> def authorization ( self ) : <EOL> """<STR_LIT>""" <EOL> data = "<STR_LIT>" . format ( self . app_id , self . app_token ) <EOL> if sys . version [ <NUM_LIT:0> ] == '<STR_LIT:2>' : <EOL> encoded = base64 . b64encode ( data ) <EOL> else : <EOL> encoded = base64 . b64encode ( bytes ( data , "<STR_LIT:ascii>" ) ) <EOL> return "<STR_LIT>" + encoded . decode ( "<STR_LIT:ascii>" ) <EOL> class JSONCredentials ( Credentials ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , filename ) : <EOL> with open ( filename ) as src : <EOL> config = json . loads ( src . read ( ) ) <EOL> super ( JSONCredentials , self ) . __init__ ( config [ '<STR_LIT>' ] , config [ '<STR_LIT>' ] , config [ '<STR_LIT>' ] , config [ '<STR_LIT>' ] ) <EOL> class Config ( object ) : <EOL> """<STR_LIT>""" <EOL> PARAMS = { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : None } <EOL> def __init__ ( self , ** kwargs ) : <EOL> for key , value in Config . PARAMS . items ( ) : <EOL> setattr ( self , key , value ) <EOL> for key , value in kwargs . items ( ) : <EOL> if key in Config . PARAMS : <EOL> setattr ( self , key , value ) <EOL> else : <EOL> raise ConfigException ( "<STR_LIT>" ) <EOL> if "<STR_LIT>" in kwargs : <EOL> logging . config . dictConfig ( kwargs [ "<STR_LIT>" ] ) <EOL> class JSONConfig ( Config ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , filename ) : <EOL> with open ( filename ) as cfgfile : <EOL> self . data = json . load ( cfgfile ) <EOL> if "<STR_LIT>" in self . data and self . data [ "<STR_LIT>" ] is not None : <EOL> logging . config . dictConfig ( self . data [ "<STR_LIT>" ] ) <EOL> def __getattr__ ( self , name ) : <EOL> return self . data . get ( name , None ) <EOL> try : <EOL> import yaml <EOL> class YAMLConfig ( Config ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , filename ) : <EOL> with open ( filename ) as cfgfile : <EOL> self . data = yaml . load ( cfgfile ) <EOL> if "<STR_LIT>" in self . data and self . data [ "<STR_LIT>" ] is not None : <EOL> logging . config . dictConfig ( self . data [ "<STR_LIT>" ] ) <EOL> def __getattr__ ( self , name ) : <EOL> return self . data . get ( name , None ) <EOL> class YAMLCredentials ( Credentials ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , filename ) : <EOL> with open ( filename ) as src : <EOL> config = yaml . load ( src . read ( ) ) <EOL> super ( YAMLCredentials , self ) . __init__ ( config [ '<STR_LIT>' ] , config [ '<STR_LIT>' ] , config [ '<STR_LIT>' ] , config [ '<STR_LIT>' ] ) <EOL> except ImportError : <EOL> pass <EOL> class JSONEnvironmentFallbackConfig ( Config ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , jsonfile , ** kwargs ) : <EOL> with open ( jsonfile ) as cfgfile : <EOL> self . data = json . load ( cfgfile ) <EOL> for key , value in kwargs . items ( ) : <EOL> if key not in Config . PARAMS : <EOL> raise ApiException ( "<STR_LIT>" ) <EOL> if key not in self . data : <EOL> self . data [ key ] = os . environ [ value ] <EOL> if "<STR_LIT>" in self . data and self . data [ "<STR_LIT>" ] is not None : <EOL> logging . config . dictConfig ( self . data [ "<STR_LIT>" ] ) <EOL> def __getattr__ ( self , name ) : <EOL> return self . data [ name ] </s>
