<s> from libcloud . common . base import ConnectionKey , JsonResponse <EOL> __all__ = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> API_HOST = '<STR_LIT>' <EOL> class BuddyNSResponse ( JsonResponse ) : <EOL> errors = [ ] <EOL> objects = [ ] <EOL> def __init__ ( self , response , connection ) : <EOL> super ( BuddyNSResponse , self ) . __init__ ( response = response , <EOL> connection = connection ) <EOL> self . errors , self . objects = self . parse_body_and_errors ( ) <EOL> if not self . success ( ) : <EOL> raise BuddyNSException ( code = self . status , <EOL> message = self . errors . pop ( ) [ '<STR_LIT>' ] ) <EOL> def parse_body_and_errors ( self ) : <EOL> js = super ( BuddyNSResponse , self ) . parse_body ( ) <EOL> if '<STR_LIT>' in js : <EOL> self . errors . append ( js ) <EOL> else : <EOL> self . objects . append ( js ) <EOL> return self . errors , self . objects <EOL> def success ( self ) : <EOL> return len ( self . errors ) == <NUM_LIT:0> <EOL> class BuddyNSConnection ( ConnectionKey ) : <EOL> host = API_HOST <EOL> responseCls = BuddyNSResponse <EOL> def add_default_headers ( self , headers ) : <EOL> headers [ '<STR_LIT>' ] = '<STR_LIT:application/json>' <EOL> headers [ '<STR_LIT>' ] = '<STR_LIT>' + '<STR_LIT:U+0020>' + self . key <EOL> return headers <EOL> class BuddyNSException ( Exception ) : <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 ) </s>
