ó
F+ÞOc           @   s€   d  Z  d d l Z d d l Z d d l Z e e d d ƒ pH e e d ƒ e j Z d Z d „  Z	 d „  Z
 d „  Z d	 „  Z d S(
   sn   
escape/unescape routines available for backends which need
alphanumeric usernames, services, or other values
iÿÿÿÿNt   letterst   ascii_letterss   _%02Xc         C   s<   t  |  t ƒ r t |  ƒ }  n  |  t k r. |  St t |  ƒ S(   sA   Single char escape. Return the char, escaped if not already legal(   t
   isinstancet   intt   unichrt   LEGAL_CHARSt
   ESCAPE_FMTt   ord(   t   c(    (    s7   /usr/lib/python2.7/dist-packages/keyring/util/escape.pyt   _escape_char   s    c         C   s    d j  d „  |  j d ƒ Dƒ ƒ S(   sd   
    Escapes given string so the result consists of alphanumeric chars and
    underscore only.
    t    c         s   s   |  ] } t  | ƒ Vq d  S(   N(   R	   (   t   .0R   (    (    s7   /usr/lib/python2.7/dist-packages/keyring/util/escape.pys	   <genexpr>   s    s   utf-8(   t   joint   encode(   t   value(    (    s7   /usr/lib/python2.7/dist-packages/keyring/util/escape.pyt   escape   s    c         C   s>   t  |  j d ƒ d ƒ } t j d k r4 t | g ƒ St | ƒ S(   Nt   codei   i   (   i   (   R   t   groupt   syst   version_infot   bytest   chr(   t   regex_matcht   ordinal(    (    s7   /usr/lib/python2.7/dist-packages/keyring/util/escape.pyt   _unescape_code   s    c         C   sF   t  j t j d d ƒ j d ƒ ƒ } | j t |  j d ƒ ƒ j d ƒ S(   s   
    Inverse of escape.
    s   %02Xs   (?P<code>[0-9A-F]{2})t   asciis   utf-8(   t   ret   compileR   t   replaceR   t   subR   t   decode(   R   t   re_esc(    (    s7   /usr/lib/python2.7/dist-packages/keyring/util/escape.pyt   unescape$   s    (   t   __doc__t   stringR   R   t   getattrt   Nonet   digitsR   R   R	   R   R   R    (    (    (    s7   /usr/lib/python2.7/dist-packages/keyring/util/escape.pyt   <module>   s   
			