§
    cÌcC+  ã                   ó‚   — d dl mZmZmZ ddlmZmZmZmZm	Z	 ddl
mZ ddlmZ  G d„ d¦  «        Z G d„ d	¦  «        Zd
S )é    )ÚUnionÚOptionalÚTypeé   )Úcounted_lockÚerrorsÚlockÚtransactionsÚurlutils)Úonly_raises)Ú	Transportc                   ó°  — e Zd ZU dZeed<   ee         ed<   eej	                 ed<   ee
j                 ed<   dededeej                 d	d
fd„Zd d„Zd„ Zd„ Zd d„Zded	efd„Zd d„Zd d„Zd d„Zd!deej	                 d	eej	                 fd„Zd d„Zd„ Zd„ Z eej        ej        ¦  «        d„ ¦   «         Z d	e!fd„Z"d	e!fd„Z#d	e
j        fd„Z$d„ Z%d„ Z&d
S )"ÚLockableFilesaT  Object representing a set of related files locked within the same scope.

    This coordinates access to the lock along with providing a transaction.

    LockableFiles manage a lock count and can be locked repeatedly by
    a single caller.  (The underlying lock implementation generally does not
    support this.)

    Instances of this class are often called control_files.

    This class is now deprecated; code should move to using the Transport
    directly for file operations and using the lock or CountedLock for
    locking.

    :ivar _lock: The real underlying lock (e.g. a LockDir)
    :ivar _lock_count: If _lock_mode is true, a positive count of the number
        of times the lock has been taken (and not yet released) *by this
        process*, through this particular object instance.
    :ivar _lock_mode: None, or 'r' or 'w'
    Ú_lock_countÚ
_lock_modeÚ_token_from_lockÚ_transactionÚ	transportÚ	lock_nameÚ
lock_classÚreturnNc                 ó  — || _         || _        d| _        d| _        d| _        |                      ¦   «          |                      |¦  «        } |||| j        | j        ¬¦  «        | _	        t          j        | j	        ¦  «        | _        dS )aF  Create a LockableFiles group

        :param transport: Transport pointing to the directory holding the
            control files and lock.
        :param lock_name: Name of the lock guarding these files.
        :param lock_class: Class of lock strategy to use: typically
            either LockDir or TransportLock.
        Nr   )Úfile_modebitsÚdir_modebits)Ú
_transportr   r   r   r   Ú_find_modesÚ_escapeÚ
_file_modeÚ	_dir_modeÚ_lockr   ÚCountedLockÚ_counted_lock)Úselfr   r   r   Úesc_names        ú7/usr/lib/python3/dist-packages/breezy/lockable_files.pyÚ__init__zLockableFiles.__init__<   s�   € ð $ˆŒØ"ˆŒØ ˆÔØˆŒØˆÔØ×ÒÑÔÐØ—<’< 	Ñ*Ô*ˆØ�Z 	¨8Ø.2¬oØ-1¬^ð=ñ =ô =ˆŒ
õ *Ô5°d´jÑAÔAˆÔÐÐó    c                 óF   — | j                              | j        ¬¦  «         dS )z‰Create the lock.

        This should normally be called only when the LockableFiles directory
        is first created on disk.
        ©ÚmodeN)r    Úcreater   ©r#   s    r%   Úcreate_lockzLockableFiles.create_lockQ   s%   € ð 	Œ
×Ò˜tœ~ÐÑ.Ô.Ð.Ð.Ð.r'   c                 óL   — d                      | j        j        | j        ¦  «        S )Nz{}({!r}))ÚformatÚ	__class__Ú__name__r   r,   s    r%   Ú__repr__zLockableFiles.__repr__Y   s&   € Ø× Ò  ¤Ô!8Øœ?ñ,ô ,ð 	,r'   c                 óL   — d                      | j        | j        j        ¦  «        S )NzLockableFiles({}, {}))r/   r   r   Úbaser,   s    r%   Ú__str__zLockableFiles.__str__]   s   € Ø&×-Ò-¨d¬n¸d¼oÔ>RÑSÔSÐSr'   c                 ó8   — | j                              ¦   «          dS )z‘Break the lock of this lockable files group if it is held.

        The current ui factory will be used to prompt for user conformation.
        N)r    Ú
break_lockr,   s    r%   r7   zLockableFiles.break_lock`   s   € ð
 	Œ
×ÒÑÔÐÐÐr'   Úfile_or_pathc                 ó:   — |dk    rdS t          j        |¦  «        S )z)DEPRECATED: Do not use outside this classÚ )r   Úescape)r#   r8   s     r%   r   zLockableFiles._escapeg   s"   € à˜2ÒÐØ�2ÝŒ˜|Ñ,Ô,Ð,r'   c                 óÆ   — 	 | j                              d¦  «        }|j        dz  dz  | _        | j        dz  | _        dS # t
          j        $ r d| _        d| _        Y dS w xY w)z‚Determine the appropriate modes for files and directories.

        :deprecated: Replaced by BzrDir._find_creation_modes.
        ú.iÿ  iÀ  i¶ñÿÿií  i¤  N)r   ÚstatÚst_moder   r   r   ÚTransportNotPossible)r#   Ústs     r%   r   zLockableFiles._find_modesm   sw   € ð	7Ø”×%Ò% cÑ*Ô*ˆBð !œj¨6Ñ1°VÑ;ˆDŒNà"œn¨wÑ6ˆDŒOˆOˆOøõ Ô*ð 	$ð 	$ð 	$Ø"ˆDŒNØ#ˆDŒOˆOˆOˆOð	$øøøs   ‚? ¿A ÁA c                 ó8   — | j                              ¦   «          dS )z@Set this LockableFiles to not clear the physical lock on unlock.N)r    Úleave_in_placer,   s    r%   rC   zLockableFiles.leave_in_placeƒ   s   € àŒ
×!Ò!Ñ#Ô#Ð#Ð#Ð#r'   c                 ó8   — | j                              ¦   «          dS )z<Set this LockableFiles to clear the physical lock on unlock.N)r    Údont_leave_in_placer,   s    r%   rE   z!LockableFiles.dont_leave_in_place‡   s   € àŒ
×&Ò&Ñ(Ô(Ð(Ð(Ð(r'   Útokenc                 óˆ  — | j         rv| j         dk    s&|                      ¦   «                              ¦   «         st          j        | ¦  «        ‚| j                             |¦  «         | xj        dz  c_        | j        S | j         	                    |¬¦  «        }d| _         d| _        |  
                    ¦   «          || _        |S )až  Lock this group of files for writing.

        :param token: if this is already locked, then lock_write will fail
            unless the token matches the existing lock.
        :returns: a token if this instance supports tokens, otherwise None.
        :raises TokenLockingNotSupported: when a token is given but this
            instance doesn't support using token locks.
        :raises MismatchedToken: if the specified token doesn't match the token
            of the existing lock.

        A token should be passed in if you know that you have locked the object
        some other way, and need to synchronise this object's state with that
        fact.
        Úwr   )rF   )r   Úget_transactionÚ	writeabler   ÚReadOnlyErrorr    Úvalidate_tokenr   r   Ú
lock_writeÚ_set_write_transaction)r#   rF   Útoken_from_locks      r%   rM   zLockableFiles.lock_write‹   sÆ   € ð Œ?ð 	#Ø” 3Ò&Ð&Ø×/Ò/Ñ1Ô1×;Ò;Ñ=Ô=ð 'åÔ*¨4Ñ0Ô0Ð0ØŒJ×%Ò% eÑ,Ô,Ð,ØÐÔ Ñ!ÐÔØÔ(Ð(à"œj×3Ò3¸%Ð3Ñ@Ô@ˆOà!ˆDŒOØ ˆDÔØ×'Ò'Ñ)Ô)Ð)Ø$3ˆDÔ!Ø"Ð"r'   c                 ó  — | j         rB| j         dvr't          d                     | j         ¦  «        ¦  «        ‚| xj        dz  c_        d S | j                             ¦   «          d| _         d| _        |                      ¦   «          d S )N)ÚrrH   zinvalid lock mode {!r}r   rQ   )r   Ú
ValueErrorr/   r   r    Ú	lock_readÚ_set_read_transactionr,   s    r%   rS   zLockableFiles.lock_readª   s�   € ØŒ?ð 		)ØŒ jÐ0Ð0Ý Ð!9×!@Ò!@ÀÄÑ!QÔ!QÑRÔRÐRØÐÔ Ñ!ÐÔÐÐàŒJ× Ò Ñ"Ô"Ð"à!ˆDŒOØ ˆDÔØ×&Ò&Ñ(Ô(Ð(Ð(Ð(r'   c                 ó    — |                       t          j        ¦   «         ¦  «         |                      ¦   «                              d¦  «         dS )zSetup a read transaction.iˆ  N)Ú_set_transactionr
   ÚReadOnlyTransactionrI   Úset_cache_sizer,   s    r%   rT   z#LockableFiles._set_read_transaction¶   sE   € à×Ò�lÔ>Ñ@Ô@ÑAÔAÐAà×ÒÑÔ×-Ò-¨dÑ3Ô3Ð3Ð3Ð3r'   c                 óR   — |                       t          j        ¦   «         ¦  «         dS )zSetup a write transaction.N)rV   r
   ÚWriteTransactionr,   s    r%   rN   z$LockableFiles._set_write_transaction¼   s%   € à×Ò�lÔ;Ñ=Ô=Ñ>Ô>Ð>Ð>Ð>r'   c                 ó  — | j         st          j        | ¦  «        S | j        dk    r| xj        dz  c_        d S |                      ¦   «          	 | j                             ¦   «          d| _        d | _         d S # d| _        d | _         w xY w)Nr   r   )r   r	   Úcant_unlock_not_heldr   Ú_finish_transactionr    Úunlockr,   s    r%   r^   zLockableFiles.unlockÀ   s£   € àŒð 	3ÝÔ,¨TÑ2Ô2Ð2ØÔ˜aÒÐØÐÔ Ñ!ÐÔÐÐð ×$Ò$Ñ&Ô&Ð&ð'Ø”
×!Ò!Ñ#Ô#Ð#à#$�Ô Ø"&�”��øð $%�Ô Ø"&�”Ð&Ð&Ð&Ð&s   ÁA7 Á7Bc                 ó   — | j         dk    S )z1Return true if this LockableFiles group is lockedr   )r   r,   s    r%   Ú	is_lockedzLockableFiles.is_lockedÏ   s   € àÔ 1Ò$Ð$r'   c                 ó\   — 	 | j                              ¦   «         duS # t          $ r Y dS w xY w)záReturn physical lock status.

        Returns true if a lock is held on the transport. If no lock is held, or
        the underlying locking mechanism does not support querying lock
        status, false is returned.
        NF)r    ÚpeekÚNotImplementedErrorr,   s    r%   Úget_physical_lock_statusz&LockableFiles.get_physical_lock_statusÓ   s@   € ð	Ø”:—?’?Ñ$Ô$¨DÐ0Ð0øÝ"ð 	ð 	ð 	Ø�5�5ð	øøøs   ‚ �
+ª+c                 óD   — | j         €t          j        ¦   «         S | j         S )zÁReturn the current active transaction.

        If no transaction is active, this returns a passthrough object
        for which all data is immediately flushed and no caching happens.
        )r   r
   ÚPassThroughTransactionr,   s    r%   rI   zLockableFiles.get_transactionß   s%   € ð ÔÐ$ÝÔ6Ñ8Ô8Ð8àÔ$Ð$r'   c                 óP   — | j         �t          j        d| z  ¦  «        ‚|| _         dS )zSet a new active transaction.Nz&Branch %s is in a transaction already.)r   r   Ú	LockError)r#   Únew_transactions     r%   rV   zLockableFiles._set_transactionê   s9   € àÔÐ(ÝÔ"Ð#KØ#'ñ$(ñ )ô )ð )à+ˆÔÐÐr'   c                 ó†   — | j         €t          j        d| z  ¦  «        ‚| j         }d| _         |                     ¦   «          dS )zExit the current transaction.Nz!Branch %s is not in a transaction)r   r   rh   Úfinish)r#   Útransactions     r%   r]   z!LockableFiles._finish_transactionñ   sS   € àÔÐ$ÝÔ"Ð#FØ#'ñ$(ñ )ô )ð )àÔ'ˆØ ˆÔØ×ÒÑÔÐÐÐr'   )r   N©N)'r1   Ú
__module__Ú__qualname__Ú__doc__ÚintÚ__annotations__r   Ústrr	   Ú	LockTokenr
   ÚTransactionr   r   ÚLockr&   r-   r2   r5   r7   r   r   rC   rE   rM   rS   rT   rN   r   r   ÚLockNotHeldÚ
LockBrokenr^   Úboolr`   rd   rI   rV   r]   © r'   r%   r   r       sR  € € € € € € ðð ð* ÐÐÑà˜”ÐÐÑØ˜tœ~Ô.Ð.Ð.Ñ.Ø˜<Ô3Ô4Ð4Ð4Ñ4ðB )ð B¸ð BÈÈdÌiÌð BÐ]að Bð Bð Bð Bð*/ð /ð /ð /ð,ð ,ð ,ðTð Tð Tð ð  ð  ð  ð- Cð -¨Cð -ð -ð -ð -ð7ð 7ð 7ð 7ð,$ð $ð $ð $ð)ð )ð )ð )ð#ð # ¨¬Ô 8ð #ÀHÈTÌ^ÔD\ð #ð #ð #ð #ð>
)ð 
)ð 
)ð 
)ð4ð 4ð 4ð?ð ?ð ?ð €[�Ô# VÔ%6Ñ7Ô7ð'ð 'ñ 8Ô7ð'ð%˜4ð %ð %ð %ð %ð
¨$ð 
ð 
ð 
ð 
ð	% Ô!9ð 	%ð 	%ð 	%ð 	%ð,ð ,ð ,ðð ð ð ð r'   r   c                   ó\   — e Zd ZdZdedefd„Zd„ Zd„ Zd„ Z	dd	„Z
d
„ Zd„ Zd„ Zdd„Zd„ ZdS )ÚTransportLocka)  Locking method which uses transport-dependent locks.

    On the local filesystem these transform into OS-managed locks.

    These do not guard against concurrent access via different
    transports.

    This is suitable for use only in WorkingTrees (which are at present
    always local).
    r   Úescaped_namec                 ó>   — || _         || _        || _        || _        d S rm   )r   Ú_escaped_nameÚ_file_modebitsÚ_dir_modebits)r#   r   r}   r   r   s        r%   r&   zTransportLock.__init__  s'   € Ø#ˆŒØ)ˆÔØ+ˆÔØ)ˆÔÐÐr'   c                 ó*   — t          | j        ¦  «        ‚rm   )rc   r7   r,   s    r%   r7   zTransportLock.break_lock  s   € Ý! $¤/Ñ2Ô2Ð2r'   c                 ó*   — t          | j        ¦  «        ‚rm   )rc   rC   r,   s    r%   rC   zTransportLock.leave_in_place  s   € Ý! $Ô"5Ñ6Ô6Ð6r'   c                 ó*   — t          | j        ¦  «        ‚rm   )rc   rE   r,   s    r%   rE   z!TransportLock.dont_leave_in_place  s   € Ý! $Ô":Ñ;Ô;Ð;r'   Nc                 óz   — |�t          j        | ¦  «        ‚| j                             | j        ¦  «        | _        d S rm   )r   ÚTokenLockingNotSupportedr   rM   r   r    ©r#   rF   s     r%   rM   zTransportLock.lock_write  s7   € ØÐÝÔ1°$Ñ7Ô7Ð7Ø”_×/Ò/°Ô0BÑCÔCˆŒ
ˆ
ˆ
r'   c                 óN   — | j                              | j        ¦  «        | _        d S rm   )r   rS   r   r    r,   s    r%   rS   zTransportLock.lock_read  s    € Ø”_×.Ò.¨tÔ/AÑBÔBˆŒ
ˆ
ˆ
r'   c                 óF   — | j                              ¦   «          d | _         d S rm   )r    r^   r,   s    r%   r^   zTransportLock.unlock  s!   € ØŒ
×ÒÑÔÐØˆŒ
ˆ
ˆ
r'   c                 ó   — t          ¦   «         ‚rm   )rc   r,   s    r%   rb   zTransportLock.peek"  s   € Ý!Ñ#Ô#Ð#r'   c                 óT   — | j                              | j        d| j        ¬¦  «         dS )zCreate lock mechanismr'   r)   N)r   Ú	put_bytesr   r€   )r#   r*   s     r%   r+   zTransportLock.create%  s:   € ð 	Œ×!Ò! $Ô"4°cØ'+Ô':ð 	"ñ 	<ô 	<ð 	<ð 	<ð 	<r'   c                 ó2   — |�t          j        | ¦  «        ‚d S rm   )r   r†   r‡   s     r%   rL   zTransportLock.validate_token+  s!   € ØÐÝÔ1°$Ñ7Ô7Ð7ð Ðr'   rm   )r1   rn   ro   rp   r   rs   r&   r7   rC   rE   rM   rS   r^   rb   r+   rL   rz   r'   r%   r|   r|   û   sØ   € € € € € ð	ð 	ð* )ð *¸3ð *ð *ð *ð *ð3ð 3ð 3ð7ð 7ð 7ð<ð <ð <ðDð Dð Dð Dð
Cð Cð Cðð ð ð$ð $ð $ð<ð <ð <ð <ð8ð 8ð 8ð 8ð 8r'   r|   N)Útypingr   r   r   r:   r   r   r	   r
   r   Ú
decoratorsr   r   r   r   r|   rz   r'   r%   ú<module>r�      s   ðð" )Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ð (ðð ð ð ð ð ð ð ð ð ð ð ð ð ðð ð ð ð ð ð !Ð  Ð  Ð  Ð  Ð  ðXð Xð Xð Xð Xñ Xô Xð Xðv28ð 28ð 28ð 28ð 28ñ 28ô 28ð 28ð 28ð 28r'   