示例#1
0
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"
示例#2
0
 def testGetIP(self):
     Pyro4.config.PREFER_IP_VERSION=4
     myip=SU.getIpAddress("")
     self.assertTrue(len(myip)>4)
     myip=SU.getIpAddress("", workaround127=True)
     self.assertTrue(len(myip)>4)
     self.assertFalse(myip.startswith("127."))
     self.assertEqual("127.0.0.1", SU.getIpAddress("127.0.0.1", workaround127=False))
     self.assertNotEqual("127.0.0.1", SU.getIpAddress("127.0.0.1", workaround127=True))
示例#3
0
 def testGetIP(self):
     config.PREFER_IP_VERSION = 4
     myip = SU.getIpAddress("")
     self.assertTrue(len(myip) > 4)
     myip = SU.getIpAddress("", workaround127=True)
     self.assertTrue(len(myip) > 4)
     self.assertFalse(myip.startswith("127."))
     self.assertEqual("127.0.0.1", SU.getIpAddress("127.0.0.1", workaround127=False))
     self.assertNotEqual("127.0.0.1", SU.getIpAddress("127.0.0.1", workaround127=True))
示例#4
0
 def testGetIP(self):
     localip=SU.getIpAddress()
     localhost=socket.getfqdn(localip)
     self.assertEqual(localip,SU.getIpAddress(localhost))
     myip=SU.getMyIpAddress()
     self.assertTrue(len(myip)>4)
     myip=SU.getMyIpAddress(workaround127=True)
     self.assertTrue(len(myip)>4)
     self.assertFalse(myip.startswith("127."))
     self.assertEqual("127.0.0.1", SU.getMyIpAddress("127.0.0.1",workaround127=False))
     self.assertNotEqual("127.0.0.1", SU.getMyIpAddress("127.0.0.1",workaround127=True))
    def get_own_ns() -> str:

        # # first try localhost if we have a good chance of finding it there
        # #sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        # sock = socketutil.createSocket(timeout=1.0, reuseaddr=config.SOCK_REUSE)
        #
        # #sock.settimeout(1.0)
        #
        # ns_uri = ''
        # # algunos sistemas Debian usan 127.0.1.1 como localhost, take careful with that
        # for _ in range(3):
        #     sock.sendto(b'GET_NSURI', ('192.168.43.234', 9090))  # direccion de escucha de pedidos broadcast del name server,
        #                             # envia su uri
        #     try:
        #         ns_uri = sock.recv(100)
        #         break
        #     except: pass  # todo esta puede no ser la flag del timeout
        #
        # try:
        #     sock.shutdown(socket.SHUT_RDWR)
        # except (OSError, socket.error,):
        #     pass
        #
        # sock.close()
        #
        # return str(ns_uri)

        my_ip = socketutil.getIpAddress('localhost', workaround127=True)

        for ns_uri in NSFinder.get_all_ns():
            if ns_uri.split('@')[1].split(':')[0] == my_ip:
                return ns_uri

        return ''
    def get_others_ns() -> list:
        my_ip = socketutil.getIpAddress('localhost', workaround127=True)

        other_ns = []

        for ns_uri in NSFinder.get_all_ns():
            if ns_uri.split('@')[1].split(':')[0] != my_ip:
                other_ns.append(ns_uri)

        return other_ns
示例#7
0
def main():
    uris_list = []

    ns_uri, ns_daemon, bc_server = naming.startNS(
        socketutil.getIpAddress('localhost', workaround127=True))

    daemon = Pyro4.Daemon(
        socketutil.getIpAddress('localhost', workaround127=True))

    algo1 = Tester()
    algo2 = Tester()

    for item in [algo1]:
        uri = daemon.register(item, 'algo')
        uris_list.append(uri)  # se dejan las uris en una lista

    daemon_thread = threading.Thread(target=daemon_instance,
                                     args=(daemon, ),
                                     name='demonio')
    daemon_thread.start()

    print(ns_uri)
    print(uris_list)

    for uri in uris_list:
        print(uri)
        ns_daemon.nameserver.register('tester', uri)

    ns_thread = threading.Thread(target=name_server_daemon,
                                 args=(ns_daemon, ),
                                 name='demonio del name server')

    bc_thread = threading.Thread(target=broadcast_server_daemon,
                                 args=(bc_server, ),
                                 name='demonio del broadcast')

    ns_thread.start()
    bc_thread.start()
示例#8
0
 def run(self):
     try:
         # application specific initialization
         self._initApp()
         # prepare service connection
         uri, name_server, broadcast_server = Pyro4.naming.startNS(host=socketutil.getIpAddress(None, workaround127=True))
         daemon = Pyro4.core.Daemon()
         service_uri = daemon.register(self)
         name_server.nameserver.register(self.__service_name, service_uri)
         # service connection waiting loop
         while True:
             try:
                 # create waiting sockets
                 name_server_sockets = set(name_server.sockets)
                 daemon_sockets = set(daemon.sockets)
                 rs = [broadcast_server]
                 rs.extend(name_server_sockets)
                 rs.extend(daemon_sockets)
                 rs, _, _ = select.select(rs, [], [], 3)
                 # socket processes
                 name_server_events = []
                 daemon_events = []
                 for s in rs:
                     if s is broadcast_server:
                         broadcast_server.processRequest()
                     elif s in name_server_sockets:
                         name_server_events.append(s)
                     elif s in daemon_sockets:
                         daemon_events.append(s)
                 if name_server_events:
                     name_server.events(name_server_events)
                 if daemon_events:
                     daemon.events(daemon_events)
             # unregister myself when service daemon exit
             except SystemExit:
                 # application specific destruction
                 self._delApp()
                 # unregister myself
                 daemon.unregister(self)
                 raise
     except Exception, e:
         self.__exception.exception(e)
示例#9
0
 def testGetIP6(self):
     self.assertTrue(":" in SU.getIpAddress("::1", ipVersion=6))
     # self.assertTrue(":" in SU.getIpAddress("", ipVersion=6))
     self.assertTrue(":" in SU.getIpAddress("localhost", ipVersion=6))
from Pyro4 import socketutil
from flask import Flask, render_template, redirect, render_template_string
from flask_bootstrap import Bootstrap

from chord_process import ChordProcess
from forms.forms import Crear_pagina, Crear_widget
from tools import flask_functions
from tools import listers

# todo ver lo del nombre en un futuro
sdApp = Flask(__name__)
sdApp.config['SECRET_KEY'] = 'hard to guess string'
bootstrap = Bootstrap(sdApp)

chord_process = ChordProcess(
    host=socketutil.getIpAddress('localhost', workaround127=True))

mi_manager_uri = chord_process.uri_dm

with Pyro4.Proxy(mi_manager_uri) as mi_manager:
    mi_manager._pyroTimeout = 7
    mi_manager.limpiar(widget=False)
    mi_manager.limpiar()

chord_process.go()

chord_widgets_uri = chord_process.chord_widgets.uri
chord_pages_uri = chord_process.chord_pages.uri

flask_functions.my_chord_widget = chord_widgets_uri
flask_functions.my_chord_page = chord_pages_uri
示例#11
0
 def testGetIP6(self):
     self.assertIn(":", SU.getIpAddress("::1", ipVersion=6))
     # self.assertTrue(":" in SU.getIpAddress("", ipVersion=6))
     self.assertIn(":", SU.getIpAddress("localhost", ipVersion=6))
示例#12
0
文件: server.py 项目: dwcharp/CS_550
from Pyro4.socketutil import getIpAddress


class Thingy(object):
    def multiply(self, a, b):
        return a * b

    def add(self, a, b):
        return a + b

    def divide(self, a, b):
        return a // b

    def error(self):
        return 1 // 0

    def delay(self, seconds):
        time.sleep(seconds)
        return seconds

    def printmessage(self, message):
        print(message)
        return 0


d = Pyro4.Daemon(host=getIpAddress("", workaround127=True), port=0)
uri = d.register(Thingy(), "example.batched")
print("server object uri:", uri)
print("batched calls server running.")
d.requestLoop()
示例#13
0
 def testGetIP6(self):
     if not has_ipv6:
         return
     self.assertTrue(":" in SU.getIpAddress("::1",ipVersion=6))
     self.assertTrue(":" in SU.getIpAddress("",ipVersion=6))
     self.assertTrue(":" in SU.getIpAddress("localhost",ipVersion=6))