Commit a3b28274 by Timothée Peignier

Ensure we flatten compressor command too

parent 012b1149
...@@ -4,15 +4,17 @@ import base64 ...@@ -4,15 +4,17 @@ import base64
import os import os
import posixpath import posixpath
import re import re
import subprocess
from itertools import takewhile from itertools import takewhile
from django.contrib.staticfiles.storage import staticfiles_storage from django.contrib.staticfiles.storage import staticfiles_storage
from django.utils.encoding import smart_bytes, force_text from django.utils.encoding import smart_bytes, force_text
from django.utils.six import string_types
from pipeline.conf import settings from pipeline.conf import settings
from pipeline.utils import to_class, relpath
from pipeline.exceptions import CompressorError from pipeline.exceptions import CompressorError
from pipeline.utils import to_class, relpath
URL_DETECTOR = r"""url\((['"]){0,1}\s*(.*?)["']{0,1}\)""" URL_DETECTOR = r"""url\((['"]){0,1}\s*(.*?)["']{0,1}\)"""
URL_REPLACER = r"""url\(__EMBED__(.+?)(\?\d+)?\)""" URL_REPLACER = r"""url\(__EMBED__(.+?)(\?\d+)?\)"""
...@@ -234,8 +236,14 @@ class CompressorBase(object): ...@@ -234,8 +236,14 @@ class CompressorBase(object):
class SubProcessCompressor(CompressorBase): class SubProcessCompressor(CompressorBase):
def execute_command(self, command, content): def execute_command(self, command, content):
import subprocess argument_list = []
pipe = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, for flattening_arg in command:
if isinstance(flattening_arg, string_types):
argument_list.append(flattening_arg)
else:
argument_list.extend(flattening_arg)
pipe = subprocess.Popen(argument_list, shell=True, stdout=subprocess.PIPE,
stdin=subprocess.PIPE, stderr=subprocess.PIPE) stdin=subprocess.PIPE, stderr=subprocess.PIPE)
if content: if content:
content = smart_bytes(content) content = smart_bytes(content)
......
...@@ -7,7 +7,6 @@ from django.test import TestCase ...@@ -7,7 +7,6 @@ from django.test import TestCase
from pipeline.collector import default_collector from pipeline.collector import default_collector
from pipeline.compilers import Compiler, CompilerBase, SubProcessCompiler from pipeline.compilers import Compiler, CompilerBase, SubProcessCompiler
from pipeline.conf import settings
from pipeline.exceptions import CompilerError from pipeline.exceptions import CompilerError
from tests.utils import _, pipeline_settings from tests.utils import _, pipeline_settings
......
...@@ -171,10 +171,9 @@ class CompressorTest(TestCase): ...@@ -171,10 +171,9 @@ class CompressorTest(TestCase):
""", output) """, output)
def test_compressor_subprocess_unicode(self): def test_compressor_subprocess_unicode(self):
tests_path = os.path.dirname(os.path.dirname(__file__)) path = os.path.dirname(os.path.dirname(__file__))
output = SubProcessCompressor(False).execute_command( content = io.open(path + '/assets/css/unicode.css', encoding="utf-8").read()
'/usr/bin/env cat', output = SubProcessCompressor(False).execute_command(('cat',), content)
io.open(tests_path + '/assets/css/unicode.css', encoding="utf-8").read())
self.assertEqual(""".some_class { self.assertEqual(""".some_class {
// Some unicode // Some unicode
content: "áéíóú"; content: "áéíóú";
......
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf import settings
from django.contrib.staticfiles import finders from django.contrib.staticfiles import finders
from django.contrib.staticfiles.storage import staticfiles_storage from django.contrib.staticfiles.storage import staticfiles_storage
from django.core.management import call_command from django.core.management import call_command
......
...@@ -7,7 +7,6 @@ from django.template import Template, Context ...@@ -7,7 +7,6 @@ from django.template import Template, Context
from django.test import TestCase from django.test import TestCase
from pipeline.jinja2 import PipelineExtension from pipeline.jinja2 import PipelineExtension
from pipeline.conf import settings
from tests.utils import pipeline_settings from tests.utils import pipeline_settings
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment