U
    ;vfY                     @   s  d Z ddddddddd	d
ddddddddddddgZddlZddlZddlmZ ddlZzddlZW n e	k
r   ddlZY nX e
Ze
fZeZeZeZdd Zdd Zdd
 Zdd Zdd Zd*d!dZd"d Zd#Zd$d Zd%d Zd&d	 Zd'd ZG d(d dZd+d)dZejZ ej!Z"dS ),a  
Python 3.X compatibility tools.

While this file was originally intended for Python 2 -> 3 transition,
it is now used to create a compatibility layer between different
minor versions of Python 3.

While the active version of numpy may not support a given version of python, we
allow downstream libraries to continue to use these shims for forward
compatibility with numpy while they transition their code to newer versions of
Python.
bytesasbytes	isfileobjgetexceptionstrcharunicode	asunicodeasbytes_nestedasunicode_nestedasstropen_latin1long
basestringsixuinteger_typesis_pathlib_pathnpy_load_modulePathpicklecontextlib_nullcontext	os_fspathos_PathLike    N)r   c                 C   s   t | tr| dS t| S Nlatin1
isinstancer   decodestrs r    5/tmp/pip-unpacked-wheel-sdaoq5e2/numpy/compat/py3k.pyr   "   s    

c                 C   s   t | tr| S t| dS r   )r   r   r   encoder   r    r    r!   r   '   s    
c                 C   s   t | tr| dS t| S r   r   r   r    r    r!   r
   ,   s    

c                 C   s   t | tjtjtjfS N)r   ioFileIOBufferedReaderBufferedWriterfr    r    r!   r   1   s    c                 C   sD   t | tjtjtjfsdS z|   W dS  tk
r>   Y dS X d S )NFT)r   r$   r%   r&   r'   filenoOSErrorr(   r    r    r!   
_isfileobj4   s    r,   rc                 C   s   t | |ddS )Nz
iso-8859-1)modeencoding)open)filenamer.   r    r    r!   r   ?   s    c                 C   s   | S r#   r    r   r    r    r!   r   B   s    Uc                   C   s   t  d S )N   )sysexc_infor    r    r    r!   r   G   s    c                 C   s2   t | dr&t| ttfs&dd | D S t| S d S )N__iter__c                 S   s   g | ]}t |qS r    )r   .0yr    r    r!   
<listcomp>L   s     z"asbytes_nested.<locals>.<listcomp>)hasattrr   r   r   r   xr    r    r!   r   J   s    c                 C   s2   t | dr&t| ttfs&dd | D S t| S d S )Nr6   c                 S   s   g | ]}t |qS r    )r	   r7   r    r    r!   r:   R   s     z$asunicode_nested.<locals>.<listcomp>)r;   r   r   r   r   r<   r    r    r!   r	   P   s    c                 C   s
   t | tS )z
    Check whether obj is a `pathlib.Path` object.

    Prefer using ``isinstance(obj, os.PathLike)`` instead of this function.
    )r   r   )objr    r    r!   r   V   s    c                   @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
r   a  Context manager that does no additional processing.

    Used as a stand-in for a normal context manager, when a particular
    block of code is only sometimes used with a normal context manager:

    cm = optional_cm if condition else nullcontext()
    with cm:
        # Perform operation, using optional_cm if condition is True

    .. note::
        Prefer using `contextlib.nullcontext` instead of this context manager.
    Nc                 C   s
   || _ d S r#   enter_result)selfr@   r    r    r!   __init__m   s    zcontextlib_nullcontext.__init__c                 C   s   | j S r#   r?   )rA   r    r    r!   	__enter__p   s    z contextlib_nullcontext.__enter__c                 G   s   d S r#   r    )rA   excinfor    r    r!   __exit__s   s    zcontextlib_nullcontext.__exit__)N)__name__
__module____qualname____doc__rB   rC   rE   r    r    r    r!   r   _   s   
c                 C   s   ddl m} || | S )a  
    Load a module. Uses ``load_module`` which will be deprecated in python
    3.12. An alternative that uses ``exec_module`` is in
    numpy.distutils.misc_util.exec_mod_from_location

    .. versionadded:: 1.11.2

    Parameters
    ----------
    name : str
        Full module name.
    fn : str
        Path to module file.
    info : tuple, optional
        Only here for backward compatibility with Python 2.*.

    Returns
    -------
    mod : module

    r   )SourceFileLoader)Zimportlib.machineryrJ   load_module)namefninforJ   r    r    r!   r   w   s    )r-   )N)#rI   __all__r4   ospathlibr   r$   Zpickle5r   ImportErrorintr   r   r   r   r   r   r   r   r
   r   r,   r   r   r   r   r   r	   r   r   r   fspathr   PathLiker   r    r    r    r!   <module>   s`   
             
	
