a
    ’À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	   úN/var/www/html/assistant/venv/lib/python3.9/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   s0   | j |du d | jr,d| j_d| j_d| _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   sB   | j r(| j  ¡ }|r| ¡  q | ¡  q 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   s"   | j D ]}| ¡  q| j  ¡  d S r   )r   r   Úclear©r   r   r	   r	   r
   r   8   s    

zFileActor.commitc                 C   s"   | j D ]}| ¡  q| j  ¡  d S r   )r   r   r!   r"   r	   r	   r
   r   =   s    

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)Zactor)ÚdistributedÚsuperr   Zdefault_clientZ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.complete)T)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