Esempio n. 1
0
    def _dispatch(self, handler, conn, n=1000):
        """Serve single call."""

        for i in range(n):
            data = conn.read()
            type, name, args, kwargs = loads(data)

            try:
                foo = handler._methods.get(name,
                                           None) or handler._get_method(name)
                result = foo(*args, **kwargs)
                error = None

            except Exception:
                logging.debug('Caught exception raised by callable.',
                              exc_info=True)
                # Use exc_info for py2.x py3.x compatibility.
                t, v, tb = sys.exc_info()
                if t in BUILTIN_EXCEPTIONS:
                    error = (t.__name__, v.args)
                else:
                    error = (repr(t), v.args)
                result = None

            if type == CALL:
                response = dumps((result, error))
                conn.write(response)
Esempio n. 2
0
    def __call__(self, *args, **kwargs):
        """Call method on server."""

        data = dumps((CALL, self._name, args, kwargs))
        self._conn.write(data)

        response = self._conn.read()
        value, error = loads(response)

        if error is None:
            return value

        try:
            name, args = error
        except TypeError:
            # Handle old way of returning error as repr.
            logging.warning('Unknown error returned by proxy, error=%s.',
                            error)
            raise ServerError(error)

        logging.warning('Error returned by proxy, name=%s, args=%s.', name,
                        args)

        # Raise built-in exceptions sent by server.
        if name in BUILTIN_EXCEPTIONS_NAMES:
            e = getattr(builtins, name)()
            e.args = args
            raise e  # Exception sent from server. Original traceback unavailable.

        self._on_exception(name, args)
Esempio n. 3
0
    def _dispatch(self, handler, conn, n=1000):
        """Serve single call."""

        for i in range(n):
            data = conn.read()
            type, name, args, kwargs = loads(data)

            try:    
                foo = handler._methods.get(name, None) or handler._get_method(name)
                result = foo(*args, **kwargs)
                error = None

            except Exception:
                logging.debug('Caught exception raised by callable.', exc_info=True)
                # Use exc_info for py2.x py3.x compatibility.
                t, v, tb = sys.exc_info()
                if t in BUILTIN_EXCEPTIONS:
                    error = (t.__name__, v.args)
                else:
                    error = (repr(t), v.args)
                result = None

            if type == CALL:
                response = dumps((result, error))
                conn.write(response)
Esempio n. 4
0
    def __call__(self, *args, **kwargs):
        """Call method on server."""
       
        data = dumps((CALL, self._name, args, kwargs))
        self._conn.write(data)
        
        response = self._conn.read()
        value, error = loads(response)
        
        if error is None:
            return value

        try:
            name, args = error
        except TypeError:
            # Handle old way of returning error as repr.
            logging.warning('Unknown error returned by proxy, error=%s.', error)
            raise ServerError(error)

        logging.warning('Error returned by proxy, name=%s, args=%s.', name, args)

        # Raise built-in exceptions sent by server.
        if name in BUILTIN_EXCEPTIONS_NAMES:
            e = getattr(builtins, name)()
            e.args = args
            raise e # Exception sent from server. Original traceback unavailable.

        self._on_exception(name, args)
Esempio n. 5
0
    def __call__(self, *args, **kwargs):
        """Call method on server, don't wait for response."""

        data = dumps((NOTIFY, self._name, args, kwargs))
        self._conn.write(data)
Esempio n. 6
0
 def dump(self, key, objs):
     self.c.basic_publish(exchange = '', routing_key = key,
         body = pickle.dumps(objs))
Esempio n. 7
0
 def dump(self, key, objs):
     self._redis.lpush(key, pickle.dumps(objs))
Esempio n. 8
0
 def __call__(self, *args, **kwargs):
     """Call method on server, don't wait for response."""
    
     data = dumps((NOTIFY, self._name, args, kwargs))
     self._conn.write(data)