o
    pf                     @   s   d Z ddlmZmZ ddlZddlZddlZddlZddlm	Z	 ddl
mZ ddlmZ ejrCddlmZmZmZmZmZ dd	lmZ zdd
lmZ W n eyZ   dd
lmZ Y nw e dkZG dd deZeZe	dd ZdS )zTools for managing OS errors.
    )print_functionunicode_literalsN)contextmanager)reraise   )errors)IteratorOptionalTextTypeUnion)TracebackType)MappingWindowsc                   @   s.  e Zd ZdZi dejejejej	ej
ejej
ejej
ejejejejdejejej
ejejejejejejejejejejejejejejejejejejiZ e ! Z"ej#e"ej< eje"ej< ej#e"ej< e$rej#e"d< ej#e"d< eje d< dddZ%d	d
 Z&dd Z'dS )_ConvertOSErrorsz4Context manager to convert OSErrors in to FS Errors.@         i  Fc                 C   s   || _ || _|| _d S N)_opname_path
_directory)selfopnamepath	directory r   G/home/ertert/spirit/venv/lib/python3.10/site-packages/fs/error_tools.py__init__A   s   
z_ConvertOSErrors.__init__c                 C   s   | S r   r   )r   r   r   r   	__enter__G   s   z_ConvertOSErrors.__enter__c                 C   s   | j r| jn| j}|r<t|tr>|j}||tj}|tj	kr/t
jdkr/t|dd dkr/tj}t||| j|d| d S d S d S )Nwin32args    )exc)r   
DIR_ERRORSFILE_ERRORS
isinstanceEnvironmentErrorerrnogetr   OperationFailedEACCESsysplatformgetattrResourceLockedr   r   )r   exc_type	exc_value	traceback	os_errors_errnofserrorr   r   r   __exit__K   s   z_ConvertOSErrors.__exit__N)F)(__name__
__module____qualname____doc__r   RemoteConnectionErrorr(   r+   PermissionDeniedENOENTResourceNotFoundEFAULTESRCH	ENOTEMPTYDirectoryNotEmptyEEXIST
FileExistsDirectoryExistsENOTDIREISDIRFileExpectedEINVALENOSPCInsufficientStorageEPERMENETDOWN
ECONNRESETENAMETOOLONG	PathError
EOPNOTSUPPUnsupportedENOSYSr%   copyr$   DirectoryExpected_WINDOWS_PLATFORMr   r   r6   r   r   r   r   r      sd    




r   c              
   c   sZ    zdV  W dS  t jy, } zt|dr't| tr$| |j|j|_ | |_ d}~ww )an  Get a context to map OS errors to their `fs.errors` counterpart.

    The context will re-write the paths in resource exceptions to be
    in the same context as the wrapped filesystem.

    The only parameter may be the path from the parent, if only one path
    is to be unwrapped. Or it may be a dictionary that maps wrapped
    paths on to unwrapped paths.

    Nr   )r   ResourceErrorhasattrr&   r   r)   r   )path_replaceer   r   r   unwrap_errors`   s   

r[   ) r:   
__future__r   r   r,   typingr(   r-   
contextlibr   sixr    r   TYPE_CHECKINGr   r	   r
   r   r   typesr   collections.abcr   ImportErrorcollectionssystemrV   objectr   convert_os_errorsr[   r   r   r   r   <module>   s,    ?