ó
%_[c           @   sŒ   d  Z  d d l Z d d l Z d d l m Z m Z m Z m Z e j ƒ  Z	 e	 e	 d „ Z
 d „  Z e ƒ  Z d „  Z d „  Z d „  Z d S(	   sÃ   
Text encoding utilities, text file I/O.

Functions 'get_coding', 'decode', 'encode' and 'to_unicode' come from Eric4
source code (Utilities/__init___.py) Copyright Â© 2003-2009 Detlev Offenbach
iÿÿÿÿN(   t   is_binary_stringt	   is_stringt
   is_unicodet   to_text_stringc         C   sa   y |  j  d ƒ j d ƒ SWn@ t k
 r\ y |  j  d ƒ j | ƒ SWq] t k
 rX |  SXn Xd S(   s   Transcode a text stringt   cp437t   cp1252N(   t   decodet   encodet   UnicodeError(   t   textt   inputt   output(    (    s?   lib/python2.7/site-packages/navigator_updater/utils/encoding.pyt	   transcode   s    c          C   s%   t  j ƒ  }  |  d k r! t }  n  |  S(   sU   
    Query the filesystem for the encoding used to encode filenames and envvars.
    N(   t   syst   getfilesystemencodingt   Nonet   PREFERRED_ENCODING(   t   encoding(    (    s?   lib/python2.7/site-packages/navigator_updater/utils/encoding.pyR   2   s    	c         C   sh   t  |  ƒ s$ t |  j ƒ  d ƒ }  n@ t |  ƒ rd y |  j t ƒ } Wn t t f k
 r\ qd X| Sn  |  S(   sT   
    Return a unicode version of string decoded using the file system encoding.
    s   utf-8(   R   R   t   toUtf8R    R   t   FS_ENCODINGR   t	   TypeError(   t   stringt   unic(    (    s?   lib/python2.7/site-packages/navigator_updater/utils/encoding.pyt   to_unicode_from_fs@   s    c         C   sD   t  |  ƒ r@ y |  j t ƒ } Wn t t f k
 r8 q@ X| Sn  |  S(   sU   
    Return a byte string version of unc encoded using the file system encoding.
    (   R   R   R   R   R   (   R   R   (    (    s?   lib/python2.7/site-packages/navigator_updater/utils/encoding.pyt   to_fs_from_unicodeQ   s    c         C   s*   y |  j  d ƒ SWn t k
 r% |  SXd S(   s2   Ensure a file is binary format. From conda/common.s   utf-8N(   R   t   AttributeError(   t   value(    (    s?   lib/python2.7/site-packages/navigator_updater/utils/encoding.pyt   ensure_binary_   s    (   t   __doc__t   localeR   t!   navigator_updater.utils.py3compatR    R   R   R   t   getpreferredencodingR   R   R   R   R   R   R   (    (    (    s?   lib/python2.7/site-packages/navigator_updater/utils/encoding.pyt   <module>   s   "				