How to use the whitenoise.storage.HelpfulExceptionMixin function in whitenoise

To help you get started, we’ve selected a few whitenoise 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 evansd / whitenoise / tests / test_storage.py View on Github external
def test_make_helpful_exception(_compressed_manifest_storage):
    class TriggerException(HashedFilesMixin):
        def exists(self, path):
            return False

    exception = None
    try:
        TriggerException().hashed_name("/missing/file.png")
    except ValueError as e:
        exception = e
    helpful_exception = HelpfulExceptionMixin().make_helpful_exception(
        exception, "styles/app.css"
    )
    assert isinstance(helpful_exception, MissingFileError)
github evansd / whitenoise / whitenoise / storage.py View on Github external
message = self.ERROR_MSG.format(
                    orig_message=message,
                    filename=name,
                    missing=match.group(1),
                    ext=extension,
                )
                exception = MissingFileError(message)
        return exception


class MissingFileError(ValueError):
    pass


class CompressedManifestStaticFilesStorage(
    HelpfulExceptionMixin, ManifestStaticFilesStorage
):
    """
    Extends ManifestStaticFilesStorage instance to create compressed versions
    of its output files and, optionally, to delete the non-hashed files (i.e.
    those without the hash in their name)
    """

    _new_files = None

    def post_process(self, *args, **kwargs):
        files = super(CompressedManifestStaticFilesStorage, self).post_process(
            *args, **kwargs
        )
        if not kwargs.get("dry_run"):
            files = self.post_process_with_compression(files)
        return files
github evansd / whitenoise / whitenoise / storage.py View on Github external
def post_process(self, *args, **kwargs):
        files = super(HelpfulExceptionMixin, self).post_process(*args, **kwargs)
        for name, hashed_name, processed in files:
            if isinstance(processed, Exception):
                processed = self.make_helpful_exception(processed, name)
            yield name, hashed_name, processed