o
    h                     @   st   d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ dd Z	dd Z
dd	d
ZdddZdd Zdd ZdS )    N)settings)constant_time_compare)	force_strc                    s$    fdd} fdd}||fS )Nc                    sZ   |   }|  dd}|jj}|j|D ]}|j|j|dd}|j|jd qd S )NwagtailimagesFilter )filterfilter_specr	   )	get_model
connectionaliasobjectsusingr   updatespec)appsschema_editor	Renditionr   db_aliasflt
renditionsapp_namerendition_model_name T/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/wagtail/images/utils.pyfill_filter_spec_forward   s   zAget_fill_filter_spec_migrations.<locals>.fill_filter_spec_forwardc           	         s   |   }|  dd}|jj}	 |j|jddjddd }|s&d S |D ]}|j|j|d\}}|j|j|dj	|d	 q(q)
Nr   r   T)filter__isnullr	   )flat)r   r
   )r   )
r   r   r   r   r   r   values_listdistinctget_or_creater   )	r   r   r   r   r   unmatched_filter_specsr	   r   _r   r   r   fill_filter_spec_reverse   s.   

zAget_fill_filter_spec_migrations.<locals>.fill_filter_spec_reverser   )r   r   r   r%   r   r   r   get_fill_filter_spec_migrations   s   r&   c                 C   s   t | dkr"t| d dd }t| d dd }t| d dd }n&t | dkrDt| dd d}t| dd d}t| dd d}ntd	|||fS )
a  
    Parses a string a user typed into a tuple of 3 integers representing the
    red, green and blue channels respectively.

    May raise a ValueError if the string cannot be parsed.

    The colour string must be a CSS 3 or 6 digit hex code without the '#' prefix.
       r                     z:Color string must be either 3 or 6 hexadecimal digits long)lenint
ValueError)color_stringrgbr   r   r   parse_color_string:   s   	
r5   c                 C   sR   |d u rt j}t|tr| }|  d| d}ttt	|| t
j S )N/)r   
SECRET_KEY
isinstancestrencoder   base64urlsafe_b64encodehmacnewhashlibsha1digest)image_idr	   keyurlr   r   r   generate_signatureQ   s   
rE   c                 C   s   t | t|||dS )N)rC   )r   rE   )	signaturerB   r	   rC   r   r   r   verify_signaturea   s   rG   c                 C   s$   | |d}|j| jdj| jdS )a  
    Finds all the duplicates of a given image.
    To keep things simple, two images are considered to be duplicates if they have the same `file_hash` value.
    This function also ensures that the `user` can choose one of the duplicate images returned (if any).
    choose)pk)	file_hash)!instances_user_has_permission_forexcluderI   r   rJ   )imageuserpermission_policy	instancesr   r   r   find_image_duplicatesg   s   rQ   c                    s8   t | tr
| d} g d  fdd| D }d|S )zJ
    Remove any directives that would require an SVG to be rasterised
    |)maxminwidthheightscalefilloriginalc                    s&   g | ] t  fd dD r qS )c                 3   s    | ]}  |V  qd S N)
startswith).0prefixxr   r   	<genexpr>   s    z.to_svg_safe_spec.<locals>.<listcomp>.<genexpr>)any)r\   svg_preserving_specsr^   r   
<listcomp>   s    z$to_svg_safe_spec.<locals>.<listcomp>)r8   r9   splitjoin)filter_specs
safe_specsr   rb   r   to_svg_safe_specr   s   


	
ri   rZ   )r;   r?   r=   django.confr   django.utils.cryptor   django.utils.encodingr   r&   r5   rE   rG   rQ   ri   r   r   r   r   <module>   s    .

