
    Of7                     @   d dl Z d dlZd dlmZ d dlZd dlmZmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dl m!Z! d dl"m#Z#m$Z$ d dl%m&Z& d dl'm(Z( ddgZ) G d dej*                  Z+ G d de          Z,dS )    N)import_module)TemplateDoesNotExistTemplateSyntaxError)Path)apps)settings)ContentFile)BaseCommandCommandError)engines)Origin)get_template)force_bytes)gettext_lazy)APPS_INCLUDE_DIRS)SassProcessor)SassFileStorage	find_file)SassSrcNode)get_custom_functionsr   Commandc                       e Zd Zd Zd ZdS )FuncCallVisitorc                 "    || _         g | _        d S N)	func_name
sass_files)selfr   s     `/var/www/html/env/lib/python3.11/site-packages/sass_processor/management/commands/compilescss.py__init__zFuncCallVisitor.__init__   s    "    c                 R   	 |j         j        | j        k    rjt          d t	          j        |          D                       d         d         }| j                            t          ||j	        d                              n# t          $ r Y nw xY w|                     |           d S )Nc              3   $   K   | ]\  }}||fV  d S r    ).0abs      r   	<genexpr>z-FuncCallVisitor.visit_Call.<locals>.<genexpr>&   s*      EEtq!QFEEEEEEr!   argsr   )funcidr   dictastiter_fieldsr   appendgetattr_fieldsAttributeErrorgeneric_visit)r   nodearg0s      r   
visit_CallzFuncCallVisitor.visit_Call#   s    	y|t~--EEst/D/DEEEEEfMaP&&wtT\!_'E'EFFF 	 	 	D	4     s   A?B 
BBN)__name__
__module____qualname__r    r6   r$   r!   r   r   r      s2          ! ! ! ! !r!   r   c                   ~     e Zd ZdZ e            Z fdZd Zd Zd Z	d Z
d Zd Zd	 Zd
 Zd Zd Zd Zd Z xZS )r   z@Compile SASS/SCSS into CSS outside of the request/response cyclec                     d | _         t          t          ddg          | _        t          t          dt          j        rdnd          | _        d| _        t                                                       d S )NSASS_TEMPLATE_EXTSz.htmlSASS_OUTPUT_STYLEnested
compressedF)	parserr0   r   template_extsDEBUGsass_output_styleuse_storagesuperr    )r   	__class__s    r   r    zCommand.__init__1   sl    $X/CgYOO!(3F5=^)U"W "W r!   c           	      D   |                     ddddt          d                     |                     ddddt          d	                     |                     d
ddt          d                     |                     ddt          t          d                     d S )Nz--delete-files
store_truedelete_filesFz8Delete generated `*.css` files instead of creating them.)actiondestdefaulthelpz--use-storagerD   z\Store resulting .css in configured storage. Default: store each css side-by-side with .scss.z--engineenginedjangoz=Set templating engine used (django, jinja2). Default: django.)rK   rL   rM   z--sass-precisionsass_precisionzcSet the precision for numeric computations in the SASS processor. Default: settings.SASS_PRECISION.)rK   typerM   )add_argument_int)r   r@   s     r   add_argumentszCommand.add_arguments9   s    MNN 	 	
 	
 	
 	 F G G 	 	
 	
 	
 	RSS	 	 	
 	
 	
 	!uw w	 	 	
 	
 	
 	
 	
r!   c                 R   g }t          j                    D ]I}t          |d          r7|                    |j                            |j        j                             Jg }|D ]B}t          |d          r|                    |j                   -|                    |           C|S )NrN   loaders)r   allhasattrextendrN   get_template_loadersrW   r/   )r   template_source_loaderserW   loaders        r   get_loaderszCommand.get_loadersW   s    "$ 	 	Aq(## '..H11(   
  . 	' 	'Fvy)) 'v~....v&&&&r!   c                     |dk    r'ddl m} t          j                    } |d|          }n<|dk    rddlm}  |d          }n#t          d	                    |
                    |S )Njinja2r   )Jinja2Parserzutf-8)charsetenvrO   )DjangoParser)rc   z/Invalid templating engine '{engine}' specified.)rN   )compressor.offline.jinja2rb   r   COMPRESS_JINJA2_GET_ENVIRONMENTcompressor.offline.djangore   r   format)r   rN   rb   rd   r@   re   s         r   
get_parserzCommand.get_parsert   s    X>>>>>>:<<C!\'s;;;FFx>>>>>>!\'222FFAHH! I    
 r!   c           	      T   t          |d                   | _        |d         | _        |d         | _        d |                    dg           D             pdg}|D ]L}|                     |          | _        	 t          |d         pt          j                  | _	        n$# t          t          t          f$ r
 d | _	        Y nw xY wg | _        |                                 D ]}| j        dk    r.| j                            d	                    |                     n'| j        dk    r| j                            d
d           	 |                     |           y# t&          t(          f$ r6}d}| j                            |                    ||                      d }~ww xY w|                                 }|D ]>}	|                     |	           | j        dk    r| j                            d
d           ?| j        dk    r| j                            d           | j        rCd}| j                            |                    t1          | j                                       d}| j                            |                    t1          | j                                       Nd S )N	verbosityrI   rD   c                 6    g | ]}|                                 S r$   )strip)r%   r]   s     r   
<listcomp>z"Command.handle.<locals>.<listcomp>   s     AAA17799AAAr!   r   rO   rP      zParsing file: {}. )endingzBSyntax error encountered processing {0}: {1}
Aborting compilation.r   z<Successfully deleted {0} previously generated `*.css` files.z3Successfully compiled {0} referred SASS/SCSS files.)rT   rl   rI   rD   getrj   r@   r   SASS_PRECISIONrP   r2   	TypeError
ValueErrorprocessed_filesfind_sourcesstdoutwriteri   parse_sourceSyntaxErrorIndentationErrorstderrfind_templatesparse_templatelen)
r   r)   optionsr   rN   	py_sourceexcmsg	templatestemplate_names
             r   handlezCommand.handle   s   W[122#N3"=1AAgkk)R&@&@AAAOhZ %	M %	MF//&11DK+&)'2B*C*^xG^&_&_##"Iz: + + +&*###+ $&D  "..00 
 
	>A%%K%%&8&?&?	&J&JKKKK^q((K%%c"%555%%i0000#%56   _CK%%cjjC&@&@AAA ++--I!* 6 6##M222>A%%K%%c"%555 ~!!!!"%%%$ MXCK%%cjjT5I1J1J&K&KLLLLOCK%%cjjT5I1J1J&K&KLLLK%	M %	Ms*   8&BC ?C EF(1FFc           	   #     	K   t          j        d          }|j        rt          j                    }|D ]}g }t	          j        |j                  D ]\  	}}	fd|D             rd|vr|                    	           /|D ]j}t          j                            |          \  }}|dk    r+t          j        	                    t          j        
                    	|                    V  kdS dS )zR
        Look for Python sources available for the current configuration.
        sass_processorc                 >    g | ]}                     |          d S )T)
startswith)r%   idirroots     r   ro   z(Command.find_sources.<locals>.<listcomp>   s*    NNN8M8MNNNNr!   z__init__.pyz.pyN)r   get_app_configauto_includeget_app_configsoswalkpathr/   splitextabspathjoin)
r   
app_configapp_configsignore_dirsdirsfilesfilenamebasenameextr   s
            @r   ry   zCommand.find_sources   s6      ()9::
" 	L.00K) L L
 )+)A)A 
L 
L%D$NNNNNNN ! $E11#**4000 $) L L(*(8(8(B(B#%<<$ goobgll4.J.JKKKKKK	L
L		L 	LL Lr!   c                 f   t          d          }t          j        t          |                                                    }|                    |           |j        D ]Q}t          |          }|r	|| j        v r| j	        r| 
                    ||           ;|                     ||           RdS )z
        Extract the statements from the given file, look for function calls
        `sass_processor(scss_file)` and compile the filename into CSS.
        r   N)r   r-   parser   
read_bytesvisitr   r   rx   rI   delete_filecompile_sass)r   r   callvisitortreesass_fileurlsass_filenames         r   r|   zCommand.parse_source   s    
 &&677yh224455$'2 	? 	?L%l33M  MT5I$I$I  ?  ====!!->>>>	? 	?r!   c                 *   
 t                      }                                 D ]n}	 t          |j                  }t	          |d|j                  } |d          }|                    d |D                        X# t          t          f$ r Y kw xY w|st          d          t                      }|D ]L}t          j        t          |                    D ](\  
}}	|                    
 fd|	D                        )M|st          d          |S )zT
        Look for templates and extract the nodes containing the SASS file.
        get_template_sourcesrr   c                 J    g | ] }t          |t                    r|j        n|!S r$   )
isinstancer   name)r%   ts     r   ro   z*Command.find_templates.<locals>.<listcomp>   s-    ___
1f(=(=Daff1___r!   zXNo template paths found. None of the configured template loaders provided template pathsc              3      K   | ]Y                     d           t          fdj        D                       7t          j                                      V  ZdS )rq   c              3   B   K   | ]}                     |          V  d S r   )endswith)r%   r   r   s     r   r(   z3Command.find_templates.<locals>.<genexpr>.<genexpr>   s/      $V$VCT]]3%7%7$V$V$V$V$V$Vr!   N)r   anyrA   r   r   r   )r%   r   r   r   s    @r   r(   z)Command.find_templates.<locals>.<genexpr>   s       !X !X%)$//#:N:N!X!$$V$V$V$V4CU$V$V$V!V!V!XdD!9!9 !X !X !X !X !X !Xr!   z[No templates found. Make sure your TEMPLATE_LOADERS and TEMPLATE_DIRS settings are correct.)setr_   r   r8   r0   r   updateImportErrorr2   r   r   r   str)r   pathsr^   moduler   template_sourcesr   r   rS   r   r   s   `         @r   r   zCommand.find_templates   s    &&(( 	 	F&v'899'.2F4O(Q (Q$#7#7#;#; __N^___````0    	ljl l lEE	 	X 	XD"$'#d))"4"4 X Xa   !X !X !X !X !X-2!X !X !X X X X XX  	omo o os   AA==BBc                 6   	 | j                             |          }n# t          $ r< | j        dk    r-| j                            d                    |                     Y d S t          $ rD}| j        dk    r.| j                            d                    ||                     Y d }~d S d }~wt          $ r< | j        dk    r-| j                            d                    |                     Y d S t          $ r; | j        dk    r-| j                            d                    |                     Y nw xY w	 t          |                     ||                    }|D ]`}t          |j                  }|r	|| j        v r"| j        r|                     ||j                   E|                     ||j                   ad S # t$          $ rJ}| j        dk    r4| j                            d                    ||                     Y d }~d S Y d }~d S d }~ww xY w)Nr   z
Unreadable template at: {}z
Invalid template {}: {}z
Non-existent template at: {}z4
UnicodeDecodeError while trying to read template {}originalz
Error parsing template {}: {})r@   r   IOErrorrl   r   r{   ri   r   r   UnicodeDecodeErrorlist
walk_nodesr   r   rx   rI   r   r   	Exception)r   r   templater]   nodesr4   r   s          r   r   zCommand.parse_template   s   	c{((77HH 	 	 	~!!!!"@"G"G"V"VWWWFF" 	 	 	~!!!!"="D"D]TU"V"VWWWFFFFF# 	 	 	~!!!!"B"I"I-"X"XYYYFF! 	c 	c 	c~!!!!KRRS`aac c c	c	@HEEFFE  @ @ )$) 4 4$ 9M(M(M$ @$$]DI>>>>%%mTY????@ @  	^ 	^ 	^~!!!!"C"J"J=Z["\"\]]]]]]]]] "!!!!!	^sB    AD7#	D7,9B++AD73AD76D7;$G 
H9HHc                    |t           j        t          z   t                      d}| j        r
| j        |d<   | j        r
| j        |d<   t          j        di |}|                     |||           | j	        
                    |           | j        dk    r/| j                            d                    |                     dS dS )z6
        Compile the given SASS file into CSS
        )r   include_pathscustom_functions	precisionoutput_stylerp   zCompiled SASS/SCSS file: '{0}'
Nr$   )r   r   r   r   rP   rC   sasscompilesave_to_destinationrx   r/   rl   rz   r{   ri   )r   r   r   compile_kwargscontents        r   r   zCommand.compile_sass  s    
 &*8;LL 4 6 6
 

  	>*.*=N;'! 	D-1-CN>*,0000  -FFF##M222>AK@GGVVWWWWW r!   c                 6   | j         r_t          j                            |          d         dz   }| j                            |          r| j                            |           n`dS t          j                            |          d         dz   }t          j                            |          rt          j        |           ndS | j	        
                    |           | j        dk    r/| j                            d                    |                     dS dS )zb
        Delete a *.css file, but only if it has been generated through a SASS/SCSS file.
        r   .cssNrp   zDeleted '{0}'
)rD   r   r   r   storageexistsdeleteisfileremoverx   r/   rl   rz   r{   ri   )r   r   r   destpaths       r   r   zCommand.delete_file)  s     	w''55a86AH|""8,, ##H----w''66q9FBHw~~h'' 	(######M222>AK/66x@@AAAAA r!   c                    | j         rt          j                            |          \  }}|dz   }| j                            |          r| j                            |           | j                            |t          |                     d S t          j                            |          \  }}|dz   }t          |d          5 }|
                    t          |                     d d d            d S # 1 swxY w Y   d S )Nr   wb)rD   r   r   r   r   r   r   saver	   openr{   r   )r   r   r   r   r   rS   r   fhs           r   r   zCommand.save_to_destination=  s2    
	/'**<88KHa&(H|""8,, .##H---LhG(<(<====='**=99KHa&(Hh%% /W--.../ / / / / / / / / / / / / / / / / /s   #C44C8;C8c              #   (  K   	 | j                             ||          }n-# t          $ r  | j                             ||d          }Y nw xY w|D ]A}t          |t                    r|j        r|V  #|                     ||          D ]}|V  BdS )zX
        Iterate over the nodes recursively yielding the templatetag 'sass_src'
        r   N)r   context)r@   get_nodelistrv   r   r   is_sassr   )r   r4   r   nodelists       r   r   zCommand.walk_nodesJ  s      	W{//x/HHHH 	W 	W 	W{//xQU/VVHHH	W 	 	D$,, < JJJ OOD8ODD  DJJJJ	 	s   ! 'A
A)r7   r8   r9   rM   r   r   r    rU   r_   rj   r   ry   r|   r   r   r   r   r   r   __classcell__)rF   s   @r   r   r   -   s       MDoG    
 
 
<  :   +M +M +MZL L L*? ? ?"  8!@ !@ !@FX X X&B B B(/ / /      r!   )-r   r-   	importlibr   r   compressor.exceptionsr   r   pathlibr   django.appsr   django.confr   django.core.files.baser	   django.core.management.baser
   r   django.templater   django.template.baser   django.template.loaderr   django.utils.encodingr   django.utils.translationr   rS   sass_processor.appsr   sass_processor.processorr   sass_processor.storager   r   %sass_processor.templatetags.sass_tagsr   sass_processor.utilsr   __all__NodeVisitorr   r   r$   r!   r   <module>r      s   				 



 # # # # # #  K K K K K K K K                         . . . . . . A A A A A A A A # # # # # # ' ' ' ' ' '      - - - - - - 6 6 6 6 6 6 1 1 1 1 1 1 2 2 2 2 2 2 = = = = = = = = = = = = = = 5 5 5 5 5 59
%! ! ! ! !co ! ! ! l l l l lk l l l l lr!   