o
    i^	                     @   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	   a/var/www/html/eduruby.in/lip-sync/lip-sync-env/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)Zactor)distributedsuperr   Z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