
    ~+hA                        d dl mZ d dlZd dlZd dlZd dlZd dlmZ ddlm	Z	 dZ
d dlZej                  dk\  rd dlZej                  Znd dlZej                   Z	 d dlZ	 e eZ	 e eZd d	lmZ 	 d d
lmZ d Z ej@                  d      Z!ejD                  jF                  fdZ$ejJ                  dd       Z&	 	 ddZ'ddZ(d Z)d Z*d Z+d Z,y# e$ r d dlZY zw xY w# e$ r	 d dlmZ Y w xY w# e$ r eZY w xY w# e$ r d dlZd dlZY w xY w)    )sixN)	takewhile   )BundleError)md5_constructorpicklesetStringIOcommon_path_prefixworking_directoryis_url)      )Set)r
   )parsec                     ddl m}  ||       S )Nr   )make_md5)cacher   )datar   s     B/var/www/html/venv/lib/python3.12/site-packages/webassets/utils.py	hash_funcr   8   s    D>    z[/\\]+c                     d }t        | D cg c]  }t        j                  |       c} }|j                  d t	        ||      D              S c c}w )a  os.path.commonpath() is completely in the wrong place; it's
    useless with paths since it only looks at one character at a time,
    see http://bugs.python.org/issue10395

    This replacement is from:
        http://rosettacode.org/wiki/Find_Common_Directory_Path#Python
    c                 2     t         fd dd  D              S )Nc              3   .   K   | ]  }|d    k(    ywr   N ).0nnames     r   	<genexpr>z<common_path_prefix.<locals>.allnamesequal.<locals>.<genexpr>I   s     0!1d1g:0s   r   )all)r    s   `r   allnamesequalz)common_path_prefix.<locals>.allnamesequalH   s    0tABx000r   c              3   &   K   | ]	  }|d      ywr   r   )r   xs     r   r!   z%common_path_prefix.<locals>.<genexpr>N   s     NQAaDNs   )zip_directory_separator_resplitjoinr   )pathssepr#   pbydirectorylevelss        r   r   r   @   sN    1
 N15;;A>NO88N)M;L"MNNN Os   Ac              #   :  K   t        |       t        |      k7  sJ | st        j                  j                  |      } t        j                         }t        j
                  |        	 d t        j
                  |       y# t        j
                  |       w xY ww)aD  A context manager which changes the working directory to the given
    path, and then changes it back to its previous value on exit.

    Filters will often find this helpful.

    Instead of a ``directory``, you may also give a ``filename``, and the
    working directory will be set to the directory that file is in.s
    N)boolospathdirnamegetcwdchdir)	directoryfilenameprev_cwds      r   r   r   Q   sj      	?d8n,,,GGOOH-	yy{HHHY
s   A$B'B +BBBc                 d      sssJ |rd|z  ndd d fd	}dz  |_         |S )a  Returns a function which can resolve an option to an object.

    The option may given as an instance or a class (of ``clazz``, or
    duck-typed with an attribute ``attribute``), or a string value referring
    to a class as defined by the registry in ``classes``.

    This support arguments, so an option may look like this:

        cache:/tmp/cachedir

    If this must instantiate a class, it will pass such an argument along,
    if given. In addition, if the class to be instantiated has a classmethod
    ``make()``, this method will be used as a factory, and will be given an
    Environment object (if one has been passed to the resolver). This allows
    classes that need it to initialize themselves based on an Environment.
    z to %sNc                 b    t        | d      r||f|z   n|} | j                  |i |S  | |i |S )Nmake)hasattrr:   )clazzenvakwargss        r   instantiatez)make_option_resolver.<locals>.instantiate{   sE     5&! "%C6A:aD5::t*r**a2r   c                    t        	      rt        | t              s 	       n	}| sry r't        |       rt        | t              r	 | |      S | S |rt        | |      r| S t        | t              rt	        | |      r	 | |      S t        | t
        j                        rE| j                  dd      }|d   }t        |      dkD  r|d   nd }|v r |   |g|r|g S g  S t        | d
      )N:r   r   z cannot be resolved)
callable
isinstancetyper;   
issubclassr   string_typesr(   len
ValueError)optionr=   	the_clazzpartskeyarg
allow_none	attributeclassesr<   desc_stringrA   s         r   resolve_optionz,make_option_resolver.<locals>.resolve_option   s    'z&$7OEGUZ	* 3&$'"63//M FI6M%*VY*Gvs++  0 01LLa(E(C!%j1n%($Cg~"73<NNN"NNfkJKKr   zResolve ``option``%s.N)__doc__)r<   rQ   rR   rP   descrT   rS   rA   s   ````  @@r   make_option_resolverrX   f   sE    $ I((%)(T/tKL L6 9;FNr   c                 J     d d  G  fddt               }|S )a
  Returns a metaclass which will keep a registry of all subclasses, keyed
    by their ``id`` attribute.

    The metaclass will also have a ``resolve`` method which can turn a string
    into an instance of one of the classes (based on ``make_option_resolver``).
    c                 n    t        | d      xr | j                  |k(  xs t        |       t        |      k(  S )z9Return equality with config values that instantiate this.id)r;   r[   )selfothers     r   eqzRegistryMetaclass.<locals>.eq   s4    d#85(8 %$x2e9$	%r   c                 R    dt        | d      r| j                  z  S t        |       z  S )Nz%sr[   )r;   r[   repr)r\   s    r   unicodez"RegistryMetaclass.<locals>.unicode   s&    '$"5twwFF4:FFr   c            	       L    e Zd Zi ZfdZ e eW W W  W e            Zy)$RegistryMetaclass.<locals>.Metaclassc                     d|vr|d<   d|vr|d<   d|vr|d<   t         j                  | |||      }t        |d      r|| j                  |j                  <   |S )N__eq____unicode____str__r[   )rF   __new__r;   REGISTRYr[   )mcsr    basesattrs	new_klassr^   ra   s        r   rh   z,RegistryMetaclass.<locals>.Metaclass.__new__   sn    u$"$h E)'.m$%#*i S$u=Iy$'-6Y\\*r   )r<   rQ   rP   rW   rR   N)__name__
__module____qualname__ri   rh   staticmethodrX   resolve)rP   rQ   r<   rW   r^   ra   s   r   	Metaclassrc      s0    
	 3! 
 r   rs   )rF   )r<   rQ   rP   rW   rs   r^   ra   s   ```` @@r   RegistryMetaclassrt      s'    %G D , r   c                 r    dddd}	 d } |||    ||         S # t         $ r}t        d|z        d}~ww xY w)zQcmp() for debug levels, returns True if ``level1`` is higher
    than ``level2``.r   r   r   )FmergeTc                     | |kD  | |k  z
  S rU   r   )r>   bs     r   <lambda>z"cmp_debug_levels.<locals>.<lambda>   s    AEa!e, r   zInvalid debug value: %sN)KeyErrorr   )level1level2
level_intscmpes        r   cmp_debug_levelsr      sT     Qa0J9,:f%z&'9:: 9 3a788	9s    	616c                     t        | t              syt        j                  |       }t	        |j
                  xr |j                        xr t        |j
                        dkD  S )NFr   )rE   strurlparseurlsplitr/   schemenetlocrI   )sparseds     r   r   r      sJ    aq!F/&--0KS5G!5KKr   c                     t        j                         }|j                  |        |j                         }t	        j
                  |      j                         }dj                  |      S )z%Calculate SRI string for data buffer.	sha384-{})hashlibsha384updatedigestbase64	b64encodedecodeformat)r   hashhash_base64s      r   calculate_srir      sO    >>DKK;;=D""4(//1Kk**r   c                 h   d}t        j                         }	 t        | d      5 }	 |j                  |      }|sn|j	                  |       &	 ddd       |j                         }t        j                  |      j                         }dj                  |      S # 1 sw Y   MxY w# t        $ r Y yw xY w)zICalculate SRI string if file can be found. Otherwise silently return Nonei   rbNr   )r   r   openreadr   r   r   r   r   r   FileNotFoundError)	file_nameBUF_SIZEr   fr   r   s         r   calculate_sri_on_filer      s    H>>D)T" 	"avvh'D!	  		" {{}&&t,335!!+..	" 	"  s)   B% (BAB% B"B% %	B10B1)NN)NNNTN)NNTN)-	webassetsr   
contextlibr0   sysre	itertoolsr   
exceptionsr   __all__r   version_infor   md5r   newcPickler   ImportErrorr	   	NameErrorsetsr   r   IOErrorwebassets.sixr
   urllibr   r   r   compiler'   r1   r+   r   contextmanagerr   rX   rt   r   r   r   r   r   r   r   <module>r      sD     	 
 	  #@ vkkOggO
 C* * #(

 %"**Y/  #%''++ O"  ( >B/3<~$N9L+_            sH   C C $C- /C: 	CCC*)C*-C76C7:D
	D
