o
    =gH                     @   s   d dl Z d dl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 Zdd	 Zd
d Zdd Zdd Zdd Zdd Zdeeeeef f fddZdS )    N)datetime)AnyDict)settings)DEFAULT_CONFIGc                  C   s.   t  d} tjtj| }tjtj|S )N%Y/%m/%d)	r   nowstrftimeospathjoinr   CKEDITOR_UPLOAD_PATH
MEDIA_ROOT)	date_pathupload_path r   ]/var/www/html/venv/lib/python3.10/site-packages/ckeditor_demo/demo_application/tests/utils.pyget_upload_directory   s   r   c                 C   s0   t jt d| g}t jddd |D  S )Nr   /c                 s   s    | ]}| d V  qdS )r   N)strip).0argr   r   r   	<genexpr>   s    z get_media_url.<locals>.<genexpr>)r   r   r   r   r	   	MEDIA_URLr   )fnameargsr   r   r   get_media_url   s   r   c                   C   s   t jt dd d S )NT)ignore_errors)shutilrmtreer   r   r   r   r   remove_upload_directory   s   r    c                 C   s(   t | d}t }||  | S )Nrb)openhashlibsha1updateread	hexdigest)r   imagefhashr   r   r   r$       s   
r$   c                 C   s   t  }tj|| S N)r   r
   r   r   )r   upload_directoryr   r   r   get_absolute_media_path'   s   r,   c                 C   s   | j  d| j S )N.)
__module____name__)class_or_functionr   r   r   get_absolute_name,   s   r1   c                 C   s   i t tj|  S r*   )r   r   CKEDITOR_CONFIGS)config_namer   r   r   
get_config0   s
   r4   returnc                 C   sZ   i }| j D ]%}d|vrq|D ]}t|tusd|vrq|d }|d d }|||< qq|S )z
    Searches through the response's context for subcontexts of widgets,
    and returns a dictionary with the widgets' `id` attribute as key
    and the widget's context dictionary as value.
    widgetattrsid)contexttypedict)responsewidget_contexts
subcontextsubcontext_dictr6   	widget_idr   r   r   get_contexts_for_widgets7   s   

rA   )r#   os.pathr
   r   r   typingr   r   django.confr   ckeditor.configsr   r   r   r    r$   r,   r1   r4   strrA   r   r   r   r   <module>   s    "