File: //opt/alt/python27/lib/python2.7/site-packages/future/utils/surrogateescape.pyo
�
�A�[c           @   s�   d  Z  d d l Z d d l Z d d l m Z d Z d �  Z d �  Z e j ra e	 Z
 d �  Z n e Z
 e	 Z d �  Z
 d	 e f d
 �  �  YZ d �  Z d �  Z d
 �  Z d �  Z d Z e d � Z e d � Z e j e � j Z d �  Z e d k r� n  d S(   s�   
This is Victor Stinner's pure-Python implementation of PEP 383: the "surrogateescape" error
handler of Python 3.
Source: misc/python/surrogateescape.py in https://bitbucket.org/haypo/misc
i����N(   t   utilst   surrogateescapec         C   s   t  j r
 |  S|  j d � Sd  S(   Nt   unicode_escape(   R    t   PY3t   decode(   t   text(    (    sM   /opt/alt/python27/lib/python2.7/site-packages/future/utils/surrogateescape.pyt   u   s    	c         C   s   t  j r |  j d � S|  Sd  S(   Nt   latin1(   R    R   t   encode(   t   data(    (    sM   /opt/alt/python27/lib/python2.7/site-packages/future/utils/surrogateescape.pyt   b   s    	
c         C   s
   t  |  f � S(   N(   t   bytes(   t   code(    (    sM   /opt/alt/python27/lib/python2.7/site-packages/future/utils/surrogateescape.pyt   <lambda>#   t    c         C   s�   |  j  |  j |  j !} yF t |  t � r7 t | � } n$ t |  t � rU t | � } n |  � Wn t k
 ru |  � n X| |  j f S(   s�   
    Pure Python implementation of the PEP 383: the "surrogateescape" error
    handler of Python 3. Undecodable bytes will be replaced by a Unicode
    character U+DCxx on decoding, and these are translated into the
    original bytes on encoding.
    (	   t   objectt   startt   endt
   isinstancet   UnicodeDecodeErrort   replace_surrogate_decodet   UnicodeEncodeErrort   replace_surrogate_encodet   NotASurrogateError(   t   exct   mystringt   decoded(    (    sM   /opt/alt/python27/lib/python2.7/site-packages/future/utils/surrogateescape.pyt   surrogateescape_handler(   s    
R   c           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sM   /opt/alt/python27/lib/python2.7/site-packages/future/utils/surrogateescape.pyR   C   s   c         C   s�   g  } x� |  D]� } t  | � } d | k o6 d k n sD t � n  d | k o[ d k n rz | j t | d � � q
 | d k r� | j t | d � � q
 t � q
 Wt �  j | � S(   s�   
    Returns a (unicode) string, not the more logical bytes, because the codecs
    register_error functionality expects this.
    i �  i��  i �  i�  (   t   ordR   t   appendt   _unichrt   strt   join(   R   R   t   chR   (    (    sM   /opt/alt/python27/lib/python2.7/site-packages/future/utils/surrogateescape.pyR   G   s    
	
c         C   s�   g  } x� |  D]� } t  | t � r+ | } n t | � } d | k oN d k n rm | j t d | � � q
 | d k r� | j t | � � q
 t � q
 Wt �  j | � S(   s$   
    Returns a (unicode) string
    i�   i�   i �  i   (   R   t   intR   R   R    R   R!   R"