ó
mÜJ]c           @` sª   d  Z  d d l m Z m Z m Z m Z d d l Z e j e ƒ Z	 d d l
 Z
 d Z d „  Z d „  Z d d „ Z d d d „ Z d d d „ Z d d „ Z d „  Z d S(   u9    Functions useful for string manipulations or encoding.

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNu   decode_utf8u   encode_utf8u   escapeu   format_docstringu   indentu	   nice_joinu   snakifyc         C` s5   d d l  } | j d d k r1 |  j d ƒ }  n  |  S(   u‚    Encode a UTF-8 string to a sequence of bytes.

    Args:
        u (str) : the string to encode

    Returns:
        bytes

    i    Ni   u   utf-8(   t   syst   version_infot   encode(   t   uR   (    (    s0   lib/python2.7/site-packages/bokeh/util/string.pyt   encode_utf80   s    
c         C` s5   d d l  } | j d d k r1 |  j d ƒ }  n  |  S(   u‡    Decode a sequence of bytes to a UTF-8 string

    Args:
        u (str) : the bytes to decode

    Returns:
        UTF-8 string

    i    Ni   u   utf-8(   R   R   t   decode(   R   R   (    (    s0   lib/python2.7/site-packages/bokeh/util/string.pyt   decode_utf8?   s    
u   'u   "c         C` s…   |  j  d d ƒ }  |  j  d d ƒ }  |  j  d d ƒ }  | r d | k r] |  j  d d ƒ }  n  d	 | k r |  j  d	 d
 ƒ }  q n  |  S(   uO   Perform HTML-safe escaping.

    Replaces special characters "&", "<" and ">" to HTML-safe sequences, and
    optionally translates quote characters.

    Args:
        s (str): a string to escape

        quote (seq[str], optional) : which quote characters to replace
            (default: ("'", '"'))

    Returns:
        str

    u   &u   &amp;u   <u   &lt;u   >u   &gt;u   "u   &quot;u   'u   &#x27;(   t   replace(   t   st   quote(    (    s0   lib/python2.7/site-packages/bokeh/util/string.pyt   escapeO   s    i   u    c         ` s0   | | ‰  d j  ‡  f d †  |  j d ƒ Dƒ ƒ S(   uH   Indent all the lines in a given block of text by a specified amount.

    Args:
        text (str) :
            The text to indent

        n (int, optional) :
            The amount to indent each line by (default: 2)

        ch (char, optional) :
            What character to fill the indentation with (default: " ")

    u   
c         3` s   |  ] } ˆ  | Vq d  S(   N(    (   t   .0t   line(   t   padding(    s0   lib/python2.7/site-packages/bokeh/util/string.pys	   <genexpr>x   s    (   t   joint   split(   t   textt   nt   ch(    (   R   s0   lib/python2.7/site-packages/bokeh/util/string.pyt   indenti   s    
u   , u   orc         C` sp   g  |  D] } t  | ƒ ^ q }  t |  ƒ d k s= | d k rJ | j |  ƒ Sd | j |  d  ƒ | |  d f Sd S(   u   Join together sequences of strings into English-friendly phrases using
    the conjunction ``or`` when appropriate.

    Args:
        seq (seq[str]) : a sequence of strings to nicely join
        sep (str, optional) : a sequence delimiter to use (default: ", ")
        conjunction (str or None, optional) : a conjuction to use for the last
            two items, or None to reproduce basic join behaviour (default: "or")

    Returns:
        a joined string

    Examples:
        >>> nice_join(["a", "b", "c"])
        'a, b or c'

    i   u   %s %s %siÿÿÿÿN(   t   strt   lent   NoneR   (   t   seqt   sept
   conjuctiont   x(    (    s0   lib/python2.7/site-packages/bokeh/util/string.pyt	   nice_joinz   s    u   _c         C` s<   t  j d d | |  ƒ }  t  j d d | |  ƒ }  |  j ƒ  S(   u"    Convert CamelCase to snake_case. u   ([A-Z]+)([A-Z][a-z])u   \1%s\2u   ([a-z\d])([A-Z])(   t   ret   subt   lower(   t   nameR   (    (    s0   lib/python2.7/site-packages/bokeh/util/string.pyt   snakify“   s    c         O` s    |  d k r d S|  j | | Ž  S(   uæ   Safely format docstrings.

    When Python is executed with the ``-OO`` option, doc strings are removed and
    replaced the value ``None``. This function guards against applying the string
    formatting options in that case.

    Args:
        docstring (str or None) : The docstring to format, or ``None``
        args (tuple) : string formatting arguments for the docsring
        kwargs (dict) : string formatting arguments for the docsring

    Returns:
        str or None

    N(   R   t   format(   t	   docstringt   argst   kwargs(    (    s0   lib/python2.7/site-packages/bokeh/util/string.pyt   format_docstring™   s    (   u   decode_utf8u   encode_utf8u   escapeu   format_docstringu   indentu	   nice_joinu   snakify(   u   'u   "(   t   __doc__t
   __future__R    R   R   R   t   loggingt	   getLoggert   __name__t   logR    t   __all__R   R
   R   R   R   R$   R)   (    (    (    s0   lib/python2.7/site-packages/bokeh/util/string.pyt   <module>	   s$   "      		