
    'YHhQ                     B    d Z ddlmZ ddlmZ  G d d      Zd Zd	dZy)
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y)EmptyContextManagerzw
    This class is needed to allow file-like object to be used as
    context manager, but without getting closed.
    c                     || _         y N_obj)selfobjs     S/var/www/html/planif/env/lib/python3.12/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    yyr   c                      y)zDo not hide anythingF )r   argss     r   __exit__zEmptyContextManager.__exit__   s    r   c                 .    t        | j                  |      S r   )getattrr
   )r   names     r   __getattr__zEmptyContextManager.__getattr__   s    tyy$''r   N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r   	   s    
(r   r   c                 p    | j                  d      rdd l}|j                  | ||      S t        | ||      S )Nz.gzr   encoding)endswithgzipopen)fnamemoder    r"   s       r   _openr&      s5    ~~eyyxy88E4(33r   Nc                    t        |       rt        |       } t        | t              r| j                  ||      S t	        | d      r| j                  ||      S 	 t        | ||      S # t
        $ rL 	 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%zzthz77		zzthz77*E4(33 	*	Md{

d{cTk 	MKLL	M"5))	*s*   A( (	B=2$BB=B,,B=<B=)r(   N)r   pathlibr   numpy.lib._iotoolsr   r   r&   r2   r   r   r   <module>r5      s&     .( (*4(*r   