def subclass(self, parent, name):
     """ creates exception stub class with custom parent exception."""
     if name not in self.__registry:
         exception = create_exception_cls(name, "celery_rpc.exceptions",
                                          parent=parent)
         self.__registry[name] = exception
     return self.__registry[name]
 def subclass(self, parent, name):
     """ creates exception stub class with custom parent exception."""
     if name not in self.__registry:
         exception = create_exception_cls(name,
                                          "celery_rpc.exceptions",
                                          parent=parent)
         self.__registry[name] = exception
     return self.__registry[name]
 def __getattr__(self, item):
     """ creates exception stub class for all missing attributes.
     """
     try:
         return object.__getattribute__(self, item)
     except AttributeError:
         if item not in self.__registry:
             exception = create_exception_cls(item, "celery_rpc.exceptions",
                                              parent=self.RemoteError)
             self.__registry[item] = exception
         return self.__registry[item]
 def __getattr__(self, item):
     """ creates exception stub class for all missing attributes.
     """
     try:
         return object.__getattribute__(self, item)
     except AttributeError:
         if item not in self.__registry:
             exception = create_exception_cls(item,
                                              "celery_rpc.exceptions",
                                              parent=self.RemoteError)
             self.__registry[item] = exception
         return self.__registry[item]
    def unpack_exception(self, data, serializer):
        """ Instantiates exception stub for original exception

        :param module: module name for original exception
        :param name: class name for original exception
        :param args: RemoteException.args
        :return: new constructed exception
        :rtype: self.RemoteError subclass
        """
        try:
            # unpacking RemoteException args
            content_type, content_encoding, dumps = registry._encoders[
                serializer]

            data = loads(data, content_type, content_encoding)
            module, name, args = data
            try:
                # trying to import original exception
                original = symbol_by_name("%s.%s" % (module, name))
                # creating parent class for original error and self.RemoteError

                class_name = from_utf8("Remote" + name)
                parent = type(class_name, (original, self.RemoteError),
                              {'__module__': module})
            except (AttributeError, ImportError):
                # alternative way for unknown errors
                parent = self.RemoteError

            # create and cache exception stub class
            if name not in self.__registry:
                self.__registry[name] = create_exception_cls(from_utf8(name),
                                                             module,
                                                             parent=parent)
            exc_class = self.__registry[name]

            return exc_class(*args)
        except (ValueError, ContentDisallowed):
            # loads error
            return None
    def unpack_exception(self, data, serializer):
        """ Instantiates exception stub for original exception

        :param module: module name for original exception
        :param name: class name for original exception
        :param args: RemoteException.args
        :return: new constructed exception
        :rtype: self.RemoteError subclass
        """
        try:
            # unpacking RemoteException args
            content_type, content_encoding, dumps = registry._encoders[serializer]

            data = loads(data, content_type, content_encoding)
            module, name, args = data
            try:
                # trying to import original exception
                original = symbol_by_name("%s.%s" % (module, name))
                # creating parent class for original error and self.RemoteError

                class_name = from_utf8("Remote" + name)
                parent = type(class_name, (original, self.RemoteError),
                              {'__module__': module})
            except (AttributeError, ImportError):
                # alternative way for unknown errors
                parent = self.RemoteError

            # create and cache exception stub class
            if name not in self.__registry:
                self.__registry[name] = create_exception_cls(
                    from_utf8(name), module, parent=parent)
            exc_class = self.__registry[name]

            return exc_class(*args)
        except (ValueError, ContentDisallowed):
            # loads error
            return None