
    Wwgg                         d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	  edd      Z
dd	ee   d
dfdZd
ee   fdZd
ee   fdZy)    )
ContextVar)Optional)settings)HttpRequest)import_stringauditlog_correlation_idN)defaultrequestreturnc                 "   t         j                  ryd}t         j                  }|rU| rS|| j                  v r| j                  j	                  |      }n)|| j
                  v r| j
                  j	                  |      }t        j                  |       y)a  
    A function to read the cid from a request.
    If the header is not in the request, then we set it to `None`.

    Note: we look for the value of `AUDITLOG_CID_HEADER` in `request.headers` and in `request.META`.

    This function doesn't do anything if the user is supplying their own `AUDITLOG_CID_GETTER`.

    :param request: The request to get the cid from.
    :return: None
    N)r   AUDITLOG_CID_GETTERAUDITLOG_CID_HEADERheadersgetMETAcorrelation_idset)r
   cidheaders      C/var/www/horilla/myenv/lib/python3.12/site-packages/auditlog/cid.pyset_cidr      su     ##
C))F'W__$//%%f-Cw||#,,""6*C s    c                  *    t         j                         S N)r   r    r   r   _get_cidr   +   s    r   c                  ~    t         j                  } | s
t               S t        |       r |        S  t	        |              S )a	  
    Calls the cid getter function based on `settings.AUDITLOG_CID_GETTER`

    If the setting value is:

    * None: then it calls the default getter (which retrieves the value set in `set_cid`)
    * callable: then it calls the function
    * type(str): then it imports the function and then call it

    The result is then returned to the caller.

    If your custom getter does not depend on `set_header()`,
    then we recommend setting `settings.AUDITLOG_CID_GETTER` to `None`.

    :return: The correlation ID
    )r   r   r   callabler   )methods    r   get_cidr    /   s9    " ))Fzx = ""r   r   )contextvarsr   typingr   django.confr   django.httpr   django.utils.module_loadingr   r   r   strr   r    r   r   r   <module>r'      sZ    "    # 55tDXk* d @ (3-  ## #r   