Various helpers not related to the Telegram API itself

class telethon.helpers.TotalList(*args, **kwargs)

Bases: list

A list with an extra total property, which may not match its len since the total represents the total amount of items available somewhere else, not the items in this list.


# Telethon returns these lists in some cases (for example,
# only when a chunk is returned, but the "total" count
# is available).
result = await client.get_messages(chat, limit=10)

print(  # large number
print(len(result))  # 10
print(result[0])  # latest message

for x in result:  # show the 10 messages

Return repr(self).


Return str(self).


list of weak references to the object (if defined)


Ensures that the parent directory exists

telethon.helpers.generate_key_data_from_nonce(server_nonce, new_nonce)

Generates the key data corresponding to the given nonce


Generates a random long integer (8 bytes), which is optionally signed

telethon.helpers.retry_range(retries, force_retry=True)

Generates an integer sequence starting from 1. If retries is not a zero or a positive integer value, the sequence will be infinite, otherwise it will end at retries + 1.

telethon.helpers.strip_text(text, entities)

Strips whitespace from the given surrogated text modifying the provided entities, also removing any empty (0-length) entities.

This assumes that the length of entities is greater or equal to 0, and that no entity is out of bounds.

telethon.helpers.within_surrogate(text, index, *, length=None)

True if index is within a surrogate (before and after it, not at!).