o
    h&                     @   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d	e
d
efddZde	d
e	fddZddddeded
e
fddZde	d
efddZded
efddZd
ef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   R/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/django_tasks/utils.pyis_module_level_function   s
   
r   objc                 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_delayr   r   c                    s,   dt ttf dt ttf f 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  dtjdtjdtf fdd}|S )Nargskwargsr   c               	      s`   t dd D ]&}z
| i |W   S  ty     ty-   |kr& t  Y qw 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)   valc                 C   s   | j  d| j S )N.)
__module__r   )r*   r   r   r   get_module_path;   s   r-   excc                 C   s   d tt| | | jS )N )joinr   type__traceback__)r.   r   r   r   get_exception_traceback?   s   r3   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   django.utils.cryptor   typing_extensionsr   r	   r
   boolr   r   intfloatr)   strr-   r"   r3   r8   r   r   r   r   <module>   s"    
