§
    öÛg-  ã                   ó‚   — d Z ddlmZmZ ddlmZ g d¢Z G d„ de¦  «        Z G d„ d	e¦  «        Z G d
„ de¦  «        Z	dS )z
Tools for Advisory Locks
é    )ÚabstractmethodÚabstractpropertyé   )ÚElement)ÚALockÚExclusiveLockÚ	ShareLockc                   ó°   — e Zd ZdZdZdZdj        fd„Zed„ ¦   «         Z	ed„ ¦   «         Z
ed„ ¦   «         Zd	efd
„Zd„ Zd„ Zd„ Zd„ Zed„ ¦   «         Zd„ ZdS )r   a¿  
	Advisory Lock class for managing the acquisition and release of a sequence
	of PostgreSQL advisory locks.

	ALock()'s are fairly consistent with threading.RLock()'s. They can be
	acquired multiple times, and they must be released the same number of times
	for the lock to actually be released.

	A notably difference is that ALock's manage a sequence of lock identifiers.
	This means that a given ALock() may represent multiple advisory locks.
	)ÚdatabaseÚidentifiersÚALOCKz	{1} [{0}]c              #   ó>   K  — d  || j         | j        ¦  «        fV — d S ©N)ÚstateÚmode)ÚselfÚheadfmts     úF/granary/edev/quantum/lib/python3.11/site-packages/postgresql/alock.pyÚ_e_metaszALock._e_metas   s/   è è € ð 	ˆgˆg�d”j $¤)Ñ,Ô,Ð,Ð,Ð,Ð,Ð,Ð,ó    c                 ó   — dS )z!
		The mode of the lock class.
		N© ©r   s    r   r   z
ALock.mode#   ó   € € € r   c                 ó   — dS )a  
		Implemented by subclasses to return the statements to try, acquire, and
		release the advisory lock.

		Returns a triple of callables where each callable takes two arguments,
		the lock-id pairs, and then the int8 lock-ids.
		``(try, acquire, release)``.
		Nr   r   s    r   Ú__select_statements__zALock.__select_statements__)   r   r   c                 ó:   — d„ | D ¦   «         }d„ | D ¦   «         }||fS )Nc                 óP   — g | ]#}|j         t          urt          |¦  «        nd d g‘Œ$S r   )Ú	__class__ÚintÚlist©Ú.0Úxs     r   ú
<listcomp>z1ALock._split_lock_identifiers.<locals>.<listcomp>7   sB   € ð ð ð àð Œk¥Ð$Ð$…4ˆ�7„7€7¨4°¨+ðð ð r   c                 ó2   — g | ]}|j         t          u r|nd ‘ŒS r   )r   r    r"   s     r   r%   z1ALock._split_lock_identifiers.<locals>.<listcomp>;   s8   € ð 	ð 	ð 	àð 	
Œ•sÐÐ€1€1 ð	ð 	ð 	r   r   )ÚidseqÚid_pairsÚidss      r   Ú_split_lock_identifierszALock._split_lock_identifiers4   sJ   € ðð àðñ ô €(ð	ð 	àð	ñ 	ô 	€#ð �CˆÐr   Tc                 ó¼  — | j         dk    rÁt          |¦  «        }|r!|                      | j        | j        ¦  «         n�|                      | j        | j        ¦  «        }d„ t          || j        ¦  «        D ¦   «         } ||¦  «         || j        ¦  «        k    r3|                     ¦   «           | j	        |  
                    |¦  «        Ž  dS | j         dz   | _         dS )z9
		Acquire the locks using the configured identifiers.
		r   c                 ó(   — g | ]\  }}|d          ¯|‘ŒS )r   r   )r#   ÚdidlockÚids      r   r%   z!ALock.acquire.<locals>.<listcomp>P   s5   € ð ð ð ÙˆG�R°w¸q´zðØðð ð r   Fr   T)Ú_countÚboolÚ_acquireÚ	_id_pairsÚ_idsÚ_tryÚzipr   ÚreverseÚ_releaser*   )r   ÚblockingÚlenÚwaitÚrÚrelease_seqs         r   ÚacquirezALock.acquireA   sï   € ð 
„[�AÒÐå
ˆx‰.Œ.€4Ø
ð Ø‡M‚M�$”. $¤)Ñ,Ô,Ð,Ð,ð
 	�	Š	�$”. $¤)Ñ,Ô,€Aðð Ý˜q $Ô"2Ñ3Ô3ðñ ô €Kð €sˆ;ÑÔ˜3˜3˜tÔ/Ñ0Ô0Ò0Ð0ð ×ÒÑÔÐØ€T„]�D×0Ò0°Ñ=Ô=Ð>Ð>àˆEØ”˜a‘€$„+Ø	ˆr   c                 ó.   — |                       ¦   «          | S r   )r=   r   s    r   Ú	__enter__zALock.__enter__a   s   € Ø‡,‚,�.„.€.Ø	€+r   c                 óú   — | j         dk     rt          d¦  «        ‚| j        j        sE| j         dk    r:|                      t          | j        ¦  «        t          | j        ¦  «        ¦  «         | j         dz
  | _         dS )z9
		Release the locks using the configured identifiers.
		r   zcannot release un-acquired lockr   N)r/   ÚRuntimeErrorr   Úclosedr7   Úreversedr2   r3   r   s    r   ÚreleasezALock.releasee   sq   € ð 
„[�1‚_€_Ý	Ð7Ñ	8Ô	8Ð8Ø	ŒÔ	ð @ $¤+°¢/ /ð ‡=‚=•˜$œ.Ñ)Ô)­8°D´IÑ+>Ô+>Ñ?Ô?Ð?à”˜a‘€$„+€+€+r   c                 ó.   — |                       ¦   «          d S r   )rD   )r   ÚtypÚvalÚtbs       r   Ú__exit__zALock.__exit__r   s   € Ø‡,‚,�.„.€.€.€.r   c                 ó2   — | j         dk    o| j        j         S )z”
		Whether the locks have been acquired. This method is sensitive to the
		connection's state. If the connection is closed, it will return False.
		r   )r/   r   rB   r   s    r   ÚlockedzALock.lockedu   s   € ð
 Œ+˜Š/Ð	9 D¤MÔ$8Ð 8Ð9r   c                 ó2   — |                       ¦   «         rdndS )NrK   Úunlocked)rK   r   s    r   r   zALock.state|   s   € à—[’[‘]”]Ð	2ˆˆ¨
Ð2r   c                 óÐ   — d| _         |x| _        | _        || _        |                      |¦  «        \  | _        | _        |                      ¦   «         \  | _        | _	        | _
        dS )zj
		Initialize the lock object to manage a sequence of advisory locks
		for use with the given database.
		r   N)r/   Ú
connectionr   r   r*   r2   r3   r   r4   r1   r7   )r   r   r   s      r   Ú__init__zALock.__init__€   s_   € ð
 €$„+Ø$,Ð,€$„/�D”MØ €$ÔØ"×:Ò:¸;ÑGÔGÑ€$„.�$”)Ø,0×,FÒ,FÑ,HÔ,HÑ)€$„)ˆTŒ]˜DœM˜M˜Mr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
_e_factorsÚ_e_labelÚformatr   r   r   r   Ústaticmethodr*   r9   r=   r?   rD   rI   rK   Úpropertyr   rP   r   r   r   r   r      s  € € € € € ð
ð 
ð +€Ø€àÔð-ð -ð -ð -ð
 ðð ñ Ôðð
 ðð ñ Ôðð ð
ð 
ñ „,ð
ð #¨#ð ð ð ð ð@ð ð ð ð  ð  ðð ð ð:ð :ð :ð ð3ð 3ñ „(ð3ð	Ið 	Ið 	Ið 	Ið 	Ir   r   c                   ó   — e Zd ZdZd„ ZdS )r	   Úsharec                 óf   — | j         j        j        | j         j        j        | j         j        j        fS r   )r   ÚsysÚtry_advisory_sharedÚacquire_advisory_sharedÚrelease_advisory_sharedr   s    r   r   zShareLock.__select_statements__Ž   s-   € à„=ÔÔ(Ø„=ÔÔ,Ø„=ÔÔ,ð
ð r   N©rQ   rR   rS   r   r   r   r   r   r	   r	   ‹   s(   € € € € € Ø€ðð ð ð ð r   r	   c                   ó   — e Zd ZdZd„ ZdS )r   Ú	exclusivec                 óf   — | j         j        j        | j         j        j        | j         j        j        fS r   )r   r]   Útry_advisory_exclusiveÚacquire_advisory_exclusiveÚrelease_advisory_exclusiver   s    r   r   z#ExclusiveLock.__select_statements__˜   s-   € à„=ÔÔ+Ø„=ÔÔ/Ø„=ÔÔ/ð
ð r   Nra   r   r   r   r   r   •   s(   € € € € € Ø€ðð ð ð ð r   r   N)
rT   Úabcr   r   Úpython.elementr   Ú__all__r   r	   r   r   r   r   ú<module>rk      så   ððð ð 1Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø #Ð #Ð #Ð #Ð #Ð #ðð ð €ðyIð yIð yIð yIð yIˆGñ yIô yIð yIðvð ð ð ð �ñ ô ð ðð ð ð ð �Eñ ô ð ð ð r   