U
    /eJ                     @  s   d Z ddlmZ ddlZeeZddlZddlm	Z	m
Z
mZmZ ddlmZ dZd'd	d
d	d	dddZd(dd	d	d	dddZd)d	d	d	dddZdd	ddddZeddddddd Zed	ddd	dd!d Zdddddd"d Zd*d	d#d	d$d%d&ZdS )+z9 Functions useful for string manipulations or encoding.

    )annotationsN)AnyDictIterableoverload
quote_plus)append_docstringformat_docstringindent	nice_joinsnakify    strint)textnchreturnc                   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 N ).0linepaddingr   5/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/util/string.py	<genexpr>A   s     zindent.<locals>.<genexpr>)joinsplit)r   r   r   r   r   r   r   2   s    r   , orzIterable[str])seqsep
conjuctionr   c                 C  sV   dd | D } t | dks"|dkr,|| S || dd  d| d| d  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   )r   )r   xr   r   r   
<listcomp>V   s     znice_join.<locals>.<listcomp>   Nr   )lenr   )r#   r$   r%   r   r   r   r   D   s    
r   _)namer$   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)r,   r$   r   r   r   r   ^   s    r   z
str | None)	docstringextrar   c                 C  s   | dkrdS | | S )a   Safely append to docstrings.

    When Python is executed with the ``-OO`` option, doc strings are removed and
    replaced the value ``None``. This function guards against appending the
    extra content in that case.

    Args:
        docstring (str or None) : The docstring to format, or None
        extra (str): the content to append if docstring is not None

    Returns:
        str or None

    Nr   )r0   r1   r   r   r   r	   d   s    r	   Noner   )r0   argskwargsr   c                 O  s   d S r   r   r0   r3   r4   r   r   r   r
   u   s    r
   c                 O  s   d S r   r   r5   r   r   r   r
   w   s    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)formatr5   r   r   r   r
   z   s    zDict[str, str] | None)url	argumentsr   c                 C  s0   |dk	r,dd |  D }| dd| 7 } | S )a!   Format a base URL with optional query arguments

    Args:
        url (str) :
            An base URL to append query arguments to
        arguments (dict or None, optional) :
            A mapping of key/value URL query arguments, or None (default: None)

    Returns:
        str

    Nc                 s  s(   | ] \}}t | d t | V  qdS )=Nr   )r   keyvaluer   r   r   r      s     z-format_url_query_arguments.<locals>.<genexpr>?&)itemsr   )r7   r8   r>   r   r   r   format_url_query_arguments   s    r?   )r   r   )r!   r"   )r+   )N)__doc__
__future__r   logging	getLogger__name__logr-   typingr   r   r   r   urllib.parser   __all__r   r   r   r	   r
   r?   r   r   r   r   <module>   s"   
