How to use the scrapbook.exceptions.ScrapbookMissingEncoder function in scrapbook

To help you get started, we’ve selected a few scrapbook examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nteract / scrapbook / scrapbook / encoders.py View on Github external
def encode(self, scrap, **kwargs):
        """
        Finds the register for the given encoder and translates the scrap's data
        from an object of the encoder type to a JSON typed object.

        Parameters
        ----------
        scrap: Scrap
            A partially filled in scrap with data that needs encoding
        """
        encoder = self._encoders.get(scrap.encoder)
        if not encoder:
            raise ScrapbookMissingEncoder(
                'No encoder found for "{data_type}" data type!'.format(
                    data_type=encoder
                )
            )
        output_scrap = encoder.encode(scrap, **kwargs)
        # Run validation on encoded data
        scrap_to_payload(output_scrap)
        return output_scrap
github nteract / scrapbook / scrapbook / encoders.py View on Github external
def decode(self, scrap, **kwargs):
        """
        Finds the register for the given encoder and translates the scrap's data
        from a string or JSON type to an object of the encoder output type.

        Parameters
        ----------
        scrap: Scrap
            A partially filled in scrap with data that needs decoding
        """
        # Run validation on encoded data
        scrap_to_payload(scrap)
        loader = self._encoders.get(scrap.encoder)
        if not loader:
            raise ScrapbookMissingEncoder(
                'No encoder found for "{}" encoder type!'.format(scrap.encoder)
            )
        return loader.decode(scrap, **kwargs)