B
    ‹æ@\d  ã               @   s~   d Z ddlmZmZmZmZ ddlZe e¡Z	ddl
Z
dZdd„ Zdd„ Zdd
d„Zddd„Zddd„Zddd„Zdd„ ZdS )z9 Functions useful for string manipulations or encoding.

é    )Úabsolute_importÚdivisionÚprint_functionÚunicode_literalsN)Údecode_utf8Úencode_utf8ÚescapeÚformat_docstringÚindentÚ	nice_joinÚsnakifyc             C   s$   ddl }|jd dkr |  d¡} | S )z‚ Encode a UTF-8 string to a sequence of bytes.

    Args:
        u (str) : the string to encode

    Returns:
        bytes

    r   Né   zutf-8)ÚsysÚversion_infoÚencode)Úur   © r   ú0lib/python3.7/site-packages/bokeh/util/string.pyr   0   s    

r   c             C   s$   ddl }|jd dkr |  d¡} | S )z‡ Decode a sequence of bytes to a UTF-8 string

    Args:
        u (str) : the bytes to decode

    Returns:
        UTF-8 string

    r   Nr   zutf-8)r   r   Údecode)r   r   r   r   r   r   ?   s    

r   ©ú'ú"c             C   sT   |   dd¡} |   dd¡} |   dd¡} |rPd|kr<|   dd¡} d	|krP|   d	d
¡} | S )aO   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

    ú&z&amp;ú<z&lt;ú>z&gt;r   z&quot;r   z&#x27;)Úreplace)ÚsZquoter   r   r   r   O   s    r   r   ú c                s&   || ‰ d  ‡ fdd„|  d¡D ƒ¡S )aH   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: " ")

    Ú
c             3   s   | ]}ˆ | V  qd S )Nr   )Ú.0Úline)Úpaddingr   r   ú	<genexpr>x   s    zindent.<locals>.<genexpr>)ÚjoinÚsplit)ÚtextÚnZchr   )r!   r   r
   i   s    r
   ú, Úorc             C   sP   dd„ | D ƒ} t | ƒdks"|dkr,| | ¡S d| | dd… ¡|| d f S dS )a   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'

    c             S   s   g | ]}t |ƒ‘qS r   )Ústr)r   Úxr   r   r   ú
<listcomp>Œ   s    znice_join.<locals>.<listcomp>é   Nz%s %s %séÿÿÿÿ)Úlenr#   )ÚseqÚsepZ
conjuctionr   r   r   r   z   s    
r   Ú_c             C   s,   t  dd| | ¡} t  dd| | ¡} |  ¡ S )z" Convert CamelCase to snake_case. z([A-Z]+)([A-Z][a-z])z\1%s\2z([a-z\d])([A-Z]))ÚreÚsubÚlower)Únamer0   r   r   r   r   “   s    r   c             O   s   | dkrdS | j ||ŽS )aæ   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)Úformat)Z	docstringÚargsÚkwargsr   r   r   r	   ™   s    r	   )r   )r   r   )r'   r(   )r1   )Ú__doc__Z
__future__r   r   r   r   ZloggingZ	getLoggerÚ__name__Úlogr2   Ú__all__r   r   r   r
   r   r   r	   r   r   r   r   Ú<module>	   s   




