o
    wvXjˆ  ã                   @   sØ   d Z ddlmZ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dd„ Zdd„ Zd#dd„Zdd„ Zdd„ Zdd„ Zd$dd„Zeed dƒZd%d!d"„ZdS )&zWorker name utilities.é    )Úabsolute_importÚunicode_literalsN)Úpartial)ÚExchangeÚQueueé   )Úmemoize)Úsimple_formatzC.dq2z{hostname}.dq2ú@Úcelery)ÚCache)Úworker_directÚgethostnameÚnodenameÚanon_nodenameÚ	nodesplitÚdefault_nodenameÚnode_formatÚhost_formatc                 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.
    ©Úhostname)Ú
isinstancer   ÚWORKER_DIRECT_QUEUE_FORMATÚformatÚWORKER_DIRECT_EXCHANGEr   © r   úS/var/www/html/myproject/venv/lib/python3.10/site-packages/celery/utils/nodenames.pyr   "   s   
	
ýr   c                 C   s   t  | |f¡S )z)Create node name from name/hostname pair.)ÚNODENAME_SEPÚjoin)Únamer   r   r   r   r   4   s   r   Úgenc                 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   ÚstrÚosÚgetpidr   )r   Úprefixr   r   r   r   9   s   ÿr   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   B   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   J   s   r   c                 K   s(   t |ƒ\}}t| ||ptfd|i|¤ŽS )z(Format worker node name (name@host.com).Úp)r   r   r)   )Úsr   ÚextraÚ	shortnamer*   r   r   r   r   P   s   
ÿÿÿr   r!   Ú0c                 C   s&   ddl m} |ƒ }|rd | |¡S |S )Nr   )Úcurrent_process_indexz{0}{1})Úlogr0   r   )r%   Údefaultr0   Úindexr   r   r   Ú_fmt_process_indexW   s   r4   ú-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   Ú	partitionÚdictr4   Ú_fmt_process_index_with_prefixr	   )r,   r*   r   r-   ÚhnameÚ_ÚdomainÚkeysr   r   r   r   `   s   
þý
r   )Nr    )r!   r/   )NN)Ú__doc__Ú
__future__r   r   r#   ÚsocketÚ	functoolsr   Úkombu.entityr   r   Ú
functionalr   Útextr	   r   r   r   r)   r=   r   Ú__all__r   r   r   r   r   r   r4   r>   r   r   r   r   r   Ú<module>   s.   
	
