コード例 #1
0
def start(zope_layer_dotted_name):

    print(WAIT("Starting Zope robot server"))

    zsl = Zope2Server()
    zsl.start_zope_server(zope_layer_dotted_name)

    print(READY("Started Zope robot server"))

    listener = SimpleXMLRPCServer((LISTENER_HOST, LISTENER_PORT),
                                  logRequests=False)
    listener.allow_none = True
    listener.register_function(zsl.zodb_setup, 'zodb_setup')
    listener.register_function(zsl.zodb_teardown, 'zodb_teardown')

    print_urls(zsl.zope_layer, listener)

    try:
        listener.serve_forever()
    finally:
        print()
        print(WAIT("Stopping Zope robot server"))

        zsl.stop_zope_server()

        print(READY("Zope robot server stopped"))
コード例 #2
0
ファイル: test_satellite.py プロジェクト: candlepin/virt-who
    def __init__(self):
        SimpleXMLRPCServer.__init__(self, ("localhost", TEST_PORT), requestHandler=RequestHandler)
        # /XMLRPC interface
        self.register_function(self.new_system_user_pass, "registration.new_system_user_pass")
        self.register_function(self.refresh_hw_profile, "registration.refresh_hw_profile")
        self.register_function(self.virt_notify, "registration.virt_notify")
        # /xml/api interface
        self.register_function(self.auth_login, "auth.login")
        self.register_function(self.get_channel_details, "channel.software.getDetails")
        self.register_function(self.create_channel, "channel.software.create")
        self.register_function(self.set_map_for_org, "distchannel.setMapForOrg")
        self.register_function(self.get_user_details, "user.getDetails")

        self.channel_created = False
        self.created_system = None
コード例 #3
0
ファイル: server.py プロジェクト: xialulee/WaveSyn
def start_xmlrpc_server(addr='localhost', port=8000):        
    server = SimpleXMLRPCServer((addr, port))
    functions   = [
        getRootNodePath,
        getitem,
        getChildNodes,
        getMethods,
        getMethodDoc,
        getRepr,
        callMethod
    ]
    for function in functions:
        server.register_function(function, function.__name__)
    thread.start_new_thread(server.serve_forever, tuple())
    return server
        
コード例 #4
0
ファイル: xmlrpc_server.py プロジェクト: maurov/xraylarch
    def __init__(self, host='localhost', port=4966,
                 logRequests=False, allow_none=True,
                 keepalive_time=3*24*3600):
        self.out_buffer = []

        self.larch = Interpreter(writer=self)
        self.larch.input.prompt = ''
        self.larch.input.prompt2 = ''
        self.larch.run_init_scripts()

        self.larch('_sys.client = group(keepalive_time=%f)' % keepalive_time)
        self.larch('_sys.wx = group(wxapp=None)')
        _sys = self.larch.symtable._sys
        _sys.color_exceptions = False
        _sys.client.last_event = int(time())
        _sys.client.pid_server = int(os.getpid())
        _sys.client.app = 'unknown'
        _sys.client.pid = 0
        _sys.client.user = '******'
        _sys.client.machine = socket.getfqdn()

        self.client = self.larch.symtable._sys.client
        self.port = port
        SimpleXMLRPCServer.__init__(self, (host, port),
                                    logRequests=logRequests,
                                    allow_none=allow_none)

        self.register_introspection_functions()
        self.register_function(self.larch_exec, 'larch')

        for method in ('ls', 'chdir', 'cd', 'cwd', 'shutdown',
                        'set_keepalive_time', 'set_client_info',
                        'get_client_info', 'get_data', 'get_rawdata',
                        'get_messages', 'len_messages'):
            self.register_function(getattr(self, method), method)

        # sys.stdout = self
        self.finished = False
        signal.signal(signal.SIGINT, self.signal_handler)
        self.activity_thread = Thread(target=self.check_activity)
コード例 #5
0
ファイル: xmlrpc_server.py プロジェクト: Henry0422/xraylarch
 def __init__(self, host='127.0.0.1', port=5465, with_wx=True,
              local_echo=True, quiet=False, **kws):
     self.keep_alive = True
     self.port = port
     self.with_wx = HAS_WX and with_wx
     self.local_echo = local_echo
     self.quiet = quiet
     self.out_buffer = []
     self.keep_alive_time = time.time() + self.IDLE_TIME
     SimpleXMLRPCServer.__init__(self, (host, port),
                                 logRequests=False, allow_none=True, **kws)
     self.initialized = False
     self.register_introspection_functions()
     self.register_function(self.list_dir,      'ls')
     self.register_function(self.change_dir,    'chdir')
     self.register_function(self.current_dir,   'cwd')
     self.register_function(self.exit,          'exit')
     self.register_function(self.larch_exec,    'larch')
     self.register_function(self.wx_update,     'wx_update')
     self.register_function(self.get_data,      'get_data')
     self.register_function(self.get_messages,  'get_messages')
     self.register_function(self.len_messages,  'len_messages')
コード例 #6
0
ファイル: scheduler.py プロジェクト: Cloudebug/pyspider
    def xmlrpc_run(self, port=23333, bind='127.0.0.1', logRequests=False):
        '''Start xmlrpc interface'''
        try:
            from six.moves.xmlrpc_server import SimpleXMLRPCServer
        except ImportError:
            from SimpleXMLRPCServer import SimpleXMLRPCServer

        server = SimpleXMLRPCServer((bind, port), allow_none=True, logRequests=logRequests)
        server.register_introspection_functions()
        server.register_multicall_functions()

        server.register_function(self.quit, '_quit')
        server.register_function(self.__len__, 'size')

        def dump_counter(_time, _type):
            try:
                return self._cnt[_time].to_dict(_type)
            except:
                logger.exception('')
        server.register_function(dump_counter, 'counter')

        def new_task(task):
            if self.task_verify(task):
                self.newtask_queue.put(task)
                return True
            return False
        server.register_function(new_task, 'newtask')

        def send_task(task):
            '''dispatch task to fetcher'''
            self.send_task(task)
            return True
        server.register_function(send_task, 'send_task')

        def update_project():
            self._force_update_project = True
        server.register_function(update_project, 'update_project')

        def get_active_tasks(project=None, limit=100):
            allowed_keys = set((
                'taskid',
                'project',
                'status',
                'url',
                'lastcrawltime',
                'updatetime',
                'track',
            ))
            track_allowed_keys = set((
                'ok',
                'time',
                'follows',
                'status_code',
            ))

            iters = [iter(x['active_tasks']) for k, x in iteritems(self.projects)
                     if x and (k == project if project else True)]
            tasks = [next(x, None) for x in iters]
            result = []

            while len(result) < limit and tasks and not all(x is None for x in tasks):
                updatetime, task = t = max(tasks)
                i = tasks.index(t)
                tasks[i] = next(iters[i], None)
                for key in list(task):
                    if key == 'track':
                        for k in list(task[key].get('fetch', [])):
                            if k not in track_allowed_keys:
                                del task[key]['fetch'][k]
                        for k in list(task[key].get('process', [])):
                            if k not in track_allowed_keys:
                                del task[key]['process'][k]
                    if key in allowed_keys:
                        continue
                    del task[key]
                result.append(t)
            # fix for "<type 'exceptions.TypeError'>:dictionary key must be string"
            # have no idea why
            return json.loads(json.dumps(result))
        server.register_function(get_active_tasks, 'get_active_tasks')

        server.timeout = 0.5
        while not self._quit:
            server.handle_request()
        server.server_close()
コード例 #7
0
ファイル: scheduler.py プロジェクト: railroadman/pyspider
    def xmlrpc_run(self, port=23333, bind="127.0.0.1", logRequests=False):
        """Start xmlrpc interface"""
        try:
            from six.moves.xmlrpc_server import SimpleXMLRPCServer
        except ImportError:
            from SimpleXMLRPCServer import SimpleXMLRPCServer

        server = SimpleXMLRPCServer((bind, port), allow_none=True, logRequests=logRequests)
        server.register_introspection_functions()
        server.register_multicall_functions()

        server.register_function(self.quit, "_quit")
        server.register_function(self.__len__, "size")

        def dump_counter(_time, _type):
            try:
                return self._cnt[_time].to_dict(_type)
            except:
                logger.exception("")

        server.register_function(dump_counter, "counter")

        def new_task(task):
            if self.task_verify(task):
                self.newtask_queue.put(task)
                return True
            return False

        server.register_function(new_task, "newtask")

        def send_task(task):
            """dispatch task to fetcher"""
            self.send_task(task)
            return True

        server.register_function(send_task, "send_task")

        def update_project():
            self._force_update_project = True

        server.register_function(update_project, "update_project")

        def get_active_tasks(project=None, limit=100):
            allowed_keys = set(("taskid", "project", "status", "url", "lastcrawltime", "updatetime", "track"))
            track_allowed_keys = set(("ok", "time", "follows", "status_code"))

            iters = [
                iter(x["active_tasks"])
                for k, x in iteritems(self.projects)
                if x and (k == project if project else True)
            ]
            tasks = [next(x, None) for x in iters]
            result = []

            while len(result) < limit and tasks and not all(x is None for x in tasks):
                updatetime, task = t = max(t for t in tasks if t)
                i = tasks.index(t)
                tasks[i] = next(iters[i], None)
                for key in list(task):
                    if key == "track":
                        for k in list(task[key].get("fetch", [])):
                            if k not in track_allowed_keys:
                                del task[key]["fetch"][k]
                        for k in list(task[key].get("process", [])):
                            if k not in track_allowed_keys:
                                del task[key]["process"][k]
                    if key in allowed_keys:
                        continue
                    del task[key]
                result.append(t)
            # fix for "<type 'exceptions.TypeError'>:dictionary key must be string"
            # have no idea why
            return json.loads(json.dumps(result))

        server.register_function(get_active_tasks, "get_active_tasks")

        server.timeout = 0.5
        while not self._quit:
            server.handle_request()
        server.server_close()
コード例 #8
0
 def __init__(self, *args, **kwargs):
     SimpleXMLRPCServer.__init__(self, *args, **kwargs)
コード例 #9
0
def start_reload(zope_layer_dotted_name, reload_paths=('src',),
                 preload_layer_dotted_name='plone.app.testing.PLONE_FIXTURE',
                 extensions=None):

    print(WAIT("Starting Zope robot server"))

    zsl = Zope2Server()
    zsl.start_zope_server(preload_layer_dotted_name)

    forkloop = ForkLoop()
    watcher = Watcher(reload_paths, forkloop)
    if extensions:
        watcher.allowed_extensions = extensions
    elif HAS_DEBUG_MODE:
        watcher.allowed_extensions.remove('pt')
    watcher.start()
    forkloop.start()

    if forkloop.exit:
        print(WAIT("Stopping Zope robot server"))
        zsl.stop_zope_server()
        print(READY("Zope robot server stopped"))
        return

    # XXX: For unknown reason call to socket.gethostbyaddr may cause malloc
    # errors on OSX in forked child when called from medusa http_server, but
    # proper sleep seem to fix it:
    import time
    import socket
    import platform
    if 'Darwin' in platform.uname():
        gethostbyaddr = socket.gethostbyaddr
        socket.gethostbyaddr = lambda x: time.sleep(0.5) or (ZSERVER_HOST,)

    # Setting smaller asyncore poll timeout will speed up restart a bit
    import plone.testing.z2
    plone.testing.z2.ZServer.timeout = 0.5

    zsl.amend_zope_server(zope_layer_dotted_name)

    if HAS_DEBUG_MODE:
        import App.config
        config = App.config.getConfiguration()
        config.debug_mode = HAS_DEBUG_MODE
        App.config.setConfiguration(config)

    if 'Darwin' in platform.uname():
        socket.gethostbyaddr = gethostbyaddr

    print(READY("Zope robot server started"))

    try:
        listener = SimpleXMLRPCServer((LISTENER_HOST, LISTENER_PORT),
                                      logRequests=False)
    except socket.error as e:
        print(ERROR(str(e)))
        print(WAIT("Pruning Zope robot server"))
        zsl.prune_zope_server()
        return

    listener.timeout = 0.5
    listener.allow_none = True
    listener.register_function(zsl.zodb_setup, 'zodb_setup')
    listener.register_function(zsl.zodb_teardown, 'zodb_teardown')

    try:
        while not forkloop.exit:
            listener.handle_request()
    except select.error:  # Interrupted system call
        pass
    finally:
        print(WAIT("Pruning Zope robot server"))
        zsl.prune_zope_server()
コード例 #10
0
    def xmlrpc_run(self, port=23333, bind='127.0.0.1', logRequests=False):
        '''Start xmlrpc interface'''
        try:
            from six.moves.xmlrpc_server import SimpleXMLRPCServer
        except ImportError:
            from SimpleXMLRPCServer import SimpleXMLRPCServer

        server = SimpleXMLRPCServer((bind, port),
                                    allow_none=True,
                                    logRequests=logRequests)
        server.register_introspection_functions()
        server.register_multicall_functions()

        server.register_function(self.quit, '_quit')
        server.register_function(self.__len__, 'size')

        def dump_counter(_time, _type):
            try:
                return self._cnt[_time].to_dict(_type)
            except:
                logger.exception('')

        server.register_function(dump_counter, 'counter')

        def new_task(task):
            if self.task_verify(task):
                self.newtask_queue.put(task)
                return True
            return False

        server.register_function(new_task, 'newtask')

        def send_task(task):
            '''dispatch task to fetcher'''
            self.send_task(task)
            return True

        server.register_function(send_task, 'send_task')

        def update_project():
            self._force_update_project = True

        server.register_function(update_project, 'update_project')

        def get_active_tasks(project=None, limit=100):
            allowed_keys = set((
                'taskid',
                'project',
                'status',
                'url',
                'lastcrawltime',
                'updatetime',
                'track',
            ))
            track_allowed_keys = set((
                'ok',
                'time',
                'follows',
                'status_code',
            ))

            iters = [
                iter(x['active_tasks']) for k, x in iteritems(self.projects)
                if x and (k == project if project else True)
            ]
            tasks = [next(x, None) for x in iters]
            result = []

            while len(result) < limit and tasks and not all(x is None
                                                            for x in tasks):
                updatetime, task = t = max(tasks)
                i = tasks.index(t)
                tasks[i] = next(iters[i], None)
                for key in list(task):
                    if key == 'track':
                        for k in list(task[key].get('fetch', [])):
                            if k not in track_allowed_keys:
                                del task[key]['fetch'][k]
                        for k in list(task[key].get('process', [])):
                            if k not in track_allowed_keys:
                                del task[key]['process'][k]
                    if key in allowed_keys:
                        continue
                    del task[key]
                result.append(t)
            # fix for "<type 'exceptions.TypeError'>:dictionary key must be string"
            # have no idea why
            return json.loads(json.dumps(result))

        server.register_function(get_active_tasks, 'get_active_tasks')

        server.timeout = 0.5
        while not self._quit:
            server.handle_request()
        server.server_close()
コード例 #11
0
 def shutdown_request(self, *args):
     try:
         return SimpleXMLRPCServer.shutdown_request(self, *args)
     except TypeError:
         return SimpleXMLRPCServer.close_request(self, *args)
コード例 #12
0
 def finish_request(self, request, client_address):
     try:
         SimpleXMLRPCServer.finish_request(self, request, client_address)
     except (socket.error, socks.SSL.ZeroReturnError, socks.SSL.Error):
         pass