
    Ih/                     N   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZmZ dd	lmZmZ dd
lmZ 	 ddlmZ efZdZdZdZdZ ee      Zd Zd Z G d de      Z G d d      Z  G d de!      Z" G d de"      Z# G d de#      Z$ G d de$      Z%y# e$ r dZY bw xY w) z0A directed acyclic graph of reusable components.    )deque)Event)ignore_errors)bytes_to_str)symbol_by_name   )DependencyGraphGraphFormatter)instantiatequalname)
get_logger)GreenletExit )	BlueprintStepStartStopStepConsumerStep      c                 &    d| j                    d| S )Nz| z: alias)nsfmts     I/var/www/html/planif/env/lib/python3.12/site-packages/celery/bootsteps.py_prer      s    zC5!!    c                 @    | j                   j                  dd      d   S )N.r   )namersplit)ss    r   _labelr$   #   s    66==a $$r   c                   <    e Zd ZdZdZdZddddZd Zd	 Zd
 Z	d Z
y)StepFormatterz'Graph formatter for :class:`Blueprint`.u   ⧉u   ∘parallelogram
slategray4
slategray3)shapecolor	fillcolorc           	          |xrQ dj                  | j                  |      t        |j                  xs t	        |      j                  dd                  S )Nz{}{}zutf-8ignore)format_get_prefixr   labelr$   encodeselfsteps     r   r1   zStepFormatter.label2   sN     
T"+vd|33GXFH
 	
r   c                 d    |j                   r| j                  S |j                  r| j                  S y)N )lastblueprint_prefixconditionalconditional_prefixr3   s     r   r0   zStepFormatter._get_prefix9   s-    99(((***r   c                 p    |j                   r| j                  n| j                  }| j                  |||      S N)r8   blueprint_schemenode_scheme	draw_node)r4   objattrsschemes       r   nodezStepFormatter.node@   s.    *-((&&8H8H~~c6511r   c                 |    |j                   r|j                  dd       | j                  ||| j                  |      S )Nnonedarkseagreen3)	arrowheadr+   )r8   update	draw_edgeedge_scheme)r4   abrB   s       r   edgezStepFormatter.edgeD   s4    66LL6LA~~aD$4$4e<<r   N)__name__
__module____qualname____doc__r9   r;   r>   r1   r0   rD   rN   r   r   r   r&   r&   '   s6    1 !
2=r   r&   c                       e Zd ZdZeZdZdZdZ e	       Z
ddededediZ	 	 ddZd	 Zd
 Zd Zd Z	 	 ddZ	 ddZddZddZd Zd Zd Zd Zd Zd Zd Zd Zd Z e!d        Z"y) r   a  Blueprint containing bootsteps that can be applied to objects.

    Arguments:
        steps Sequence[Union[str, Step]]: List of steps.
        name (str): Set explicit name for this blueprint.
        on_start (Callable): Optional callback applied after blueprint start.
        on_close (Callable): Optional callback applied before blueprint close.
        on_stopped (Callable): Optional callback applied after
            blueprint stopped.
    Nr   initializingrunningclosingterminatingc                    |xs" | j                   xs t        t        |             | _         t        |xs g       t        | j                        z  | _        || _        || _        || _        t               | _
        i | _        y r=   )r!   r   typesetdefault_stepstypeson_starton_close
on_stoppedr   shutdown_completesteps)r4   ra   r!   r]   r^   r_   s         r   __init__zBlueprint.__init__c   sf    =DII=$t*)=	"%D,>,>(??
  $!&
r   c                 2   t         | _        | j                  r| j                          t        d |j                  D              D ]Q  \  }}| j                  d|j                         |dz   | _        |j                  |       t        j                  d       S y )Nc              3   &   K   | ]	  }||  y wr=   r   .0r#   s     r   	<genexpr>z"Blueprint.start.<locals>.<genexpr>q   s      JqAM Js   zStarting %sr   z^-- substep ok)RUNstater]   	enumeratera   _debugr   startedstartloggerdebug)r4   parentir5   s       r   rm   zBlueprint.startm   sq    
==MMO  JFLL JJ 	+GAtKKtzz2q5DLJJvLL)*		+r   c                 <    | j                   | j                  xs d   S Nr   )state_to_nameri   r4   s    r   human_statezBlueprint.human_statew   s    !!$**/22r   c                 t    i }|j                   D ]&  }|j                  |j                  |      xs i        ( |S r=   )ra   rI   info)r4   rp   rx   r5   s       r   rx   zBlueprint.infoz   s9    LL 	1DKK		&)/R0	1r   c                 f    | j                   r| j                          | j                  |ddd       y )NcloserV   F)reverse)r^   send_allr4   rp   s     r   rz   zBlueprint.close   s&    ==MMOfgy%@r   c                 .    | j                  ||||       y )N)	propagate)r|   )r4   rp   methoddescriptionr   s        r   restartzBlueprint.restart   s    ffkYGr   c                    |xs |j                  dd      }|rt        |j                        n|j                  }|D ]J  }|st        ||d       }	|	| j	                  d|j                         |j                         	  |	|g|  L y # t        $ r/}
|r t        j                  d||j                  |
       Y d }
~
d }
~
ww xY w)N_ z%s %s...zError on %s %s: %r)
replacereversedra   getattrrk   
capitalizer   	Exceptionrn   	exception)r4   rp   r   r   r{   r   argsra   r5   funexcs              r   r|   zBlueprint.send_all   s    !=V^^C%=*1&v|| 	PDdFD1?KK
 + 6 6 8$**FPF*T*	P % P$!((0+tzz3P PPs   >	B

	C%B==Cc                    |rdnd}| j                   t        t        fv ry | j                   t        k7  s"| j                  t        |j                        k7  r&t        | _         | j                  j                          y | j                  |       t        | _         | j                  ||rdnd|d       | j                  r| j                          t        | _         | j                  j                          y )NrW   stopping	terminatestopF)r   r   )ri   CLOSE	TERMINATErh   rl   lenra   r`   rZ   rz   r   r_   )r4   rp   rz   r   whats        r   r   zBlueprint.stop   s     )}z::%++::FLL0A A"DJ""&&(

6
9K& 	 	

 ??OO
""$r   c                 \    	 | j                   j                  |       y # t        $ r Y y w xY w)N)timeout)r`   waitIGNORE_ERRORS)r4   r   s     r   joinzBlueprint.join   s2    	 ""'''8 		s    	++c                    | j                  d       g x}| _        | j                         x}| _        | j                  d       | j	                  |      D ]+  } ||fi |}|||j
                  <   |j                  |       - | j                  ddj                  d | j                  D                     |D ]  }|j                  |        | S )ar  Apply the steps in this blueprint to an object.

        This will apply the ``__init__`` and ``include`` methods
        of each step, with the object as argument::

            step = Step(obj)
            ...
            step.include(obj)

        For :class:`StartStopStep` the services created
        will also be added to the objects ``steps`` attribute.
        zPreparing bootsteps.zBuilding graph...zNew boot order: {%s}z, c              3   4   K   | ]  }|j                     y wr=   r   re   s     r   rg   z"Blueprint.apply.<locals>.<genexpr>   s     :!agg:   )	rk   orderclaim_stepsra   _finalize_stepsr!   appendr   include)r4   rp   kwargsr   ra   Sr5   s          r   applyzBlueprint.apply   s     	*+
!--//
'(%%e, 	AV&v&D#E$))LL	 	*II:tzz::	< 	!DLL 	!r   c                    | j                   j                  j                  |j                   j                         | j                   j                  t	        |j
                  d         t	        | j
                  d                y )Nr   r    )graphadjacentrI   add_edgerY   r   )r4   others     r   connect_withzBlueprint.connect_with   sR    

""5;;#7#78

DQ0$tzz"~2FGr   c                      | j                   |   S r=   )ra   )r4   r!   s     r   __getitem__zBlueprint.__getitem__   s    zz$r   c                 X    t        d | j                  j                         D        d       S )Nc              3   :   K   | ]  }|j                   s|  y wr=   )r8   rf   Cs     r   rg   z'Blueprint._find_last.<locals>.<genexpr>   s     >1qvvQ>s   )nextra   valuesru   s    r   
_find_lastzBlueprint._find_last   s"    >

 1 1 3>EEr   c                    |j                         D ]*  }|j                  D cg c]  }t        |       c}|_        , t        d |j                         D              }|rf|j	                         D ]O  }t        |      }|j
                  | j                  vr|||j
                  <   |j                  |j                         Q |rey y c c}w )Nc              3   4   K   | ]  }|j                     y wr=   requires)rf   r5   s     r   rg   z'Blueprint._firstpass.<locals>.<genexpr>   s     @t}}@r   )r   r   r   r   popleftr!   ra   r   )r4   ra   r5   depstreamrD   s         r   
_firstpasszBlueprint._firstpass   s    LLN 	KD<@MMJS^C0JDM	K@@@( -%d+99DJJ.'+E$))$dmm,	-  Ks   Cc                 \   | j                         }| j                  |       d |j                         D        }t        || j	                  |            x}| _        |r|D ]  }||k7  s	|j                  ||        	 |j                         S # t        $ r}t        d|z        d }~ww xY w)Nc              3   8   K   | ]  }||j                   f  y wr=   r   r   s     r   rg   z,Blueprint._finalize_steps.<locals>.<genexpr>   s     6!q!**o6s   )root)	formatterzunknown bootstep: %s)	r   r   r   r	   r
   r   r   topsortKeyError)r4   ra   r8   itGrA   r   s          r   r   zBlueprint._finalize_steps   s     6u||~6($--4-8
 	
DJ  *$;JJtS)*	999; 	91C788	9s   ?B 	B+B&&B+c                 @     t         fd j                  D              S )Nc              3   @   K   | ]  }j                  |        y wr=   )	load_step)rf   r5   r4   s     r   rg   z(Blueprint.claim_steps.<locals>.<genexpr>   s     @TDNN4(@s   )dictr\   ru   s   `r   r   zBlueprint.claim_steps   s    @TZZ@@@r   c                 4    t        |      }|j                  |fS r=   )r   r!   r3   s     r   r   zBlueprint.load_step   s    d#yy$r   c                 B    t        j                  t        | |      g| S r=   )rn   ro   r   )r4   msgr   s      r   rk   zBlueprint._debug  s    ||DsO3d33r   c                     t        |       S r=   )r$   ru   s    r   r   zBlueprint.alias  s    d|r   )NNNNN)r   
restartingF)NTTr   )TFr=   )#rO   rP   rQ   rR   r&   r
   r!   ri   rl   rZ   r[   rh   r   r   rt   rb   rm   rv   rx   rz   r   r|   r   r   r   r   r   r   r   r   r   r   rk   propertyr   r   r   r   r   r   J   s    	 #NDEGEM	>Yy=	M )-:>+3A
 &,49H
 GIP$%.8H F	-9 A4  r   r   c                   6     e Zd ZdZdZdZ fdZd Zd Z xZ	S )StepTypezMeta-class for steps.Nc                     |j                  d      }|r| d| n|}|j                  ||j                  d      xs |       t        |   | |||      S )NrP   r   r!   )rQ   r!   )getrI   super__new__)clsr!   basesrB   moduleqname	__class__s         r   r   zStepType.__new__  sa    <(&,6(!D6"$6"+e 	 	
 wsD%77r   c                     | j                   S r=   )r!   r   s    r   __str__zStepType.__str__  s    xxr   c                 $    dj                  |       S )Nzstep:{0.name}{{{0.requires!r}}})r/   r   s    r   __repr__zStepType.__repr__  s    077<<r   )
rO   rP   rQ   rR   r!   r   r   r   r   __classcell__)r   s   @r   r   r   
  s    DH8=r   r   c                   h    e Zd ZdZdZdZdZdZdZdZ	d Z
d Zd Zd	 Zd
 Zd Zd Zed        Zd Zy)r   zA Bootstep.

    The :meth:`__init__` method is called when the step
    is bound to a parent object, and can as such be used
    to initialize attributes in the parent object at
    parent instantiation-time.
    NFr   Tc                      y r=   r   )r4   rp   r   s      r   rb   zStep.__init__?      r   c                     | j                   S )zReturn true if bootstep should be included.

        You can define this as an optional predicate that decides whether
        this step should be created.
        )enabledr}   s     r   
include_ifzStep.include_ifB  s     ||r   c                      t        |g|i |S r=   )r   )r4   r!   r   r   s       r   r   zStep.instantiateJ  s    41$1&11r   c                 L    | j                  |      rd| j                  |      fS y)NT)FN)r   creater}   s     r   _should_includezStep._should_includeM  s%    ??6"V,,,r   c                 *    | j                  |      d   S rs   )r   r}   s     r   r   zStep.includeR  s    ##F+A..r   c                      y)zCreate the step.Nr   r}   s     r   r   zStep.createU  s    r   c                 "    d| j                    dS )Nz<step: >r   ru   s    r   r   zStep.__repr__X  s    A&&r   c                 4    | j                   xs t        |       S r=   )r1   r$   ru   s    r   r   z
Step.alias[  s    zz)VD\)r   c                      y r=   r   )r4   rA   s     r   rx   z	Step.info_  r   r   )rO   rP   rQ   rR   r!   r1   r:   r   r8   r   rb   r   r   r   r   r   r   r   r   rx   r   r   r   r   r      sm     D E K H D G2
/' * *r   r   )	metaclassc                   2    e Zd ZdZdZd Zd Zd Zd Zd Z	y)r   z3Bootstep that must be started and stopped in order.Nc                 P    | j                   r| j                   j                         S y r=   )rA   rm   r}   s     r   rm   zStartStopStep.startk  s    8888>>## r   c                 P    | j                   r| j                   j                         S y r=   )rA   r   r}   s     r   r   zStartStopStep.stopo  s    8888==?" r   c                      y r=   r   r}   s     r   rz   zStartStopStep.closes  r   r   c                 |    | j                   r0 t        | j                   d| j                   j                               S y )Nr   )rA   r   r   r}   s     r   r   zStartStopStep.terminatev  s.    88@7488[$((--@BB r   c                 v    | j                  |      \  }}|r"|| _        |j                  j                  |        |S r=   )r   rA   ra   r   )r4   rp   increts       r   r   zStartStopStep.includez  s7    ''/SDHLL%
r   )
rO   rP   rQ   rR   rA   rm   r   rz   r   r   r   r   r   r   r   c  s&    =
 C$#Cr   r   c                   8    e Zd ZdZdZdZd Zd Zd Zd Z	d	dZ
y)
r   z(Bootstep that starts a message consumer.)z!celery.worker.consumer:ConnectionNc                     t        d      )Nzmissing get_consumers)NotImplementedError)r4   channels     r   get_consumerszConsumerStep.get_consumers  s    !"9::r   c                     |j                   j                         }| j                  |      | _        | j                  xs g D ]  }|j	                           y r=   )
connectionr   r   	consumersconsume)r4   cr   consumers       r   rm   zConsumerStep.start  sJ    ,,&&(++G4," 	H	r   c                 (    | j                  |d       y )NT_closer4   r  s     r   r   zConsumerStep.stop  s    Atr   c                 (    | j                  |d       y )NFr  r  s     r   shutdownzConsumerStep.shutdown  s    Aur   c                 $   t               }| j                  xs g D ]L  }|r t        |j                  |j                         |j
                  s2|j                  |j
                         N |D ]"  }t        |j                  |j                         $ y r=   )rZ   r  r   r   cancelr   addrz   )r4   r  cancel_consumerschannelsr  r   s         r   r  zConsumerStep._close  st    5," 	/HallHOO<X--.		/
   	7G!,,6	7r   )T)rO   rP   rQ   rR   r   r  r   rm   r   r
  r  r   r   r   r   r     s(    25HI;7r   r   N)&rR   collectionsr   	threadingr   kombu.commonr   kombu.utils.encodingr   kombu.utils.importsr   utils.graphr	   r
   utils.importsr   r   	utils.logr   greenletr   r   ImportError__all__rh   r   r   rO   rn   r   r$   r&   r   rY   r   r   r   r   r   r   r   <module>r     s    6   & - . 8 0 !$% "OM
@ 
		H	"% =N  =F} }@=t =,@X @FD >7= 7e  Ms   B B$#B$