3
d                 @   sT   d Z ddlZddlZddlZddlZddlZddlZdddZdddZd	d
 Z	dS )zp Provides functions that mange strings to avoid characters that would be
    problematic in certain situations.
    N c             C   s^   t jdtdd tjd| jddjd} tjdd| j	 j
 } tjd	d
| }|dkrZ|S |S )a  
    Make a user-supplied string safe for filename use.

    Returns an ASCII-encodable string based on the input string that's safe for
    use as a component of a filename or URL. The returned value is a string
    containing only lowercase ASCII letters, digits, and the characters '-' and
    '_'.

    This does not give a faithful representation of the original string:
    different input strings can result in the same output string.

    .. deprecated:: 6.3.0
        This function will be removed in a future version of Traits.

    Parameters
    ----------
    name : str
        The string to be made safe.
    replace_empty : str, optional
        The return value to be used in the event that the sanitised
        string ends up being empty. No validation is done on this
        input - it's up to the user to ensure that the default is
        itself safe. The default is to return the empty string.

    Returns
    -------
    safe_string : str
        A filename-safe version of string.

    z;clean_filename is deprecated and will eventually be removed   )
stacklevelZNFKDasciiignorez[^\w\s-]r   z[-\s]+-)warningswarnDeprecationWarningunicodedata	normalizeencodedecoderesubstriplower)nameZreplace_empty	safe_name r   ;/tmp/pip-build-7vycvbft/traits/traits/util/clean_strings.pyclean_filename   s    r   Fc             C   sR   t jdtdd | dkr$tjj } n
tj| } |s>| jdd} | j jdd}|S )	a  
    Return a timestamp that has been cleansed of characters that might
    cause problems in filenames, namely colons.  If no datetime object
    is provided, then uses the current time.

    The timestamp is in ISO-8601 format with the following exceptions:

    * Colons ':' are replaced by underscores '_'.
    * Microseconds are not displayed if the 'microseconds' parameter is
        False.

    .. deprecated:: 6.3.0
        This function will be removed in a future version of Traits.

    Parameters
    ----------
    dt : None or datetime.datetime
        If None, then the current time is used.
    microseconds : bool
        Display microseconds or not.

    Returns
    -------
    A string timestamp.
    z<clean_timestamp is deprecated and will eventually be removedr   )r   Nr   )microsecond:_)r   r	   r
   datetimenowcopyreplace	isoformat)dtmicrosecondsZstampr   r   r   clean_timestampK   s    
r"   c             C   sF   t | dkrB| jddj } tj| r.d|  } | d j rBd|  } | S )z> Attempt to make a valid Python identifier out of a name.
    r    r   )lenr   r   keyword	iskeywordisdigit)r   r   r   r   python_namez   s    
r(   )r   )NF)
__doc__r   r   r%   r   r   r   r   r"   r(   r   r   r   r   <module>   s   
3
/