def metaweblog(request): # request_log.info("目标请求:{0}".format(request.body)) dispatcher = SimpleXMLRPCDispatcher(allow_none=False, encoding="UTF-8") dispatcher.register_introspection_functions() dispatcher.register_function(Api().getUsersBlogs, 'blogger.getUsersBlogs') dispatcher.register_function(Api().getCategories, 'metaWeblog.getCategories') dispatcher.register_function(Api().getRecentPosts, 'metaWeblog.getRecentPosts') dispatcher.register_function(Api().getPost, 'metaWeblog.getPost') dispatcher.register_function(Api().newPost, 'metaWeblog.newPost') dispatcher.register_function(Api().newMediaObject, 'metaWeblog.newMediaObject') dispatcher.register_function(Api().editPost, 'metaWeblog.editPost') dispatcher.register_function(Api().deletePost, 'metaWeblog.deletePost') response = dispatcher._marshaled_dispatch(request.body) # request_log.info("响应目标:{0}".format(response)) return HttpResponse(response)
def metaweblog(request): # request_log.info("目标请求:{0}".format(request.body)) dispatcher = SimpleXMLRPCDispatcher(allow_none=False, encoding="UTF-8") dispatcher.register_introspection_functions() dispatcher.register_function(Api().getUsersBlogs, 'blogger.getUsersBlogs') dispatcher.register_function(Api().getCategories, 'metaWeblog.getCategories') dispatcher.register_function(Api().getRecentPosts, 'metaWeblog.getRecentPosts') dispatcher.register_function(Api().getPost, 'metaWeblog.getPost') dispatcher.register_function(Api().newPost, 'metaWeblog.newPost') dispatcher.register_function(Api().newMediaObject, 'metaWeblog.newMediaObject') dispatcher.register_function(Api().editPost, 'metaWeblog.editPost') dispatcher.register_function(Api().deletePost, 'metaWeblog.deletePost') response = dispatcher._marshaled_dispatch(request.body) # request_log.info("响应目标:{0}".format(response)) return HttpResponse(response)
from flask import Blueprint, request, Response from xmlrpc.server import SimpleXMLRPCDispatcher from adif import parse as adif_parser bp_extapi = Blueprint("bp_extapi", __name__) handler = SimpleXMLRPCDispatcher(allow_none=True, encoding=None) """ Register the XML-RPC introspection functions system.listMethods, system.methodHelp and system.methodSignature. """ handler.register_introspection_functions() """ <value>log.add_record</value> log.add_record ADIF RECORD <value>log.check_dup</value> log.check_dup CALL, MODE(0), TIME_SPAN (0), FREQ_HZ(0), STATE(0), XCHG_IN(0) <value>log.get_record</value> log.get_record CALL """ def add_record(adif_record): print("Log.add_record") # FLDIGI send only a record, add fake end-of-header to not break parser parsed = adif_parser(b"<eoh>" + adif_record.encode("UTF-8")) if len(parsed) >= 1: parsed = parsed[0] """ freq in MHz, time_off HHMMSS, qso_date YYYYMMDD, qso_date_off time_on same {'freq': '14.070997', 'mode': 'PSK31', 'time_off': '152417', 'qso_date': '20160824', 'call': 'F4TEST', 'qso_date_off': '20160824', 'time_on': '1503'} """ return "xxx"
class WSGIXMLRPCApplication(object): """Application to handle requests to the XMLRPC service""" def __init__(self, instance=None, methods=None): """Create windmill xmlrpc dispatcher""" if methods is None: methods = [] try: self.dispatcher = SimpleXMLRPCDispatcher(allow_none=True, encoding=None) except TypeError: # python 2.4 self.dispatcher = SimpleXMLRPCDispatcher() if instance is not None: self.dispatcher.register_instance(instance) for method in methods: self.dispatcher.register_function(method) self.dispatcher.register_introspection_functions() def register_instance(self, instance): return self.dispatcher.register_instance(instance) def register_function(self, function, name=None): return self.dispatcher.register_function(function, name) def handler(self, environ, start_response): """XMLRPC service for windmill browser core to communicate with""" if environ['REQUEST_METHOD'] == 'POST': return self.handle_POST(environ, start_response) else: start_response("400 Bad request", [('Content-Type', 'text/plain')]) return [''] def handle_POST(self, environ, start_response): """Handles the HTTP POST request. Attempts to interpret all HTTP POST requests as XML-RPC calls, which are forwarded to the server's _dispatch method for handling. Most code taken from SimpleXMLRPCServer with modifications for wsgi and my custom dispatcher. """ try: # Get arguments by reading body of request. # We read this in chunks to avoid straining # socket.read(); around the 10 or 15Mb mark, some platforms # begin to have problems (bug #792570). length = int(environ['CONTENT_LENGTH']) data = environ['wsgi.input'].read(length) print('-------wsgi----data') print(data) # In previous versions of SimpleXMLRPCServer, _dispatch # could be overridden in this class, instead of in # SimpleXMLRPCDispatcher. To maintain backwards compatibility, # check to see if a subclass implements _dispatch and # using that method if present. response = self.dispatcher._marshaled_dispatch( data, getattr(self.dispatcher, '_dispatch', None)) response += b'\n' except Exception as e: # This should only happen if the module is buggy # internal error, report as HTTP server error print(e) start_response("500 Server error", [('Content-Type', 'text/plain')]) return [] else: # got a valid XML RPC response start_response("200 OK", [('Content-Type', 'text/xml'), ( 'Content-Length', str(len(response)), )]) return [response] def __call__(self, environ, start_response): print(environ) return self.handler(environ, start_response)
class WSGIXMLRPCApplication(object): """ 基于WSGI的XMLRPC应用 """ def __init__(self, instance=None, methods=None, **kwargs): """ 创建xmlrpc dispatcher """ if methods is None: methods = [] self.dispatcher = SimpleXMLRPCDispatcher(allow_none=True, encoding=None) if instance is not None: self.dispatcher.register_instance(instance) for method in methods: self.dispatcher.register_function(method) self.dispatcher.register_introspection_functions() self.logger = kwargs.get('logger', logging.getLogger(__name__)) def register_instance(self, instance): return self.dispatcher.register_instance(instance) def register_function(self, function, name=None): return self.dispatcher.register_function(function, name) def handler(self, environ, start_response): """ 处理HTTP访问 """ if environ['REQUEST_METHOD'] == 'POST': return self.handle_POST(environ, start_response) else: start_response("400 Bad request", [('Content-Type', 'text/plain')]) return [] def handle_POST(self, environ, start_response): """ 处理HTTP POST请求 """ try: length = int(environ['CONTENT_LENGTH']) data = environ['wsgi.input'].read(length) response = self.dispatcher._marshaled_dispatch( data, getattr(self.dispatcher, '_dispatch', None)) response += b'\n' except Exception as e: self.logger.exception(e) start_response("500 Server error", [('Content-Type', 'text/plain')]) return [] else: start_response("200 OK", [('Content-Type', 'text/xml'), ( 'Content-Length', str(len(response)), )]) return [response] def __call__(self, environ, start_response): return self.handler(environ, start_response)
self.s.shutdown(socket.SHUT_RDWR) self.s.close() except: pass self.s = None def spawn(self): t = threading.Thread(target=self.connect_thread) t.daemon = True t.start() t = threading.Thread(target=self.emit_thread) t.daemon = True t.start() def test_stuff_add(a, b): return a + b server = SimpleXMLRPCDispatcher(allow_none=True) # register_module(idc) server.register_function(wrap(test_stuff_add), 'test_stuff_add') server.register_introspection_functions() conn = ReverseConn('/tmp/talon_editor_socket') conn.spawn() # time.sleep(2) # conn.emit("test", {'a':"lol hi", 'b':5}) # time.sleep(2)