B
    ZW                 @   sP   d Z ddlmZ ddlmZ G dd deZer:dd Zndd ZdddZd
S )z$
Handle file opening for read/write
    )_is_string_like)PY3c               @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )EmptyContextManagerzw
    This class is needed to allow file-like object to be used as
    context manager, but without getting closed.
    c             C   s
   || _ d S )N)_obj)selfobj r   9lib/python3.7/site-packages/statsmodels/iolib/openfile.py__init__   s    zEmptyContextManager.__init__c             C   s   | j S )z)When entering, return the embedded object)r   )r   r   r   r	   	__enter__   s    zEmptyContextManager.__enter__c             G   s   dS )zDon't hide anythingFr   )r   argsr   r   r	   __exit__   s    zEmptyContextManager.__exit__c             C   s   t | j|S )N)getattrr   )r   namer   r   r	   __getattr__   s    zEmptyContextManager.__getattr__N)__name__
__module____qualname____doc__r
   r   r   r   r   r   r   r	   r      s
   r   c             C   s4   |  dr"dd l}|j| ||dS t| ||dS d S )Nz.gzr   )encoding)endswithgzipopen)fnamemoder   r   r   r   r	   _open   s    
r   c             C   s,   |  drdd l}|| |S t| |S d S )Nz.gzr   )r   r   r   )r   r   r   r   r   r   r	   r   "   s    
rNc             C   sb   t | rt| ||S y(d|kr$| j d|ks4d|kr:| j W n tk
rX   tdY nX t| S )a7  
    Light wrapper to handle strings and let files (anything else) pass through.

    It also handle '.gz' files.

    Parameters
    ==========
    fname: string or file-like object
        File to open / forward
    mode: string
        Argument passed to the 'open' or 'gzip.open' function
    encoding: string
        For Python 3 only, specify the encoding of the file

    Returns
    =======
    A file-like object that is always a context-manager. If the `fname` was already a file-like object,
    the returned context manager *will not close the file*.
    r   waz,fname must be a string or a file-like object)r   r   readwriteAttributeError
ValueErrorr   )r   r   r   r   r   r	   get_file_obj)   s    
r#   )r   N)	r   Znumpy.lib._iotoolsr   Zstatsmodels.compat.pythonr   objectr   r   r#   r   r   r   r	   <module>   s   
