<s> """<STR_LIT>""" <EOL> import sys <EOL> import xmlrpclib <EOL> from xmlrpclib import Fault <EOL> from SimpleXMLRPCServer import SimpleXMLRPCDispatcher <EOL> import traceback <EOL> from django . conf import settings <EOL> import logging <EOL> logger = logging . getLogger ( "<STR_LIT>" ) <EOL> class XMLRPCDispatcher ( SimpleXMLRPCDispatcher ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . funcs = { } <EOL> self . instance = None <EOL> self . allow_none = True <EOL> self . encoding = None <EOL> self . debug = getattr ( settings , "<STR_LIT>" , False ) <EOL> def dispatch ( self , data , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> params , method = xmlrpclib . loads ( data ) <EOL> try : <EOL> response = self . _dispatch ( method , params , ** kwargs ) <EOL> except TypeError as e : <EOL> if "<STR_LIT>" in "<STR_LIT:%s>" % e : <EOL> response = self . _dispatch ( method , params ) <EOL> else : <EOL> raise <EOL> response = ( response , ) <EOL> response = xmlrpclib . dumps ( response , methodresponse = <NUM_LIT:1> , <EOL> allow_none = self . allow_none , <EOL> encoding = self . encoding ) <EOL> except Fault , fault : <EOL> logger . warn ( "<STR_LIT>" % method ) <EOL> traceback . print_exc ( ) <EOL> response = xmlrpclib . dumps ( fault , allow_none = self . allow_none , <EOL> encoding = self . encoding ) <EOL> except : <EOL> logger . error ( "<STR_LIT>" % method ) <EOL> traceback . print_exc ( ) <EOL> exc_type , exc_value , exc_tb = sys . exc_info ( ) <EOL> exc_info = "<STR_LIT>" % ( exc_type , exc_value ) <EOL> if self . debug : <EOL> tb = traceback . extract_tb ( exc_tb ) <EOL> tb = traceback . format_list ( tb ) <EOL> tb = "<STR_LIT>" . join ( tb ) <EOL> exc_info += "<STR_LIT>" % tb <EOL> response = xmlrpclib . dumps ( <EOL> xmlrpclib . Fault ( <NUM_LIT:1> , exc_info ) , <EOL> encoding = self . encoding , allow_none = self . allow_none , <EOL> ) <EOL> return response <EOL> def _dispatch ( self , method , params , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> func = self . funcs . get ( method , None ) <EOL> if func is not None : <EOL> if len ( kwargs ) > <NUM_LIT:0> : <EOL> return func ( * params , ** kwargs ) <EOL> else : <EOL> return func ( * params ) <EOL> else : <EOL> raise Exception ( '<STR_LIT>' % method ) </s>
