U
    ‰d¥  ã                   @   sX   d Z ddlmZmZ ddlmZ edƒZedƒZdZG dd„ de	ƒZ
d	d
„ Zdd„ ZdS )z½Task Annotations.

Annotations is a nice term for monkey-patching task classes
in the configuration.

This prepares and performs the annotations in the
:setting:`task_annotations` setting.
é    )ÚfirstmethodÚmlazy)ÚinstantiateÚannotateÚannotate_any)ÚMapAnnotationÚprepareÚresolve_allc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )r   z(Annotation map: task_name => attributes.c                 C   s(   zt | d ƒW S  tk
r"   Y nX d S )NÚ*)ÚdictÚKeyError)Úself© r   ú:/tmp/pip-unpacked-wheel-mu1yl971/celery/app/annotations.pyr      s    zMapAnnotation.annotate_anyc                 C   s*   zt | |j ƒW S  tk
r$   Y nX d S ©N)r   Únamer   )r   Útaskr   r   r   r      s    zMapAnnotation.annotateN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s   r   c                    s:   dd„ ‰ | dkrdS t | ttfƒs(| f} ‡ fdd„| D ƒS )z/Expand the :setting:`task_annotations` setting.c                 S   s*   t | tƒrt| ƒS t | tƒr&tt| ƒS | S r   )Ú
isinstancer   r   Ústrr   r   )Ú
annotationr   r   r   Úexpand_annotation$   s
    


z"prepare.<locals>.expand_annotationNr   c                    s   g | ]}ˆ |ƒ‘qS r   r   )Ú.0Úanno©r   r   r   Ú
<listcomp>/   s     zprepare.<locals>.<listcomp>)r   ÚlistÚtuple)Úannotationsr   r   r   r   "   s    r   c                 C   s   dd„ t | |ƒt| ƒfD ƒS )z Resolve all pending annotations.c                 s   s   | ]}|r|V  qd S r   r   )r   Úxr   r   r   Ú	<genexpr>4   s      zresolve_all.<locals>.<genexpr>)Ú_first_matchÚ_first_match_any)r   r   r   r   r   r	   2   s    r	   N)r   Zcelery.utils.functionalr   r   Zcelery.utils.importsr   r$   r%   Ú__all__r   r   r   r	   r   r   r   r   Ú<module>   s   