a
    Cg&                     @   s   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 dlm	Z	m
Z
mZ d dlmZ d dlmZ edZedZe
ed	d
dZe	e	dddZdddeee
dddZe	edddZeedddZedddZdS )    N)wraps)format_exception)AnyCallableTypeVar)RANDOM_STRING_CHARS)	ParamSpecTP)funcreturnc                 C   s*   t | rt | rdS d| jv r&dS dS )NFz<locals>T)inspect
isfunction	isbuiltin__qualname__)r    r   Q/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/django_tasks/utils.pyis_module_level_function   s
    
r   )objr   c                 C   s   t t | S )z>
    Round-trip encode object as JSON to normalize types.
    )jsonloadsdumps)r   r   r   r   json_normalize   s    r      g?)retriesbackoff_delay)r   r   r   c                    s*   t ttf t ttf d fdd}|S )z
    Retry the given code `retries` times, raising the final error.

    `backoff_delay` can be used to add a delay between attempts.
    )fr   c                    s*   t  tjtjtd fdd}|S )N)argskwargsr   c               	      sf   t dd D ]R}z| i |W   S  ty:    Y q ty^   |krP t  Y q0 qd S )N   )rangeKeyboardInterruptBaseExceptiontimesleep)r   r   attempt)r   r   r   r   r   inner_wrapper)   s    z-retry.<locals>.wrapper.<locals>.inner_wrapper)r   r
   r   r   r	   )r   r&   r   r   )r   r   wrapper(   s     zretry.<locals>.wrapper)r   r
   r	   )r   r   r(   r   r'   r   retry!   s    &r)   )valr   c                 C   s   | j  d| j S )N.)
__module__r   )r*   r   r   r   get_module_path;   s    r-   )excr   c                 C   s   d tt| | | jS )N )joinr   type__traceback__)r.   r   r   r   get_exception_traceback?   s    r3   )r   c                   C   s   d tjtddS )z
    Return a random string for use as a task id.

    Whilst 64 characters is the max, just use 32 as a sensible middle-ground.

    This should be much faster than Django's `get_random_string`, since
    it's not cryptographically secure.
    r/       )k)r0   randomchoicesr   r   r   r   r   get_random_idC   s    	r8   )r   r   r6   r#   	functoolsr   	tracebackr   typingr   r   r   Zdjango.utils.cryptor   Ztyping_extensionsr   r	   r
   boolr   r   intfloatr)   strr-   r"   r3   r8   r   r   r   r   <module>   s    
