<s> """<STR_LIT>""" <EOL> import os <EOL> from os import path <EOL> import tempfile <EOL> import shutil <EOL> import subprocess <EOL> from io import open <EOL> from webassets import six <EOL> from webassets . exceptions import FilterError <EOL> from webassets . filter import Filter , option <EOL> __all__ = ( '<STR_LIT>' , ) <EOL> class CompassConfig ( dict ) : <EOL> """<STR_LIT>""" <EOL> def to_string ( self ) : <EOL> def string_rep ( val ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( val , bool ) : <EOL> return six . text_type ( val ) . lower ( ) <EOL> elif isinstance ( val , six . string_types ) and val . startswith ( '<STR_LIT::>' ) : <EOL> return six . text_type ( val ) <EOL> elif isinstance ( val , dict ) : <EOL> return u'<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( "<STR_LIT>" % i for i in val . items ( ) ) <EOL> elif isinstance ( val , tuple ) : <EOL> val = list ( val ) <EOL> return repr ( val ) <EOL> return u'<STR_LIT:\n>' . join ( [ '<STR_LIT>' % ( k , string_rep ( v ) ) for k , v in self . items ( ) ] ) <EOL> class Compass ( Filter ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> max_debug_level = None <EOL> options = { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : option ( '<STR_LIT>' , type = list ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def open ( self , out , source_path , ** kw ) : <EOL> """<STR_LIT>""" <EOL> tempout_dir = path . normpath ( <EOL> path . join ( path . dirname ( kw [ '<STR_LIT>' ] ) , '<STR_LIT>' ) <EOL> ) <EOL> tempout = tempfile . mkdtemp ( dir = tempout_dir ) <EOL> old_wd = os . getcwd ( ) <EOL> os . chdir ( tempout ) <EOL> try : <EOL> sassdir = path . normpath ( path . dirname ( source_path ) ) <EOL> source_path = path . normpath ( source_path ) <EOL> config = CompassConfig ( <EOL> project_path = self . ctx . directory , <EOL> http_path = self . ctx . url , <EOL> http_images_dir = '<STR_LIT>' , <EOL> http_stylesheets_dir = '<STR_LIT>' , <EOL> http_fonts_dir = '<STR_LIT>' , <EOL> http_javascripts_dir = '<STR_LIT>' , <EOL> images_dir = '<STR_LIT>' , <EOL> output_style = '<STR_LIT>' , <EOL> ) <EOL> if self . config : <EOL> config . update ( self . config ) <EOL> config_file = path . join ( tempout , '<STR_LIT>' ) <EOL> f = open ( config_file , '<STR_LIT:w>' ) <EOL> try : <EOL> f . write ( config . to_string ( ) ) <EOL> f . flush ( ) <EOL> finally : <EOL> f . close ( ) <EOL> command = [ self . compass or '<STR_LIT>' , '<STR_LIT>' ] <EOL> for plugin in self . plugins or [ ] : <EOL> command . extend ( ( '<STR_LIT>' , plugin ) ) <EOL> command . extend ( [ '<STR_LIT>' , sassdir , <EOL> '<STR_LIT>' , tempout , <EOL> '<STR_LIT>' , config_file , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> source_path ] ) <EOL> proc = subprocess . Popen ( command , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> shell = ( os . name == '<STR_LIT>' ) ) <EOL> stdout , stderr = proc . communicate ( ) <EOL> if proc . returncode != <NUM_LIT:0> : <EOL> raise FilterError ( ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) % ( <EOL> stderr , stdout , proc . returncode ) ) <EOL> guessed_outputfilename = path . splitext ( path . basename ( source_path ) ) [ <NUM_LIT:0> ] <EOL> guessed_outputfilepath = path . join ( tempout , guessed_outputfilename ) <EOL> output_file = open ( "<STR_LIT>" % guessed_outputfilepath , encoding = '<STR_LIT:utf-8>' ) <EOL> if config . get ( '<STR_LIT>' ) : <EOL> sourcemap_file = open ( "<STR_LIT>" % guessed_outputfilepath ) <EOL> sourcemap_output_filepath = path . join ( <EOL> path . dirname ( kw [ '<STR_LIT>' ] ) , <EOL> path . basename ( sourcemap_file . name ) <EOL> ) <EOL> if not path . exists ( path . dirname ( sourcemap_output_filepath ) ) : <EOL> os . mkdir ( path . dirname ( sourcemap_output_filepath ) ) <EOL> sourcemap_output_file = open ( sourcemap_output_filepath , '<STR_LIT:w>' ) <EOL> sourcemap_output_file . write ( sourcemap_file . read ( ) ) <EOL> try : <EOL> contents = output_file . read ( ) <EOL> out . write ( contents ) <EOL> finally : <EOL> output_file . close ( ) <EOL> finally : <EOL> os . chdir ( old_wd ) <EOL> shutil . rmtree ( tempout ) </s>
