'Sanitizes @import rules, remove duplicates @import rules, then compile'

def compile_css(self, cmd, source):

    imports = []
    def sanitize(matchobj):
        ref = matchobj.group(2)
        line = ('@import    "%s"%s' % (ref, matchobj.group(3)))
        if (('.' not in ref) and (line not in imports) and (not ref.startswith(('.', '/', '~')))):
            imports.append(line)
            return line
        msg = ("Local    import    '%s'    is    forbidden    for    security    reasons." % ref)
        _logger.warning(msg)
        self.css_errors.append(msg)
        return ''
    source = re.sub(self.rx_preprocess_imports, sanitize, source)
    try:
        compiler = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
    except Exception:
        msg = ('Could    not    execute    command    %r' % cmd[0])
        _logger.error(msg)
        self.css_errors.append(msg)
        return ''
    result = compiler.communicate(input=source.encode('utf-8'))
    if compiler.returncode:
        error = self.get_preprocessor_error(''.join(result), source=source)
        _logger.warning(error)
        self.css_errors.append(error)
        return ''
    compiled = result[0].strip().decode('utf8')
    return compiled
