
    j_5                     F    d Z ddlZddlZddlZddZddZ e            ZdS )z+
Utilities for dealing with text encodings
    Nc                 B    t          | d          r| j        s|S | j        S )a)  Return the given stream's encoding or a default.

    There are cases where ``sys.std*`` might not actually be a stream, so
    check for the encoding attribute prior to returning it, and return
    a default if it doesn't exist or evaluates as False. ``default``
    is None if not provided.
    encoding)hasattrr   )streamdefaults     9lib/python3.11/site-packages/ipython_genutils/encoding.pyget_stream_encr	      s,     6:&& fo     Tc                    d}| rt          t          j                  }|r|dk    r%	 t          j                    }n# t
          $ r Y nw xY w|pt          j                    }|dk    rt          j        dt                     dS |S )a  Return IPython's guess for the default encoding for bytes as text.
    
    If prefer_stream is True (default), asks for stdin.encoding first,
    to match the calling Terminal, but that is often None for subprocesses.
    
    Then fall back on locale.getpreferredencoding(),
    which should be a sensible platform default (that respects LANG environment),
    and finally to sys.getdefaultencoding() which is the most conservative option,
    and usually ASCII on Python 2 or UTF8 on Python 3.
    Nasciicp0zInvalid code page cp0 detected - using cp1252 instead.If cp1252 is incorrect please ensure a valid code page is defined for the process.cp1252)
r	   sysstdinlocalegetpreferredencoding	ExceptiongetdefaultencodingwarningswarnRuntimeWarning)prefer_streamencs     r   r   r   &   s     C (SY'' #w,,	 -//CC 	 	 	D	

)'))C e||*+9	; 	; 	; xJs   ; 
AA)N)T)__doc__r   r   r   r	   r   DEFAULT_ENCODING r
   r   <module>r      sl     


     "   B &%''   r
   