U
    bh[                     @  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dddddZddddddZd0ddddddZddddd Zdddd!d"Zddd#dd$d%d&Zd1dddd)d*d+Zeed,d'Zd2dddd#dd-d.d/ZdS )3zWorker name utilities.    )annotationsN)partial)ExchangeQueue   )memoize)simple_formatzC.dq2z{hostname}.dq2@Zcelery)Cache)worker_directgethostnamenodenameanon_nodename	nodesplitdefault_nodenamenode_formathost_formatzstr | Queuer   )hostnamereturnc                 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   :/tmp/pip-unpacked-wheel-kcem4wq5/celery/utils/nodenames.pyr   &   s    	

r   str)namer   r   c                 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   genz
str | None)r   prefixr   c                 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   ztuple[None, str] | list[str])r   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   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   dict)sr   extrar   c                 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)r!   defaultr   c                 C  s&   ddl m} | }|r"|  | S |S )Nr   )current_process_index)logr1   )r!   r0   r1   indexr   r   r   _fmt_process_indexY   s    r4   -)r+   r)   r   r,   r   c                 K  sD   |pt  }|d\}}}|p |}t|||ttdf|}t| |S )zFormat host %x abbreviations..)hndiI)r   	partitionr*   r4   _fmt_process_index_with_prefixr   )r+   r)   r   r,   hname_domainkeysr   r   r   r   c   s    

r   )Nr    )r"   r/   )NN)__doc__
__future__r   r#   socket	functoolsr   Zkombu.entityr   r   Z
functionalr   textr   r   r   r   r(   r*   r   __all__r   r   r   r   r   r   r4   r=   r   r   r   r   r   <module>   s,   