import subprocess

from compress.conf import settings
from compress.filter_base import FilterBase, FilterError

class YUICompressorFilter(FilterBase):

    def filter_common(self, content, type_, arguments):
        command = '%s --type=%s %s' % (settings.COMPRESS_YUI_BINARY, type_, arguments)

        if self.verbose:
            command += ' --verbose'

        p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, \
            stdin=subprocess.PIPE, stderr=subprocess.PIPE)
        p.stdin.write(content)
        p.stdin.close()

        filtered_css = p.stdout.read()
        p.stdout.close()

        err = p.stderr.read()
        p.stderr.close()

        if p.wait() != 0:
            if not err:
                err = 'Unable to apply YUI Compressor filter'

            raise FilterError(err)

        if self.verbose:
            print err

        return filtered_css

    def filter_js(self, js):
        return self.filter_common(js, 'js', settings.COMPRESS_YUI_CSS_ARGUMENTS)

    def filter_css(self, css):
        return self.filter_common(css, 'css', settings.COMPRESS_YUI_JS_ARGUMENTS)
import subprocess

from compress.conf import settings
from compress.filter_base import FilterBase, FilterError

class YUICompressorFilter(FilterBase):

    def filter_common(self, content, type_, arguments):
        command = '%s --type=%s %s' % (settings.COMPRESS_YUI_BINARY, type_, arguments)

        if self.verbose:
            command += ' --verbose'

        p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, \
            stdin=subprocess.PIPE, stderr=subprocess.PIPE)
        p.stdin.write(content)
        p.stdin.close()

        filtered_css = p.stdout.read()
        p.stdout.close()

        err = p.stderr.read()
        p.stderr.close()

        if p.wait() != 0:
            if not err:
                err = 'Unable to apply YUI Compressor filter'

            raise FilterError(err)

        if self.verbose:
            print err

        return filtered_css

    def filter_js(self, js):
        return self.filter_common(js, 'js', settings.COMPRESS_YUI_JS_ARGUMENTS)

    def filter_css(self, css):
        return self.filter_common(css, 'css', settings.COMPRESS_YUI_CSS_ARGUMENTS)
Fix YUI arg passing, had CSS/JS flipped
Fix YUI arg passing, had CSS/JS flipped
