ó
æNXc           @   sO   d  Z  d d l Z d d l Z d d l Z d d „ Z e d „ Z e ƒ  Z d S(   s+   
Utilities for dealing with text encodings
iÿÿÿÿNc         C   s)   t  |  d ƒ s |  j r | S|  j Sd S(   s)  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.
    t   encodingN(   t   hasattrR    (   t   streamt   default(    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/ipython_genutils/encoding.pyt   get_stream_enc   s    c         C   sŽ   d } |  r t t j ƒ } n  | s1 | d k rX y t j ƒ  } WqX t k
 rT qX Xn  | pg t j ƒ  } | d k rŠ t j	 d t
 ƒ d S| S(   sõ  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.
    t   asciit   cp0sˆ   Invalid code page cp0 detected - using cp1252 instead.If cp1252 is incorrect please ensure a valid code page is defined for the process.t   cp1252N(   t   NoneR   t   syst   stdint   localet   getpreferredencodingt	   Exceptiont   getdefaultencodingt   warningst   warnt   RuntimeWarning(   t   prefer_streamt   enc(    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/ipython_genutils/encoding.pyR   &   s    (	   t   __doc__R	   R   R   R   R   t   TrueR   t   DEFAULT_ENCODING(    (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/ipython_genutils/encoding.pyt   <module>   s   !