<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , unicode_literals <EOL> import functools <EOL> import logging <EOL> from . errors import TemporarilyUnavailableError , ServerError <EOL> from . errors import FatalClientError , OAuth2Error <EOL> log = logging . getLogger ( __name__ ) <EOL> class BaseEndpoint ( object ) : <EOL> def __init__ ( self ) : <EOL> self . _available = True <EOL> self . _catch_errors = False <EOL> @ property <EOL> def available ( self ) : <EOL> return self . _available <EOL> @ available . setter <EOL> def available ( self , available ) : <EOL> self . _available = available <EOL> @ property <EOL> def catch_errors ( self ) : <EOL> return self . _catch_errors <EOL> @ catch_errors . setter <EOL> def catch_errors ( self , catch_errors ) : <EOL> self . _catch_errors = catch_errors <EOL> def catch_errors_and_unavailability ( f ) : <EOL> @ functools . wraps ( f ) <EOL> def wrapper ( endpoint , uri , * args , ** kwargs ) : <EOL> if not endpoint . available : <EOL> e = TemporarilyUnavailableError ( ) <EOL> log . info ( '<STR_LIT>' % uri ) <EOL> return { } , e . json , <NUM_LIT> <EOL> if endpoint . catch_errors : <EOL> try : <EOL> return f ( endpoint , uri , * args , ** kwargs ) <EOL> except OAuth2Error : <EOL> raise <EOL> except FatalClientError : <EOL> raise <EOL> except Exception as e : <EOL> error = ServerError ( ) <EOL> log . warning ( <EOL> '<STR_LIT>' % e ) <EOL> return { } , error . json , <NUM_LIT> <EOL> else : <EOL> return f ( endpoint , uri , * args , ** kwargs ) <EOL> return wrapper </s>
