| 12345678910111213141516171819202122232425262728293031323334353637383940414243 | import typingimport collections.abcfrom .product import productfrom .exception import not_ready_exceptionclass product_response:    def __new__(        cls,         target: product | typing.Iterable[product]    ) -> list | dict:        if isinstance(target, product):            return cls.single(target)        if isinstance(target, collections.abc.Iterable):            return cls.collection(target)        raise TypeError("Bad type for product response generator.")    def single(target: product) -> dict:        if not target.ready:            raise not_ready_exception(target)        return {            "name": target.name,            "description": target.description,            "author": target.author,            "image": target.image,            "stock_count": target.stock_count,            "barcode": target.barcode        }    def collection(targets: typing.Iterable[product]) -> list:        result = list()        for count in targets:            if not isinstance(count, product):                raise TypeError("Products iterable must contain products.")            result.append(product_response.single(count))        return result
 |