o
    Q `
                     @   s   d Z ddlmZ ddl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rGdd	lmZ dd
lmZmZmZmZmZ zddlmZ W n ey^   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)TracebackType)IteratorOptionalTextTypeUnion)MappingZ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 )_ConvertOSErrorsz9Context manager to convert OSErrors in to FS Errors.
    @         i  Fc                 C   s   || _ || _|| _d S N)Z_opname_path
_directory)selfopnamepathZ	directory r   0/usr/lib/python3/dist-packages/fs/error_tools.py__init__B   s   
z_ConvertOSErrors.__init__c                 C   s   | S r   r   )r   r   r   r   	__enter__H   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   ZOperationFailedEACCESsysplatformgetattrZResourceLockedr   r   )r   exc_type	exc_value	tracebackZ	os_errorsZ_errnoZfserrorr   r   r   __exit__L   s   z_ConvertOSErrors.__exit__N)F)(__name__
__module____qualname____doc__r   ZRemoteConnectionErrorr%   r'   ZPermissionDeniedENOENTZResourceNotFoundZEFAULTZESRCHZ	ENOTEMPTYZDirectoryNotEmptyZEEXISTZ
FileExistsZDirectoryExistsZENOTDIRZEISDIRZFileExpectedEINVALENOSPCZInsufficientStorageEPERMZENETDOWNZ
ECONNRESETZENAMETOOLONGZ	PathError
EOPNOTSUPPZUnsupportedZENOSYSr"   copyr!   ZDirectoryExpected_WINDOWS_PLATFORMr   r   r.   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   ZResourceErrorhasattrr#   r   r&   r   )Zpath_replaceer   r   r   unwrap_errorsa   s   

r<   ) r2   Z
__future__r   r   r%   r)   r(   typing
contextlibr   Zsixr    r   ZTYPE_CHECKINGtypesr   r	   r
   r   r   r   Zcollections.abcr   ImportErrorcollectionssystemr9   objectr   Zconvert_os_errorsr<   r   r   r   r   <module>   s.    @