3
K^                 @   s8  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yddlmZmZ W n ek
rt   d ZZY nX ejd dkrddl	Z	y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d9d dZd!d Zd"ZnNddlZeZeZeZeZeefZeZeZd#Zd$d Zd%d Zd:d&dZd'd Zd(d Zd)d Zd*d	 Zd+d ZG d,d deZ ejd dkrejd- d.krd;d/dZ!n
d<d0dZ!ddl"Z"ejdd1 d=kre"j#Z$ne"j%d2efd3f iZ$ejdd1 d>krej&Z'ej(Z)n d5d6 Z*G d7d de$Z)d8d Z'dS )?a  
Python 3.X compatibility tools.

While this file was originally intented 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   PurePath   c             C   s   t | tr| jdS t| S )Nlatin1)
isinstancer   decodestr)s r   5/tmp/pip-unpacked-wheel-4ferv4jf/numpy/compat/py3k.pyr   (   s    

c             C   s   t | tr| S t| jdS )Nr   )r   r   r   encode)r   r   r   r    r   -   s    
c             C   s   t | tr| jdS t| S )Nr   )r   r   r   r   )r   r   r   r    r
   2   s    

c             C   s   t | tjtjtjfS )N)r   ioFileIOBufferedReaderBufferedWriter)fr   r   r    r   7   s    rc             C   s   t | |ddS )Nz
iso-8859-1)modeencoding)open)filenamer(   r   r   r    r   :   s    c             C   s   | S )Nr   )r   r   r   r    r   =   s    USc             C   s
   t | tS )N)r   file)r&   r   r   r    r   N   s    c             C   s   t | tr| S t| jdS )Nascii)r   r   r   r   )r   r   r   r    r   Q   s    
c             C   s   t | |dS )N)r(   )r*   )r+   r(   r   r   r    r   V   s    c             C   s
   t | dS )NZunicode_escape)r   )r   r   r   r    r   Y   s    c               C   s   t j d S )N   )sysexc_infor   r   r   r    r   \   s    c             C   s4   t | dr(t| ttf r(dd | D S t| S d S )N__iter__c             S   s   g | ]}t |qS r   )r   ).0yr   r   r    
<listcomp>a   s    z"asbytes_nested.<locals>.<listcomp>)hasattrr   r   r   r   )xr   r   r    r   _   s    c             C   s4   t | dr(t| ttf r(dd | D S t| S d S )Nr3   c             S   s   g | ]}t |qS r   )r	   )r4   r5   r   r   r    r6   g   s    z$asunicode_nested.<locals>.<listcomp>)r7   r   r   r   r   )r8   r   r   r    r	   e   s    c             C   s   t dk	ot| t S )z
    Check whether obj is a pathlib.Path object.

    Prefer using `isinstance(obj, os_PathLike)` instead of this function.
    N)r   r   )objr   r   r    r   k   s    c               @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
r   aO  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
    Nc             C   s
   || _ d S )N)enter_result)selfr:   r   r   r    __init__   s    zcontextlib_nullcontext.__init__c             C   s   | j S )N)r:   )r;   r   r   r    	__enter__   s    z contextlib_nullcontext.__enter__c             G   s   d S )Nr   )r;   excinfor   r   r    __exit__   s    zcontextlib_nullcontext.__exit__)N)__name__
__module____qualname____doc__r<   r=   r?   r   r   r   r    r   t   s   	
r0      c             C   s   ddl }|jj| |j S )ad  
        Load a module.

        .. 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   N)Zimportlib.machinery	machinerySourceFileLoaderload_module)namefninfo	importlibr   r   r    r      s    c             C   sd   ddl }|dkr2tjj|}|j| |g\}}}nt||d }z|j| |||}W d|j  X |S )a}  
        Load a module.

        .. versionadded:: 1.11.2

        Parameters
        ----------
        name : str
            Full module name.
        fn : str
            Path to module file.
        info : tuple, optional
            Information as returned by `imp.find_module`
            (suffix, mode, type).

        Returns
        -------
        mod : module

        r   Nr0   )impospathdirnamefind_moduler*   rG   close)rH   rI   rJ   rL   rN   fomodr   r   r    r      s    
   ABC	__slots__   c             C   s   t | S )N)r   )r;   r   r   r    _PurePath__fspath__   s    rX   c               @   s*   e Zd ZdZejdd Zedd ZdS )r   zCAbstract base class for implementing the file system path protocol.c             C   s   t dS )z9Return the file system path representation of the object.N)NotImplementedError)r;   r   r   r    
__fspath__   s    zos_PathLike.__fspath__c             C   s    t d k	rt|t rdS t|dS )NTrZ   )r   
issubclassr7   )clssubclassr   r   r    __subclasshook__   s    zos_PathLike.__subclasshook__N)	r@   rA   rB   rC   abcabstractmethodrZ   classmethodr^   r   r   r   r    r      s   c             C   s   t | ttfr| S t| }y|j| }W nJ tk
rr   t|drF n(tdk	r`t|tr`t	| S t
d|j Y nX t |ttfr|S t
dj|jt|jdS )at  Return the path representation of a path-like object.
        If str or bytes is passed in, it is returned unchanged. Otherwise the
        os.PathLike interface is used to get the path representation. If the
        path representation is not str or bytes, TypeError is raised. If the
        provided path is not str, bytes, or os.PathLike, TypeError is raised.
        rZ   Nz/expected str, bytes or os.PathLike object, not z7expected {}.__fspath__() to return str or bytes, not {})r   r   r   typerZ   AttributeErrorr7   r   r[   rX   	TypeErrorr@   format)rN   	path_type	path_reprr   r   r    r      s"    
)r'   )r'   )N)N)r   rD   )r   rW   )+rC   __all__r1   rM   pathlibr   r   ImportErrorversion_infor"   Zpickle5r   intr   r   r   r   r   r   r   r   r
   r   r   r   r   Zcpickler   r   r	   r   objectr   r   r_   rU   Zabc_ABCABCMetafspathr   PathLiker   rX   r   r   r   r    <module>   sx   



	 
"