
    "dL                         d Z ddlmZmZ ddlmZmZ ddlZddlZddl	Z	ddl
mZmZ ddlmZmZmZ ddlmZ eeedZdZ ej*                  e      Zd	 Zdd
Zd ZddZddZy)z4qtsass - Compile SCSS files to valid Qt stylesheets.    )absolute_importprint_function)MappingSequenceN)
qt_conformscss_conform)qlineargradientqradialgradientrgba)qss_importerFc           	         |j                  dt               |j                  dg        |j                  dg        |j                  dg        t        |d   t              r!t	        |d         dt        |d    fgz   |d<   n&t        dj                  t        |d                     t        |d   t              r0t        t        fi |d   D ci c]  }|j                  | c}|d<   nRt        |d   t              r|d   j                  t               n&t        dj                  t        |d                     	 t        |       |d<   t         j%                  t&        j(                        rmdd
lm} t        |      }d|d<   t         j/                  d       t         j/                   ||             t         j/                  dj                  |d                	 t1        t3        j4                  di |      S c c}w # t        $ r t         j#                  d	        w xY w# t2        j6                  $ r t         j#                  d        w xY w)a=  
    Conform and Compile QtSASS source code to CSS.

    This function conforms QtSASS to valid SCSS before passing it to
    sass.compile. Any keyword arguments you provide will be combined with
    qtsass's default keyword arguments and passed to sass.compile.

    .. code-block:: python

        >>> import qtsass
        >>> qtsass.compile("QWidget {background: rgb(0, 0, 0);}")
        QWidget {background:black;}

    :param string: QtSASS source code to conform and compile.
    :param kwargs: Keyword arguments to pass to sass.compile
    :returns: CSS string
    source_commentscustom_functions	importersinclude_pathsr   z&Expected Sequence for importers got {}z8Expected Sequence or Mapping for custom_functions got {}stringzFailed to conform source code)pformatzConformed SCSS<...>zCalling sass.compile with:zConformed scss:
{}zFailed to compile source code )
setdefaultDEFAULT_SOURCE_COMMENTS
isinstancer   listr   
ValueErrorformattypedictDEFAULT_CUSTOM_FUNCTIONS__name__r   updater   	Exception_logerrorisEnabledForloggingDEBUGpprintr   debugr   sasscompileCompileError)r   kwargsfnr   
log_kwargss        ,/usr/lib/python3/dist-packages/qtsass/api.pyr)   r)   +   s2   $ ')@A
("-
k2&
or* &%x0#F;$78!"L&2I$J KL M{  ""(&f[.A)B"CE 	E &+,h7%)$&6   235 {{B 5&6!" 
F-.	8!"))*BC ""(&f5G.H)I"JL 	L'/x
 '"&\
4
8

/0

7:&'

(//x0@AB$,,001135  

23  

23s   G:=G? H" ? H"*Ic                 r   t         j                  j                  t         j                  j                  |             }|j	                  d|g       t        | d      5 }|j                         }ddd       t        j                  dj                  t         j                  j                  |                    t        fi |}|t         j                  j                  t         j                  j                  |            }t         j                  j                  |      st        j                  |       t        |d      5 }|j                  |       t        j                  dj                  t         j                  j                  |                   ddd       |S |S # 1 sw Y   4xY w# 1 sw Y   |S xY w)a  Compile and return a QtSASS file as Qt compliant CSS.
    Optionally save to a file.

    .. code-block:: python

        >>> import qtsass
        >>> qtsass.compile_filename("dummy.scss", "dummy.css")
        >>> css = qtsass.compile_filename("dummy.scss")

    :param input_file: Path to QtSass file.
    :param output_file: Optional path to write Qt compliant CSS.
    :param kwargs: Keyword arguments to pass to sass.compile
    :returns: CSS string
    r   rNzCompiling {}...wzCreated CSS file {})ospathabspathdirnamer   openreadr!   infor   normpathr)   isdirmakedirswrite)	
input_fileoutput_filer+   
input_rootfr   cssoutput_rootcss_files	            r.   compile_filenamerD   m   s@    !<=J
o
|4	j#	 ! 	II&&rww'7'7
'CDE
&
#F
#Cggoobggook&BCww}}[)KK$+s# 	0xNN3II+22  -/ 0	0
 J3J! 	0
 Js   F AF,F),F6c                    |j                  d| g       d }t        j                  |       D ]"  \  }}}t        j                  j	                  ||       }t        j                  j                  ||      }t        |      }	|	d   |gz   |	d<   |D 
cg c]  }
 ||
      s|
 c}
D ]  }t        j                  j                  ||      }t        j                  j                  |      d   dz   }t        j                  j                  ||      }t        j                  j                  |      st        j                  |       t        ||fi |	  % yc c}
w )au  Compiles QtSASS files in a directory including subdirectories.

    .. code-block:: python

        >>> import qtsass
        >>> qtsass.compile_dirname("./scss", "./css")

    :param input_dir: Directory containing QtSass files.
    :param output_dir: Directory to write compiled Qt compliant CSS files to.
    :param kwargs: Keyword arguments to pass to sass.compile
    r   c                 L    | j                  d       xr | j                  d      S )N_z.scss)
startswithendswith)	file_names    r.   is_validz!compile_dirname.<locals>.is_valid   s&    '',,L1C1CG1LL    r   z.cssN)r   r2   walkr3   relpathjoinr   splitextr:   r;   rD   )	input_dir
output_dirr+   rK   rootrG   filesrelative_rootrB   fkwargsr@   rJ   	scss_pathrC   css_paths                  r.   compile_dirnamerY      s    o	{3M ''), =ai8ggll:}=v,#*?#;tf#D %*:hqk!: 	=IT95Iww''	215>Hww||K:H77==-K(Y<G<	== ;s   EEc                 L   | Et         j                  j                  dd      }|dv rt        j                  } nt        j
                  } t        j                  d      }|j                  |        |r|j                  |       t        j                  dj                  |              y)ae  Enable logging for qtsass.

    Sets the qtsass logger's level to:
        1. the provided logging level
        2. logging.DEBUG if the QTSASS_DEBUG envvar is a True value
        3. logging.WARNING

    .. code-block:: python
        >>> import logging
        >>> import qtsass
        >>> handler = logging.StreamHandler()
        >>> formatter = logging.Formatter('%(level)-8s: %(name)s> %(message)s')
        >>> handler.setFormatter(formatter)
        >>> qtsass.enable_logging(level=logging.DEBUG, handler=handler)

    :param level: Optional logging level
    :param handler: Optional handler to add
    NQTSASS_DEBUGF)1trueTrueTRUEonOnONqtsasszlogging level set to {}.)r2   environgetr$   r%   WARNING	getLoggersetLevel
addHandlerr!   r'   r   )levelhandlerr'   loggers       r.   enable_loggingrm      s}    & }

~u5CCMMEOOEx(F
OOE'"JJ)0078rL   c                 .   t         j                  j                  |       r*t         j                  j                  |       }|xs t        }n7t         j                  j                  |       r| }|xs t        }nt        d      |ddlm	}  |||| |f      }|S )a  
    Watches a source file or directory, compiling QtSass files when modified.

    The compiler function defaults to compile_filename when source is a file
    and compile_dirname when source is a directory.

    :param source: Path to source QtSass file or directory.
    :param destination: Path to output css file or directory.
    :param compiler: Compile function (optional)
    :param Watcher: Defaults to qtsass.watchers.Watcher (optional)
    :returns: qtsass.watchers.Watcher instance
    z+source arg must be a dirname or filename...r   )Watcher)
r2   r3   isfiler5   rD   r:   rY   r   qtsass.watchersro   )sourcedestinationcompilerro   	watch_dirwatchers         r.   watchrw      s|     
ww~~fGGOOF+	//	v		.FGG+iFK+@AGNrL   )N)NN)__doc__
__future__r   r   collections.abcr   r   r$   r2   r(   qtsass.conformersr   r   qtsass.functionsr	   r
   r   qtsass.importersr   r   r   rg   r   r!   r)   rD   rY   rm   rw   r   rL   r.   <module>r~      sy    ; 7 .  	  7 C C ) '& 
    w"?D"J=D9BrL   