Esempio n. 1
0
 def create_client(self,methods):
     registry = ServerRegistry.get_instance()
     try:
         server = registry.get_server(
             ServerDirect._SERVER_PREFIX + self.address
             #ServerDirect._SERVER_PREFIX + self._machine_id + "__" + self._instance_id + "__" + self._server_id
         )
     except RegistryErrors.RegistryError as rex:
         raise ProtocolErrors.ClientCreationError(
                 ("Registry exception while retrieving server from registry: %s" % rex),
                 rex
         )
     try:
         client_class = ClientSkel.factory(Protocols.Direct,methods)
     except Exception as e:
         raise ProtocolErrors.ClientClassCreationError(
                 ("Client class creation exception: %s" % e),
                 e
             )
     try:
         return client_class(server)
     except Exception as e:
         raise ProtocolErrors.ClientInstanciationError(
                 ("Exception instaciating the client: %s" % e),
                 e
             )
Esempio n. 2
0
def generate(methods):
    clientSkel = ClientSkel.generate(methods)

    class ClientDirect(clientSkel):
        def __init__(self,server):
            clientSkel.__init__(self,server)

    # Adding properly the testing method to check availability
    if isinstance(methods,dict):
        all_methods = methods.keys()
    else:
        all_methods = list(methods[:])
    all_methods.append('test_me')

    # Generating stubs dinamically
    for method_name in all_methods:

        # Each method can have many stubs (with different prefixes)
        for stub in stubs:
            func = stub(method_name)
            # Setting docstring
            func.__doc__ = (func.__doc__ if func.__doc__ is not None else '').replace('METHOD_NAME', method_name)
            if isinstance(all_methods, dict):
                func.__doc__ = (func.__doc__ if func.__doc__ is not None else '').replace('DOCUMENTATION', all_methods[method_name])
            # Taking "prefix_" from "_prefix_stub"
            stub_prefix = stub.func_name[len('_generate_'):]
            stub_prefix = stub_prefix[:stub_prefix.rfind('stub')]
            func_name = stub_prefix + method_name
            func.func_name = func_name
            setattr(ClientDirect, func_name, func)

    return ClientDirect
Esempio n. 3
0
def generate(methods):
    clientSkel = ClientSkel.generate(methods)

    class ClientXMLRPC(clientSkel):

        def __init__(self, url, port=80, uri='/'):
            clientSkel.__init__(self,xmlrpclib.Server('http://'+url+':'+str(port)+uri, allow_none = True))

    # Adding properly the testing method to check availability
    if isinstance(methods,dict):
        all_methods = methods.keys()
    else:
        all_methods = list(methods[:])
    all_methods.append('test_me')

    # Generating stubs dinamically
    for method_name in all_methods:
        # Each method can have many stubs (with different prefixes)
        for stub in stubs:
            func = stub(method_name)
            # Setting docstring
            func.__doc__ = (func.__doc__ if func.__doc__ is not None else '').replace('METHOD_NAME', method_name)
            if isinstance(all_methods, dict):
                func.__doc__ = (func.__doc__ if func.__doc__ is not None else '').replace('DOCUMENTATION', all_methods[method_name])
            # Taking "prefix_" from "_prefix_stub"
            stub_prefix = stub.func_name[len('_generate_'):]
            stub_prefix = stub_prefix[:stub_prefix.rfind('stub')]
            func_name = stub_prefix + method_name
            func.func_name = func_name
            setattr(ClientXMLRPC, func_name, func)

    return ClientXMLRPC
Esempio n. 4
0
def generate(methods):
    clientSkel = ClientSkel.generate(methods)

    class ClientDirect(clientSkel):
        def __init__(self, server):
            clientSkel.__init__(self, server)

    # Adding properly the testing method to check availability
    if isinstance(methods, dict):
        all_methods = methods.keys()
    else:
        all_methods = list(methods[:])
    all_methods.append("test_me")

    # Generating stubs dinamically
    for method_name in all_methods:

        # Each method can have many stubs (with different prefixes)
        for stub in stubs:
            func = stub(method_name)
            # Setting docstring
            func.__doc__ = (func.__doc__ if func.__doc__ is not None else "").replace("METHOD_NAME", method_name)
            if isinstance(all_methods, dict):
                func.__doc__ = (func.__doc__ if func.__doc__ is not None else "").replace(
                    "DOCUMENTATION", all_methods[method_name]
                )
            # Taking "prefix_" from "_prefix_stub"
            stub_prefix = stub.func_name[len("_generate_") :]
            stub_prefix = stub_prefix[: stub_prefix.rfind("stub")]
            func_name = stub_prefix + method_name
            func.func_name = func_name
            setattr(ClientDirect, func_name, func)

    return ClientDirect
def generate(methods):
    clientSkel = ClientSkel.generate(methods)

    class ClientInternetSocket(clientSkel):
        def __init__(self, hostname, port):
            clientSkel.__init__(self, InternetSocketManager(hostname=hostname, port=port))

    return ClientBaseSocket.generate_base(methods, ClientInternetSocket)
Esempio n. 6
0
    def generate(methods):
        clientSkel = ClientSkel.generate(methods)

        class ClientUnixSocket(clientSkel):
            def __init__(self, path):
                clientSkel.__init__(self, UnixSocketManager(path=path))

        return ClientBaseSocket.generate_base(methods, ClientUnixSocket)
def generate(methods):
    clientSkel = ClientSkel.generate(methods)

    class ClientInternetSocket(clientSkel):
        def __init__(self, hostname, port):
            clientSkel.__init__(
                self, InternetSocketManager(hostname=hostname, port=port))

    return ClientBaseSocket.generate_base(methods, ClientInternetSocket)
Esempio n. 8
0
 def create_client(self, methods):
     try:
         client_class = ClientSkel.factory(Protocols.UnixSocket,methods)
     except Exception as e:
         raise ProtocolErrors.ClientClassCreationError(("Client class creation exception: %s" % e),  e)
     try:
         return client_class(path=self._path_id)
     except Exception as e:
         raise ProtocolErrors.ClientInstanciationError(("Exception instaciating the client: %s" % e), e)
Esempio n. 9
0
 def create_client(self, methods):
     try:
         client_class = ClientSkel.factory(Protocols.InternetSocket, methods)
     except Exception as e:
         raise ProtocolErrors.ClientClassCreationError(("Client class creation exception: %s" % e), e)
     try:
         return client_class(hostname=self.ip_address, port=self.port)
     except Exception as e:
         raise ProtocolErrors.ClientInstanciationError(("Unable to instanciate the InternetSocket client: %s" % e),e)
Esempio n. 10
0
def generate(methods):
    clientSkel = ClientSkel.generate(methods)

    class ClientSOAP(clientSkel):
        def __init__(self, url, port=80):
            if SOAPPY_AVAILABLE:
                proxy = SOAPpy.SOAPProxy('http://' + url + ':' + str(port))
            else:
                proxy = None
                msg = "The optional library 'SOAPpy' is not available. The communications between different servers will not work through SOAP. Since the client is being instanciated, there will probably be uncommon errors."
                print >> sys.stderr, msg
                log.log(self, log.level.Error, msg)

            clientSkel.__init__(self, proxy)

    # Adding properly the testing method to check availability
    if isinstance(methods, dict):
        all_methods = methods.keys()
    else:
        all_methods = list(methods[:])
    all_methods.append('test_me')

    # Generating stubs dinamically
    for method_name in all_methods:

        # Each method can have many stubs (with different prefixes)
        for stub in stubs:
            func = stub(method_name)
            # Setting docstring
            func.__doc__ = (func.__doc__ if func.__doc__ is not None else
                            '').replace('METHOD_NAME', method_name)
            if isinstance(all_methods, dict):
                func.__doc__ = (func.__doc__ if func.__doc__ is not None else
                                '').replace('DOCUMENTATION',
                                            all_methods[method_name])
            # Taking "prefix_" from "_prefix_stub"
            stub_prefix = stub.func_name[len('_generate_'):]
            stub_prefix = stub_prefix[:stub_prefix.rfind('stub')]
            func_name = stub_prefix + method_name
            func.func_name = func_name
            setattr(ClientSOAP, func_name, func)

    return ClientSOAP
Esempio n. 11
0
def generate(methods):
    clientSkel = ClientSkel.generate(methods)

    class ClientSOAP(clientSkel):
        def __init__(self, url, port=80):
            if SOAPPY_AVAILABLE:
                proxy = SOAPpy.SOAPProxy("http://" + url + ":" + str(port))
            else:
                proxy = None
                msg = "The optional library 'SOAPpy' is not available. The communications between different servers will not work through SOAP. Since the client is being instanciated, there will probably be uncommon errors."
                print >>sys.stderr, msg
                log.log(self, log.level.Error, msg)

            clientSkel.__init__(self, proxy)

    # Adding properly the testing method to check availability
    if isinstance(methods, dict):
        all_methods = methods.keys()
    else:
        all_methods = list(methods[:])
    all_methods.append("test_me")

    # Generating stubs dinamically
    for method_name in all_methods:

        # Each method can have many stubs (with different prefixes)
        for stub in stubs:
            func = stub(method_name)
            # Setting docstring
            func.__doc__ = (func.__doc__ if func.__doc__ is not None else "").replace("METHOD_NAME", method_name)
            if isinstance(all_methods, dict):
                func.__doc__ = (func.__doc__ if func.__doc__ is not None else "").replace(
                    "DOCUMENTATION", all_methods[method_name]
                )
            # Taking "prefix_" from "_prefix_stub"
            stub_prefix = stub.func_name[len("_generate_") :]
            stub_prefix = stub_prefix[: stub_prefix.rfind("stub")]
            func_name = stub_prefix + method_name
            func.func_name = func_name
            setattr(ClientSOAP, func_name, func)

    return ClientSOAP
Esempio n. 12
0
 def create_client(self, methods):
     registry = ServerRegistry.get_instance()
     try:
         server = registry.get_server(
             ServerDirect._SERVER_PREFIX + self.address
             #ServerDirect._SERVER_PREFIX + self._machine_id + "__" + self._instance_id + "__" + self._server_id
         )
     except RegistryErrors.RegistryError as rex:
         raise ProtocolErrors.ClientCreationError(
             ("Registry exception while retrieving server from registry: %s"
              % rex), rex)
     try:
         client_class = ClientSkel.factory(Protocols.Direct, methods)
     except Exception as e:
         raise ProtocolErrors.ClientClassCreationError(
             ("Client class creation exception: %s" % e), e)
     try:
         return client_class(server)
     except Exception as e:
         raise ProtocolErrors.ClientInstanciationError(
             ("Exception instaciating the client: %s" % e), e)
Esempio n. 13
0
def get_client(protocol,methods):
    return ClientSkel.factory(protocol,methods)
Esempio n. 14
0
def get_client(protocol, methods):
    return ClientSkel.factory(protocol, methods)