ó
X¾÷Xc           @   sŸ  d  Z  d d l Z d d l Z g  e d d ƒ D] Z e e ƒ ^ q. Z d e d <d e d <d	 e d
 <d e d <d e d <d e d <g  e d d ƒ D] Z d e ^ q’ g  e d d ƒ D] Z e e ƒ ^ qµ g  e d d ƒ D] Z d e ^ qÛ Z d e d <d e d <d	 e d
 <d e d <d e d <d e d <d „  Z e j	 d ƒ Z
 g  e d d ƒ D] Z e e ƒ ^ qVg  e d d ƒ D] Z d e ^ q{Z d „  Z d S(   s   Encoding related utilities.iÿÿÿÿNi    i   s   \ti	   s   \ni
   s   \ri   s   \'i'   s   \"i"   s   \\i\   i    s   \%03oi   c            sa   t  |  t j ƒ r t n d „  ‰  | rD d j ‡  f d †  |  Dƒ ƒ Sd j ‡  f d †  |  Dƒ ƒ S(   s-  Escape a bytes string for use in an ascii protocol buffer.

  text.encode('string_escape') does not seem to satisfy our needs as it
  encodes unprintable characters using two-digit hex escapes whereas our
  C++ unescaping function allows hex escapes to be any length.  So,
  "1".encode('string_escape') ends up being "\x011", which will be
  decoded in C++ as a single-character string with char code 0x11.

  Args:
    text: A byte string to be escaped
    as_utf8: Specifies if result should be returned in UTF-8 encoding
  Returns:
    Escaped string
  c         S   s   |  S(   N(    (   t   x(    (    s?   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_encoding.pyt   <lambda>L   s    t    c         3   s   |  ] } t  ˆ  | ƒ Vq d  S(   N(   t   _cescape_utf8_to_str(   t   .0t   c(   t   Ord(    s?   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_encoding.pys	   <genexpr>N   s    c         3   s   |  ] } t  ˆ  | ƒ Vq d  S(   N(   t   _cescape_byte_to_str(   R   R   (   R   (    s?   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_encoding.pys	   <genexpr>O   s    (   t
   isinstancet   sixt   string_typest   ordt   join(   t   textt   as_utf8(    (   R   s?   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_encoding.pyt   CEscape;   s    !s"   (\\+)x([0-9a-fA-F])(?![0-9a-fA-F])c         C   sl   d „  } t  j | |  ƒ } t t k r4 | j d ƒ Sd j d „  | Dƒ ƒ } | j d ƒ j d ƒ j d ƒ S(   sD   Unescape a text string with C-style escape sequences to UTF-8 bytes.c         S   sD   t  |  j d ƒ ƒ d @r7 |  j d ƒ d |  j d ƒ S|  j d ƒ S(   Ni   t   x0i   i    (   t   lent   group(   t   m(    (    s?   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_encoding.pyt
   ReplaceHexZ   s    t   string_escapeR   c         s   s   |  ] } t  t | ƒ Vq d  S(   N(   t   _cescape_highbit_to_strR   (   R   R   (    (    s?   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_encoding.pys	   <genexpr>g   s    t   asciit   unicode_escapet   raw_unicode_escape(   t   _CUNESCAPE_HEXt   subt   strt   bytest   decodeR   t   encode(   R   R   t   result(    (    s?   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_encoding.pyt	   CUnescapeW   s    			(   t   __doc__t   reR	   t   ranget   it   chrR   R   R   t   compileR   R   R!   (    (    (    s?   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/text_encoding.pyt   <module>   s,   (





I'





	%'