o
    vZŽhÜ  ã                   @   sZ   d dl mZ d dlmZ d dlZe d e 	ee ¡¡¡Z
	 dd„ Zdd„ Zddd„ZdS )é    )ÚALL_PUNC)Ú
whitespaceNz^[{}]*$c                 C   sx   |   |¡r| t|ƒd… } t| ƒ|kr9z	|  |d|¡}W n ty'   |}Y nw | d|… gt| |d… ||ƒ S | gS )aF  Recursively split a string in the largest chunks
    possible from the highest position of a delimiter all the way
    to a maximum size

    Args:
        the_string (string): The string to split.
        delim (string): The delimiter to split on.
        max_size (int): The maximum size of a chunk.

    Returns:
        list: the minimized string in tokens

    Every chunk size will be at minimum ``the_string[0:idx]`` where ``idx``
    is the highest index of ``delim`` found in ``the_string``; and at maximum
    ``the_string[0:max_size]`` if no ``delim`` was found in ``the_string``.
    In the latter case, the split will occur at ``the_string[max_size]``
    which can be any character. The function runs itself again on the rest of
    ``the_string`` (``the_string[idx:]``) until no chunk is larger than
    ``max_size``.

    Nr   )Ú
startswithÚlenÚrindexÚ
ValueErrorÚ	_minimize)Z
the_stringÚdelimÚmax_sizeÚidx© r   ú9/var/www/auris/lib/python3.10/site-packages/gtts/utils.pyr      s   
ý"r   c                 C   s   dd„ | D ƒS )a  Clean a list of strings

    Args:
        tokens (list): A list of strings (tokens) to clean.

    Returns:
        list: Stripped strings ``tokens`` without the original elements
            that only consisted of whitespace and/or punctuation characters.

    c                 S   s   g | ]}t  |¡s| ¡ ‘qS r   )Ú_ALL_PUNC_OR_SPACEÚmatchÚstrip)Ú.0Útr   r   r   Ú
<listcomp>C   s    z!_clean_tokens.<locals>.<listcomp>r   )Útokensr   r   r   Ú_clean_tokens8   s   r   ÚcomÚ c                 C   s   d}|  | |¡S )a¬  Generates a Google Translate URL

    Args:
        tld (string): Top-level domain for the Google Translate host,
            i.e ``https://translate.google.<tld>``. Default is ``com``.
        path: (string): A path to append to the Google Translate host,
            i.e ``https://translate.google.com/<path>``. Default is ``""``.

    Returns:
        string: A Google Translate URL `https://translate.google.<tld>/path`
    zhttps://translate.google.{}/{})Úformat)ÚtldÚpathZ_GOOGLE_TTS_URLr   r   r   Ú_translate_urlF   s   r   )r   r   )Zgtts.tokenizer.symbolsr   ZpuncÚstringr   ÚwsÚreÚcompiler   Úescaper   r   r   r   r   r   r   r   Ú<module>   s   +