<s> from libcloud . common . base import ConnectionKey , JsonResponse <EOL> from libcloud . common . types import InvalidCredsError <EOL> from libcloud . utils . py3 import PY3 <EOL> from libcloud . utils . py3 import b <EOL> __all__ = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> API_HOST = '<STR_LIT>' <EOL> API_ROOT = '<STR_LIT:/>' <EOL> LINODE_PLAN_IDS = { <NUM_LIT> : '<STR_LIT:1>' , <EOL> <NUM_LIT> : '<STR_LIT:2>' , <EOL> <NUM_LIT> : '<STR_LIT:4>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' } <EOL> LINODE_DISK_FILESYSTEMS = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> class LinodeException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , code , message ) : <EOL> self . code = code <EOL> self . message = message <EOL> self . args = ( code , message ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . code , self . message ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . code , self . message ) <EOL> class LinodeResponse ( JsonResponse ) : <EOL> """<STR_LIT>""" <EOL> objects = None <EOL> def __init__ ( self , response , connection ) : <EOL> """<STR_LIT>""" <EOL> self . connection = connection <EOL> self . headers = dict ( response . getheaders ( ) ) <EOL> self . error = response . reason <EOL> self . status = response . status <EOL> original_data = getattr ( response , '<STR_LIT>' , None ) <EOL> if original_data : <EOL> self . body = response . _original_data <EOL> else : <EOL> self . body = self . _decompress_response ( body = response . read ( ) , <EOL> headers = self . headers ) <EOL> if PY3 : <EOL> self . body = b ( self . body ) . decode ( '<STR_LIT:utf-8>' ) <EOL> self . invalid = LinodeException ( <NUM_LIT> , <EOL> "<STR_LIT>" ) <EOL> self . objects , self . errors = self . parse_body ( ) <EOL> if not self . success ( ) : <EOL> raise self . errors [ <NUM_LIT:0> ] <EOL> def parse_body ( self ) : <EOL> """<STR_LIT>""" <EOL> js = super ( LinodeResponse , self ) . parse_body ( ) <EOL> try : <EOL> if isinstance ( js , dict ) : <EOL> js = [ js ] <EOL> ret = [ ] <EOL> errs = [ ] <EOL> for obj in js : <EOL> if ( "<STR_LIT>" not in obj or "<STR_LIT>" not in obj or <EOL> "<STR_LIT>" not in obj ) : <EOL> ret . append ( None ) <EOL> errs . append ( self . invalid ) <EOL> continue <EOL> ret . append ( obj [ "<STR_LIT>" ] ) <EOL> errs . extend ( self . _make_excp ( e ) for e in obj [ "<STR_LIT>" ] ) <EOL> return ( ret , errs ) <EOL> except : <EOL> return ( None , [ self . invalid ] ) <EOL> def success ( self ) : <EOL> """<STR_LIT>""" <EOL> return len ( self . errors ) == <NUM_LIT:0> <EOL> def _make_excp ( self , error ) : <EOL> """<STR_LIT>""" <EOL> if "<STR_LIT>" not in error or "<STR_LIT>" not in error : <EOL> return None <EOL> if error [ "<STR_LIT>" ] == <NUM_LIT:4> : <EOL> return InvalidCredsError ( error [ "<STR_LIT>" ] ) <EOL> return LinodeException ( error [ "<STR_LIT>" ] , error [ "<STR_LIT>" ] ) <EOL> class LinodeConnection ( ConnectionKey ) : <EOL> """<STR_LIT>""" <EOL> host = API_HOST <EOL> responseCls = LinodeResponse <EOL> def add_default_params ( self , params ) : <EOL> """<STR_LIT>""" <EOL> params [ "<STR_LIT>" ] = self . key <EOL> params [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> return params </s>
