def processRequest(self): try: data, addr = self.sock.recvfrom(100) if data == b"GET_NSURI": responsedata = core.URI(self.nsUri) if responsedata.host == "0.0.0.0": # replace INADDR_ANY address by the interface IP address that connects to the requesting client try: interface_ip = socketutil.getInterfaceAddress(addr[0]) responsedata.host = interface_ip except socket.error: pass log.debug( "responding to broadcast request from %s: interface %s", addr[0], responsedata.host) responsedata = str(responsedata).encode("iso-8859-1") self.sock.sendto(responsedata, 0, addr) except socket.error: pass except SystemError: if sys.platform == "cli" and not self.running: # ironpython throws these systemerrors when shutting down... we can ignore them. pass else: raise
def test_compat_layer(): from Pyro4 import naming from Pyro4 import socketutil from Pyro4 import util try: _ = 1 // 0 except ZeroDivisionError: tb = util.getPyroTraceback() assert len(tb) == 3 assert "Traceback" in tb[0] assert "zero" in tb[2] assert 4 == socketutil.getIpVersion("127.0.0.1") assert 6 == socketutil.getIpVersion("::1") Pyro4.URI("PYRO:test@localhost:5555") p = Pyro4.Proxy("PYRO:test@localhost:5555") Pyro4.BatchProxy(p) Pyro4.Daemon() assert socketutil.getIpAddress("localhost", ipVersion=4).startswith("127.0") if socket.has_ipv6: try: assert ":" in socketutil.getIpAddress("localhost", ipVersion=6) except socket.error as x: if str(x) != "unable to determine IPV6 address": raise assert "127.0.0.1" == socketutil.getIpAddress("127.0.0.1") assert "::1" == socketutil.getIpAddress("::1") assert "127.0.0.1" == socketutil.getInterfaceAddress("127.0.0.1") with pytest.raises(NotImplementedError): naming.NameServer() with pytest.raises(NotImplementedError): _ = p._pyroHmacKey with pytest.raises(NotImplementedError): p._pyroHmacKey = b"fail"
def processRequest(self): try: data, addr = self.sock.recvfrom(100) if data == self.REQUEST_NSURI: responsedata = core.URI(self.nsUri) if responsedata.host == "0.0.0.0": # replace INADDR_ANY address by the interface IP address that connects to the requesting client try: interface_ip = socketutil.getInterfaceAddress(addr[0]) responsedata.host = interface_ip except socket.error: pass log.debug("responding to broadcast request from %s: interface %s", addr[0], responsedata.host) responsedata = str(responsedata).encode("iso-8859-1") self.sock.sendto(responsedata, 0, addr) except socket.error: pass
def processRequest(self): try: data, addr = self.sock.recvfrom(100) if data == self.REQUEST_NSURI: responsedata = core.URI(self.nsUri) if responsedata.host == "0.0.0.0": # replace INADDR_ANY address by the interface IP adress that connects to the requesting client try: interface_ip = socketutil.getInterfaceAddress(addr[0]) responsedata.host = interface_ip except socket.error: pass log.debug( "responding to broadcast request from %s: interface %s", addr[0], responsedata.host) responsedata = str(responsedata).encode("iso-8859-1") self.sock.sendto(responsedata, 0, addr) except socket.error: pass
def processRequest(self): try: data, addr = self.sock.recvfrom(100) if data == self.REQUEST_NSURI: responsedata = core.URI(self.nsUri) if responsedata.host == "0.0.0.0": # replace INADDR_ANY address by the interface IP address that connects to the requesting client try: interface_ip = socketutil.getInterfaceAddress(addr[0]) responsedata.host = interface_ip except socket.error: pass log.debug("responding to broadcast request from %s: interface %s", addr[0], responsedata.host) responsedata = str(responsedata).encode("iso-8859-1") self.sock.sendto(responsedata, 0, addr) except socket.error: pass except SystemError: if sys.platform == 'cli' and not self.running: # ironpython throws these systemerrors when shutting down... we can ignore them. pass else: raise
def testGetInterfaceAddress(self): self.assertTrue(SU.getInterfaceAddress("localhost").startswith("127.")) if has_ipv6: self.assertTrue(":" in SU.getInterfaceAddress("::1"))
def testGetInterfaceAddress(self): self.assertTrue(SU.getInterfaceAddress("localhost").startswith("127.")) if has_ipv6: self.assertIn(":", SU.getInterfaceAddress("::1"))
class Foo(object): def ping(self): log.info("Foo was pinged!!!") return "pong" class Bar(object): def ping(self): log.info("Bar was pinged!!!") return "bong" factory = pyro.protocol.Pyro4ServerFactory() tcp_port = pyro.protocol.reactor.listenTCP(5555, factory) # Because the reactor is responsible for the actual TCP connection, we # have to proactively route the data back into the factory to ensure # that URIs generated by the factory include correct location data. host = getInterfaceAddress("8.8.8.8") port = tcp_port.getHost().port log.debug("Setting PYRO Factory to host %s and port %d" % (host, port)) factory.setAddress(host, port) foo = Foo() bar = Bar() fooId = factory.register(foo) log.info("fooId is %s" % fooId) barId = factory.register(bar) log.info("barId is %s" % barId) log.info("PYRO available on tcp_port %d" % tcp_port.getHost().port) pyro.protocol.reactor.run()
def testGetInterfaceAddress(self): self.assertTrue(SU.getInterfaceAddress("localhost").startswith("127.")) self.assertTrue(":" in SU.getInterfaceAddress("::1"))