Exemplo n.º 1
0
 def proxy(self, factory=None):
     """
     Return a new xmlrpc.Proxy for the test site created in
     setUp(), using the given factory as the queryFactory, or
     self.queryFactory if no factory is provided.
     """
     p = xmlrpc.Proxy(networkString("http://127.0.0.1:%d/" % self.port))
     if factory is None:
         p.queryFactory = self.queryFactory
     else:
         p.queryFactory = factory
     return p
Exemplo n.º 2
0
 def test_sslTimeout(self):
     """
     For I{HTTPS} URIs, L{xmlrpc.Proxy.callRemote} passes the value it
     received for the C{connectTimeout} parameter as the C{timeout} argument
     to the underlying connectSSL call.
     """
     reactor = MemoryReactor()
     proxy = xmlrpc.Proxy(b"https://127.0.0.1:69",
                          connectTimeout=3.0,
                          reactor=reactor)
     proxy.callRemote("someMethod")
     self.assertEqual(reactor.sslClients[0][4], 3.0)
Exemplo n.º 3
0
 def init(self, xml_rpc_url_or_object):
     """
     """
     if _Debug:
         lg.out(4, 'tcp_interface.init %d' % id(proxy()))
     if not proxy():
         if isinstance(xml_rpc_url_or_object, six.string_types):
             proxy(xmlrpc.Proxy(xml_rpc_url_or_object, allowNone=True))
         else:
             proxy(xml_rpc_url_or_object)
     proxy().callRemote('transport_initialized', 'tcp')
     return True
Exemplo n.º 4
0
 def test_longPassword(self):
     """
     C{QueryProtocol} uses the C{base64.b64encode} function to encode user
     name and password in the I{Authorization} header, so that it doesn't
     embed new lines when using long inputs.
     """
     longPassword = self.password * 40
     p = xmlrpc.Proxy(networkString("http://127.0.0.1:%d/" % (self.port, )),
                      self.user, longPassword)
     d = p.callRemote("authinfo")
     d.addCallback(self.assertEqual, [self.user, longPassword])
     return d
Exemplo n.º 5
0
 def setUp(self):
     """
     Create a new XML-RPC server with C{allowNone} set to C{True}.
     """
     kwargs = {self.flagName: True}
     self.p = reactor.listenTCP(0,
                                server.Site(Test(**kwargs)),
                                interface="127.0.0.1")
     self.addCleanup(self.p.stopListening)
     self.port = self.p.getHost().port
     self.proxy = xmlrpc.Proxy(
         networkString("http://127.0.0.1:%d/" % (self.port, )), **kwargs)
Exemplo n.º 6
0
        def rpcCall():
            """
            Communicate with our local JMX process to collect results.
            This is a generator function

            @param driver: generator
            @type driver: string
            """
            port = self._client.listenPort
            xmlRpcProxy = xmlrpc.Proxy('http://localhost:%s/' % port)
            d = xmlRpcProxy.callRemote('zenjmx.collect', configMaps)
            d.addCallback(processResults)
            return d
Exemplo n.º 7
0
 def init(self, xml_rpc_url_or_object):
     """
     """
     if _Debug:
         lg.out(4, 'http_interface.init')
     if not proxy():
         global _GateProxy
         if isinstance(xml_rpc_url_or_object, str):
             _GateProxy = xmlrpc.Proxy(xml_rpc_url_or_object, allowNone=True)
         else:
             _GateProxy = xml_rpc_url_or_object
     proxy().callRemote('transport_initialized', 'http')
     return True
Exemplo n.º 8
0
 def start(self, eid):
     if eid in self.engine_registry:
         result = 'already started'
     else:
         port = runtime.find_port()
         self.engine_registry[eid] = xmlrpc.Proxy('http://localhost:%s' %
                                                  port)
         result = yield self.addProcess(str(eid), [
             '/Users/james/Documents/virtualenvs/backplay/bin/python', '-c',
             runtime.boot,
             str(port)
         ])
     defer.returnValue(result)
Exemplo n.º 9
0
 def setUp(self):
     p = self.proxy = repeatingproxy.RepeatingProxy(xmlrpc.Proxy(url='http://127.0.0.1:54123/'))
     #p.is_accepted_failure = self.accepted_failure
     p.RPC_TIMEOUT = 0.75
     p.TIMEOUT_FACTOR = 1.5
     p.DELAY_TIMEOUT = 0.5
     p.LONG_CALL = 3.0
     p.delay = repeatingproxy.AdaptiveTimeout(p.DELAY_TIMEOUT, factor=p.TIMEOUT_FACTOR)
     p.set_timeout(repeatingproxy.IncreasingTimeout(p.RPC_TIMEOUT, factor=p.TIMEOUT_FACTOR))
     p.max_retries = 6
     p.serializing = True
     self.handler = TestHandler()
     self.site = server.Site(self.handler, timeout=30)
     self.tcp_port = None
Exemplo n.º 10
0
    def join_cluster(self, hostport):
        s = xmlrpc.Proxy("http://%s/RPC2" % (hostport))

        def done(result):
            action_id, redCut, snapshot = result
            action_id = replication.ActionId().decode(action_id)
            df = self.delegate.processSnapshot(snapshot.data)

            def start(res, self, action_id, redCut):
                self.rep.startMainProtocol(action_id, redCut)
                self.initializeDatabase(self.rep.db)

            df.addCallback(start, self, action_id, redCut)

        df = s.callRemote("join_cluster", self.group, self.rep.serverId)
        df.addCallback(done)
Exemplo n.º 11
0
 def init(self, xml_rpc_url_or_object):
     """
     """
     global _GateProxy
     if _Debug:
         lg.out(4, 'proxy_interface.init')
     from transport.proxy import proxy_receiver
     from transport.proxy import proxy_sender
     if isinstance(xml_rpc_url_or_object, str):
         _GateProxy = xmlrpc.Proxy(xml_rpc_url_or_object, allowNone=True)
     else:
         _GateProxy = xml_rpc_url_or_object
     proxy_receiver.A('init')
     proxy_sender.A('init')
     proxy().callRemote('transport_initialized', 'proxy')
     return True
Exemplo n.º 12
0
 def __init__(self, addr):
     """Create a client that will connect to addr.
     
     Once created, this class will autoconnect and reconnect to the
     controller as needed.
     
     :Parameters:
         addr : tuple
             The (ip, port) of the IMultiEngine adapted controller.
     """
     self.addr = addr
     self.url = 'http://%s:%s/' % self.addr
     self._proxy = webxmlrpc.Proxy(self.url)
     self._deferredIDCallbacks = {}
     # This class manages some pending deferreds through this instance.  This
     # is required for methods like gather/scatter as it enables us to
     # create our own pending deferreds for composite operations.
     self.pdm = PendingDeferredManager()
Exemplo n.º 13
0
    def message(self, uri, message, content):
        groups = self.parseURI(uri)

        # Add the implicit /RPC2 and http://, creating a server proxy object
        server = groups['server']
        if server.find('/') < 0:
            server = server + '/RPC2'
        server = 'http://' + server
        proxy = xmlrpc.Proxy(server)

        # Parse arguments, allowing use of our 'message' and 'content' variables.
        args = self.parseArgs(groups['args'],
                              message = str(message),
                              content = content)

        # Make the call, ignoring the resulting Deferred. If it succeeds,
        # we don't really care. If it fails, the error will get logged.
        proxy.callRemote(groups['function'], *args)
Exemplo n.º 14
0
    def _publisher_thread(self, url):
        while True:
            try:
                proxy = rosxmlrpc.Proxy(xmlrpc.Proxy(url), self._node_handle._name)
                value = yield proxy.requestTopic(self._name, [['TCPROS']])

                protocol, host, port = value
                conn = yield endpoints.TCP4ClientEndpoint(reactor, host, port).connect(
                    util.AutoServerFactory(lambda addr: tcpros.Protocol()))
                try:
                    conn.sendString(tcpros.serialize_dict(dict(
                        message_definition=self._type._full_text,
                        callerid=self._node_handle._name,
                        topic=self._name,
                        md5sum=self._type._md5sum,
                        type=self._type._type,
                    )))
                    header = tcpros.deserialize_dict((yield conn.receiveString()))
                    self._connections[conn] = header.get('callerid', None)
                    try:
                        while True:
                            data = yield conn.receiveString()
                            msg = self._type().deserialize(data)
                            try:
                                self._callback(msg)
                            except:
                                traceback.print_exc()

                            self._last_message = msg
                            self._last_message_time = self._node_handle.get_time()

                            old, self._message_dfs = self._message_dfs, []
                            for df in old:
                                df.callback(msg)
                    finally:
                        del self._connections[conn]
                finally:
                    conn.transport.loseConnection()
            except (error.ConnectionDone, error.ConnectionLost, error.ConnectionRefusedError):
                pass
            except Exception:
                traceback.print_exc()

            yield util.wall_sleep(1)  # pause so that we don't repeatedly reconnect immediately on failure
Exemplo n.º 15
0
    def __init__(self,
                 name,
                 handler,
                 topic,
                 topic_type,
                 caller_api,
                 ros_master_uri=None):
        if ros_master_uri is None:
            ros_master_uri = os.environ['ROS_MASTER_URI']
        self.handler = handler  # to be called when a new message comes in
        self.caller_id = rospy.names.resolve_name(name)

        from twisted.web import xmlrpc
        self.master = xmlrpc.Proxy(ros_master_uri)

        self.topic = topic
        self.topic_type = topic_type

        self.caller_api = caller_api  # local xml uri
Exemplo n.º 16
0
    def __init__(self,
                 handler,
                 service_class,
                 name,
                 ros_service,
                 rpc_uri,
                 caller_api,
                 ros_master_uri=None):
        if ros_master_uri is None:
            ros_master_uri = os.environ['ROS_MASTER_URI']
        self.handler = handler
        self.service_class = service_class
        self.resolved_name = rospy.names.resolve_name(ros_service)
        self.caller_id = rospy.names.resolve_name(name)

        from twisted.web import xmlrpc
        self.master = xmlrpc.Proxy(ros_master_uri)

        self.rpc_uri = rpc_uri  # local rpc
        self.caller_api = caller_api  # xmlrpc local uri
Exemplo n.º 17
0
    def setup_transport(self):
        log.msg('Starting the OperaInboundTransport config: %s' %
                self.transport_name)
        self.r_server = redis.Redis(**self.r_config)
        self.r_prefix = "%(transport_name)s@%(url)s" % self.config

        self.proxy = xmlrpc.Proxy(self.opera_url)
        self.default_values = {
            'Service': self.opera_service,
            'Password': self.opera_password,
            'Channel': self.opera_channel,
        }

        # start receipt web resource
        self.web_resource = yield self.start_web_resources([
            (OperaReceiptResource(
                self.handle_raw_incoming_receipt), self.web_receipt_path),
            (OperaReceiveResource(
                self.publish_message), self.web_receive_path),
            (OperaHealthResource(), 'health'),
        ], self.web_port)
Exemplo n.º 18
0
    def makeBuilderSlave(cls,
                         builder_url,
                         vm_host,
                         timeout,
                         reactor=None,
                         proxy=None):
        """Create and return a `BuilderSlave`.

        :param builder_url: The URL of the slave buildd machine,
            e.g. http://localhost:8221
        :param vm_host: If the slave is virtual, specify its host machine
            here.
        :param reactor: Used by tests to override the Twisted reactor.
        :param proxy: Used By tests to override the xmlrpc.Proxy.
        """
        rpc_url = urlappend(builder_url.encode('utf-8'), 'rpc')
        if proxy is None:
            server_proxy = xmlrpc.Proxy(rpc_url,
                                        allowNone=True,
                                        connectTimeout=timeout)
            server_proxy.queryFactory = QuietQueryFactory
        else:
            server_proxy = proxy
        return cls(server_proxy, builder_url, vm_host, timeout, reactor)
Exemplo n.º 19
0
 def proxy(self):
     return xmlrpc.Proxy("http://127.0.0.1:%d" % (self.port, ),
                         allowNone=True)
Exemplo n.º 20
0
 def proxy(self):
     p = xmlrpc.Proxy("http://127.0.0.1:%d" % self.port)
     p.queryFactory = self.queryFactory
     return p
Exemplo n.º 21
0
 def createServer(self, resource):
     self.p = reactor.listenTCP(
         0, server.Site(resource), interface="127.0.0.1")
     self.addCleanup(self.p.stopListening)
     self.port = self.p.getHost().port
     self.proxy = xmlrpc.Proxy('http://127.0.0.1:%d' % self.port)
Exemplo n.º 22
0
 def test_explicitAuthInfoOverride(self):
     p = xmlrpc.Proxy("http://*****:*****@127.0.0.1:%d/" % (
             self.port,), self.user, self.password)
     d = p.callRemote("authinfo")
     d.addCallback(self.assertEquals, [self.user, self.password])
     return d
Exemplo n.º 23
0
 def _main(self, job_id):
     worker = CodeImportWorkerMonitor(
         job_id, self.logger,
         xmlrpc.Proxy(config.codeimportdispatcher.codeimportscheduler_url),
         self.options.access_policy)
     return worker.run()
Exemplo n.º 24
0
 def __init__(self, addr_str='http://localhost:5000'):
     self.proxy = xmlrpc.Proxy(addr_str)
Exemplo n.º 25
0
 def __init__(self, rptSystem=None):
     OaF.Notifier.__init__(self, rptSystem)
     self.xmlProxy = xmlrpc.Proxy(
         "http://xmlrpc.secondlife.com/cgi-bin/xmlrpc.cgi")
     self.rptSystem = rptSystem
Exemplo n.º 26
0
 def test_explicitAuthInfo(self):
     p = xmlrpc.Proxy(networkString("http://127.0.0.1:%d/" % (
         self.port,)), self.user, self.password)
     d = p.callRemote("authinfo")
     d.addCallback(self.assertEqual, [self.user, self.password])
     return d
Exemplo n.º 27
0
 def test_authInfoInURL(self):
     p = xmlrpc.Proxy("http://%s:%[email protected]:%d/" % (
         self.user, self.password, self.port))
     d = p.callRemote("authinfo")
     d.addCallback(self.assertEquals, [self.user, self.password])
     return d
Exemplo n.º 28
0
 def __init__(self, port):
     """
     """
     self.client = xmlrpc.Proxy("http://localhost:%s" % port)
     self.engine_id = ''
     self.backend = None
Exemplo n.º 29
0
    def __new__(cls, ns, name, addr, master_uri, remappings):
        # constraints: anything blocking here should print something if it's
        # taking a long time in order to avoid confusion

        self = object.__new__(cls)

        if ns:
            assert ns[0] == '/'
        assert not ns.endswith('/')
        self._ns = ns  # valid values: '', '/a', '/a/b'

        assert '/' not in name
        self._name = self._ns + '/' + name

        self._shutdown_callbacks = set()
        reactor.addSystemEventTrigger('before', 'shutdown', self.shutdown)

        self._addr = addr
        self._master_uri = master_uri
        self._remappings = remappings

        self._master_proxy = rosxmlrpc.Proxy(xmlrpc.Proxy(self._master_uri),
                                             self._name)
        self._is_running = True

        self._xmlrpc_handlers = {}
        self._xmlrpc_server = reactor.listenTCP(
            0, server.Site(_XMLRPCSlave(self)))
        self._shutdown_callbacks.add(self._xmlrpc_server.loseConnection)
        self._xmlrpc_server_uri = 'http://%s:%i/' % (
            self._addr, self._xmlrpc_server.getHost().port)

        self._tcpros_handlers = {}

        @util.cancellableInlineCallbacks
        def _handle_tcpros_conn(conn):
            try:
                header = tcpros.deserialize_dict((yield conn.receiveString()))

                def default(header, conn):
                    conn.sendString(
                        tcpros.serialize_dict(
                            dict(error='unhandled connection')))
                    conn.transport.loseConnection()

                if 'service' in header:
                    self._tcpros_handlers.get(('service', header['service']),
                                              default)(header, conn)
                elif 'topic' in header:
                    self._tcpros_handlers.get(('topic', header['topic']),
                                              default)(header, conn)
                else:
                    conn.sendString(
                        tcpros.serialize_dict(
                            dict(error='no topic or service name detected')))
                    conn.transport.loseConnection()
            except:
                conn.transport.loseConnection()
                raise

        def _make_tcpros_protocol(addr):
            conn = tcpros.Protocol()
            _handle_tcpros_conn(conn)
            return conn

        self._tcpros_server = reactor.listenTCP(
            0, util.AutoServerFactory(_make_tcpros_protocol))
        self._shutdown_callbacks.add(self._tcpros_server.loseConnection)
        self._tcpros_server_uri = 'rosrpc://%s:%i' % (
            self._addr, self._tcpros_server.getHost().port)
        self._tcpros_server_addr = self._addr, self._tcpros_server.getHost(
        ).port

        while True:
            try:
                other_node_uri = yield self._master_proxy.lookupNode(
                    self._name)
            except rosxmlrpc.Error:
                break  # assume that error means unknown node
            except Exception:
                traceback.print_exc()
                yield util.wall_sleep(1)  # pause so we don't retry immediately
            else:
                other_node_proxy = rosxmlrpc.Proxy(
                    xmlrpc.Proxy(other_node_uri), self._name)
                try:
                    yield util.wrap_timeout(
                        other_node_proxy.shutdown(
                            'new node registered with same name'), 3)
                except error.ConnectionRefusedError:
                    pass
                except Exception:
                    traceback.print_exc()
                break

        try:
            self._use_sim_time = yield self.get_param('/use_sim_time')
        except rosxmlrpc.Error:  # assume that error means not found
            self._use_sim_time = False
        if self._use_sim_time:

            def got_clock(msg):
                self._sim_time = msg.clock

            self._clock_sub = self.subscribe('/clock', Clock, got_clock)
            # make sure self._sim_time gets set before we continue
            yield util.wrap_time_notice(self._clock_sub.get_next_message(), 1,
                                        'getting simulated time from /clock')

        for k, v in self._remappings.iteritems():
            if k.startswith('_') and not k.startswith('__'):
                yield self.set_param(self.resolve_name('~' + k[1:]),
                                     yaml.load(v))

        self.advertise_service('~get_loggers', GetLoggers,
                               lambda req: GetLoggersResponse())
        self.advertise_service('~set_logger_level', SetLoggerLevel,
                               lambda req: SetLoggerLevelResponse())

        defer.returnValue(self)
Exemplo n.º 30
0
 def __init__(self):
     self.wiki = xmlrpc.Proxy('http://localhost:8082/RPC2')