File: //kunden/lib/python3/dist-packages/breezy/__pycache__/inter.cpython-39.pyc
a
�*�^& � @ sL d Z ddlmZ ddlmZ ddlmZ G dd� de�ZG dd � d e�Z d
S )zInter-object utility class.� )�absolute_import� )�BzrError)�LogicalLockResultc @ s e Zd ZdZdd� ZdS )�NoCompatibleInterzLNo compatible object available for operations from %(source)r to %(target)r.c C s || _ || _d S )N��source�target��selfr r � r �./usr/lib/python3/dist-packages/breezy/inter.py�__init__ s zNoCompatibleInter.__init__N)�__name__�
__module__�__qualname__Z_fmtr r r r r
r s r c @ s\ e Zd ZdZdd� Zdd� Zedd� �Zdd � Zd
d� Z edd
� �Z
dd� Zedd� �ZdS )�InterObjecta\ This class represents operations taking place between two objects.
Its instances have methods like join or copy_content or fetch, and contain
references to the source and target objects these operations can be
carried out between.
Often we will provide convenience methods on the objects which carry out
operations with another of similar type - they will always forward to
a subclass of InterObject - i.e.
InterVersionedFile.get(other).method_name(parameters).
If the source and target objects implement the locking protocol -
lock_read, lock_write, unlock, then the InterObject's lock_read,
lock_write and unlock methods may be used.
When looking for an inter, the most recently registered types are tested
first. So typically the most generic and slowest InterObjects should be
registered first.
c C s || _ || _dS )a� Construct a default InterObject instance. Please use 'get'.
Only subclasses of InterObject should call
InterObject.__init__ - clients should call InterFOO.get where FOO
is the base type of the objects they are interacting between. I.e.
InterVersionedFile or InterRepository.
get() is a convenience class method which will create an optimised
InterFOO if possible.
Nr r
r r r
r ; s
zInterObject.__init__c C s4 |� z
|� W n t y. | j�� � Y n0 dS )z@Take out two locks, rolling back the first if the second throws.N)� Exceptionr �unlock)r Zlock_sourceZlock_targetr r r
�_double_lockH s
zInterObject._double_lockc C s8 t | j�D ]}|�||�r
|||� S q
t||��dS )a� Retrieve a Inter worker object for these objects.
:param source: the object to be the 'source' member of
the InterObject instance.
:param target: the object to be the 'target' member of
the InterObject instance.
If an optimised worker exists it will be used otherwise
a default Inter worker instance will be created.
N)�reversed�_optimisersZ
is_compatibler )�klassr r Zproviderr r r
�getS s zInterObject.getc C s | � | jj| jj� t| j�S )z�Take out a logical read lock.
This will lock the source branch and the target branch. The source gets
a read lock and the target a read lock.
)r r � lock_readr r r �r r r r
r d s zInterObject.lock_readc C s | � | jj| jj� t| j�S )z�Take out a logical write lock.
This will lock the source branch and the target branch. The source gets
a read lock and the target a write lock.
)r r r r �
lock_writer r r r r r
r m s zInterObject.lock_writec C s | j �|� dS )z"Register an InterObject optimiser.N)r �append�r Z optimiserr r r
�register_optimiserv s zInterObject.register_optimiserc C s* z| j �� W | j�� n| j�� 0 dS )z'Release the locks on source and target.N)r r r r r r r
r { s zInterObject.unlockc C s | j �|� dS )z$Unregister an InterObject optimiser.N)r �remover r r r
�unregister_optimiser� s z InterObject.unregister_optimiserN)
r r r �__doc__r r �classmethodr r r r r r! r r r r
r # s
r N)
r"