<s> """<STR_LIT>""" <EOL> import sys <EOL> from libcloud . utils . py3 import xmlrpclib <EOL> from libcloud . utils . py3 import httplib <EOL> from libcloud . common . base import Response , Connection <EOL> class ProtocolError ( Exception ) : <EOL> pass <EOL> class ErrorCodeMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> exceptions = { } <EOL> def raise_exception_for_error ( self , error_code , message ) : <EOL> exceptionCls = self . exceptions . get ( error_code , None ) <EOL> if exceptionCls is None : <EOL> return <EOL> context = self . connection . context <EOL> driver = self . connection . driver <EOL> params = { } <EOL> if hasattr ( exceptionCls , '<STR_LIT>' ) : <EOL> for key in exceptionCls . kwargs : <EOL> if key in context : <EOL> params [ key ] = context [ key ] <EOL> raise exceptionCls ( value = message , driver = driver , ** params ) <EOL> class XMLRPCResponse ( ErrorCodeMixin , Response ) : <EOL> defaultExceptionCls = Exception <EOL> def success ( self ) : <EOL> return self . status == httplib . OK <EOL> def parse_body ( self ) : <EOL> try : <EOL> params , methodname = xmlrpclib . loads ( self . body ) <EOL> if len ( params ) == <NUM_LIT:1> : <EOL> params = params [ <NUM_LIT:0> ] <EOL> return params <EOL> except xmlrpclib . Fault : <EOL> e = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> self . raise_exception_for_error ( e . faultCode , e . faultString ) <EOL> error_string = '<STR_LIT>' % ( e . faultCode , e . faultString ) <EOL> raise self . defaultExceptionCls ( error_string ) <EOL> def parse_error ( self ) : <EOL> msg = '<STR_LIT>' % ( self . status ) <EOL> raise ProtocolError ( msg ) <EOL> class XMLRPCConnection ( Connection ) : <EOL> """<STR_LIT>""" <EOL> responseCls = XMLRPCResponse <EOL> endpoint = None <EOL> def add_default_headers ( self , headers ) : <EOL> headers [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> return headers <EOL> def request ( self , method_name , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> endpoint = kwargs . get ( '<STR_LIT>' , self . endpoint ) <EOL> data = xmlrpclib . dumps ( args , methodname = method_name , allow_none = True ) <EOL> return super ( XMLRPCConnection , self ) . request ( endpoint , <EOL> data = data , <EOL> method = '<STR_LIT:POST>' ) </s>
