U
    Zf	                     @   s>   d Z ddlZddddgZdd Zdd Zd	d ZdddZdS )z
tool.py - helper code
    Nsame_string_type_asas_stras_str_pathraise_for_empty_pathc                 C   sD   t | trt |tr||S t | tr<t |tr<||S |S dS )z
    Return a string of the same type as `type_source` with the content from
    `string`.

    If the `type_source` and `string` don't have the same type, use `encoding`
    to encode or decode, whatever operation is needed.
    N)
isinstancebytesstrencodedecode)Ztype_sourcestringencoding r   0/tmp/pip-unpacked-wheel-g7w5sq0v/ftputil/tool.pyr      s
    

c                 C   s.   t | tr| |S t | tr"| S tddS )z
    Return the argument `string` converted to a unicode string if it's a
    `bytes` object. Otherwise just return the string.

    If a conversion is necessary, use `encoding`.

    If `string` is neither `str` nor `bytes`, raise a `TypeError`.
    z*`as_str` argument must be `bytes` or `str`N)r   r   r
   r   	TypeError)r   r   r   r   r   r      s
    	


c                 C   s   t | } t| |S )a  
    Return the argument `path` converted to a unicode string if it's a `bytes`
    object. Otherwise just return the string.

    If a conversion is necessary, use `encoding`.

    Instead of passing a `bytes` or `str` object for `path`, you can pass a
    `PathLike` object that can be converted to a `bytes` or `str` object.

    If the `path` can't be converted to a `bytes` or `str`, a `TypeError` is
    raised.
    )osfspathr   )pathr   r   r   r   r   0   s    
r   c                 C   s:   ddl }| dkr6|dkrd}nd| d}|j|dS )zi
    Raise an exception of class `exception_class` if `path` is an empty string
    (text or bytes).
    r   N)     zpath argument is emptyzpath argument `z
` is empty)Zftputil.errorerrorZ
FTPIOError)r   Zpath_argument_nameZftputilmessager   r   r   r   A   s    )r   )__doc__r   __all__r   r   r   r   r   r   r   r   <module>   s   