
    /I_!                         S SK r S SKrS SKr " S S5      r " S S5      rS rS r " S S	\5      r " S
 S\5      r	 " S S\5      r
g)    Nc                   $    \ rS rSrSrS rS rSrg)__WeakMethodBound+   %ActiveState recipes 81253-weakmethod c                 p    UR                   U l        [        R                  " UR                  5      U l        g N)__func__fweakrefref__self__cselfr
   s     #/usr/share/ifupdown2/lib/dry_run.py__init____WeakMethodBound.__init__.   s!    QZZ(    c                     U R                  5       (       d  [        S5      eU R                  " U R                  5       4U-   0 UD6  g )NzMethod called on dead object)r   	TypeErrorr
   r   argkwargss      r   __call____WeakMethodBound.__call__2   s7    vvxx:;;c!,V,r   )r   r
   N__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes__ r   r   r   r   +   s    0)-r   r   c                   $    \ rS rSrSrS rS rSrg)__WeakMethodFree8   r   c                 :    [         R                  " U5      U l        g r   )r   r   r
   r   s     r   r   __WeakMethodFree.__init__;   s    Qr   c                 p    U R                  5       (       d  [        S5      eU R                  5       " U0 UD6  g )NzFunction no longer exist)r
   r   r   s      r   r   __WeakMethodFree.__call__>   s,    vvxx677#  r   r
   Nr   r#   r   r   r%   r%   8   s    0 !r   r%   c                 h     U R                     [        U 5      $ ! [         a    [        U 5      s $ f = f)r   )r	   AttributeErrorr%   r   r+   s    r   
WeakMethodr.   D   s7    #	

 Q  #""#s    11c                 l     [         R                  5       R                  U 5        g ! [         a     g f = fr   )DryRunManagerget_instance+unregister_dry_run_handler_weakref_callback	Exception)	references    r   _weakref_call_back_deleter5   M   s1    ""$PPQZ[ s   #& 
33c                   >    \ rS rSrSrSrS rS rS r\	S 5       r
Srg	)
DryRunT   z:
Detect dry_run functions and save the associated handler
zDRY-RUNc           	      0   [         R                  " SU R                  R                  -  5      U l        [        U 5       H  n UR                  5       R                  S5      (       a  [        X5      nU R                  U5      (       d  MK  US S n[        X5      nU R                  U5      (       d  Ms  [        R                  5       R                  [        R                  " U [        5      U[!        U5      [!        U5      S9  M  M     g ! ["         a     M  f = f)Nzifupdown2.%s_dry_runi)handler_namehandler_code_weakrefdry_run_code_weakref)logging	getLogger	__class__r   loggerdirlowerendswithgetattr_DryRun__is_method_or_functionr0   r1   register_dry_run_handlerr   r   r5   r.   r3   )r   	attr_name
attr_valuebase_attr_namebase_attr_values        r   r   DryRun.__init__Z   s    ''9P9P(PQTI ??$--j99!(!9J  77
CC %.s^N&-d&CO  77HH  "..0IID*CD%3-7-H-7
-C	 J ' :	 #:  s    AD	&D1AD
DDc                 J    U R                   R                  SU< SU< 35        g )Nz	DRY-RUN: : rA   info)r   ifnamestrings      r   log_info_ifname_dry_runDryRun.log_info_ifname_dry_run}   s    ff=>r   c                 @    U R                   R                  SU-  5        g )NzDRY-RUN: %srO   )r   rR   s     r   log_info_dry_runDryRun.log_info_dry_run   s    /0r   c                     [        U 5      =(       a3    [        R                  " U 5      =(       d    [        R                  " U 5      $ r   )callableinspectismethod
isfunction)objs    r   __is_method_or_functionDryRun.__is_method_or_function   s,    }S'"2"23"7"R7;M;Mc;RSr   )rA   N)r   r   r   r    r!   _DryRun__DRY_RUN_PREFIXr   rS   rV   staticmethodrF   r"   r#   r   r   r7   r7   T   s5     !!F?1 T Tr   r7   c                   ,    \ rS rSrS rS rS rS rSrg)_DryRunEntry   c                 B    Xl         X l        X0l        X@l        SU l        g NF)target_module_weakrefr;   r<   r=   _DryRunEntry__status)r   rg   r;   r<   r=   s        r   r   _DryRunEntry.__init__   s!    %:"($8!$8!r   c                    U R                  5       nU(       a=  U R                  (       a+  U R                  UR                  U R                  '   SU l        g g [
        R                  5       R                  U R                   5        g )NT)rg   r=   __dict__r;   rh   r0   r1   r2   r   target_module_refs     r   set_DryRunEntry.set   sf     668((@D@Y@Y!**4+<+<= $ )
 &&(TTUYUoUopr   c                    U R                  5       nU(       a=  U R                  (       a+  U R                  UR                  U R                  '   SU l        g g [
        R                  5       R                  U R                   5        g rf   )rg   r<   rk   r;   rh   r0   r1   r2   rl   s     r   unset_DryRunEntry.unset   sf     668((@D@Y@Y!**4+<+<= % )
 &&(TTUYUoUopr   c                     U R                   $ r   )rh   r   s    r   
get_status_DryRunEntry.get_status   s    }}r   )__statusr=   r<   r;   rg   N)	r   r   r   r    r   rn   rq   ru   r"   r#   r   r   rc   rc      s    	q	qr   rc   c                   R    \ rS rSrSr\S 5       rS rS rS r	S r
S rS	 rS
 rSrg)r0      Nc                  r    [         R                  (       d  [        5       [         l        [         R                  $ r   )r0   _DryRunManager__instancer#   r   r   r1   DryRunManager.get_instance   s!    '''4M$'''r   c                     [         R                  (       a  [        S5      eU [         l        [        5       U l        SU l        g )NzEDryRunManager: invalid access. Please use DryRunManager.getInstance()F)r0   r{   RuntimeErrordict_DryRunManager__entries_DryRunManager__is_onrt   s    r   r   DryRunManager.__init__   s/    ##fgg'+M$r   c                     [        UUUUS9nU R                  (       a  UR                  5         XR                  ;   a  U R                  U   R	                  U5        gU/U R                  U'   g)z
Register the dry run handler only using weakrefs - we don't want to mess up with garbage collection
:param module_weakref:
:param handler_name:
:param handler_code_weakref:
:param dry_run_code_weakref:
:return:
)rg   r;   r<   r=   N)rc   r   rn   r   append)r   module_weakrefr;   r<   r=   dry_run_entrys         r   rG   &DryRunManager.register_dry_run_handler   s`     %"0%!5!5	
 <<^^+NN>*11-@.;_DNN>*r   c                 @     U R                   U	 g! [         a     gf = f)za
If we detect a dead reference, we should remove this reference from our
internal data structure
N)r   r3   )r   r4   s     r   r2   9DryRunManager.unregister_dry_run_handler_weakref_callback   s%    
	y) 		s    
c                     U R                   R                  5        H  nU H  nUR                  5         M     M     SU l        g)z2
Enable the dry run mode
WARNING: not thread-safe
TN)r   valuesrn   r   r   entriesentrys      r   dry_run_mode_onDryRunManager.dry_run_mode_on   s7    
 ~~,,.G 		 ! / r   c                     U R                   R                  5        H  nU H  nUR                  5         M     M     SU l        g)z3
Disable the dry run mode
WARNING: not thread-safe
FN)r   r   rq   r   r   s      r   dry_run_mode_offDryRunManager.dry_run_mode_off   s7    
 ~~,,.G  ! / r   c                 0   [        S5        [        S5        U R                  R                  5        HW  nU HN  n[        S[        UR                  5      < SUR
                  < SUR                  5       (       a  SOS< 35        MP     MY     [        S5        g )	Nz== DryRunManager dump ==z  MODULE:    HANDLER  STATUSz  rN   z() ONOFFz========================)printr   r   reprrg   r;   ru   r   s      r   dump_entries_stdout!DryRunManager.dump_entries_stdout   s    (),-~~,,.G e.I.I)JEL^L^hmhxhxhzhz`d  AF  aF  G  H ! / 	()r   c                     U R                   $ r   )r   rt   s    r   is_dry_mode_onDryRunManager.is_dry_mode_on   s    ||r   )	__entries__is_on)r   r   r   r    r{   ra   r1   r   rG   r2   r   r   r   r   r"   r#   r   r   r0   r0      s<    J( (
=.*r   r0   )r>   rZ   r   r   r%   r.   r5   objectr7   rc   r0   r#   r   r   <module>r      sY   L   
- 
-	! 	! 1TV 1Th6 DPF Pr   