
    M/PhQ                     J    d Z ddlmZ ddlmZ  G d d          Zd Zd
d	ZdS )z$
Handle file opening for read/write
    )Path)_is_string_likec                   *    e Zd ZdZd Zd Zd Z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                     || _         d S N_obj)selfobjs     Z/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/iolib/openfile.py__init__zEmptyContextManager.__init__   s    			    c                     | j         S )z)When entering, return the embedded objectr	   )r   s    r   	__enter__zEmptyContextManager.__enter__   s
    yr   c                     dS )zDo not hide anythingF )r   argss     r   __exit__zEmptyContextManager.__exit__   s    ur   c                 ,    t          | j        |          S r   )getattrr
   )r   names     r   __getattr__zEmptyContextManager.__getattr__   s    ty$'''r   N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r   	   sZ         
      ( ( ( ( (r   r   c                     |                      d          rdd l}|                    | ||          S t          | ||          S )Nz.gzr   encoding)endswithgzipopen)fnamemoder    r"   s       r   _openr&      sL    ~~e 4yyxy888E4(3333r   rNc                    t          |           rt          |           } t          | t                    r|                     ||          S t	          | d          r|                     ||          S 	 t          | ||          S # t
          $ rK 	 d|v r| j         d|v sd|v r| j         n# t          $ r t          d          w xY wt          |           cY S w xY w)aT  
    Light wrapper to handle strings, path objects and let files (anything else)
    pass through.

    It also handle '.gz' files.

    Parameters
    ----------
    fname : str, path object or file-like object
        File to open / forward
    mode : str
        Argument passed to the 'open' or 'gzip.open' function
    encoding : str
        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%   r    r#   r   r'   waz,fname must be a string or a file-like object)r   r   
isinstancer#   hasattr	TypeErrorreadwriteAttributeError
ValueErrorr   )r$   r%   r    s      r   get_file_objr2   '   s   . u U% 8zzthz777			 8zzthz777*E4(3333 	* 	* 	*	Md{{

d{{cTkk 	M 	M 	MKLLL	M"5)))))	*s*   3B 
CB+*C+CCC)r'   N)r   pathlibr   numpy.lib._iotoolsr   r   r&   r2   r   r   r   <module>r5      s           . . . . . .( ( ( ( ( ( ( (*4 4 4(* (* (* (* (* (*r   