o
    jA                     @   s&   d dl mZ d dlT G dd dZdS )    )SMBFile)*c                   @   s    e Zd ZdZdd Zdd ZdS )SMBBlockingFileMgra!  
	This class implements a file object manager which can open/read/write files over the smbconnection
	The input/output queues used for communicating are process/thread/async safe!
	Therefore this creates a bridge between a non-async thread/process and the smb connection (file ops only!)
	c                 C   s"   || _ || _|| _i | _d| _d S )Nr   )
connectionin_qout_q
filehandle	curhandle)selfr   r   r    r   /root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/aiosmb/commons/interfaces/blocking/file/file.py__init__   s
   
zSMBBlockingFileMgr.__init__c              
      s  	 d }z| j  I d H }|d u rW d S |jtjkrz?t| j|j}|	| j|j
I d H \}}|d ur7||| j| j< |  jd7  _t|j| jd |j}| j|I d H  W nn ty~ } zt|jt|}| j|I d H  W Y d }~nOd }~ww |jtjkrz>| j|j}||jdI d H \}}|d ur|||jI d H \}}|d ur|t|j|j|}| j|I d H  W n ty } zt|jt|}| j|I d H  W Y d }~nd }~ww |jtjkr8z%| j|j}| I d H  | j|j= t|j|j}| j|I d H  W n ty7 } zt|jt|}| j|I d H  W Y d }~nd }~ww |jtj krzD| j|j}||jdI d H \}}|d urZ||!|j"I d H \}	}|d url|| j|j= t#|j|j|	}| j|I d H  W nE ty } zt|jt|}| j|I d H  W Y d }~n&d }~ww |jtj$kr| jD ]}
| j|
 }| I d H  | j|
= qW d S W n$ ty } zt|t|}| j|I d H  W Y d }~d S d }~ww q)NT   r   )%r   coro_getcmd_type
SMBFILECMDOPENr   from_remotepathr   pathopenmoder   r	   SMBFileOpenReplycmd_idsizer   coro_put	ExceptionSMBFileErrorstrREADgethandleseekpositionreadcountSMBFileReadReplyCLOSEcloseSMBFileCloseReplyWRITEwritedataSMBFileWriteReply	TERMINATE)r
   ecmdidcmdsf_errreser+   r$   r    r   r   r   run   s    





zSMBBlockingFileMgr.runN)__name__
__module____qualname____doc__r   r5   r   r   r   r   r      s    r   N)aiosmb.commons.interfaces.filer   0aiosmb.commons.interfaces.blocking.file.protocolr   r   r   r   r   <module>   s   