o
    .i*                     @   s   d 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.    N)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   Q/var/www/html/philips/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   1   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   6   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   ?   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   G   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   M   s   
r   r   0c                 C   s&   ddl m} | }|r|  | S |S )Nr   )current_process_index)logr.   )r#   defaultr.   indexr   r   r   _fmt_process_indexT   s   r2   -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dictr2   _fmt_process_index_with_prefixr   )r*   r(   r   r+   hname_domainkeysr   r   r   r   ]   s   

r   )Nr   )r   r-   )NN)__doc__r!   socket	functoolsr   kombu.entityr   r   
functionalr   textr   r   r   r   r'   r;   r   __all__r   r   r   r   r   r   r2   r<   r   r   r   r   r   <module>   s,    
	
