o
    ôj@  ã                   @   sN   d dl Z d dlmZ e  d¡ZG dd„ dƒZG dd„ dƒZG dd	„ d	eƒZdS )
é    N)ÚdequeÚfsspecc                   @   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
   úc/var/www/html/academy/tools/voices/clone/sv-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   s  d}zP| j r| j  ¡ }|r| ¡  n| ¡  d}| j sW |dur&| j  |¡ | j rFz	| j  ¡  ¡  W n tyB   tjddd� Y nw | j s)d| j_	d| j_
d| _dS |dur]| j  |¡ | j r}z	| j  ¡  ¡  W n tyy   tjddd� Y nw | j s`d| j_	d| j_
d| _w )ú8Finish transaction: commit or discard all deferred filesNzDiscarding deferred file failedT)Úexc_infoF)r   Úpopleftr   ÚdiscardÚ
appendleftÚ	ExceptionÚloggerÚdebugr   r   r   )r   r   Úfr
   r
   r   r   *   sD   

ú€
ÿý
óÿý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   I   s   
zFileActor.__init__c                 C   ó"   | j D ]}| ¡  q| j  ¡  d S r   )r   r   Úclear©r   r!   r
   r
   r   r   L   ó   

zFileActor.commitc                 C   r(   r   )r   r   r)   r*   r
   r
   r   r   Q   r+   zFileActor.discardc                 C   s   | j  |¡ d S r   )r   Úappendr*   r
   r
   r   r,   V   s   zFileActor.appendN)r#   r$   r%   r   r   r   r,   r
   r
   r
   r   r'   H   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   [   s   zDaskTransaction.__init__Tc                 C   st   z-|r| j  ¡  ¡  n| j  ¡  ¡  W d| j_d| j_d| _dS W d| j_d| j_d| _dS d| j_d| j_d| _w )r   FN)r   r   r1   r   r   r   r   )r   r   r
   r
   r   r   g   s   
ú
þzDaskTransaction.completer"   )r#   r$   r%   r   r   Ú__classcell__r
   r
   r3   r   r-   Z   s    r-   )ÚloggingÚcollectionsr   Ú	getLoggerr   r   r'   r-   r
   r
   r
   r   Ú<module>   s    
A