Exemple #1
0
    def to_dict(self):
        request_dict = {}

        self.callback = (getattr(self.callback, "__name__")
                         if callable(self.callback) else self.callback)
        self.download_midware = (getattr(self.download_midware, "__name__")
                                 if callable(self.download_midware) else
                                 self.download_midware)

        for key, value in self.__dict__.items():
            if (key in self.__class__.DEFAULT_KEY_VALUE
                    and self.__class__.DEFAULT_KEY_VALUE.get(key) == value
                    or key == "requests_kwargs"):
                continue

            if key in self.__class__.__REQUEST_ATTRS__:
                if not isinstance(
                        value,
                    (bytes, bool, float, int, str, tuple, list, dict)):
                    value = tools.dumps_obj(value)
            else:
                if not isinstance(value, (bytes, bool, float, int, str)):
                    value = tools.dumps_obj(value)

            request_dict[key] = value

        return request_dict
Exemple #2
0
    def to_dict(self):
        request_dict = {}

        self.callback = (
            getattr(self.callback, "__name__")
            if callable(self.callback)
            else self.callback
        )
        self.download_midware = (
            getattr(self.download_midware, "__name__")
            if callable(self.download_midware)
            else self.download_midware
        )

        for key, value in self.__dict__.items():
            if (
                key in self.__class__.DEFAULT_KEY_VALUE
                and self.__class__.DEFAULT_KEY_VALUE.get(key) == value
                or key == "requests_kwargs"
            ):
                continue

            if callable(value) or isinstance(value, Item):  # 序列化 如item
                value = tools.dumps_obj(value)

            request_dict[key] = value

        return request_dict