a
    9XhH                     @   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eeeeef f d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_PATHZ
MEDIA_ROOT)Z	date_pathZupload_path r   o/var/www/viveiro_mudafortebrasil/venv/lib/python3.9/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>       z get_media_url.<locals>.<genexpr>)r   r   r   r   r	   Z	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   imageZfhashr   r   r   r!       s    
r!   c                 C   s   t  }tj|| S N)r   r
   r   r   )r   Zupload_directoryr   r   r   get_absolute_media_path'   s    r'   c                 C   s   | j  d| j S )N.)
__module____name__)Zclass_or_functionr   r   r   get_absolute_name,   s    r+   c                 C   s   i t tj|  S r&   )r   r   ZCKEDITOR_CONFIGS)Zconfig_namer   r   r   
get_config0   s
    r,   )returnc                 C   sZ   i }| j D ]J}d|vrq
|D ]6}t|tusd|vr6q|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)responseZwidget_contextsZ
subcontextZsubcontext_dictr.   Z	widget_idr   r   r   get_contexts_for_widgets7   s    
r5   )r    os.pathr
   r   r   typingr   r   Zdjango.confr   Zckeditor.configsr   r   r   r   r!   r'   r+   r,   strr5   r   r   r   r   <module>   s   