Skip to content

Commit

Permalink
Extract method .create_compressor x2 (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
hartwork committed Nov 19, 2018
1 parent 4cdbe2a commit 7000c93
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions whitenoise/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ def fallback_post_process(self, paths, dry_run=False, **options):
for path in paths:
yield path, None, False

def create_compressor(self, **kwargs):
return Compressor(**kwargs)

def post_process_with_compression(self, files):
extensions = getattr(settings,
'WHITENOISE_SKIP_COMPRESS_EXTENSIONS', None)
compressor = Compressor(extensions=extensions, quiet=True)
compressor = self.create_compressor(extensions=extensions, quiet=True)
for name, hashed_name, processed in files:
yield name, hashed_name, processed
if isinstance(processed, Exception):
Expand Down Expand Up @@ -171,10 +174,13 @@ def delete_files(self, files_to_delete):
if e.errno != errno.ENOENT:
raise

def create_compressor(self, **kwargs):
return Compressor(**kwargs)

def compress_files(self, names):
extensions = getattr(settings,
'WHITENOISE_SKIP_COMPRESS_EXTENSIONS', None)
compressor = Compressor(extensions=extensions, quiet=True)
compressor = self.create_compressor(extensions=extensions, quiet=True)
for name in names:
if compressor.should_compress(name):
path = self.path(name)
Expand Down

0 comments on commit 7000c93

Please sign in to comment.