
    Ōj(                    \   U d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	 ddl
mZmZmZ ddlmZmZmZmZ ddlmZ dd	lmZ dd
lmZmZmZmZmZmZmZ ddlm Z m!Z!m"Z"m#Z#m$Z$ ddl%m&Z&m'Z' ddl(m)Z)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/m0Z0m1Z1m2Z2 dZ3de4d<    G d d      Z5ddZ6ddZ7ddl8m9Z9m:Z:m;Z;m<Z<m=Z= y)zAProfile-owned flat-root storage capability for weekly operations.    )annotationsN)	get_ident)TracebackType)FinalNeverSelf)#WeeklyOperationsAuthorityCompromiseWeeklyOperationsCorruptionWeeklyOperationsErrorWeeklyOperationsInputError)MARKER_NAME)REGISTRY_NAME)AuthorityId WeeklyOperationsAuthorityBindingWeeklyOperationsParentAuthorityauthority_marker_bytescanonical_authority_markerconstruct_authority_bindingvalidate_authority_binding)MarkerNameOccupiedPreparedMarkerclassify_existing_markercommit_authority_markerprepare_authority_marker)WeeklyOperationsAuthorityRootverify_authority_descriptor)EMPTY_REGISTRY_DIGESTPreparedRegistrycommit_registryprepare_registryremove_owned_registry)InitializationCancellationInitializationCommitContextInitializationSignalGuard'WeeklyOperationsInitializationCommitted)r   r   r%   )WeeklyOperationsInitializationTransactionbegin_authority_initializationr   r   __all__c                      e Zd ZU dZdZded<   ddZddZddZddZ	e
dd	       Ze
dd
       ZddZddZddZddZy)r&   zFSame-thread binding handoff that keeps catchable cancellation blocked.)	_parent_authority_id_creator_guard_entered_active_acknowledged_binding
_authorityr   	__slots__c                    t        |      dk7  st        d |D              rt        d      || _        || _        t               | _        t               | _        d| _	        d| _
        d| _        d | _        d | _        y )N@   c              3  $   K   | ]  }|d v 
 yw)0123456789abcdefN ).0	characters     /home/cube/projects/richard/traning coach/task-12-independent-verification-r9/build/hermes-full/dualcoach/profile/checkin_cli/weekly_operations_authority.py	<genexpr>zEWeeklyOperationsInitializationTransaction.__init__.<locals>.<genexpr>'   s     )l_kR[);M*M_ks   zauthority idF)lenanyr   r*   r+   r   r,   r$   r-   r.   r/   r0   r1   r2   )selfparentauthority_ids      r;   __init__z2WeeklyOperationsInitializationTransaction.__init__&   sn    |"c)l_k)l&l,^<<8>*6&[1J1L#"#(AE@D    c                H    t               | j                  k7  rt        d      y )Nz*initialization transaction thread mismatch)r   r,   r   r?   s    r;   _require_creatorz:WeeklyOperationsInitializationTransaction._require_creator3   s!    ;$--',-YZZ (rC   c                R    | j                          | j                  st        d      y )Nz&initialization transaction is inactive)rF   r/   r   rE   s    r;   _require_activez9WeeklyOperationsInitializationTransaction._require_active7   s&    ||,-UVV rC   c                
   | j                          | j                  rt        d      d| _        | j                  j	                          d| _        t        j                  | j                  j                  t        j                         d }d }d }d}d}d }d }	 	 t        t        j                  | j                  j                        v rd}t        d      t        | j                        }t!        | j                  |      }t#        | j$                  |      }	t'        | j                  |	t(        t+        t,        f            }t        j.                  | j                  j                        }t1        | j                  |      }
t3        | j$                  t        j4                  |      |
j6                  |
j8                  |t:              | _        t?        | j                  || j<                        | _         d }t        jB                  |j                         d }t        jB                  |j                         d }d}t        j                  | j                  j                  t        jD                         |s|t        jB                  |       |t        jB                  |j                         |et        t        j                  | j                  j                        vr	 tG        | j                  |       t        jB                  |j                         d| _        |r| j                  jM                         }nStO        |tP              r|n$tS        jT                         xs |xs tW        d      }| j                  jM                  |      }	 |r0	 tY        | j                  j                  t(               t[        d      | S # t        $ r d}Y w xY w# tH        tJ        f$ r}|}Y d }~d }~ww xY w# t        j                  | j                  j                  t        jD                         |s5|t        jB                  |       |t        jB                  |j                         |t        t        j                  | j                  j                        vr6	 tG        | j                  |       n# tH        tJ        f$ r}|}Y d }~nd }~ww xY wt        jB                  |j                         d| _        |r| j                  jM                         }w tO        |tP              r|n$tS        jT                         xs |xs tW        d      }| j                  jM                  |      }w w xY w# tJ        $ r}||| d }~ww xY w)Nz+initialization transaction cannot be reusedTFz!authority marker name is occupied)allowedz'initialization transaction enter failedz#existing marker classifier returned).rF   r.   r   r-   blockr/   fcntlflockr*   
descriptorLOCK_EXr   oslistdirr   r    r   r   r+   r   r   	frozensetr   dupr   r   fstatmarkermarker_digestr   r1   r   r2   closeLOCK_UNr!   OSErrorr   restore
isinstancer	   sys	exceptionr
   r   AssertionError)r?   preparedregistry_preparedrN   	completedoccupiedcancellationcleanup_failureregistrypayload	publishedcleanup_errorerror_s                 r;   	__enter__z3WeeklyOperationsInitializationTransaction.__enter__<   s`   ==,-Z[[DLL++U]];*.59!%
	:>043	3 "**T\\-D-D"EE#H,-PQQ$4T\\$B!*4<<9JK01C1CXN3LL'+E%}&67  VVDLL$;$;<
3DLL(K	 ;&&(<i>N>N++X7L! #@jZ^ZgZg"h!
,,-*556$(! 	 KK//?)HHZ('HHX001$0""**T\\5L5L*MM<1$,,@QR HH.99:$#';;#6#6#8L &o7Z[ ( ]]_ a a56_`	  ++E2A()@)@B\]
 !!FGGG &    !()>? <.;O< KK//?)HHZ('HHX001$0""**T\\5L5L*MM<1$,,@QR ')>? <.;O<HH.99:$#';;#6#6#8L &o7Z[ ( ]]_ a a56_`	  ++E2A- 4 ) +\1s   FN: O 	$U :O	O* O		O* O'O""O'*B%UR'&U'S6R=8U=SBU	U3(U..U3c                h    | j                          | j                  t        d      | j                  S )Nz%initialization binding is unavailable)rH   r1   r   rE   s    r;   bindingz1WeeklyOperationsInitializationTransaction.binding   s.    == ,-TUU}}rC   c                h    | j                          | j                  t        d      | j                  S )Nz$initialized authority is unavailable)rH   r2   r   rE   s    r;   	authorityz3WeeklyOperationsInitializationTransaction.authority   s.    ??",-STTrC   c                J    | j                          | j                  }d| _        y )NT)rH   rm   r0   )r?   rj   s     r;   acknowledge_bindingz=WeeklyOperationsInitializationTransaction.acknowledge_binding   s    LL!rC   c                   | j                          | j                  }| j                  }d| _        | j                  s|j                          d | _        | j                  r | j                  j                  |      }||y| j                  j                         }|}|t        j                  }n#|t        j                  }nt        j                  }t        |||d n|j                  |      }	||	|||	||	)NF)rH   rm   ro   r/   r0   rW   r2   r-   rZ   r#   BODY_EXCEPTIONCANCELLATIONMISSING_ACKNOWLEDGEMENTr%   cancellation_kind)
r?   _kindri   
_tracebackrm   ro   rc   originalcontext	committeds
             r;   __exit__z2WeeklyOperationsInitializationTransaction.__exit__   s    ,,NN	!!OO"DO;;..u5L'""{{**,1@@G%1>>G1IIG; (Dl.L.L	
	 )#-rC   c                    t        d      Nz+initialization transaction cannot be copiedr   rE   s    r;   __copy__z2WeeklyOperationsInitializationTransaction.__copy__       ()VWWrC   c                    t        d      r~   r   )r?   _memos     r;   __deepcopy__z6WeeklyOperationsInitializationTransaction.__deepcopy__   r   rC   N)r@   r   rA   r   returnNone)r   r   )r   r   )r   r   )r   r   )rw   ztype[BaseException] | Noneri   zBaseException | Nonerx   zTracebackType | Noner   bool)r   r   )r   zdict[int, Self]r   r   )__name__
__module____qualname____doc__r3   __annotations__rB   rF   rH   rk   propertyrm   ro   rq   r|   r   r   r8   rC   r;   r&   r&   !   sm    P LIu  LE[W
KZ    "
BXXrC   r&   c                    t        | |      S )zEConstruct an inert transaction; signal blocking starts only on enter.)r&   )r@   rA   s     r;   r'   r'      s    4V\JJrC   c                   t        |       | j                         5  t        j                  | j                        }	 t        ||       t        | ||      cddd       S # t        $ r t        j                  |        w xY w# 1 sw Y   yxY w)z/Open the caller-bound dedicated authority root.N)	r   lockedrP   rS   rN   r   r   r
   rW   )r@   rm   rN   s      r;   open_authority_rootr      sq    w'	VVF--.
	'
G<0WM	 

 * 	HHZ 	 
s    BA A??BB)LegacySidecarInventory!WeeklyOperationsMigrationRequireddiscover_legacy_sidecarsissue_repair_authorityopen_authority_root_for_repair)r@   r   rA   r   r   r&   )r@   r   rm   r   r   r   )>r   
__future__r   rL   rP   r\   	threadingr   typesr   typingr   r   r   checkin_cli.weekly_operationsr	   r
   r   r   $checkin_cli.weekly_operations_layoutr   8checkin_cli.weekly_operations_canonical_registry_historyr   $checkin_cli.weekly_operations_parentr   r   r   r   r   r   r   %checkin_cli.weekly_operations_publishr   r   r   r   r   ,checkin_cli.weekly_operations_authority_rootr   r   0checkin_cli.weekly_operations_registry_bootstrapr   r   r   r    r!   %checkin_cli.weekly_operations_signalsr"   r#   r$   r%   r(   r   r&   r'   r   .checkin_cli.weekly_operations_authority_accessr   r   r   r   r   r8   rC   r;   <module>r      s    G "  	 
   % % ]  ] < R m  m  m b  b _  _ n  n `X `XFK

 rC   