
    +hJ                        d Z ddlmZ ddl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mZmZmZmZ dd	lmZmZ dd
lmZmZ dZdZdZ G d de      Z ee        G d de      Zd Z G d de      Z G d de      Z 	 ddl!Z"ddl#Z#ddl$m%Z%m&Z&  G d de%      Z' G d de"jP                        Z)edz   Z	 ddl+Z+ddlm,Z, d Z- e+j\                         d        Z/e/ja                         e,jb                  d                Z2e/ja                         e,jb                  d!               Z3e/ja                         e,jb                  d"               Z4ed#z   Zy# e*$ r Y w xY w# e*$ r Y yw xY w)$z4Integration of the ``webassets`` library with Flask.    )print_functionN)path)_request_ctx_stackcurrent_app)render_template_string)Bundle)BaseEnvironmentConfigStorageResolverenv_optionsurl_prefix_join)Filterregister_filter)PythonLoader
YAMLLoader)   r   )z>=2.0)Environmentr   FlaskConfigStorageFlaskResolverJinja2Filterc                   2     e Zd ZdZdZdZd fd	Zd Z xZS )r   z]Will compile all source files as Jinja2 templates using the standard
    Flask contexts.
    jinja2Nc                 @    t         t        |           |xs i | _        y N)superr   __init__context)selfr   	__class__s     ?/var/www/html/venv/lib/python3.12/site-packages/flask_assets.pyr   zJinja2Filter.__init__%   s    lD*,}"    c                 j    |j                  t        |j                         fi | j                         y r   )writer   readr   )r   _inoutsource_pathoutput_pathkws         r    inputzJinja2Filter.input)   s#    		(Dt||DEr!   r   )	__name__
__module____qualname____doc__namemax_debug_levelr   r*   __classcell__r   s   @r    r   r      s     DO%Fr!   r   c                   F     e Zd ZdZd Zd Z fdZd Zd Zd Z	d Z
 xZS )	r   ay  Uses the config object of a Flask app as the backend: either the app
    instance bound to the extension directly, or the current Flask app on
    the stack.

    Also provides per-application defaults for some values.

    Note that if no app is available, this config object is basically
    unusable - this is by design; this could also let the user set defaults
    by writing to a container not related to any app, which would be used
    as a fallback if a current app does not include a key. However, at least
    for now, I specifically made the choice to keep things simple and not
    allow global across-app defaults.
    c                 D    i | _         t        j                  | g|i | y r   )	_defaultsr
   r   )r   ar)   s      r    r   zFlaskConfigStorage.__init__A   s!    t.a.2.r!   c                 t    |j                         t        v rd|j                         z  S |j                         S )Nz	ASSETS_%s)lowerr   upperr   keys     r    _transform_keyz!FlaskConfigStorage._transform_keyE   s-    99;+%,,99;r!   c                     	 t         t        |   ||       y# t        $ r | j                  j                  ||       Y yw xY w)zWe may not always be connected to an app, but we still need
        to provide a way to the base environment to set it's defaults.
        N)r   r   
setdefaultRuntimeErrorr5   __setitem__)r   r;   valuer   s      r    r>   zFlaskConfigStorage.setdefaultK   s=    	3$d6sEB 	3NN&&sE2	3s    %A A c                 d    | j                  |      | j                  j                  j                  v S r   )r<   env_appconfigr:   s     r    __contains__zFlaskConfigStorage.__contains__T   s&    ""3'488==+?+???r!   c                    | j                  |      }|r|S | j                  |      }| j                  j                  rE|| j                  j                  j                  v r#| j                  j                  j                  |   S || j
                  v r| j
                  j                  |      S t        | d|z  d      }|r |       S t               )Nz_app_default_%sF)	_get_deprecatedr<   rC   rD   rE   r5   __getitem__getattrKeyError)r   r;   rA   
public_keydeffuncs        r    rI   zFlaskConfigStorage.__getitem__W   s    $$S)L ((-
88==TXX]]111xx}}++J77 $.. >>--c22 $ 1C 7?9 jr!   c                     | j                  ||      s3|| j                  j                  j                  | j	                  |      <   y y r   )_set_deprecatedrC   rD   rE   r<   )r   r;   rA   s      r    r@   zFlaskConfigStorage.__setitem__n   s:    ##C/=BDHHMM  !4!4S!9: 0r!   c                 d    | j                   j                  j                  | j                  |      = y r   )rC   rD   rE   r<   r:   s     r    __delitem__zFlaskConfigStorage.__delitem__r   s#    HHMM  !4!4S!9:r!   )r+   r,   r-   r.   r   r<   r>   rF   rI   r@   rQ   r1   r2   s   @r    r   r   2   s-    /3@.C;r!   r   c                     t        | d      s t        j                  | j                  d      S | j                  st        d| z        | j                  S )zReturn the static folder of the given Flask app
    instance, or module/blueprint.

    In newer Flask versions this can be customized, in older
    ones (<=0.6) the folder is fixed.
    static_folderstaticz1The referenced blueprint %s has no static folder.)hasattrr   join	root_pathhas_static_folder	TypeErrorrS   )app_or_blueprints    r    get_static_folderr[   v   sX     #_5 yy)33X>>-- #&67 8 	8)))r!   c                   N     e Zd ZdZd Zd Zd Zd Zd Z fdZ	d Z
d
d	Z xZS )r   a  Adds support for Flask blueprints.

    This resolver is designed to use the Flask staticfile system to
    locate files, by looking at directory prefixes (``foo/bar.png``
    looks in the static folder of the ``foo`` blueprint. ``url_for``
    is used to generate urls to these files.

    This default behaviour changes when you start setting certain
    standard *webassets* path and url configuration values:

    If a :attr:`Environment.directory` is set, output files will
    always be written there, while source files still use the Flask
    system.

    If a :attr:`Environment.load_path` is set, it is used to look
    up source files, replacing the Flask system. Blueprint prefixes
    are no longer resolved.
    c                 T   |j                   }	 t        |d      r5|j                  dd      \  }}t        |j                  |         }d|z  }|}n4|j                  dd      \  }}t        |j
                  |         }d|z  }|}|||fS # t        t        f$ r t        |      }d}Y #w xY w)zLSee if ``item`` has blueprint prefix, return (directory, rel_path).
        
blueprints/   z	%s.staticrT   )rD   rU   splitr[   r^   modules
ValueErrorrK   )	r   ctxitemapp	blueprintr/   	directoryendpointmodules	            r    split_prefixzFlaskResolver.split_prefix   s     hh	 sL)"&**S!"4	4-cnnY.GH	&2  $zz#q1-ckk&.AB	&/
 $((	 H% 	 )#.IH	 s   A5B B'&B'c                 z    |j                   j                  d      d uxs |j                   j                  d      d uS )Nrh   url)rE   getr   rd   s     r    use_webassets_system_for_outputz-FlaskResolver.use_webassets_system_for_output   s6    zz~~k*$6 1zz~~e$D0	1r!   c                 ,    t        |j                        S r   )bool	load_pathro   s     r     use_webassets_system_for_sourcesz.FlaskResolver.use_webassets_system_for_sources   s    CMM""r!   c                    | j                  |      rt        j                  | ||      S | j                  ||      \  }}}	 | j	                  ||      S # t
        $ r, t        j                  t        j                  ||            cY S w xY wr   )	rt   r   search_for_sourcerk   consider_single_directoryIOErrorr   normpathrV   )r   rd   re   rh   ri   s        r    rv   zFlaskResolver.search_for_source   s    
 005--dC>> %)$5$5c4$@!	4	=11)TBB 	= ==9d!;<<	=s    A 2BBc                     | j                  |      rt        j                  | |||      S | j                  ||      \  }}}t	        j
                  t	        j                  ||            S r   )rp   r   resolve_output_to_pathrk   r   ry   rV   )r   rd   targetbundlerh   rel_pathri   s          r    r{   z$FlaskResolver.resolve_output_to_path   s\    //4224ffMM )-(9(9#v(F%	8X}}TYYy(;<<r!   c                 v    | j                  |      rt        t        |   |||      S | j	                  |||      S r   )rt   r   r   resolve_source_to_urlconvert_item_to_flask_url)r   rd   filepathre   r   s       r    r   z#FlaskResolver.resolve_source_to_url   s=    005CCSWXX--c4BBr!   c                 v    | j                  |      rt        j                  | ||      S | j                  ||      S r   )rp   r   resolve_output_to_urlr   )r   rd   r|   s      r    r   z#FlaskResolver.resolve_output_to_url   s:    //411$VDD --c6::r!   c                    |j                   j                  j                  j                  d      r	 ddlm} nt|j                   j                  j                  j                  d      r	 ddlm} n=|j                   j                  j                  j                  d      r	 ddl	m} nddl
m} | j                  ||      \  }}}||t        |      d
z   d }	n|}	d}
t        j                  s4|j                   j                  j                         }
|
j!                          	  |||	      }|r|j#                  d      r|dd }||
r|
j%                          S S # t        $ r}t        d       |d}~ww xY w# t        $ r}t        d       |d}~ww xY w# t        $ r}t        d	       |d}~ww xY w# |
r|
j%                          w w xY w)a  Given a relative reference like `foo/bar.css`, returns
        the Flask static url. By doing so it takes into account
        blueprints, i.e. in the aformentioned example,
        ``foo`` may reference a blueprint.

        If an absolute path is given via ``filepath``, it will be
        used instead. This is needed because ``item`` may be a
        glob instruction that was resolved to multiple files.

        If app.config("FLASK_ASSETS_USE_S3") exists and is True
        then we import the url_for function from flask_s3,
        otherwise we import url_for from flask directly.

        If app.config("FLASK_ASSETS_USE_CDN") exists and is True
        then we import the url_for function from flask.
        FLASK_ASSETS_USE_S3r   )url_forz8You must have Flask S3 to use FLASK_ASSETS_USE_S3 optionNFLASK_ASSETS_USE_CDNz:You must have Flask CDN to use FLASK_ASSETS_USE_CDN optionFLASK_ASSETS_USE_AZUREzFYou must have Flask Azure Storage to use FLASK_ASSETS_USE_AZURE optionr`   )filenamezhttp:   )environmentrD   rE   rn   flask_s3r   ImportErrorprint	flask_cdnflask_azure_storageflaskrk   lenr   toptest_request_contextpush
startswithpop)r   rd   re   r   r   erh   r~   ri   r   	flask_ctxrm   s               r    r   z'FlaskResolver.convert_item_to_flask_url   s   " ??&&**+@A, __!!((,,-CD- __!!((,,-EF7
 &(,(9(9#t(D%	8XIq 0 12HH	!%%,,AACINN	 (X6C s~~g.!"g U  PQ  RS  ^_<  sS   E (E4 F #F0 	E1E,,E14	F=F

F	F-F((F-0Gr   )r+   r,   r-   r.   rk   rp   rt   rv   r{   r   r   r   r1   r2   s   @r    r   r      s1    &),1#="=C;? r!   r   c                        e Zd ZdZeZeZd fd	Ze	d        Z
d Zd Z e	eed      Zd Zd	 Z e	eed
      Zd Zd Zd Z xZS )r   zThis object is used to hold a collection of bundles and configuration.

    If it initialized with an instance of Flask application then webassets
    Jinja2 extension is automatically registered.
    c                 `    || _         t        t        |           |r| j	                  |       y y r   )rf   r   r   r   init_app)r   rf   r   s     r    r   zEnvironment.__init__/  s+    k4)+MM# r!   c                     | j                   | j                   S t        j                  }||j                   S 	 ddlm} |j                  }||j                   S 	 t        d      # t
        $ r Y t        d      w xY w)zThe application object to work with; this is either the app
        that we have been bound to, or the current application.
        r   )_app_ctx_stackzRassets instance not bound to an application, and no application in current context)rf   r   r   r   r   r   r?   )r   rd   r   app_ctxs       r    rD   zEnvironment._app5  s    
 8888O $$?77N	,$((G"{{" #
  D E 	E  	 D E 	E	s   A$ $	A:9A:c                 "    || j                   d<   y Nrh   rE   )r   rh   s     r    set_directoryzEnvironment.set_directoryS  s    #,K r!   c                     | j                   j                  d      | j                   d   S t        | j                        S r   )rE   rn   r[   rD   r   s    r    get_directoryzEnvironment.get_directoryU  s3    ;;??;'3;;{++ ++r!   z?The base directory to which all paths will be relative to.
    )docc                 "    || j                   d<   y Nrm   r   )r   rm   s     r    set_urlzEnvironment.set_url\  s     Er!   c                     | j                   j                  d      | j                   d   S | j                  j                  S r   )rE   rn   rD   static_url_pathr   s    r    get_urlzEnvironment.get_url^  s4    ;;??5!-;;u%%yy(((r!   z:The base url to which all static urls will be relative to.c                 \    |j                   j                  d       | |j                   _        y )Nz$webassets.ext.jinja2.AssetsExtension)	jinja_envadd_extensionassets_environment)r   rf   s     r    r   zEnvironment.init_appe  s!    ##$JK+/(r!   c                 n    t        |      j                         }|D ]  }| j                  |||           y)z/Register bundles from a YAML configuration fileN)r   load_bundlesregisterr   r   bundlesr/   s       r    	from_yamlzEnvironment.from_yamli  s6    T"//1 	/DMM$.	/r!   c                 n    t        |      j                         }|D ]  }| j                  |||           y)z%Register bundles from a Python moduleN)r   r   r   r   s       r    from_modulezEnvironment.from_moduleo  s6    t$113 	/DMM$.	/r!   r   )r+   r,   r-   r.   r   config_storage_classr   resolver_classr   propertyrD   r   r   rh   r   r   rm   r   r   r   r1   r2   s   @r    r   r   %  s|     ."N E E:-, 	I!) 7GDFC0//r!   r   )GenericArgparseImplementationCommandErrorc                   2     e Zd ZdZ fdZ fdZd Z xZS )FlaskArgparseInterfacezBSubclass the CLI implementation to add a --parse-templates option.c                     t        t        | 
  |i | | j                  j	                  ddd       | j                  j	                  ddd       y )	Nz--jinja-extensionz*.htmlz?specify the glob pattern for Jinja extensions (default: *.html))defaulthelpz--parse-templates
store_truez(search project templates to find bundles)actionr   )r   r   _construct_parserparseradd_argument)r   r6   r)   r   s      r    r   z(FlaskArgparseInterface._construct_parser  sb    ($ "#$,(*,KK$$#XV % X KK$$#L? % Ar!   c                 *   t         t        |   ||      }|v|j                  rT|j	                  d        |j
                  | j                  ||j                        D cg c]  }|j                  s| c}  t        |      st        d      |S c c}w )NzSearching templates...zNo asset bundles were found. If you are defining assets directly within your templates, you want to use the --parse-templates option.)r   r   _setup_assets_envparse_templatesinfoaddload_from_templatesjinja_extensionis_containerr   r   )r   nslogrC   br   s        r    r   z(FlaskArgparseInterface._setup_assets_env  s    .GCPC%%HH56 CGG)A)A#rGYGY)Z ;A+,>>   ; < 3x&45 5
 J;s   Bc                    ddl m}m} ddlm} |j
                  }t        j                  |j                  |j                        g}|j                  j                         D ]H  }|j                  |j                  t        j                  |j                  |j                               J  ||||g|      j                         S )Nr   )Jinja2LoaderAssetsExtensionr   )	jinja_ext)webassets.ext.jinja2r   r   r   r   r   r   rV   rW   template_folderr^   valuesappendr   )	r   rC   r   r   r   rf   
jinja2_envtemplate_dirsrg   s	            r    r   z*FlaskArgparseInterface.load_from_templates  s    J0 J "YYs}}c6I6IJKM ^^224 O	,,4$$IIi1193L3LMOO  ]ZLO\r!   )r+   r,   r-   r.   r   r   r   r1   r2   s   @r    r   r   }  s    P	A	&	r!   r   c                   (    e Zd ZdZdZdedfdZd Zy)ManageAssetszManage assets.TNc                 .    || _         || _        || _        y r   )rC   implementationr   )r   
assets_envimplr   s       r    r   zManageAssets.__init__  s    !DH"&DDHr!   c                 R   | j                   s!ddlm} |j                  j                  | _         ddl}ddl}|j                  j                  |j                  d         d|j                  d   }| j                  | j                   || j                        }|j                  |      S )zRuns the management script.
            If ``self.env`` is not defined, it will import it from
            ``current_app``.
            r   r   N r`   )progr   )rC   r   r   r   r   sysos.pathr   basenameargvr   r   main)r   argsr   r   osr   r   s          r    runzManageAssets.run  s|     88-&00CC   gg..sxx{;SXXa[ID&&txxd&ID99T?"r!   )r+   r,   r-   r.   capture_all_argsr   r   r    r!   r    r   r     s    &*1G		#r!   r   )r   )clic                 "   ddl m} t        j                  d      }|j	                  t        j
                                |j                  t        j                          |t        j                  j                  |      } t        ||               y)z"Helper to run a webassets command.r   )CommandLineEnvironment	webassetsN)webassets.scriptr   logging	getLogger
addHandlerStreamHandlersetLevelDEBUGr   r   r   rJ   )cmdr   loggercmdenvs       r    _webassets_cmdr    sh    ;"";/'//12&'!!44f
 	r!   c                       y)zWeb assets commands.Nr   r   r!   r    assetsr    s    r!   c                      t        d       y)zBuild bundles.buildNr  r   r!   r    r  r         	wr!   c                      t        d       y)zClean bundles.cleanNr  r   r!   r    r	  r	    r  r!   c                      t        d       y)zWatch bundles for file changes.watchNr  r   r!   r    r  r    r  r!   )r  r  r	  r  )5r.   
__future__r   r   r   r   r   r   r   flask.templatingr   r   r   webassets.envr	   r
   r   r   r   webassets.filterr   r   webassets.loadersr   r   __version____webassets_version____all__r   r   r[   r   r   flask_scriptscriptargparser   r   r   r   Commandr   r   clickr   r  groupr  commandwith_appcontextr  r	  r  r   r!   r    <module>r     s   : %   1 3 9 9 4 6# F6 F"  A; A;H*&Y H Y xN// N/`Y*! L0!> 0d#v~~ #> ))G+>	 U[[]# # ^^    
 ^^    
 ^^     ==GK  		z  		s$   E 9
E EEE%$E%