Example #1
0
 def __init__(self, address, name):
     self.address = address
     if not termformat.is_atom(name):
         message = "Module name must be an atom '{0}' ~> '{1}'"
         name_as_atom = termformat.binary_to_atom(name)
         raise ValueError(message.format(name, name_as_atom))
     self.name = name
     self.connections = kyoto.conf.settings.CONNECTION_MANAGER_CLASS(self.address)
Example #2
0
 def handle(self, request, **kwargs):
     rtype, module, function, args = request
     if module in self.modules:
         module = self.modules.get(module)
         name = termformat.atom_to_binary(function)
         function = getattr(module, name, None)
         if function and kyoto.utils.modules.is_callable_object(function):
             if kyoto.is_blocking(function):
                 future = kyoto.conf.settings.BLOCKING_POOL.submit(self.handle_call, function, args, **kwargs)
                 if rtype == ":call":
                     response = future.result()
                 else:
                     response = None
             else:
                 response = self.handlers[rtype](function, args, **kwargs)
             return response
         else:
             function = termformat.binary_to_atom(name)
             return (":error", (":server", 2, "NameError", "No such function: '{0}'".format(function), []))
     else:
         return (":error", (":server", 1, "NameError", "No such module: '{0}'".format(module), []))
Example #3
0
 def test_pass_invalid_value_to_binary_to_atom(self):
   with self.assertRaises(ValueError):
     termformat.binary_to_atom(":foo")
Example #4
0
 def test_success_binary_to_atom(self):
   result = termformat.binary_to_atom("foo")
   self.assertEqual(result, ":foo")
Example #5
0
 def transform(module):
     name = kyoto.utils.modules.get_module_name(module)
     return (termformat.binary_to_atom(name), module)