a
    /3e                     @   s   d dl Z d dlZd dlmZ zd dlmZ dZW n eyF   dZY n0 edddZ	edd	d
Z
edddZedddZdddZdd ZedddZdS )    N)BytesIO)ImageTF)returnc                 C   s
   t | tS )z7
    Returns True if the given object is a string.
    )
isinstancestrvar r	   H/home/pi/bot/my_env/lib/python3.9/site-packages/telebot/service_utils.py	is_string   s    r   c                 C   s
   t | tS )z
    Returns True if the given object is a dictionary.

    :param var: object to be checked
    :type var: :obj:`object`

    :return: True if the given object is a dictionary.
    :rtype: :obj:`bool`
    )r   dictr   r	   r	   r
   is_dict   s    
r   c                 C   s
   t | tS )z
    Returns True if the given object is a bytes object.

    :param var: object to be checked
    :type var: :obj:`object`

    :return: True if the given object is a bytes object.
    :rtype: :obj:`bool`
    )r   bytesr   r	   r	   r
   is_bytes!   s    
r   c                 C   s   t ot| tjS )z
    Returns True if the given object is a PIL.Image.Image object.

    :param var: object to be checked
    :type var: :obj:`object`

    :return: True if the given object is a PIL.Image.Image object.
    :rtype: :obj:`bool`
    )pil_importedr   r   r   r	   r	   r
   is_pil_image.   s    
r   JPEGweb_lowc                 C   s:   t r.t }| dj|||d |d |S tdd S )NZRGB)qualityr   zPIL module is not imported)r   r   convertsaveseekRuntimeError)image	extensionr   ZphotoBufferr	   r	   r
   pil_image_to_file;   s    
r   c                 c   s,   t dt| |D ]}| |||  V  qdS )z)Yield successive n-sized chunks from lst.r   N)rangelen)lstnir	   r	   r
   chunksF   s    r!   c                   C   s   d ttjdS )z
    Generates a random token consisting of letters and digits, 16 characters long.

    :return: a random token
    :rtype: :obj:`str`
        )joinrandomsamplestringascii_lettersr	   r	   r	   r
   generate_random_tokenM   s    r)   )r   r   )r%   r'   ior   ZPILr   r   ImportErrorboolr   r   r   r   r   r!   r   r)   r	   r	   r	   r
   <module>   s   

