o
    ²Çh^	  ã                   @   s<   d dl mZ G dd„ dƒZG dd„ dƒZG dd„ deƒZdS )	é    )Údequec                   @   s:   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zddd„ZdS )ÚTransactiona  Filesystem transaction write context

    Gathers files for deferred commit or discard, so that several write
    operations can be finalized semi-atomically. This works by having this
    instance as the ``.transaction`` attribute of the given filesystem
    c                 K   s   || _ tƒ | _dS )úO
        Parameters
        ----------
        fs: FileSystem instance
        N)Úfsr   Úfiles)Úselfr   Úkwargs© r	   úf/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/fsspec/transaction.pyÚ__init__   s   zTransaction.__init__c                 C   s   |   ¡  | S ©N)Ústart©r   r	   r	   r
   Ú	__enter__   s   zTransaction.__enter__c                 C   s4   | j |du d | jrd| j_d| j_d| _dS dS )z;End transaction and commit, if exit is not due to exceptionN)ÚcommitF)Úcompleter   Ú_intransÚ_transaction)r   Úexc_typeÚexc_valÚexc_tbr	   r	   r
   Ú__exit__   s   
ýzTransaction.__exit__c                 C   s   t ƒ | _d| j_dS )z&Start a transaction on this FileSystemTN)r   r   r   r   r   r	   r	   r
   r   "   s   zTransaction.startTc                 C   sF   | j r| j  ¡ }|r| ¡  n| ¡  | j sd| j_d| j_d| _dS ©z8Finish transaction: commit or discard all deferred filesFN)r   Úpopleftr   Údiscardr   r   r   )r   r   Úfr	   r	   r
   r   '   s   

û
zTransaction.completeN©T)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r	   r	   r	   r
   r      s    		r   c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
Ú	FileActorc                 C   s
   g | _ d S r   )r   r   r	   r	   r
   r   5   s   
zFileActor.__init__c                 C   ó"   | j D ]}| ¡  q| j  ¡  d S r   )r   r   Úclear©r   r   r	   r	   r
   r   8   ó   

zFileActor.commitc                 C   r"   r   )r   r   r#   r$   r	   r	   r
   r   =   r%   zFileActor.discardc                 C   s   | j  |¡ d S r   )r   Úappendr$   r	   r	   r
   r&   B   s   zFileActor.appendN)r   r   r   r   r   r   r&   r	   r	   r	   r
   r!   4   s
    r!   c                       s&   e Zd Z‡ fdd„Zddd„Z‡  ZS )ÚDaskTransactionc                    s4   ddl }tƒ  |¡ | ¡ }|jtdd ¡ | _dS )r   r   NT)Úactor)ÚdistributedÚsuperr   Údefault_clientÚsubmitr!   Úresultr   )r   r   r)   Úclient©Ú	__class__r	   r
   r   G   s   zDaskTransaction.__init__Tc                 C   s4   |r
| j  ¡  ¡  n| j  ¡  ¡  d| j_d| _dS r   )r   r   r-   r   r   r   )r   r   r	   r	   r
   r   S   s
   
zDaskTransaction.completer   )r   r   r   r   r   Ú__classcell__r	   r	   r/   r
   r'   F   s    r'   N)Úcollectionsr   r   r!   r'   r	   r	   r	   r
   Ú<module>   s    0