o
    @Mh                     @   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y#   dZY nw defddZ	defd	d
Z
defddZdefddZdddZdd ZdefddZdS )    N)BytesIO)ImageTFreturnc                 C   
   t | tS )z7
    Returns True if the given object is a string.
    )
isinstancestrvar r
   H/var/www/html/venv/lib/python3.10/site-packages/telebot/service_utils.py	is_string   s   
r   c                 C   r   )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      

r   c                 C   r   )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!   r   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   s6   t rt }| dj|||d |d |S td)NRGB)qualityr   zPIL module is not imported)r   r   convertsaveseekRuntimeError)image	extensionr   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   PILr   r   ImportErrorboolr   r   r   r   r   r%   r   r-   r
   r
   r
   r   <module>   s     
