3
hR                 @   sd  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mZ ddlZddlZddlm	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d0d dZd!d Zd"Zd#d Zd$d Zd%d	 Zd&d ZG d'd dZ d1d(dZ!ej"dd) d2kr@ej#Z$ej%Z&n d,d- Z'G d.d de
Z&d/d Z$dS )3a  
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   PurePath)ABCc             C   s   t | tr| jdS t| S )Nlatin1)
isinstancer   decodestr)s r   2/tmp/pip-build-fibhr3ey/numpy/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
   0   s    

c             C   s   t | tjtjtjfS )N)r   ioFileIOBufferedReaderBufferedWriter)fr   r   r    r   5   s    rc             C   s   t | |ddS )Nz
iso-8859-1)modeencoding)open)filenamer(   r   r   r    r   8   s    c             C   s   | S )Nr   )r   r   r   r    r   ;   s    Uc               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>E   s    z"asbytes_nested.<locals>.<listcomp>)hasattrr   r   r   r   )xr   r   r    r   C   s    c             C   s4   t | dr(t| ttf r(dd | D S t| S d S )Nr0   c             S   s   g | ]}t |qS r   )r	   )r1   r2   r   r   r    r3   K   s    z$asunicode_nested.<locals>.<listcomp>)r4   r   r   r   r   )r5   r   r   r    r	   I   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   O   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)selfr7   r   r   r    __init__c   s    zcontextlib_nullcontext.__init__c             C   s   | j S )N)r7   )r8   r   r   r    	__enter__f   s    z contextlib_nullcontext.__enter__c             G   s   d S )Nr   )r8   Zexcinfor   r   r    __exit__i   s    zcontextlib_nullcontext.__exit__)N)__name__
__module____qualname____doc__r9   r:   r;   r   r   r   r    r   X   s   	
c             C   s   ddl m} || |j S )a,  
    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   )SourceFileLoader)importlib.machineryr@   load_module)namefninfor@   r   r   r    r   m   s             c             C   s   t | S )N)r   )r8   r   r   r    _PurePath__fspath__   s    rI   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)r8   r   r   r    
__fspath__   s    zos_PathLike.__fspath__c             C   s    t d k	rt|t rdS t|dS )NTrK   )r   
issubclassr4   )clssubclassr   r   r    __subclasshook__   s    zos_PathLike.__subclasshook__N)	r<   r=   r>   r?   abcabstractmethodrK   classmethodrO   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.
        rK   Nz/expected str, bytes or os.PathLike object, not z7expected {}.__fspath__() to return str or bytes, not {})r   r   r   typerK   AttributeErrorr4   r   rL   rI   	TypeErrorr<   format)path	path_type	path_reprr   r   r    r      s"    
)r'   )N)rG   rH   )(r?   __all__r.   osZpathlibr   r   r"   rP   r   Zabc_ABCZpickle5r   ImportErrorintr   r   r   r   r   r   r   r   r
   r   r   r   r   r   r   r	   r   r   r   version_infofspathr   PathLiker   rI   r   r   r   r    <module>   sN   


	
