o
    Df[                     @  s   d Z ddlm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 ed	Zd
ZdZdZededejZdZd1ddZd2ddZd3d4ddZd5dd Zd6d!d"Zd7d&d'Zd8d9d+d,Zeed-d(Zd:d;d/d0ZdS )<zWorker name utilities.    )annotationsN)partial)ExchangeQueue   )memoize)simple_formatzC.dq2z{hostname}.dq2@celery)Cache)worker_directgethostnamenodenameanon_nodename	nodesplitdefault_nodenamenode_formathost_formathostnamestr | Queuereturnr   c                 C  s"   t | tr| S ttj| dt| S )a5  Return the :class:`kombu.Queue` being a direct route to a worker.

    Arguments:
        hostname (str, ~kombu.Queue): The fully qualified node name of
            a worker (e.g., ``w1@example.com``).  If passed a
            :class:`kombu.Queue` instance it will simply return
            that instead.
    r   )
isinstancer   WORKER_DIRECT_QUEUE_FORMATformatWORKER_DIRECT_EXCHANGEr    r   O/home/ubuntu/webapp/venv/lib/python3.10/site-packages/celery/utils/nodenames.pyr   &   s   
	
r   namestrc                 C  s   t | |fS )z)Create node name from name/hostname pair.)NODENAME_SEPjoin)r   r   r   r   r   r   8   s   r   gen
str | Noneprefixc                 C  s"   t d|tt g| pt S )zsReturn the nodename for this process (not a worker).

    This is used for e.g. the origin task message field.
     )r   r!   r   osgetpidr   )r   r$   r   r   r   r   =   s   "r   tuple[None, str] | list[str]c                 C  s(   |  td}t|dkrd|d fS |S )z,Split node name into tuple of name/hostname.r   Nr   )splitr    len)r   partsr   r   r   r   E   s   r   c                 C  s$   t | pd\}}t|pt|pt S )z-Return the default nodename for this process.r%   )r   r   NODENAME_DEFAULTr   )r   r   hostr   r   r   r   M   s   r   sextradictc                 K  s(   t |\}}t| ||ptfd|i|S )z(Format worker node name (name@host.com).p)r   r   r,   )r.   r   r/   	shortnamer-   r   r   r   r   S   s   r   r%   0defaultc                 C  s&   ddl m} | }|r|  | S |S )Nr   )current_process_index)logr5   )r$   r4   r5   indexr   r   r   _fmt_process_indexY   s   r8   -r-   c                 K  sH   |pt  }|d\}}}|p|}t|||ttdfi |}t| |S )zFormat host %x abbreviations..)hndiI)r   	partitionr0   r8   _fmt_process_index_with_prefixr   )r.   r-   r   r/   hname_domainkeysr   r   r   r   c   s   


r   )r   r   r   r   )r   r   r   r   r   r   )Nr"   )r   r#   r$   r   r   r   )r   r   r   r(   )r   r   r   r   )r.   r   r   r   r/   r0   r   r   )r%   r3   )r$   r   r4   r   r   r   )NN)
r.   r   r-   r#   r   r#   r/   r0   r   r   )__doc__
__future__r   r&   socket	functoolsr   kombu.entityr   r   
functionalr   textr   r   r   r    r,   r0   r   __all__r   r   r   r   r   r   r8   rA   r   r   r   r   r   <module>   s.    




