partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
train
MTProtoSender.send
This method enqueues the given request to be sent. Its send state will be saved until a response arrives, and a ``Future`` that will be resolved when the response arrives will be returned: .. code-block:: python async def method(): # Sending (enqueued for the send l...
telethon/network/mtprotosender.py
def send(self, request, ordered=False): """ This method enqueues the given request to be sent. Its send state will be saved until a response arrives, and a ``Future`` that will be resolved when the response arrives will be returned: .. code-block:: python async def ...
def send(self, request, ordered=False): """ This method enqueues the given request to be sent. Its send state will be saved until a response arrives, and a ``Future`` that will be resolved when the response arrives will be returned: .. code-block:: python async def ...
[ "This", "method", "enqueues", "the", "given", "request", "to", "be", "sent", ".", "Its", "send", "state", "will", "be", "saved", "until", "a", "response", "arrives", "and", "a", "Future", "that", "will", "be", "resolved", "when", "the", "response", "arrive...
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/mtprotosender.py#L135-L175
[ "def", "send", "(", "self", ",", "request", ",", "ordered", "=", "False", ")", ":", "if", "not", "self", ".", "_user_connected", ":", "raise", "ConnectionError", "(", "'Cannot send requests while disconnected'", ")", "if", "not", "utils", ".", "is_list_like", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
MTProtoSender._connect
Performs the actual connection, retrying, generating the authorization key if necessary, and starting the send and receive loops.
telethon/network/mtprotosender.py
async def _connect(self): """ Performs the actual connection, retrying, generating the authorization key if necessary, and starting the send and receive loops. """ self._log.info('Connecting to %s...', self._connection) for attempt in retry_range(self._retries): ...
async def _connect(self): """ Performs the actual connection, retrying, generating the authorization key if necessary, and starting the send and receive loops. """ self._log.info('Connecting to %s...', self._connection) for attempt in retry_range(self._retries): ...
[ "Performs", "the", "actual", "connection", "retrying", "generating", "the", "authorization", "key", "if", "necessary", "and", "starting", "the", "send", "and", "receive", "loops", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/mtprotosender.py#L190-L251
[ "async", "def", "_connect", "(", "self", ")", ":", "self", ".", "_log", ".", "info", "(", "'Connecting to %s...'", ",", "self", ".", "_connection", ")", "for", "attempt", "in", "retry_range", "(", "self", ".", "_retries", ")", ":", "try", ":", "self", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
MTProtoSender._reconnect
Cleanly disconnects and then reconnects.
telethon/network/mtprotosender.py
async def _reconnect(self, last_error): """ Cleanly disconnects and then reconnects. """ self._log.debug('Closing current connection...') await self._connection.disconnect() await helpers._cancel( self._log, send_loop_handle=self._send_loop_handle...
async def _reconnect(self, last_error): """ Cleanly disconnects and then reconnects. """ self._log.debug('Closing current connection...') await self._connection.disconnect() await helpers._cancel( self._log, send_loop_handle=self._send_loop_handle...
[ "Cleanly", "disconnects", "and", "then", "reconnects", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/mtprotosender.py#L282-L332
[ "async", "def", "_reconnect", "(", "self", ",", "last_error", ")", ":", "self", ".", "_log", ".", "debug", "(", "'Closing current connection...'", ")", "await", "self", ".", "_connection", ".", "disconnect", "(", ")", "await", "helpers", ".", "_cancel", "(",...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
MTProtoSender._start_reconnect
Starts a reconnection in the background.
telethon/network/mtprotosender.py
def _start_reconnect(self, error): """Starts a reconnection in the background.""" if self._user_connected and not self._reconnecting: # We set reconnecting to True here and not inside the new task # because it may happen that send/recv loop calls this again # while th...
def _start_reconnect(self, error): """Starts a reconnection in the background.""" if self._user_connected and not self._reconnecting: # We set reconnecting to True here and not inside the new task # because it may happen that send/recv loop calls this again # while th...
[ "Starts", "a", "reconnection", "in", "the", "background", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/mtprotosender.py#L334-L347
[ "def", "_start_reconnect", "(", "self", ",", "error", ")", ":", "if", "self", ".", "_user_connected", "and", "not", "self", ".", "_reconnecting", ":", "# We set reconnecting to True here and not inside the new task", "# because it may happen that send/recv loop calls this again...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
MTProtoSender._send_loop
This loop is responsible for popping items off the send queue, encrypting them, and sending them over the network. Besides `connect`, only this method ever sends data.
telethon/network/mtprotosender.py
async def _send_loop(self): """ This loop is responsible for popping items off the send queue, encrypting them, and sending them over the network. Besides `connect`, only this method ever sends data. """ while self._user_connected and not self._reconnecting: ...
async def _send_loop(self): """ This loop is responsible for popping items off the send queue, encrypting them, and sending them over the network. Besides `connect`, only this method ever sends data. """ while self._user_connected and not self._reconnecting: ...
[ "This", "loop", "is", "responsible", "for", "popping", "items", "off", "the", "send", "queue", "encrypting", "them", "and", "sending", "them", "over", "the", "network", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/mtprotosender.py#L351-L394
[ "async", "def", "_send_loop", "(", "self", ")", ":", "while", "self", ".", "_user_connected", "and", "not", "self", ".", "_reconnecting", ":", "if", "self", ".", "_pending_ack", ":", "ack", "=", "RequestState", "(", "MsgsAck", "(", "list", "(", "self", "...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
MTProtoSender._recv_loop
This loop is responsible for reading all incoming responses from the network, decrypting and handling or dispatching them. Besides `connect`, only this method ever receives data.
telethon/network/mtprotosender.py
async def _recv_loop(self): """ This loop is responsible for reading all incoming responses from the network, decrypting and handling or dispatching them. Besides `connect`, only this method ever receives data. """ while self._user_connected and not self._reconnecting: ...
async def _recv_loop(self): """ This loop is responsible for reading all incoming responses from the network, decrypting and handling or dispatching them. Besides `connect`, only this method ever receives data. """ while self._user_connected and not self._reconnecting: ...
[ "This", "loop", "is", "responsible", "for", "reading", "all", "incoming", "responses", "from", "the", "network", "decrypting", "and", "handling", "or", "dispatching", "them", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/mtprotosender.py#L396-L445
[ "async", "def", "_recv_loop", "(", "self", ")", ":", "while", "self", ".", "_user_connected", "and", "not", "self", ".", "_reconnecting", ":", "self", ".", "_log", ".", "debug", "(", "'Receiving items from the network...'", ")", "try", ":", "body", "=", "awa...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
MTProtoSender._process_message
Adds the given message to the list of messages that must be acknowledged and dispatches control to different ``_handle_*`` method based on its type.
telethon/network/mtprotosender.py
async def _process_message(self, message): """ Adds the given message to the list of messages that must be acknowledged and dispatches control to different ``_handle_*`` method based on its type. """ self._pending_ack.add(message.msg_id) handler = self._handlers.g...
async def _process_message(self, message): """ Adds the given message to the list of messages that must be acknowledged and dispatches control to different ``_handle_*`` method based on its type. """ self._pending_ack.add(message.msg_id) handler = self._handlers.g...
[ "Adds", "the", "given", "message", "to", "the", "list", "of", "messages", "that", "must", "be", "acknowledged", "and", "dispatches", "control", "to", "different", "_handle_", "*", "method", "based", "on", "its", "type", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/mtprotosender.py#L449-L458
[ "async", "def", "_process_message", "(", "self", ",", "message", ")", ":", "self", ".", "_pending_ack", ".", "add", "(", "message", ".", "msg_id", ")", "handler", "=", "self", ".", "_handlers", ".", "get", "(", "message", ".", "obj", ".", "CONSTRUCTOR_ID...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
MTProtoSender._pop_states
Pops the states known to match the given ID from pending messages. This method should be used when the response isn't specific.
telethon/network/mtprotosender.py
def _pop_states(self, msg_id): """ Pops the states known to match the given ID from pending messages. This method should be used when the response isn't specific. """ state = self._pending_state.pop(msg_id, None) if state: return [state] to_pop = [] ...
def _pop_states(self, msg_id): """ Pops the states known to match the given ID from pending messages. This method should be used when the response isn't specific. """ state = self._pending_state.pop(msg_id, None) if state: return [state] to_pop = [] ...
[ "Pops", "the", "states", "known", "to", "match", "the", "given", "ID", "from", "pending", "messages", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/mtprotosender.py#L460-L482
[ "def", "_pop_states", "(", "self", ",", "msg_id", ")", ":", "state", "=", "self", ".", "_pending_state", ".", "pop", "(", "msg_id", ",", "None", ")", "if", "state", ":", "return", "[", "state", "]", "to_pop", "=", "[", "]", "for", "state", "in", "s...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
MTProtoSender._handle_rpc_result
Handles the result for Remote Procedure Calls: rpc_result#f35c6d01 req_msg_id:long result:bytes = RpcResult; This is where the future results for sent requests are set.
telethon/network/mtprotosender.py
async def _handle_rpc_result(self, message): """ Handles the result for Remote Procedure Calls: rpc_result#f35c6d01 req_msg_id:long result:bytes = RpcResult; This is where the future results for sent requests are set. """ rpc_result = message.obj state = sel...
async def _handle_rpc_result(self, message): """ Handles the result for Remote Procedure Calls: rpc_result#f35c6d01 req_msg_id:long result:bytes = RpcResult; This is where the future results for sent requests are set. """ rpc_result = message.obj state = sel...
[ "Handles", "the", "result", "for", "Remote", "Procedure", "Calls", ":" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/mtprotosender.py#L484-L523
[ "async", "def", "_handle_rpc_result", "(", "self", ",", "message", ")", ":", "rpc_result", "=", "message", ".", "obj", "state", "=", "self", ".", "_pending_state", ".", "pop", "(", "rpc_result", ".", "req_msg_id", ",", "None", ")", "self", ".", "_log", "...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
MTProtoSender._handle_container
Processes the inner messages of a container with many of them: msg_container#73f1f8dc messages:vector<%Message> = MessageContainer;
telethon/network/mtprotosender.py
async def _handle_container(self, message): """ Processes the inner messages of a container with many of them: msg_container#73f1f8dc messages:vector<%Message> = MessageContainer; """ self._log.debug('Handling container') for inner_message in message.obj.messages: ...
async def _handle_container(self, message): """ Processes the inner messages of a container with many of them: msg_container#73f1f8dc messages:vector<%Message> = MessageContainer; """ self._log.debug('Handling container') for inner_message in message.obj.messages: ...
[ "Processes", "the", "inner", "messages", "of", "a", "container", "with", "many", "of", "them", ":" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/mtprotosender.py#L525-L533
[ "async", "def", "_handle_container", "(", "self", ",", "message", ")", ":", "self", ".", "_log", ".", "debug", "(", "'Handling container'", ")", "for", "inner_message", "in", "message", ".", "obj", ".", "messages", ":", "await", "self", ".", "_process_messag...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
MTProtoSender._handle_gzip_packed
Unpacks the data from a gzipped object and processes it: gzip_packed#3072cfa1 packed_data:bytes = Object;
telethon/network/mtprotosender.py
async def _handle_gzip_packed(self, message): """ Unpacks the data from a gzipped object and processes it: gzip_packed#3072cfa1 packed_data:bytes = Object; """ self._log.debug('Handling gzipped data') with BinaryReader(message.obj.data) as reader: message...
async def _handle_gzip_packed(self, message): """ Unpacks the data from a gzipped object and processes it: gzip_packed#3072cfa1 packed_data:bytes = Object; """ self._log.debug('Handling gzipped data') with BinaryReader(message.obj.data) as reader: message...
[ "Unpacks", "the", "data", "from", "a", "gzipped", "object", "and", "processes", "it", ":" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/mtprotosender.py#L535-L544
[ "async", "def", "_handle_gzip_packed", "(", "self", ",", "message", ")", ":", "self", ".", "_log", ".", "debug", "(", "'Handling gzipped data'", ")", "with", "BinaryReader", "(", "message", ".", "obj", ".", "data", ")", "as", "reader", ":", "message", ".",...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
MTProtoSender._handle_pong
Handles pong results, which don't come inside a ``rpc_result`` but are still sent through a request: pong#347773c5 msg_id:long ping_id:long = Pong;
telethon/network/mtprotosender.py
async def _handle_pong(self, message): """ Handles pong results, which don't come inside a ``rpc_result`` but are still sent through a request: pong#347773c5 msg_id:long ping_id:long = Pong; """ pong = message.obj self._log.debug('Handling pong for message %d...
async def _handle_pong(self, message): """ Handles pong results, which don't come inside a ``rpc_result`` but are still sent through a request: pong#347773c5 msg_id:long ping_id:long = Pong; """ pong = message.obj self._log.debug('Handling pong for message %d...
[ "Handles", "pong", "results", "which", "don", "t", "come", "inside", "a", "rpc_result", "but", "are", "still", "sent", "through", "a", "request", ":" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/mtprotosender.py#L552-L563
[ "async", "def", "_handle_pong", "(", "self", ",", "message", ")", ":", "pong", "=", "message", ".", "obj", "self", ".", "_log", ".", "debug", "(", "'Handling pong for message %d'", ",", "pong", ".", "msg_id", ")", "state", "=", "self", ".", "_pending_state...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
MTProtoSender._handle_bad_server_salt
Corrects the currently used server salt to use the right value before enqueuing the rejected message to be re-sent: bad_server_salt#edab447b bad_msg_id:long bad_msg_seqno:int error_code:int new_server_salt:long = BadMsgNotification;
telethon/network/mtprotosender.py
async def _handle_bad_server_salt(self, message): """ Corrects the currently used server salt to use the right value before enqueuing the rejected message to be re-sent: bad_server_salt#edab447b bad_msg_id:long bad_msg_seqno:int error_code:int new_server_salt:long = BadM...
async def _handle_bad_server_salt(self, message): """ Corrects the currently used server salt to use the right value before enqueuing the rejected message to be re-sent: bad_server_salt#edab447b bad_msg_id:long bad_msg_seqno:int error_code:int new_server_salt:long = BadM...
[ "Corrects", "the", "currently", "used", "server", "salt", "to", "use", "the", "right", "value", "before", "enqueuing", "the", "rejected", "message", "to", "be", "re", "-", "sent", ":" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/mtprotosender.py#L565-L579
[ "async", "def", "_handle_bad_server_salt", "(", "self", ",", "message", ")", ":", "bad_salt", "=", "message", ".", "obj", "self", ".", "_log", ".", "debug", "(", "'Handling bad salt for message %d'", ",", "bad_salt", ".", "bad_msg_id", ")", "self", ".", "_stat...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
MTProtoSender._handle_bad_notification
Adjusts the current state to be correct based on the received bad message notification whenever possible: bad_msg_notification#a7eff811 bad_msg_id:long bad_msg_seqno:int error_code:int = BadMsgNotification;
telethon/network/mtprotosender.py
async def _handle_bad_notification(self, message): """ Adjusts the current state to be correct based on the received bad message notification whenever possible: bad_msg_notification#a7eff811 bad_msg_id:long bad_msg_seqno:int error_code:int = BadMsgNotification; "...
async def _handle_bad_notification(self, message): """ Adjusts the current state to be correct based on the received bad message notification whenever possible: bad_msg_notification#a7eff811 bad_msg_id:long bad_msg_seqno:int error_code:int = BadMsgNotification; "...
[ "Adjusts", "the", "current", "state", "to", "be", "correct", "based", "on", "the", "received", "bad", "message", "notification", "whenever", "possible", ":" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/mtprotosender.py#L581-L615
[ "async", "def", "_handle_bad_notification", "(", "self", ",", "message", ")", ":", "bad_msg", "=", "message", ".", "obj", "states", "=", "self", ".", "_pop_states", "(", "bad_msg", ".", "bad_msg_id", ")", "self", ".", "_log", ".", "debug", "(", "'Handling ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
MTProtoSender._handle_detailed_info
Updates the current status with the received detailed information: msg_detailed_info#276d3ec6 msg_id:long answer_msg_id:long bytes:int status:int = MsgDetailedInfo;
telethon/network/mtprotosender.py
async def _handle_detailed_info(self, message): """ Updates the current status with the received detailed information: msg_detailed_info#276d3ec6 msg_id:long answer_msg_id:long bytes:int status:int = MsgDetailedInfo; """ # TODO https://goo.gl/VvpCC6 msg_i...
async def _handle_detailed_info(self, message): """ Updates the current status with the received detailed information: msg_detailed_info#276d3ec6 msg_id:long answer_msg_id:long bytes:int status:int = MsgDetailedInfo; """ # TODO https://goo.gl/VvpCC6 msg_i...
[ "Updates", "the", "current", "status", "with", "the", "received", "detailed", "information", ":" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/mtprotosender.py#L617-L627
[ "async", "def", "_handle_detailed_info", "(", "self", ",", "message", ")", ":", "# TODO https://goo.gl/VvpCC6", "msg_id", "=", "message", ".", "obj", ".", "answer_msg_id", "self", ".", "_log", ".", "debug", "(", "'Handling detailed info for message %d'", ",", "msg_i...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
MTProtoSender._handle_new_session_created
Updates the current status with the received session information: new_session_created#9ec20908 first_msg_id:long unique_id:long server_salt:long = NewSession;
telethon/network/mtprotosender.py
async def _handle_new_session_created(self, message): """ Updates the current status with the received session information: new_session_created#9ec20908 first_msg_id:long unique_id:long server_salt:long = NewSession; """ # TODO https://goo.gl/LMyN7A self....
async def _handle_new_session_created(self, message): """ Updates the current status with the received session information: new_session_created#9ec20908 first_msg_id:long unique_id:long server_salt:long = NewSession; """ # TODO https://goo.gl/LMyN7A self....
[ "Updates", "the", "current", "status", "with", "the", "received", "session", "information", ":" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/mtprotosender.py#L641-L650
[ "async", "def", "_handle_new_session_created", "(", "self", ",", "message", ")", ":", "# TODO https://goo.gl/LMyN7A", "self", ".", "_log", ".", "debug", "(", "'Handling new session created'", ")", "self", ".", "_state", ".", "salt", "=", "message", ".", "obj", "...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
MTProtoSender._handle_ack
Handles a server acknowledge about our messages. Normally these can be ignored except in the case of ``auth.logOut``: auth.logOut#5717da40 = Bool; Telegram doesn't seem to send its result so we need to confirm it manually. No other request is known to have this behaviour. ...
telethon/network/mtprotosender.py
async def _handle_ack(self, message): """ Handles a server acknowledge about our messages. Normally these can be ignored except in the case of ``auth.logOut``: auth.logOut#5717da40 = Bool; Telegram doesn't seem to send its result so we need to confirm it manually. N...
async def _handle_ack(self, message): """ Handles a server acknowledge about our messages. Normally these can be ignored except in the case of ``auth.logOut``: auth.logOut#5717da40 = Bool; Telegram doesn't seem to send its result so we need to confirm it manually. N...
[ "Handles", "a", "server", "acknowledge", "about", "our", "messages", ".", "Normally", "these", "can", "be", "ignored", "except", "in", "the", "case", "of", "auth", ".", "logOut", ":" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/mtprotosender.py#L652-L673
[ "async", "def", "_handle_ack", "(", "self", ",", "message", ")", ":", "ack", "=", "message", ".", "obj", "self", ".", "_log", ".", "debug", "(", "'Handling acknowledge for %s'", ",", "str", "(", "ack", ".", "msg_ids", ")", ")", "for", "msg_id", "in", "...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
MTProtoSender._handle_future_salts
Handles future salt results, which don't come inside a ``rpc_result`` but are still sent through a request: future_salts#ae500895 req_msg_id:long now:int salts:vector<future_salt> = FutureSalts;
telethon/network/mtprotosender.py
async def _handle_future_salts(self, message): """ Handles future salt results, which don't come inside a ``rpc_result`` but are still sent through a request: future_salts#ae500895 req_msg_id:long now:int salts:vector<future_salt> = FutureSalts; """ # TOD...
async def _handle_future_salts(self, message): """ Handles future salt results, which don't come inside a ``rpc_result`` but are still sent through a request: future_salts#ae500895 req_msg_id:long now:int salts:vector<future_salt> = FutureSalts; """ # TOD...
[ "Handles", "future", "salt", "results", "which", "don", "t", "come", "inside", "a", "rpc_result", "but", "are", "still", "sent", "through", "a", "request", ":" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/mtprotosender.py#L675-L688
[ "async", "def", "_handle_future_salts", "(", "self", ",", "message", ")", ":", "# TODO save these salts and automatically adjust to the", "# correct one whenever the salt in use expires.", "self", ".", "_log", ".", "debug", "(", "'Handling future salts for message %d'", ",", "m...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
MTProtoSender._handle_state_forgotten
Handles both :tl:`MsgsStateReq` and :tl:`MsgResendReq` by enqueuing a :tl:`MsgsStateInfo` to be sent at a later point.
telethon/network/mtprotosender.py
async def _handle_state_forgotten(self, message): """ Handles both :tl:`MsgsStateReq` and :tl:`MsgResendReq` by enqueuing a :tl:`MsgsStateInfo` to be sent at a later point. """ self._send_queue.append(RequestState(MsgsStateInfo( req_msg_id=message.msg_id, info=chr(1) ...
async def _handle_state_forgotten(self, message): """ Handles both :tl:`MsgsStateReq` and :tl:`MsgResendReq` by enqueuing a :tl:`MsgsStateInfo` to be sent at a later point. """ self._send_queue.append(RequestState(MsgsStateInfo( req_msg_id=message.msg_id, info=chr(1) ...
[ "Handles", "both", ":", "tl", ":", "MsgsStateReq", "and", ":", "tl", ":", "MsgResendReq", "by", "enqueuing", "a", ":", "tl", ":", "MsgsStateInfo", "to", "be", "sent", "at", "a", "later", "point", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/mtprotosender.py#L690-L697
[ "async", "def", "_handle_state_forgotten", "(", "self", ",", "message", ")", ":", "self", ".", "_send_queue", ".", "append", "(", "RequestState", "(", "MsgsStateInfo", "(", "req_msg_id", "=", "message", ".", "msg_id", ",", "info", "=", "chr", "(", "1", ")"...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
InlineBuilder.article
Creates new inline result of article type. Args: title (`str`): The title to be shown for this result. description (`str`, optional): Further explanation of what this result means. url (`str`, optional): The URL to be shown f...
telethon/tl/custom/inlinebuilder.py
async def article( self, title, description=None, *, url=None, thumb=None, content=None, id=None, text=None, parse_mode=(), link_preview=True, geo=None, period=60, contact=None, game=False, buttons=None ): """ Creates new inline result of article type....
async def article( self, title, description=None, *, url=None, thumb=None, content=None, id=None, text=None, parse_mode=(), link_preview=True, geo=None, period=60, contact=None, game=False, buttons=None ): """ Creates new inline result of article type....
[ "Creates", "new", "inline", "result", "of", "article", "type", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/tl/custom/inlinebuilder.py#L59-L108
[ "async", "def", "article", "(", "self", ",", "title", ",", "description", "=", "None", ",", "*", ",", "url", "=", "None", ",", "thumb", "=", "None", ",", "content", "=", "None", ",", "id", "=", "None", ",", "text", "=", "None", ",", "parse_mode", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
InlineBuilder.photo
Creates a new inline result of photo type. Args: file (`obj`, optional): Same as ``file`` for `client.send_file <telethon.client.uploads.UploadMethods.send_file>`.
telethon/tl/custom/inlinebuilder.py
async def photo( self, file, *, id=None, text=None, parse_mode=(), link_preview=True, geo=None, period=60, contact=None, game=False, buttons=None ): """ Creates a new inline result of photo type. Args: file (`obj`, optional): S...
async def photo( self, file, *, id=None, text=None, parse_mode=(), link_preview=True, geo=None, period=60, contact=None, game=False, buttons=None ): """ Creates a new inline result of photo type. Args: file (`obj`, optional): S...
[ "Creates", "a", "new", "inline", "result", "of", "photo", "type", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/tl/custom/inlinebuilder.py#L110-L152
[ "async", "def", "photo", "(", "self", ",", "file", ",", "*", ",", "id", "=", "None", ",", "text", "=", "None", ",", "parse_mode", "=", "(", ")", ",", "link_preview", "=", "True", ",", "geo", "=", "None", ",", "period", "=", "60", ",", "contact", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
InlineBuilder.document
Creates a new inline result of document type. `use_cache`, `mime_type`, `attributes`, `force_document`, `voice_note` and `video_note` are described in `client.send_file <telethon.client.uploads.UploadMethods.send_file>`. Args: file (`obj`): Same as ``file`` ...
telethon/tl/custom/inlinebuilder.py
async def document( self, file, title=None, *, description=None, type=None, mime_type=None, attributes=None, force_document=False, voice_note=False, video_note=False, use_cache=True, id=None, text=None, parse_mode=(), link_preview=True, geo=None, period=60, co...
async def document( self, file, title=None, *, description=None, type=None, mime_type=None, attributes=None, force_document=False, voice_note=False, video_note=False, use_cache=True, id=None, text=None, parse_mode=(), link_preview=True, geo=None, period=60, co...
[ "Creates", "a", "new", "inline", "result", "of", "document", "type", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/tl/custom/inlinebuilder.py#L154-L239
[ "async", "def", "document", "(", "self", ",", "file", ",", "title", "=", "None", ",", "*", ",", "description", "=", "None", ",", "type", "=", "None", ",", "mime_type", "=", "None", ",", "attributes", "=", "None", ",", "force_document", "=", "False", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
InlineBuilder.game
Creates a new inline result of game type. Args: short_name (`str`): The short name of the game to use.
telethon/tl/custom/inlinebuilder.py
async def game( self, short_name, *, id=None, text=None, parse_mode=(), link_preview=True, geo=None, period=60, contact=None, game=False, buttons=None ): """ Creates a new inline result of game type. Args: short_name (`str`): T...
async def game( self, short_name, *, id=None, text=None, parse_mode=(), link_preview=True, geo=None, period=60, contact=None, game=False, buttons=None ): """ Creates a new inline result of game type. Args: short_name (`str`): T...
[ "Creates", "a", "new", "inline", "result", "of", "game", "type", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/tl/custom/inlinebuilder.py#L241-L267
[ "async", "def", "game", "(", "self", ",", "short_name", ",", "*", ",", "id", "=", "None", ",", "text", "=", "None", ",", "parse_mode", "=", "(", ")", ",", "link_preview", "=", "True", ",", "geo", "=", "None", ",", "period", "=", "60", ",", "conta...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
Dialog.send_message
Sends a message to this dialog. This is just a wrapper around ``client.send_message(dialog.input_entity, *args, **kwargs)``.
telethon/tl/custom/dialog.py
async def send_message(self, *args, **kwargs): """ Sends a message to this dialog. This is just a wrapper around ``client.send_message(dialog.input_entity, *args, **kwargs)``. """ return await self._client.send_message( self.input_entity, *args, **kwargs)
async def send_message(self, *args, **kwargs): """ Sends a message to this dialog. This is just a wrapper around ``client.send_message(dialog.input_entity, *args, **kwargs)``. """ return await self._client.send_message( self.input_entity, *args, **kwargs)
[ "Sends", "a", "message", "to", "this", "dialog", ".", "This", "is", "just", "a", "wrapper", "around", "client", ".", "send_message", "(", "dialog", ".", "input_entity", "*", "args", "**", "kwargs", ")", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/tl/custom/dialog.py#L91-L97
[ "async", "def", "send_message", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "await", "self", ".", "_client", ".", "send_message", "(", "self", ".", "input_entity", ",", "*", "args", ",", "*", "*", "kwargs", ")" ]
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
Dialog.delete
Deletes the dialog from your dialog list. If you own the channel this won't destroy it, only delete it from the list.
telethon/tl/custom/dialog.py
async def delete(self): """ Deletes the dialog from your dialog list. If you own the channel this won't destroy it, only delete it from the list. """ if self.is_channel: await self._client(functions.channels.LeaveChannelRequest( self.input_entity)) ...
async def delete(self): """ Deletes the dialog from your dialog list. If you own the channel this won't destroy it, only delete it from the list. """ if self.is_channel: await self._client(functions.channels.LeaveChannelRequest( self.input_entity)) ...
[ "Deletes", "the", "dialog", "from", "your", "dialog", "list", ".", "If", "you", "own", "the", "channel", "this", "won", "t", "destroy", "it", "only", "delete", "it", "from", "the", "list", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/tl/custom/dialog.py#L99-L112
[ "async", "def", "delete", "(", "self", ")", ":", "if", "self", ".", "is_channel", ":", "await", "self", ".", "_client", "(", "functions", ".", "channels", ".", "LeaveChannelRequest", "(", "self", ".", "input_entity", ")", ")", "else", ":", "if", "self", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
BinaryReader.read_int
Reads an integer (4 bytes) value.
telethon/extensions/binaryreader.py
def read_int(self, signed=True): """Reads an integer (4 bytes) value.""" return int.from_bytes(self.read(4), byteorder='little', signed=signed)
def read_int(self, signed=True): """Reads an integer (4 bytes) value.""" return int.from_bytes(self.read(4), byteorder='little', signed=signed)
[ "Reads", "an", "integer", "(", "4", "bytes", ")", "value", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/extensions/binaryreader.py#L39-L41
[ "def", "read_int", "(", "self", ",", "signed", "=", "True", ")", ":", "return", "int", ".", "from_bytes", "(", "self", ".", "read", "(", "4", ")", ",", "byteorder", "=", "'little'", ",", "signed", "=", "signed", ")" ]
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
BinaryReader.read_long
Reads a long integer (8 bytes) value.
telethon/extensions/binaryreader.py
def read_long(self, signed=True): """Reads a long integer (8 bytes) value.""" return int.from_bytes(self.read(8), byteorder='little', signed=signed)
def read_long(self, signed=True): """Reads a long integer (8 bytes) value.""" return int.from_bytes(self.read(8), byteorder='little', signed=signed)
[ "Reads", "a", "long", "integer", "(", "8", "bytes", ")", "value", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/extensions/binaryreader.py#L43-L45
[ "def", "read_long", "(", "self", ",", "signed", "=", "True", ")", ":", "return", "int", ".", "from_bytes", "(", "self", ".", "read", "(", "8", ")", ",", "byteorder", "=", "'little'", ",", "signed", "=", "signed", ")" ]
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
BinaryReader.read_large_int
Reads a n-bits long integer value.
telethon/extensions/binaryreader.py
def read_large_int(self, bits, signed=True): """Reads a n-bits long integer value.""" return int.from_bytes( self.read(bits // 8), byteorder='little', signed=signed)
def read_large_int(self, bits, signed=True): """Reads a n-bits long integer value.""" return int.from_bytes( self.read(bits // 8), byteorder='little', signed=signed)
[ "Reads", "a", "n", "-", "bits", "long", "integer", "value", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/extensions/binaryreader.py#L55-L58
[ "def", "read_large_int", "(", "self", ",", "bits", ",", "signed", "=", "True", ")", ":", "return", "int", ".", "from_bytes", "(", "self", ".", "read", "(", "bits", "//", "8", ")", ",", "byteorder", "=", "'little'", ",", "signed", "=", "signed", ")" ]
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
BinaryReader.read
Read the given amount of bytes.
telethon/extensions/binaryreader.py
def read(self, length=None): """Read the given amount of bytes.""" if length is None: return self.reader.read() result = self.reader.read(length) if len(result) != length: raise BufferError( 'No more data left to read (need {}, got {}: {}); last r...
def read(self, length=None): """Read the given amount of bytes.""" if length is None: return self.reader.read() result = self.reader.read(length) if len(result) != length: raise BufferError( 'No more data left to read (need {}, got {}: {}); last r...
[ "Read", "the", "given", "amount", "of", "bytes", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/extensions/binaryreader.py#L60-L73
[ "def", "read", "(", "self", ",", "length", "=", "None", ")", ":", "if", "length", "is", "None", ":", "return", "self", ".", "reader", ".", "read", "(", ")", "result", "=", "self", ".", "reader", ".", "read", "(", "length", ")", "if", "len", "(", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
BinaryReader.tgread_bytes
Reads a Telegram-encoded byte array, without the need of specifying its length.
telethon/extensions/binaryreader.py
def tgread_bytes(self): """ Reads a Telegram-encoded byte array, without the need of specifying its length. """ first_byte = self.read_byte() if first_byte == 254: length = self.read_byte() | (self.read_byte() << 8) | ( self.read_byte() << 16) ...
def tgread_bytes(self): """ Reads a Telegram-encoded byte array, without the need of specifying its length. """ first_byte = self.read_byte() if first_byte == 254: length = self.read_byte() | (self.read_byte() << 8) | ( self.read_byte() << 16) ...
[ "Reads", "a", "Telegram", "-", "encoded", "byte", "array", "without", "the", "need", "of", "specifying", "its", "length", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/extensions/binaryreader.py#L83-L102
[ "def", "tgread_bytes", "(", "self", ")", ":", "first_byte", "=", "self", ".", "read_byte", "(", ")", "if", "first_byte", "==", "254", ":", "length", "=", "self", ".", "read_byte", "(", ")", "|", "(", "self", ".", "read_byte", "(", ")", "<<", "8", "...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
BinaryReader.tgread_bool
Reads a Telegram boolean value.
telethon/extensions/binaryreader.py
def tgread_bool(self): """Reads a Telegram boolean value.""" value = self.read_int(signed=False) if value == 0x997275b5: # boolTrue return True elif value == 0xbc799737: # boolFalse return False else: raise RuntimeError('Invalid boolean code ...
def tgread_bool(self): """Reads a Telegram boolean value.""" value = self.read_int(signed=False) if value == 0x997275b5: # boolTrue return True elif value == 0xbc799737: # boolFalse return False else: raise RuntimeError('Invalid boolean code ...
[ "Reads", "a", "Telegram", "boolean", "value", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/extensions/binaryreader.py#L108-L116
[ "def", "tgread_bool", "(", "self", ")", ":", "value", "=", "self", ".", "read_int", "(", "signed", "=", "False", ")", "if", "value", "==", "0x997275b5", ":", "# boolTrue", "return", "True", "elif", "value", "==", "0xbc799737", ":", "# boolFalse", "return",...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
BinaryReader.tgread_date
Reads and converts Unix time (used by Telegram) into a Python datetime object.
telethon/extensions/binaryreader.py
def tgread_date(self): """Reads and converts Unix time (used by Telegram) into a Python datetime object. """ value = self.read_int() if value == 0: return None else: return datetime.fromtimestamp(value, tz=timezone.utc)
def tgread_date(self): """Reads and converts Unix time (used by Telegram) into a Python datetime object. """ value = self.read_int() if value == 0: return None else: return datetime.fromtimestamp(value, tz=timezone.utc)
[ "Reads", "and", "converts", "Unix", "time", "(", "used", "by", "Telegram", ")", "into", "a", "Python", "datetime", "object", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/extensions/binaryreader.py#L118-L126
[ "def", "tgread_date", "(", "self", ")", ":", "value", "=", "self", ".", "read_int", "(", ")", "if", "value", "==", "0", ":", "return", "None", "else", ":", "return", "datetime", ".", "fromtimestamp", "(", "value", ",", "tz", "=", "timezone", ".", "ut...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
BinaryReader.tgread_object
Reads a Telegram object.
telethon/extensions/binaryreader.py
def tgread_object(self): """Reads a Telegram object.""" constructor_id = self.read_int(signed=False) clazz = tlobjects.get(constructor_id, None) if clazz is None: # The class was None, but there's still a # chance of it being a manually parsed value like bool! ...
def tgread_object(self): """Reads a Telegram object.""" constructor_id = self.read_int(signed=False) clazz = tlobjects.get(constructor_id, None) if clazz is None: # The class was None, but there's still a # chance of it being a manually parsed value like bool! ...
[ "Reads", "a", "Telegram", "object", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/extensions/binaryreader.py#L128-L152
[ "def", "tgread_object", "(", "self", ")", ":", "constructor_id", "=", "self", ".", "read_int", "(", "signed", "=", "False", ")", "clazz", "=", "tlobjects", ".", "get", "(", "constructor_id", ",", "None", ")", "if", "clazz", "is", "None", ":", "# The clas...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
BinaryReader.tgread_vector
Reads a vector (a list) of Telegram objects.
telethon/extensions/binaryreader.py
def tgread_vector(self): """Reads a vector (a list) of Telegram objects.""" if 0x1cb5c415 != self.read_int(signed=False): raise RuntimeError('Invalid constructor code, vector was expected') count = self.read_int() return [self.tgread_object() for _ in range(count)]
def tgread_vector(self): """Reads a vector (a list) of Telegram objects.""" if 0x1cb5c415 != self.read_int(signed=False): raise RuntimeError('Invalid constructor code, vector was expected') count = self.read_int() return [self.tgread_object() for _ in range(count)]
[ "Reads", "a", "vector", "(", "a", "list", ")", "of", "Telegram", "objects", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/extensions/binaryreader.py#L154-L160
[ "def", "tgread_vector", "(", "self", ")", ":", "if", "0x1cb5c415", "!=", "self", ".", "read_int", "(", "signed", "=", "False", ")", ":", "raise", "RuntimeError", "(", "'Invalid constructor code, vector was expected'", ")", "count", "=", "self", ".", "read_int", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
Factorization.factorize
Factorizes the given large integer. :param pq: the prime pair pq. :return: a tuple containing the two factors p and q.
telethon/crypto/factorization.py
def factorize(cls, pq): """ Factorizes the given large integer. :param pq: the prime pair pq. :return: a tuple containing the two factors p and q. """ if pq % 2 == 0: return 2, pq // 2 y, c, m = randint(1, pq - 1), randint(1, pq - 1), randint(1, pq -...
def factorize(cls, pq): """ Factorizes the given large integer. :param pq: the prime pair pq. :return: a tuple containing the two factors p and q. """ if pq % 2 == 0: return 2, pq // 2 y, c, m = randint(1, pq - 1), randint(1, pq - 1), randint(1, pq -...
[ "Factorizes", "the", "given", "large", "integer", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/crypto/factorization.py#L12-L51
[ "def", "factorize", "(", "cls", ",", "pq", ")", ":", "if", "pq", "%", "2", "==", "0", ":", "return", "2", ",", "pq", "//", "2", "y", ",", "c", ",", "m", "=", "randint", "(", "1", ",", "pq", "-", "1", ")", ",", "randint", "(", "1", ",", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
Factorization.gcd
Calculates the Greatest Common Divisor. :param a: the first number. :param b: the second number. :return: GCD(a, b)
telethon/crypto/factorization.py
def gcd(a, b): """ Calculates the Greatest Common Divisor. :param a: the first number. :param b: the second number. :return: GCD(a, b) """ while b: a, b = b, a % b return a
def gcd(a, b): """ Calculates the Greatest Common Divisor. :param a: the first number. :param b: the second number. :return: GCD(a, b) """ while b: a, b = b, a % b return a
[ "Calculates", "the", "Greatest", "Common", "Divisor", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/crypto/factorization.py#L54-L65
[ "def", "gcd", "(", "a", ",", "b", ")", ":", "while", "b", ":", "a", ",", "b", "=", "b", ",", "a", "%", "b", "return", "a" ]
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
AccountMethods.takeout
Creates a proxy object over the current :ref:`TelegramClient` through which making requests will use :tl:`InvokeWithTakeoutRequest` to wrap them. In other words, returns the current client modified so that requests are done as a takeout: >>> from telethon.sync import TelegramClient ...
telethon/client/account.py
def takeout( self, finalize=True, *, contacts=None, users=None, chats=None, megagroups=None, channels=None, files=None, max_file_size=None): """ Creates a proxy object over the current :ref:`TelegramClient` through which making requests will use :tl:`InvokeWithTakeoutRequ...
def takeout( self, finalize=True, *, contacts=None, users=None, chats=None, megagroups=None, channels=None, files=None, max_file_size=None): """ Creates a proxy object over the current :ref:`TelegramClient` through which making requests will use :tl:`InvokeWithTakeoutRequ...
[ "Creates", "a", "proxy", "object", "over", "the", "current", ":", "ref", ":", "TelegramClient", "through", "which", "making", "requests", "will", "use", ":", "tl", ":", "InvokeWithTakeoutRequest", "to", "wrap", "them", ".", "In", "other", "words", "returns", ...
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/client/account.py#L107-L193
[ "def", "takeout", "(", "self", ",", "finalize", "=", "True", ",", "*", ",", "contacts", "=", "None", ",", "users", "=", "None", ",", "chats", "=", "None", ",", "megagroups", "=", "None", ",", "channels", "=", "None", ",", "files", "=", "None", ",",...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
AccountMethods.end_takeout
Finishes a takeout, with specified result sent back to Telegram. Returns: ``True`` if the operation was successful, ``False`` otherwise.
telethon/client/account.py
async def end_takeout(self, success): """ Finishes a takeout, with specified result sent back to Telegram. Returns: ``True`` if the operation was successful, ``False`` otherwise. """ try: async with _TakeoutClient(True, self, None) as takeout: ...
async def end_takeout(self, success): """ Finishes a takeout, with specified result sent back to Telegram. Returns: ``True`` if the operation was successful, ``False`` otherwise. """ try: async with _TakeoutClient(True, self, None) as takeout: ...
[ "Finishes", "a", "takeout", "with", "specified", "result", "sent", "back", "to", "Telegram", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/client/account.py#L195-L207
[ "async", "def", "end_takeout", "(", "self", ",", "success", ")", ":", "try", ":", "async", "with", "_TakeoutClient", "(", "True", ",", "self", ",", "None", ")", "as", "takeout", ":", "takeout", ".", "success", "=", "success", "except", "ValueError", ":",...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
syncify
Converts all the methods in the given types (class definitions) into synchronous, which return either the coroutine or the result based on whether ``asyncio's`` event loop is running.
telethon/sync.py
def syncify(*types): """ Converts all the methods in the given types (class definitions) into synchronous, which return either the coroutine or the result based on whether ``asyncio's`` event loop is running. """ # Our asynchronous generators all are `RequestIter`, which already # provide a ...
def syncify(*types): """ Converts all the methods in the given types (class definitions) into synchronous, which return either the coroutine or the result based on whether ``asyncio's`` event loop is running. """ # Our asynchronous generators all are `RequestIter`, which already # provide a ...
[ "Converts", "all", "the", "methods", "in", "the", "given", "types", "(", "class", "definitions", ")", "into", "synchronous", "which", "return", "either", "the", "coroutine", "or", "the", "result", "based", "on", "whether", "asyncio", "s", "event", "loop", "i...
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/sync.py#L43-L56
[ "def", "syncify", "(", "*", "types", ")", ":", "# Our asynchronous generators all are `RequestIter`, which already", "# provide a synchronous iterator variant, so we don't need to worry", "# about asyncgenfunction's here.", "for", "t", "in", "types", ":", "for", "name", "in", "di...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
MessagePacker.get
Returns (batch, data) if one or more items could be retrieved. If the cancellation occurs or only invalid items were in the queue, (None, None) will be returned instead.
telethon/extensions/messagepacker.py
async def get(self): """ Returns (batch, data) if one or more items could be retrieved. If the cancellation occurs or only invalid items were in the queue, (None, None) will be returned instead. """ if not self._deque: self._ready.clear() await se...
async def get(self): """ Returns (batch, data) if one or more items could be retrieved. If the cancellation occurs or only invalid items were in the queue, (None, None) will be returned instead. """ if not self._deque: self._ready.clear() await se...
[ "Returns", "(", "batch", "data", ")", "if", "one", "or", "more", "items", "could", "be", "retrieved", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/extensions/messagepacker.py#L40-L112
[ "async", "def", "get", "(", "self", ")", ":", "if", "not", "self", ".", "_deque", ":", "self", ".", "_ready", ".", "clear", "(", ")", "await", "self", ".", "_ready", ".", "wait", "(", ")", "buffer", "=", "io", ".", "BytesIO", "(", ")", "batch", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
Connection.connect
Establishes a connection with the server.
telethon/network/connection/connection.py
async def connect(self, timeout=None, ssl=None): """ Establishes a connection with the server. """ await self._connect(timeout=timeout, ssl=ssl) self._connected = True self._send_task = self._loop.create_task(self._send_loop()) self._recv_task = self._loop.create...
async def connect(self, timeout=None, ssl=None): """ Establishes a connection with the server. """ await self._connect(timeout=timeout, ssl=ssl) self._connected = True self._send_task = self._loop.create_task(self._send_loop()) self._recv_task = self._loop.create...
[ "Establishes", "a", "connection", "with", "the", "server", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/connection/connection.py#L87-L95
[ "async", "def", "connect", "(", "self", ",", "timeout", "=", "None", ",", "ssl", "=", "None", ")", ":", "await", "self", ".", "_connect", "(", "timeout", "=", "timeout", ",", "ssl", "=", "ssl", ")", "self", ".", "_connected", "=", "True", "self", "...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
Connection.disconnect
Disconnects from the server, and clears pending outgoing and incoming messages.
telethon/network/connection/connection.py
async def disconnect(self): """ Disconnects from the server, and clears pending outgoing and incoming messages. """ self._connected = False await helpers._cancel( self._log, send_task=self._send_task, recv_task=self._recv_task ...
async def disconnect(self): """ Disconnects from the server, and clears pending outgoing and incoming messages. """ self._connected = False await helpers._cancel( self._log, send_task=self._send_task, recv_task=self._recv_task ...
[ "Disconnects", "from", "the", "server", "and", "clears", "pending", "outgoing", "and", "incoming", "messages", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/connection/connection.py#L97-L113
[ "async", "def", "disconnect", "(", "self", ")", ":", "self", ".", "_connected", "=", "False", "await", "helpers", ".", "_cancel", "(", "self", ".", "_log", ",", "send_task", "=", "self", ".", "_send_task", ",", "recv_task", "=", "self", ".", "_recv_task"...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
Connection.send
Sends a packet of data through this connection mode. This method returns a coroutine.
telethon/network/connection/connection.py
def send(self, data): """ Sends a packet of data through this connection mode. This method returns a coroutine. """ if not self._connected: raise ConnectionError('Not connected') return self._send_queue.put(data)
def send(self, data): """ Sends a packet of data through this connection mode. This method returns a coroutine. """ if not self._connected: raise ConnectionError('Not connected') return self._send_queue.put(data)
[ "Sends", "a", "packet", "of", "data", "through", "this", "connection", "mode", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/connection/connection.py#L115-L124
[ "def", "send", "(", "self", ",", "data", ")", ":", "if", "not", "self", ".", "_connected", ":", "raise", "ConnectionError", "(", "'Not connected'", ")", "return", "self", ".", "_send_queue", ".", "put", "(", "data", ")" ]
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
Connection.recv
Receives a packet of data through this connection mode. This method returns a coroutine.
telethon/network/connection/connection.py
async def recv(self): """ Receives a packet of data through this connection mode. This method returns a coroutine. """ while self._connected: result = await self._recv_queue.get() if result: # None = sentinel value = keep trying return re...
async def recv(self): """ Receives a packet of data through this connection mode. This method returns a coroutine. """ while self._connected: result = await self._recv_queue.get() if result: # None = sentinel value = keep trying return re...
[ "Receives", "a", "packet", "of", "data", "through", "this", "connection", "mode", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/connection/connection.py#L126-L137
[ "async", "def", "recv", "(", "self", ")", ":", "while", "self", ".", "_connected", ":", "result", "=", "await", "self", ".", "_recv_queue", ".", "get", "(", ")", "if", "result", ":", "# None = sentinel value = keep trying", "return", "result", "raise", "Conn...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
Connection._send_loop
This loop is constantly popping items off the queue to send them.
telethon/network/connection/connection.py
async def _send_loop(self): """ This loop is constantly popping items off the queue to send them. """ try: while self._connected: self._send(await self._send_queue.get()) await self._writer.drain() except asyncio.CancelledError: ...
async def _send_loop(self): """ This loop is constantly popping items off the queue to send them. """ try: while self._connected: self._send(await self._send_queue.get()) await self._writer.drain() except asyncio.CancelledError: ...
[ "This", "loop", "is", "constantly", "popping", "items", "off", "the", "queue", "to", "send", "them", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/connection/connection.py#L139-L155
[ "async", "def", "_send_loop", "(", "self", ")", ":", "try", ":", "while", "self", ".", "_connected", ":", "self", ".", "_send", "(", "await", "self", ".", "_send_queue", ".", "get", "(", ")", ")", "await", "self", ".", "_writer", ".", "drain", "(", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
Connection._recv_loop
This loop is constantly putting items on the queue as they're read.
telethon/network/connection/connection.py
async def _recv_loop(self): """ This loop is constantly putting items on the queue as they're read. """ while self._connected: try: data = await self._recv() except asyncio.CancelledError: break except Exception as e: ...
async def _recv_loop(self): """ This loop is constantly putting items on the queue as they're read. """ while self._connected: try: data = await self._recv() except asyncio.CancelledError: break except Exception as e: ...
[ "This", "loop", "is", "constantly", "putting", "items", "on", "the", "queue", "as", "they", "re", "read", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/connection/connection.py#L157-L188
[ "async", "def", "_recv_loop", "(", "self", ")", ":", "while", "self", ".", "_connected", ":", "try", ":", "data", "=", "await", "self", ".", "_recv", "(", ")", "except", "asyncio", ".", "CancelledError", ":", "break", "except", "Exception", "as", "e", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
Connection._init_conn
This method will be called after `connect` is called. After this method finishes, the writer will be drained. Subclasses should make use of this if they need to send data to Telegram to indicate which connection mode will be used.
telethon/network/connection/connection.py
def _init_conn(self): """ This method will be called after `connect` is called. After this method finishes, the writer will be drained. Subclasses should make use of this if they need to send data to Telegram to indicate which connection mode will be used. """ ...
def _init_conn(self): """ This method will be called after `connect` is called. After this method finishes, the writer will be drained. Subclasses should make use of this if they need to send data to Telegram to indicate which connection mode will be used. """ ...
[ "This", "method", "will", "be", "called", "after", "connect", "is", "called", ".", "After", "this", "method", "finishes", "the", "writer", "will", "be", "drained", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/connection/connection.py#L190-L200
[ "def", "_init_conn", "(", "self", ")", ":", "if", "self", ".", "_codec", ".", "tag", ":", "self", ".", "_writer", ".", "write", "(", "self", ".", "_codec", ".", "tag", ")" ]
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
GzipPacked.gzip_if_smaller
Calls bytes(request), and based on a certain threshold, optionally gzips the resulting data. If the gzipped data is smaller than the original byte array, this is returned instead. Note that this only applies to content related requests.
telethon/tl/core/gzippacked.py
def gzip_if_smaller(content_related, data): """Calls bytes(request), and based on a certain threshold, optionally gzips the resulting data. If the gzipped data is smaller than the original byte array, this is returned instead. Note that this only applies to content related requ...
def gzip_if_smaller(content_related, data): """Calls bytes(request), and based on a certain threshold, optionally gzips the resulting data. If the gzipped data is smaller than the original byte array, this is returned instead. Note that this only applies to content related requ...
[ "Calls", "bytes", "(", "request", ")", "and", "based", "on", "a", "certain", "threshold", "optionally", "gzips", "the", "resulting", "data", ".", "If", "the", "gzipped", "data", "is", "smaller", "than", "the", "original", "byte", "array", "this", "is", "re...
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/tl/core/gzippacked.py#L14-L25
[ "def", "gzip_if_smaller", "(", "content_related", ",", "data", ")", ":", "if", "content_related", "and", "len", "(", "data", ")", ">", "512", ":", "gzipped", "=", "bytes", "(", "GzipPacked", "(", "data", ")", ")", "return", "gzipped", "if", "len", "(", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
TLObject.sorted_args
Returns the arguments properly sorted and ready to plug-in into a Python's method header (i.e., flags and those which can be inferred will go last so they can default =None)
telethon_generator/parsers/tlobject/tlobject.py
def sorted_args(self): """Returns the arguments properly sorted and ready to plug-in into a Python's method header (i.e., flags and those which can be inferred will go last so they can default =None) """ return sorted(self.args, key=lambda x: x.is_flag...
def sorted_args(self): """Returns the arguments properly sorted and ready to plug-in into a Python's method header (i.e., flags and those which can be inferred will go last so they can default =None) """ return sorted(self.args, key=lambda x: x.is_flag...
[ "Returns", "the", "arguments", "properly", "sorted", "and", "ready", "to", "plug", "-", "in", "into", "a", "Python", "s", "method", "header", "(", "i", ".", "e", ".", "flags", "and", "those", "which", "can", "be", "inferred", "will", "go", "last", "so"...
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon_generator/parsers/tlobject/tlobject.py#L59-L65
[ "def", "sorted_args", "(", "self", ")", ":", "return", "sorted", "(", "self", ".", "args", ",", "key", "=", "lambda", "x", ":", "x", ".", "is_flag", "or", "x", ".", "can_be_inferred", ")" ]
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
SQLiteSession._cursor
Asserts that the connection is open and returns a cursor
telethon/sessions/sqlite.py
def _cursor(self): """Asserts that the connection is open and returns a cursor""" if self._conn is None: self._conn = sqlite3.connect(self.filename, check_same_thread=False) return self._conn.cursor()
def _cursor(self): """Asserts that the connection is open and returns a cursor""" if self._conn is None: self._conn = sqlite3.connect(self.filename, check_same_thread=False) return self._conn.cursor()
[ "Asserts", "that", "the", "connection", "is", "open", "and", "returns", "a", "cursor" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/sessions/sqlite.py#L214-L219
[ "def", "_cursor", "(", "self", ")", ":", "if", "self", ".", "_conn", "is", "None", ":", "self", ".", "_conn", "=", "sqlite3", ".", "connect", "(", "self", ".", "filename", ",", "check_same_thread", "=", "False", ")", "return", "self", ".", "_conn", "...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
SQLiteSession._execute
Gets a cursor, executes `stmt` and closes the cursor, fetching one row afterwards and returning its result.
telethon/sessions/sqlite.py
def _execute(self, stmt, *values): """ Gets a cursor, executes `stmt` and closes the cursor, fetching one row afterwards and returning its result. """ c = self._cursor() try: return c.execute(stmt, values).fetchone() finally: c.close()
def _execute(self, stmt, *values): """ Gets a cursor, executes `stmt` and closes the cursor, fetching one row afterwards and returning its result. """ c = self._cursor() try: return c.execute(stmt, values).fetchone() finally: c.close()
[ "Gets", "a", "cursor", "executes", "stmt", "and", "closes", "the", "cursor", "fetching", "one", "row", "afterwards", "and", "returning", "its", "result", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/sessions/sqlite.py#L221-L230
[ "def", "_execute", "(", "self", ",", "stmt", ",", "*", "values", ")", ":", "c", "=", "self", ".", "_cursor", "(", ")", "try", ":", "return", "c", ".", "execute", "(", "stmt", ",", "values", ")", ".", "fetchone", "(", ")", "finally", ":", "c", "...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
SQLiteSession.close
Closes the connection unless we're working in-memory
telethon/sessions/sqlite.py
def close(self): """Closes the connection unless we're working in-memory""" if self.filename != ':memory:': if self._conn is not None: self._conn.commit() self._conn.close() self._conn = None
def close(self): """Closes the connection unless we're working in-memory""" if self.filename != ':memory:': if self._conn is not None: self._conn.commit() self._conn.close() self._conn = None
[ "Closes", "the", "connection", "unless", "we", "re", "working", "in", "-", "memory" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/sessions/sqlite.py#L232-L238
[ "def", "close", "(", "self", ")", ":", "if", "self", ".", "filename", "!=", "':memory:'", ":", "if", "self", ".", "_conn", "is", "not", "None", ":", "self", ".", "_conn", ".", "commit", "(", ")", "self", ".", "_conn", ".", "close", "(", ")", "sel...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
SQLiteSession.delete
Deletes the current session file
telethon/sessions/sqlite.py
def delete(self): """Deletes the current session file""" if self.filename == ':memory:': return True try: os.remove(self.filename) return True except OSError: return False
def delete(self): """Deletes the current session file""" if self.filename == ':memory:': return True try: os.remove(self.filename) return True except OSError: return False
[ "Deletes", "the", "current", "session", "file" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/sessions/sqlite.py#L240-L248
[ "def", "delete", "(", "self", ")", ":", "if", "self", ".", "filename", "==", "':memory:'", ":", "return", "True", "try", ":", "os", ".", "remove", "(", "self", ".", "filename", ")", "return", "True", "except", "OSError", ":", "return", "False" ]
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
SQLiteSession.list_sessions
Lists all the sessions of the users who have ever connected using this client and never logged out
telethon/sessions/sqlite.py
def list_sessions(cls): """Lists all the sessions of the users who have ever connected using this client and never logged out """ return [os.path.splitext(os.path.basename(f))[0] for f in os.listdir('.') if f.endswith(EXTENSION)]
def list_sessions(cls): """Lists all the sessions of the users who have ever connected using this client and never logged out """ return [os.path.splitext(os.path.basename(f))[0] for f in os.listdir('.') if f.endswith(EXTENSION)]
[ "Lists", "all", "the", "sessions", "of", "the", "users", "who", "have", "ever", "connected", "using", "this", "client", "and", "never", "logged", "out" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/sessions/sqlite.py#L251-L256
[ "def", "list_sessions", "(", "cls", ")", ":", "return", "[", "os", ".", "path", ".", "splitext", "(", "os", ".", "path", ".", "basename", "(", "f", ")", ")", "[", "0", "]", "for", "f", "in", "os", ".", "listdir", "(", "'.'", ")", "if", "f", "...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
SQLiteSession.process_entities
Processes all the found entities on the given TLObject, unless .enabled is False. Returns True if new input entities were added.
telethon/sessions/sqlite.py
def process_entities(self, tlo): """Processes all the found entities on the given TLObject, unless .enabled is False. Returns True if new input entities were added. """ if not self.save_entities: return rows = self._entities_to_rows(tlo) if not...
def process_entities(self, tlo): """Processes all the found entities on the given TLObject, unless .enabled is False. Returns True if new input entities were added. """ if not self.save_entities: return rows = self._entities_to_rows(tlo) if not...
[ "Processes", "all", "the", "found", "entities", "on", "the", "given", "TLObject", "unless", ".", "enabled", "is", "False", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/sessions/sqlite.py#L260-L278
[ "def", "process_entities", "(", "self", ",", "tlo", ")", ":", "if", "not", "self", ".", "save_entities", ":", "return", "rows", "=", "self", ".", "_entities_to_rows", "(", "tlo", ")", "if", "not", "rows", ":", "return", "c", "=", "self", ".", "_cursor"...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
parse_methods
Parses the input CSV file with columns (method, usability, errors) and yields `MethodInfo` instances as a result.
telethon_generator/parsers/methods.py
def parse_methods(csv_file, errors_dict): """ Parses the input CSV file with columns (method, usability, errors) and yields `MethodInfo` instances as a result. """ with csv_file.open(newline='') as f: f = csv.reader(f) next(f, None) # header for line, (method, usability, err...
def parse_methods(csv_file, errors_dict): """ Parses the input CSV file with columns (method, usability, errors) and yields `MethodInfo` instances as a result. """ with csv_file.open(newline='') as f: f = csv.reader(f) next(f, None) # header for line, (method, usability, err...
[ "Parses", "the", "input", "CSV", "file", "with", "columns", "(", "method", "usability", "errors", ")", "and", "yields", "MethodInfo", "instances", "as", "a", "result", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon_generator/parsers/methods.py#L28-L43
[ "def", "parse_methods", "(", "csv_file", ",", "errors_dict", ")", ":", "with", "csv_file", ".", "open", "(", "newline", "=", "''", ")", "as", "f", ":", "f", "=", "csv", ".", "reader", "(", "f", ")", "next", "(", "f", ",", "None", ")", "# header", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
TelegramBaseClient.connect
Connects to Telegram.
telethon/client/telegrambaseclient.py
async def connect(self): """ Connects to Telegram. """ await self._sender.connect(self._connection( self.session.server_address, self.session.port, self.session.dc_id, loop=self._loop, loggers=self._log, proxy=self._...
async def connect(self): """ Connects to Telegram. """ await self._sender.connect(self._connection( self.session.server_address, self.session.port, self.session.dc_id, loop=self._loop, loggers=self._log, proxy=self._...
[ "Connects", "to", "Telegram", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/client/telegrambaseclient.py#L352-L370
[ "async", "def", "connect", "(", "self", ")", ":", "await", "self", ".", "_sender", ".", "connect", "(", "self", ".", "_connection", "(", "self", ".", "session", ".", "server_address", ",", "self", ".", "session", ".", "port", ",", "self", ".", "session...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
TelegramBaseClient.disconnect
Disconnects from Telegram. If the event loop is already running, this method returns a coroutine that you should await on your own code; otherwise the loop is ran until said coroutine completes.
telethon/client/telegrambaseclient.py
def disconnect(self): """ Disconnects from Telegram. If the event loop is already running, this method returns a coroutine that you should await on your own code; otherwise the loop is ran until said coroutine completes. """ if self._loop.is_running(): ...
def disconnect(self): """ Disconnects from Telegram. If the event loop is already running, this method returns a coroutine that you should await on your own code; otherwise the loop is ran until said coroutine completes. """ if self._loop.is_running(): ...
[ "Disconnects", "from", "Telegram", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/client/telegrambaseclient.py#L379-L390
[ "def", "disconnect", "(", "self", ")", ":", "if", "self", ".", "_loop", ".", "is_running", "(", ")", ":", "return", "self", ".", "_disconnect_coro", "(", ")", "else", ":", "self", ".", "_loop", ".", "run_until_complete", "(", "self", ".", "_disconnect_co...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
TelegramBaseClient._disconnect
Disconnect only, without closing the session. Used in reconnections to different data centers, where we don't want to close the session file; user disconnects however should close it since it means that their job with the client is complete and we should clean it up all.
telethon/client/telegrambaseclient.py
async def _disconnect(self): """ Disconnect only, without closing the session. Used in reconnections to different data centers, where we don't want to close the session file; user disconnects however should close it since it means that their job with the client is complete and we...
async def _disconnect(self): """ Disconnect only, without closing the session. Used in reconnections to different data centers, where we don't want to close the session file; user disconnects however should close it since it means that their job with the client is complete and we...
[ "Disconnect", "only", "without", "closing", "the", "session", ".", "Used", "in", "reconnections", "to", "different", "data", "centers", "where", "we", "don", "t", "want", "to", "close", "the", "session", "file", ";", "user", "disconnects", "however", "should",...
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/client/telegrambaseclient.py#L406-L415
[ "async", "def", "_disconnect", "(", "self", ")", ":", "await", "self", ".", "_sender", ".", "disconnect", "(", ")", "await", "helpers", ".", "_cancel", "(", "self", ".", "_log", "[", "__name__", "]", ",", "updates_handle", "=", "self", ".", "_updates_han...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
TelegramBaseClient._switch_dc
Permanently switches the current connection to the new data center.
telethon/client/telegrambaseclient.py
async def _switch_dc(self, new_dc): """ Permanently switches the current connection to the new data center. """ self._log[__name__].info('Reconnecting to new data center %s', new_dc) dc = await self._get_dc(new_dc) self.session.set_dc(dc.id, dc.ip_address, dc.port) ...
async def _switch_dc(self, new_dc): """ Permanently switches the current connection to the new data center. """ self._log[__name__].info('Reconnecting to new data center %s', new_dc) dc = await self._get_dc(new_dc) self.session.set_dc(dc.id, dc.ip_address, dc.port) ...
[ "Permanently", "switches", "the", "current", "connection", "to", "the", "new", "data", "center", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/client/telegrambaseclient.py#L417-L431
[ "async", "def", "_switch_dc", "(", "self", ",", "new_dc", ")", ":", "self", ".", "_log", "[", "__name__", "]", ".", "info", "(", "'Reconnecting to new data center %s'", ",", "new_dc", ")", "dc", "=", "await", "self", ".", "_get_dc", "(", "new_dc", ")", "...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
TelegramBaseClient._auth_key_callback
Callback from the sender whenever it needed to generate a new authorization key. This means we are not authorized.
telethon/client/telegrambaseclient.py
def _auth_key_callback(self, auth_key): """ Callback from the sender whenever it needed to generate a new authorization key. This means we are not authorized. """ self.session.auth_key = auth_key self.session.save()
def _auth_key_callback(self, auth_key): """ Callback from the sender whenever it needed to generate a new authorization key. This means we are not authorized. """ self.session.auth_key = auth_key self.session.save()
[ "Callback", "from", "the", "sender", "whenever", "it", "needed", "to", "generate", "a", "new", "authorization", "key", ".", "This", "means", "we", "are", "not", "authorized", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/client/telegrambaseclient.py#L433-L439
[ "def", "_auth_key_callback", "(", "self", ",", "auth_key", ")", ":", "self", ".", "session", ".", "auth_key", "=", "auth_key", "self", ".", "session", ".", "save", "(", ")" ]
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
TelegramBaseClient._get_dc
Gets the Data Center (DC) associated to 'dc_id
telethon/client/telegrambaseclient.py
async def _get_dc(self, dc_id, cdn=False): """Gets the Data Center (DC) associated to 'dc_id'""" cls = self.__class__ if not cls._config: cls._config = await self(functions.help.GetConfigRequest()) if cdn and not self._cdn_config: cls._cdn_config = await self(fun...
async def _get_dc(self, dc_id, cdn=False): """Gets the Data Center (DC) associated to 'dc_id'""" cls = self.__class__ if not cls._config: cls._config = await self(functions.help.GetConfigRequest()) if cdn and not self._cdn_config: cls._cdn_config = await self(fun...
[ "Gets", "the", "Data", "Center", "(", "DC", ")", "associated", "to", "dc_id" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/client/telegrambaseclient.py#L445-L460
[ "async", "def", "_get_dc", "(", "self", ",", "dc_id", ",", "cdn", "=", "False", ")", ":", "cls", "=", "self", ".", "__class__", "if", "not", "cls", ".", "_config", ":", "cls", ".", "_config", "=", "await", "self", "(", "functions", ".", "help", "."...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
TelegramBaseClient._create_exported_sender
Creates a new exported `MTProtoSender` for the given `dc_id` and returns it. This method should be used by `_borrow_exported_sender`.
telethon/client/telegrambaseclient.py
async def _create_exported_sender(self, dc_id): """ Creates a new exported `MTProtoSender` for the given `dc_id` and returns it. This method should be used by `_borrow_exported_sender`. """ # Thanks badoualy/kotlogram on /telegram/api/DefaultTelegramClient.kt # for clearl...
async def _create_exported_sender(self, dc_id): """ Creates a new exported `MTProtoSender` for the given `dc_id` and returns it. This method should be used by `_borrow_exported_sender`. """ # Thanks badoualy/kotlogram on /telegram/api/DefaultTelegramClient.kt # for clearl...
[ "Creates", "a", "new", "exported", "MTProtoSender", "for", "the", "given", "dc_id", "and", "returns", "it", ".", "This", "method", "should", "be", "used", "by", "_borrow_exported_sender", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/client/telegrambaseclient.py#L462-L490
[ "async", "def", "_create_exported_sender", "(", "self", ",", "dc_id", ")", ":", "# Thanks badoualy/kotlogram on /telegram/api/DefaultTelegramClient.kt", "# for clearly showing how to export the authorization", "dc", "=", "await", "self", ".", "_get_dc", "(", "dc_id", ")", "# ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
TelegramBaseClient._borrow_exported_sender
Borrows a connected `MTProtoSender` for the given `dc_id`. If it's not cached, creates a new one if it doesn't exist yet, and imports a freshly exported authorization key for it to be usable. Once its job is over it should be `_return_exported_sender`.
telethon/client/telegrambaseclient.py
async def _borrow_exported_sender(self, dc_id): """ Borrows a connected `MTProtoSender` for the given `dc_id`. If it's not cached, creates a new one if it doesn't exist yet, and imports a freshly exported authorization key for it to be usable. Once its job is over it should be `...
async def _borrow_exported_sender(self, dc_id): """ Borrows a connected `MTProtoSender` for the given `dc_id`. If it's not cached, creates a new one if it doesn't exist yet, and imports a freshly exported authorization key for it to be usable. Once its job is over it should be `...
[ "Borrows", "a", "connected", "MTProtoSender", "for", "the", "given", "dc_id", ".", "If", "it", "s", "not", "cached", "creates", "a", "new", "one", "if", "it", "doesn", "t", "exist", "yet", "and", "imports", "a", "freshly", "exported", "authorization", "key...
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/client/telegrambaseclient.py#L492-L518
[ "async", "def", "_borrow_exported_sender", "(", "self", ",", "dc_id", ")", ":", "async", "with", "self", ".", "_borrow_sender_lock", ":", "n", ",", "sender", "=", "self", ".", "_borrowed_senders", ".", "get", "(", "dc_id", ",", "(", "0", ",", "None", ")"...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
TelegramBaseClient._return_exported_sender
Returns a borrowed exported sender. If all borrows have been returned, the sender is cleanly disconnected.
telethon/client/telegrambaseclient.py
async def _return_exported_sender(self, sender): """ Returns a borrowed exported sender. If all borrows have been returned, the sender is cleanly disconnected. """ async with self._borrow_sender_lock: dc_id = sender.dc_id n, _ = self._borrowed_senders[dc_i...
async def _return_exported_sender(self, sender): """ Returns a borrowed exported sender. If all borrows have been returned, the sender is cleanly disconnected. """ async with self._borrow_sender_lock: dc_id = sender.dc_id n, _ = self._borrowed_senders[dc_i...
[ "Returns", "a", "borrowed", "exported", "sender", ".", "If", "all", "borrows", "have", "been", "returned", "the", "sender", "is", "cleanly", "disconnected", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/client/telegrambaseclient.py#L520-L533
[ "async", "def", "_return_exported_sender", "(", "self", ",", "sender", ")", ":", "async", "with", "self", ".", "_borrow_sender_lock", ":", "dc_id", "=", "sender", ".", "dc_id", "n", ",", "_", "=", "self", ".", "_borrowed_senders", "[", "dc_id", "]", "n", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
TelegramBaseClient._get_cdn_client
Similar to ._borrow_exported_client, but for CDNs
telethon/client/telegrambaseclient.py
async def _get_cdn_client(self, cdn_redirect): """Similar to ._borrow_exported_client, but for CDNs""" # TODO Implement raise NotImplementedError session = self._exported_sessions.get(cdn_redirect.dc_id) if not session: dc = await self._get_dc(cdn_redirect.dc_id, cdn=...
async def _get_cdn_client(self, cdn_redirect): """Similar to ._borrow_exported_client, but for CDNs""" # TODO Implement raise NotImplementedError session = self._exported_sessions.get(cdn_redirect.dc_id) if not session: dc = await self._get_dc(cdn_redirect.dc_id, cdn=...
[ "Similar", "to", ".", "_borrow_exported_client", "but", "for", "CDNs" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/client/telegrambaseclient.py#L535-L559
[ "async", "def", "_get_cdn_client", "(", "self", ",", "cdn_redirect", ")", ":", "# TODO Implement", "raise", "NotImplementedError", "session", "=", "self", ".", "_exported_sessions", ".", "get", "(", "cdn_redirect", ".", "dc_id", ")", "if", "not", "session", ":",...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
chunks
Turns the given iterable into chunks of the specified size, which is 100 by default since that's what Telegram uses the most.
telethon/utils.py
def chunks(iterable, size=100): """ Turns the given iterable into chunks of the specified size, which is 100 by default since that's what Telegram uses the most. """ it = iter(iterable) size -= 1 for head in it: yield itertools.chain([head], itertools.islice(it, size))
def chunks(iterable, size=100): """ Turns the given iterable into chunks of the specified size, which is 100 by default since that's what Telegram uses the most. """ it = iter(iterable) size -= 1 for head in it: yield itertools.chain([head], itertools.islice(it, size))
[ "Turns", "the", "given", "iterable", "into", "chunks", "of", "the", "specified", "size", "which", "is", "100", "by", "default", "since", "that", "s", "what", "Telegram", "uses", "the", "most", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L73-L81
[ "def", "chunks", "(", "iterable", ",", "size", "=", "100", ")", ":", "it", "=", "iter", "(", "iterable", ")", "size", "-=", "1", "for", "head", "in", "it", ":", "yield", "itertools", ".", "chain", "(", "[", "head", "]", ",", "itertools", ".", "is...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
get_display_name
Gets the display name for the given entity, if it's an :tl:`User`, :tl:`Chat` or :tl:`Channel`. Returns an empty string otherwise.
telethon/utils.py
def get_display_name(entity): """ Gets the display name for the given entity, if it's an :tl:`User`, :tl:`Chat` or :tl:`Channel`. Returns an empty string otherwise. """ if isinstance(entity, types.User): if entity.last_name and entity.first_name: return '{} {}'.format(entity.firs...
def get_display_name(entity): """ Gets the display name for the given entity, if it's an :tl:`User`, :tl:`Chat` or :tl:`Channel`. Returns an empty string otherwise. """ if isinstance(entity, types.User): if entity.last_name and entity.first_name: return '{} {}'.format(entity.firs...
[ "Gets", "the", "display", "name", "for", "the", "given", "entity", "if", "it", "s", "an", ":", "tl", ":", "User", ":", "tl", ":", "Chat", "or", ":", "tl", ":", "Channel", ".", "Returns", "an", "empty", "string", "otherwise", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L84-L102
[ "def", "get_display_name", "(", "entity", ")", ":", "if", "isinstance", "(", "entity", ",", "types", ".", "User", ")", ":", "if", "entity", ".", "last_name", "and", "entity", ".", "first_name", ":", "return", "'{} {}'", ".", "format", "(", "entity", ".",...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
get_extension
Gets the corresponding extension for any Telegram media.
telethon/utils.py
def get_extension(media): """Gets the corresponding extension for any Telegram media.""" # Photos are always compressed as .jpg by Telegram if isinstance(media, (types.UserProfilePhoto, types.ChatPhoto, types.MessageMediaPhoto)): return '.jpg' # Documents will come wi...
def get_extension(media): """Gets the corresponding extension for any Telegram media.""" # Photos are always compressed as .jpg by Telegram if isinstance(media, (types.UserProfilePhoto, types.ChatPhoto, types.MessageMediaPhoto)): return '.jpg' # Documents will come wi...
[ "Gets", "the", "corresponding", "extension", "for", "any", "Telegram", "media", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L105-L124
[ "def", "get_extension", "(", "media", ")", ":", "# Photos are always compressed as .jpg by Telegram", "if", "isinstance", "(", "media", ",", "(", "types", ".", "UserProfilePhoto", ",", "types", ".", "ChatPhoto", ",", "types", ".", "MessageMediaPhoto", ")", ")", ":...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
get_input_peer
Gets the input peer for the given "entity" (user, chat or channel). A ``TypeError`` is raised if the given entity isn't a supported type or if ``check_hash is True`` but the entity's ``access_hash is None``. Note that ``check_hash`` **is ignored** if an input peer is already passed since in that case ...
telethon/utils.py
def get_input_peer(entity, allow_self=True, check_hash=True): """ Gets the input peer for the given "entity" (user, chat or channel). A ``TypeError`` is raised if the given entity isn't a supported type or if ``check_hash is True`` but the entity's ``access_hash is None``. Note that ``check_hash``...
def get_input_peer(entity, allow_self=True, check_hash=True): """ Gets the input peer for the given "entity" (user, chat or channel). A ``TypeError`` is raised if the given entity isn't a supported type or if ``check_hash is True`` but the entity's ``access_hash is None``. Note that ``check_hash``...
[ "Gets", "the", "input", "peer", "for", "the", "given", "entity", "(", "user", "chat", "or", "channel", ")", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L132-L193
[ "def", "get_input_peer", "(", "entity", ",", "allow_self", "=", "True", ",", "check_hash", "=", "True", ")", ":", "try", ":", "if", "entity", ".", "SUBCLASS_OF_ID", "==", "0xc91c90b6", ":", "# crc32(b'InputPeer')", "return", "entity", "except", "AttributeError",...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
get_input_channel
Similar to :meth:`get_input_peer`, but for :tl:`InputChannel`'s alone.
telethon/utils.py
def get_input_channel(entity): """Similar to :meth:`get_input_peer`, but for :tl:`InputChannel`'s alone.""" try: if entity.SUBCLASS_OF_ID == 0x40f202fd: # crc32(b'InputChannel') return entity except AttributeError: _raise_cast_fail(entity, 'InputChannel') if isinstance(enti...
def get_input_channel(entity): """Similar to :meth:`get_input_peer`, but for :tl:`InputChannel`'s alone.""" try: if entity.SUBCLASS_OF_ID == 0x40f202fd: # crc32(b'InputChannel') return entity except AttributeError: _raise_cast_fail(entity, 'InputChannel') if isinstance(enti...
[ "Similar", "to", ":", "meth", ":", "get_input_peer", "but", "for", ":", "tl", ":", "InputChannel", "s", "alone", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L196-L210
[ "def", "get_input_channel", "(", "entity", ")", ":", "try", ":", "if", "entity", ".", "SUBCLASS_OF_ID", "==", "0x40f202fd", ":", "# crc32(b'InputChannel')", "return", "entity", "except", "AttributeError", ":", "_raise_cast_fail", "(", "entity", ",", "'InputChannel'"...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
get_input_user
Similar to :meth:`get_input_peer`, but for :tl:`InputUser`'s alone.
telethon/utils.py
def get_input_user(entity): """Similar to :meth:`get_input_peer`, but for :tl:`InputUser`'s alone.""" try: if entity.SUBCLASS_OF_ID == 0xe669bf46: # crc32(b'InputUser'): return entity except AttributeError: _raise_cast_fail(entity, 'InputUser') if isinstance(entity, types.U...
def get_input_user(entity): """Similar to :meth:`get_input_peer`, but for :tl:`InputUser`'s alone.""" try: if entity.SUBCLASS_OF_ID == 0xe669bf46: # crc32(b'InputUser'): return entity except AttributeError: _raise_cast_fail(entity, 'InputUser') if isinstance(entity, types.U...
[ "Similar", "to", ":", "meth", ":", "get_input_peer", "but", "for", ":", "tl", ":", "InputUser", "s", "alone", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L213-L239
[ "def", "get_input_user", "(", "entity", ")", ":", "try", ":", "if", "entity", ".", "SUBCLASS_OF_ID", "==", "0xe669bf46", ":", "# crc32(b'InputUser'):", "return", "entity", "except", "AttributeError", ":", "_raise_cast_fail", "(", "entity", ",", "'InputUser'", ")",...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
get_input_dialog
Similar to :meth:`get_input_peer`, but for dialogs
telethon/utils.py
def get_input_dialog(dialog): """Similar to :meth:`get_input_peer`, but for dialogs""" try: if dialog.SUBCLASS_OF_ID == 0xa21c9795: # crc32(b'InputDialogPeer') return dialog if dialog.SUBCLASS_OF_ID == 0xc91c90b6: # crc32(b'InputPeer') return types.InputDialogPeer(dialo...
def get_input_dialog(dialog): """Similar to :meth:`get_input_peer`, but for dialogs""" try: if dialog.SUBCLASS_OF_ID == 0xa21c9795: # crc32(b'InputDialogPeer') return dialog if dialog.SUBCLASS_OF_ID == 0xc91c90b6: # crc32(b'InputPeer') return types.InputDialogPeer(dialo...
[ "Similar", "to", ":", "meth", ":", "get_input_peer", "but", "for", "dialogs" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L242-L257
[ "def", "get_input_dialog", "(", "dialog", ")", ":", "try", ":", "if", "dialog", ".", "SUBCLASS_OF_ID", "==", "0xa21c9795", ":", "# crc32(b'InputDialogPeer')", "return", "dialog", "if", "dialog", ".", "SUBCLASS_OF_ID", "==", "0xc91c90b6", ":", "# crc32(b'InputPeer')"...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
get_input_document
Similar to :meth:`get_input_peer`, but for documents
telethon/utils.py
def get_input_document(document): """Similar to :meth:`get_input_peer`, but for documents""" try: if document.SUBCLASS_OF_ID == 0xf33fdb68: # crc32(b'InputDocument'): return document except AttributeError: _raise_cast_fail(document, 'InputDocument') if isinstance(document, ...
def get_input_document(document): """Similar to :meth:`get_input_peer`, but for documents""" try: if document.SUBCLASS_OF_ID == 0xf33fdb68: # crc32(b'InputDocument'): return document except AttributeError: _raise_cast_fail(document, 'InputDocument') if isinstance(document, ...
[ "Similar", "to", ":", "meth", ":", "get_input_peer", "but", "for", "documents" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L260-L282
[ "def", "get_input_document", "(", "document", ")", ":", "try", ":", "if", "document", ".", "SUBCLASS_OF_ID", "==", "0xf33fdb68", ":", "# crc32(b'InputDocument'):", "return", "document", "except", "AttributeError", ":", "_raise_cast_fail", "(", "document", ",", "'Inp...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
get_input_photo
Similar to :meth:`get_input_peer`, but for photos
telethon/utils.py
def get_input_photo(photo): """Similar to :meth:`get_input_peer`, but for photos""" try: if photo.SUBCLASS_OF_ID == 0x846363e0: # crc32(b'InputPhoto'): return photo except AttributeError: _raise_cast_fail(photo, 'InputPhoto') if isinstance(photo, types.photos.Photo): ...
def get_input_photo(photo): """Similar to :meth:`get_input_peer`, but for photos""" try: if photo.SUBCLASS_OF_ID == 0x846363e0: # crc32(b'InputPhoto'): return photo except AttributeError: _raise_cast_fail(photo, 'InputPhoto') if isinstance(photo, types.photos.Photo): ...
[ "Similar", "to", ":", "meth", ":", "get_input_peer", "but", "for", "photos" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L285-L316
[ "def", "get_input_photo", "(", "photo", ")", ":", "try", ":", "if", "photo", ".", "SUBCLASS_OF_ID", "==", "0x846363e0", ":", "# crc32(b'InputPhoto'):", "return", "photo", "except", "AttributeError", ":", "_raise_cast_fail", "(", "photo", ",", "'InputPhoto'", ")", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
get_input_chat_photo
Similar to :meth:`get_input_peer`, but for chat photos
telethon/utils.py
def get_input_chat_photo(photo): """Similar to :meth:`get_input_peer`, but for chat photos""" try: if photo.SUBCLASS_OF_ID == 0xd4eb2d74: # crc32(b'InputChatPhoto') return photo elif photo.SUBCLASS_OF_ID == 0xe7655f1f: # crc32(b'InputFile'): return types.InputChatUpload...
def get_input_chat_photo(photo): """Similar to :meth:`get_input_peer`, but for chat photos""" try: if photo.SUBCLASS_OF_ID == 0xd4eb2d74: # crc32(b'InputChatPhoto') return photo elif photo.SUBCLASS_OF_ID == 0xe7655f1f: # crc32(b'InputFile'): return types.InputChatUpload...
[ "Similar", "to", ":", "meth", ":", "get_input_peer", "but", "for", "chat", "photos" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L319-L335
[ "def", "get_input_chat_photo", "(", "photo", ")", ":", "try", ":", "if", "photo", ".", "SUBCLASS_OF_ID", "==", "0xd4eb2d74", ":", "# crc32(b'InputChatPhoto')", "return", "photo", "elif", "photo", ".", "SUBCLASS_OF_ID", "==", "0xe7655f1f", ":", "# crc32(b'InputFile')...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
get_input_geo
Similar to :meth:`get_input_peer`, but for geo points
telethon/utils.py
def get_input_geo(geo): """Similar to :meth:`get_input_peer`, but for geo points""" try: if geo.SUBCLASS_OF_ID == 0x430d225: # crc32(b'InputGeoPoint'): return geo except AttributeError: _raise_cast_fail(geo, 'InputGeoPoint') if isinstance(geo, types.GeoPoint): retur...
def get_input_geo(geo): """Similar to :meth:`get_input_peer`, but for geo points""" try: if geo.SUBCLASS_OF_ID == 0x430d225: # crc32(b'InputGeoPoint'): return geo except AttributeError: _raise_cast_fail(geo, 'InputGeoPoint') if isinstance(geo, types.GeoPoint): retur...
[ "Similar", "to", ":", "meth", ":", "get_input_peer", "but", "for", "geo", "points" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L338-L358
[ "def", "get_input_geo", "(", "geo", ")", ":", "try", ":", "if", "geo", ".", "SUBCLASS_OF_ID", "==", "0x430d225", ":", "# crc32(b'InputGeoPoint'):", "return", "geo", "except", "AttributeError", ":", "_raise_cast_fail", "(", "geo", ",", "'InputGeoPoint'", ")", "if...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
get_input_media
Similar to :meth:`get_input_peer`, but for media. If the media is :tl:`InputFile` and ``is_photo`` is known to be ``True``, it will be treated as an :tl:`InputMediaUploadedPhoto`. Else, the rest of parameters will indicate how to treat it.
telethon/utils.py
def get_input_media( media, *, is_photo=False, attributes=None, force_document=False, voice_note=False, video_note=False, supports_streaming=False ): """ Similar to :meth:`get_input_peer`, but for media. If the media is :tl:`InputFile` and ``is_photo`` is known to be ``True``, i...
def get_input_media( media, *, is_photo=False, attributes=None, force_document=False, voice_note=False, video_note=False, supports_streaming=False ): """ Similar to :meth:`get_input_peer`, but for media. If the media is :tl:`InputFile` and ``is_photo`` is known to be ``True``, i...
[ "Similar", "to", ":", "meth", ":", "get_input_peer", "but", "for", "media", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L361-L454
[ "def", "get_input_media", "(", "media", ",", "*", ",", "is_photo", "=", "False", ",", "attributes", "=", "None", ",", "force_document", "=", "False", ",", "voice_note", "=", "False", ",", "video_note", "=", "False", ",", "supports_streaming", "=", "False", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
get_input_message
Similar to :meth:`get_input_peer`, but for input messages.
telethon/utils.py
def get_input_message(message): """Similar to :meth:`get_input_peer`, but for input messages.""" try: if isinstance(message, int): # This case is really common too return types.InputMessageID(message) elif message.SUBCLASS_OF_ID == 0x54b6bcc5: # crc32(b'InputMessage'): ...
def get_input_message(message): """Similar to :meth:`get_input_peer`, but for input messages.""" try: if isinstance(message, int): # This case is really common too return types.InputMessageID(message) elif message.SUBCLASS_OF_ID == 0x54b6bcc5: # crc32(b'InputMessage'): ...
[ "Similar", "to", ":", "meth", ":", "get_input_peer", "but", "for", "input", "messages", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L457-L469
[ "def", "get_input_message", "(", "message", ")", ":", "try", ":", "if", "isinstance", "(", "message", ",", "int", ")", ":", "# This case is really common too", "return", "types", ".", "InputMessageID", "(", "message", ")", "elif", "message", ".", "SUBCLASS_OF_ID...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
get_message_id
Similar to :meth:`get_input_peer`, but for message IDs.
telethon/utils.py
def get_message_id(message): """Similar to :meth:`get_input_peer`, but for message IDs.""" if message is None: return None if isinstance(message, int): return message try: if message.SUBCLASS_OF_ID == 0x790009e3: # hex(crc32(b'Message')) = 0x790009e3 ret...
def get_message_id(message): """Similar to :meth:`get_input_peer`, but for message IDs.""" if message is None: return None if isinstance(message, int): return message try: if message.SUBCLASS_OF_ID == 0x790009e3: # hex(crc32(b'Message')) = 0x790009e3 ret...
[ "Similar", "to", ":", "meth", ":", "get_input_peer", "but", "for", "message", "IDs", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L472-L487
[ "def", "get_message_id", "(", "message", ")", ":", "if", "message", "is", "None", ":", "return", "None", "if", "isinstance", "(", "message", ",", "int", ")", ":", "return", "message", "try", ":", "if", "message", ".", "SUBCLASS_OF_ID", "==", "0x790009e3", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
get_attributes
Get a list of attributes for the given file and the mime type as a tuple ([attribute], mime_type).
telethon/utils.py
def get_attributes(file, *, attributes=None, mime_type=None, force_document=False, voice_note=False, video_note=False, supports_streaming=False): """ Get a list of attributes for the given file and the mime type as a tuple ([attribute], mime_type). """ # Note: `...
def get_attributes(file, *, attributes=None, mime_type=None, force_document=False, voice_note=False, video_note=False, supports_streaming=False): """ Get a list of attributes for the given file and the mime type as a tuple ([attribute], mime_type). """ # Note: `...
[ "Get", "a", "list", "of", "attributes", "for", "the", "given", "file", "and", "the", "mime", "type", "as", "a", "tuple", "(", "[", "attribute", "]", "mime_type", ")", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L503-L568
[ "def", "get_attributes", "(", "file", ",", "*", ",", "attributes", "=", "None", ",", "mime_type", "=", "None", ",", "force_document", "=", "False", ",", "voice_note", "=", "False", ",", "video_note", "=", "False", ",", "supports_streaming", "=", "False", "...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
sanitize_parse_mode
Converts the given parse mode into an object with ``parse`` and ``unparse`` callable properties.
telethon/utils.py
def sanitize_parse_mode(mode): """ Converts the given parse mode into an object with ``parse`` and ``unparse`` callable properties. """ if not mode: return None if callable(mode): class CustomMode: @staticmethod def unparse(text, entities): ...
def sanitize_parse_mode(mode): """ Converts the given parse mode into an object with ``parse`` and ``unparse`` callable properties. """ if not mode: return None if callable(mode): class CustomMode: @staticmethod def unparse(text, entities): ...
[ "Converts", "the", "given", "parse", "mode", "into", "an", "object", "with", "parse", "and", "unparse", "callable", "properties", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L571-L601
[ "def", "sanitize_parse_mode", "(", "mode", ")", ":", "if", "not", "mode", ":", "return", "None", "if", "callable", "(", "mode", ")", ":", "class", "CustomMode", ":", "@", "staticmethod", "def", "unparse", "(", "text", ",", "entities", ")", ":", "raise", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
get_input_location
Similar to :meth:`get_input_peer`, but for input messages. Note that this returns a tuple ``(dc_id, location)``, the ``dc_id`` being present if known.
telethon/utils.py
def get_input_location(location): """ Similar to :meth:`get_input_peer`, but for input messages. Note that this returns a tuple ``(dc_id, location)``, the ``dc_id`` being present if known. """ try: if location.SUBCLASS_OF_ID == 0x1523d462: return None, location # crc32(b'In...
def get_input_location(location): """ Similar to :meth:`get_input_peer`, but for input messages. Note that this returns a tuple ``(dc_id, location)``, the ``dc_id`` being present if known. """ try: if location.SUBCLASS_OF_ID == 0x1523d462: return None, location # crc32(b'In...
[ "Similar", "to", ":", "meth", ":", "get_input_peer", "but", "for", "input", "messages", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L604-L643
[ "def", "get_input_location", "(", "location", ")", ":", "try", ":", "if", "location", ".", "SUBCLASS_OF_ID", "==", "0x1523d462", ":", "return", "None", ",", "location", "# crc32(b'InputFileLocation'):", "except", "AttributeError", ":", "_raise_cast_fail", "(", "loca...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
_get_extension
Gets the extension for the given file, which can be either a str or an ``open()``'ed file (which has a ``.name`` attribute).
telethon/utils.py
def _get_extension(file): """ Gets the extension for the given file, which can be either a str or an ``open()``'ed file (which has a ``.name`` attribute). """ if isinstance(file, str): return os.path.splitext(file)[-1] elif isinstance(file, bytes): kind = imghdr.what(io.BytesIO(f...
def _get_extension(file): """ Gets the extension for the given file, which can be either a str or an ``open()``'ed file (which has a ``.name`` attribute). """ if isinstance(file, str): return os.path.splitext(file)[-1] elif isinstance(file, bytes): kind = imghdr.what(io.BytesIO(f...
[ "Gets", "the", "extension", "for", "the", "given", "file", "which", "can", "be", "either", "a", "str", "or", "an", "open", "()", "ed", "file", "(", "which", "has", "a", ".", "name", "attribute", ")", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L646-L663
[ "def", "_get_extension", "(", "file", ")", ":", "if", "isinstance", "(", "file", ",", "str", ")", ":", "return", "os", ".", "path", ".", "splitext", "(", "file", ")", "[", "-", "1", "]", "elif", "isinstance", "(", "file", ",", "bytes", ")", ":", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
is_image
Returns ``True`` if the file extension looks like an image file to Telegram.
telethon/utils.py
def is_image(file): """ Returns ``True`` if the file extension looks like an image file to Telegram. """ match = re.match(r'\.(png|jpe?g)', _get_extension(file), re.IGNORECASE) if match: return True else: return isinstance(resolve_bot_file_id(file), types.Photo)
def is_image(file): """ Returns ``True`` if the file extension looks like an image file to Telegram. """ match = re.match(r'\.(png|jpe?g)', _get_extension(file), re.IGNORECASE) if match: return True else: return isinstance(resolve_bot_file_id(file), types.Photo)
[ "Returns", "True", "if", "the", "file", "extension", "looks", "like", "an", "image", "file", "to", "Telegram", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L666-L674
[ "def", "is_image", "(", "file", ")", ":", "match", "=", "re", ".", "match", "(", "r'\\.(png|jpe?g)'", ",", "_get_extension", "(", "file", ")", ",", "re", ".", "IGNORECASE", ")", "if", "match", ":", "return", "True", "else", ":", "return", "isinstance", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
parse_phone
Parses the given phone, or returns ``None`` if it's invalid.
telethon/utils.py
def parse_phone(phone): """Parses the given phone, or returns ``None`` if it's invalid.""" if isinstance(phone, int): return str(phone) else: phone = re.sub(r'[+()\s-]', '', str(phone)) if phone.isdigit(): return phone
def parse_phone(phone): """Parses the given phone, or returns ``None`` if it's invalid.""" if isinstance(phone, int): return str(phone) else: phone = re.sub(r'[+()\s-]', '', str(phone)) if phone.isdigit(): return phone
[ "Parses", "the", "given", "phone", "or", "returns", "None", "if", "it", "s", "invalid", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L707-L714
[ "def", "parse_phone", "(", "phone", ")", ":", "if", "isinstance", "(", "phone", ",", "int", ")", ":", "return", "str", "(", "phone", ")", "else", ":", "phone", "=", "re", ".", "sub", "(", "r'[+()\\s-]'", ",", "''", ",", "str", "(", "phone", ")", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
parse_username
Parses the given username or channel access hash, given a string, username or URL. Returns a tuple consisting of both the stripped, lowercase username and whether it is a joinchat/ hash (in which case is not lowercase'd). Returns ``(None, False)`` if the ``username`` or link is not valid.
telethon/utils.py
def parse_username(username): """ Parses the given username or channel access hash, given a string, username or URL. Returns a tuple consisting of both the stripped, lowercase username and whether it is a joinchat/ hash (in which case is not lowercase'd). Returns ``(None, False)`` if the ``user...
def parse_username(username): """ Parses the given username or channel access hash, given a string, username or URL. Returns a tuple consisting of both the stripped, lowercase username and whether it is a joinchat/ hash (in which case is not lowercase'd). Returns ``(None, False)`` if the ``user...
[ "Parses", "the", "given", "username", "or", "channel", "access", "hash", "given", "a", "string", "username", "or", "URL", ".", "Returns", "a", "tuple", "consisting", "of", "both", "the", "stripped", "lowercase", "username", "and", "whether", "it", "is", "a",...
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L717-L739
[ "def", "parse_username", "(", "username", ")", ":", "username", "=", "username", ".", "strip", "(", ")", "m", "=", "USERNAME_RE", ".", "match", "(", "username", ")", "or", "TG_JOIN_RE", ".", "match", "(", "username", ")", "if", "m", ":", "username", "=...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
get_inner_text
Gets the inner text that's surrounded by the given entities. For instance: text = 'hey!', entity = MessageEntityBold(2, 2) -> 'y!'. :param text: the original text. :param entities: the entity or entities that must be matched. :return: a single result or a list of the text surrounded by the entities...
telethon/utils.py
def get_inner_text(text, entities): """ Gets the inner text that's surrounded by the given entities. For instance: text = 'hey!', entity = MessageEntityBold(2, 2) -> 'y!'. :param text: the original text. :param entities: the entity or entities that must be matched. :return: a single result ...
def get_inner_text(text, entities): """ Gets the inner text that's surrounded by the given entities. For instance: text = 'hey!', entity = MessageEntityBold(2, 2) -> 'y!'. :param text: the original text. :param entities: the entity or entities that must be matched. :return: a single result ...
[ "Gets", "the", "inner", "text", "that", "s", "surrounded", "by", "the", "given", "entities", ".", "For", "instance", ":", "text", "=", "hey!", "entity", "=", "MessageEntityBold", "(", "2", "2", ")", "-", ">", "y!", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L742-L758
[ "def", "get_inner_text", "(", "text", ",", "entities", ")", ":", "text", "=", "add_surrogate", "(", "text", ")", "result", "=", "[", "]", "for", "e", "in", "entities", ":", "start", "=", "e", ".", "offset", "end", "=", "e", ".", "offset", "+", "e",...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
get_peer_id
Finds the ID of the given peer, and converts it to the "bot api" format so it the peer can be identified back. User ID is left unmodified, chat ID is negated, and channel ID is prefixed with -100. The original ID and the peer type class can be returned with a call to :meth:`resolve_id(marked_id)`.
telethon/utils.py
def get_peer_id(peer, add_mark=True): """ Finds the ID of the given peer, and converts it to the "bot api" format so it the peer can be identified back. User ID is left unmodified, chat ID is negated, and channel ID is prefixed with -100. The original ID and the peer type class can be returned with...
def get_peer_id(peer, add_mark=True): """ Finds the ID of the given peer, and converts it to the "bot api" format so it the peer can be identified back. User ID is left unmodified, chat ID is negated, and channel ID is prefixed with -100. The original ID and the peer type class can be returned with...
[ "Finds", "the", "ID", "of", "the", "given", "peer", "and", "converts", "it", "to", "the", "bot", "api", "format", "so", "it", "the", "peer", "can", "be", "identified", "back", ".", "User", "ID", "is", "left", "unmodified", "chat", "ID", "is", "negated"...
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L791-L832
[ "def", "get_peer_id", "(", "peer", ",", "add_mark", "=", "True", ")", ":", "# First we assert it's a Peer TLObject, or early return for integers", "if", "isinstance", "(", "peer", ",", "int", ")", ":", "return", "peer", "if", "add_mark", "else", "resolve_id", "(", ...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
resolve_id
Given a marked ID, returns the original ID and its :tl:`Peer` type.
telethon/utils.py
def resolve_id(marked_id): """Given a marked ID, returns the original ID and its :tl:`Peer` type.""" if marked_id >= 0: return marked_id, types.PeerUser # There have been report of chat IDs being 10000xyz, which means their # marked version is -10000xyz, which in turn looks like a channel but ...
def resolve_id(marked_id): """Given a marked ID, returns the original ID and its :tl:`Peer` type.""" if marked_id >= 0: return marked_id, types.PeerUser # There have been report of chat IDs being 10000xyz, which means their # marked version is -10000xyz, which in turn looks like a channel but ...
[ "Given", "a", "marked", "ID", "returns", "the", "original", "ID", "and", "its", ":", "tl", ":", "Peer", "type", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L835-L848
[ "def", "resolve_id", "(", "marked_id", ")", ":", "if", "marked_id", ">=", "0", ":", "return", "marked_id", ",", "types", ".", "PeerUser", "# There have been report of chat IDs being 10000xyz, which means their", "# marked version is -10000xyz, which in turn looks like a channel b...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
_rle_decode
Decodes run-length-encoded `data`.
telethon/utils.py
def _rle_decode(data): """ Decodes run-length-encoded `data`. """ if not data: return data new = b'' last = b'' for cur in data: if last == b'\0': new += last * cur last = b'' else: new += last last = bytes([cur]) ...
def _rle_decode(data): """ Decodes run-length-encoded `data`. """ if not data: return data new = b'' last = b'' for cur in data: if last == b'\0': new += last * cur last = b'' else: new += last last = bytes([cur]) ...
[ "Decodes", "run", "-", "length", "-", "encoded", "data", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L851-L868
[ "def", "_rle_decode", "(", "data", ")", ":", "if", "not", "data", ":", "return", "data", "new", "=", "b''", "last", "=", "b''", "for", "cur", "in", "data", ":", "if", "last", "==", "b'\\0'", ":", "new", "+=", "last", "*", "cur", "last", "=", "b''...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
_decode_telegram_base64
Decodes an url-safe base64-encoded string into its bytes by first adding the stripped necessary padding characters. This is the way Telegram shares binary data as strings, such as Bot API-style file IDs or invite links. Returns ``None`` if the input string was not valid.
telethon/utils.py
def _decode_telegram_base64(string): """ Decodes an url-safe base64-encoded string into its bytes by first adding the stripped necessary padding characters. This is the way Telegram shares binary data as strings, such as Bot API-style file IDs or invite links. Returns ``None`` if the input str...
def _decode_telegram_base64(string): """ Decodes an url-safe base64-encoded string into its bytes by first adding the stripped necessary padding characters. This is the way Telegram shares binary data as strings, such as Bot API-style file IDs or invite links. Returns ``None`` if the input str...
[ "Decodes", "an", "url", "-", "safe", "base64", "-", "encoded", "string", "into", "its", "bytes", "by", "first", "adding", "the", "stripped", "necessary", "padding", "characters", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L886-L899
[ "def", "_decode_telegram_base64", "(", "string", ")", ":", "try", ":", "return", "base64", ".", "urlsafe_b64decode", "(", "string", "+", "'='", "*", "(", "len", "(", "string", ")", "%", "4", ")", ")", "except", "(", "binascii", ".", "Error", ",", "Valu...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
_encode_telegram_base64
Inverse for `_decode_telegram_base64`.
telethon/utils.py
def _encode_telegram_base64(string): """ Inverse for `_decode_telegram_base64`. """ try: return base64.urlsafe_b64encode(string).rstrip(b'=').decode('ascii') except (binascii.Error, ValueError, TypeError): return None
def _encode_telegram_base64(string): """ Inverse for `_decode_telegram_base64`. """ try: return base64.urlsafe_b64encode(string).rstrip(b'=').decode('ascii') except (binascii.Error, ValueError, TypeError): return None
[ "Inverse", "for", "_decode_telegram_base64", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L902-L909
[ "def", "_encode_telegram_base64", "(", "string", ")", ":", "try", ":", "return", "base64", ".", "urlsafe_b64encode", "(", "string", ")", ".", "rstrip", "(", "b'='", ")", ".", "decode", "(", "'ascii'", ")", "except", "(", "binascii", ".", "Error", ",", "V...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
resolve_bot_file_id
Given a Bot API-style `file_id`, returns the media it represents. If the `file_id` is not valid, ``None`` is returned instead. Note that the `file_id` does not have information such as image dimensions or file size, so these will be zero if present. For thumbnails, the photo ID and hash will always be...
telethon/utils.py
def resolve_bot_file_id(file_id): """ Given a Bot API-style `file_id`, returns the media it represents. If the `file_id` is not valid, ``None`` is returned instead. Note that the `file_id` does not have information such as image dimensions or file size, so these will be zero if present. For th...
def resolve_bot_file_id(file_id): """ Given a Bot API-style `file_id`, returns the media it represents. If the `file_id` is not valid, ``None`` is returned instead. Note that the `file_id` does not have information such as image dimensions or file size, so these will be zero if present. For th...
[ "Given", "a", "Bot", "API", "-", "style", "file_id", "returns", "the", "media", "it", "represents", ".", "If", "the", "file_id", "is", "not", "valid", "None", "is", "returned", "instead", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L912-L998
[ "def", "resolve_bot_file_id", "(", "file_id", ")", ":", "data", "=", "_rle_decode", "(", "_decode_telegram_base64", "(", "file_id", ")", ")", "if", "not", "data", "or", "data", "[", "-", "1", "]", "==", "b'\\x02'", ":", "return", "None", "data", "=", "da...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
pack_bot_file_id
Inverse operation for `resolve_bot_file_id`. The only parameters this method will accept are :tl:`Document` and :tl:`Photo`, and it will return a variable-length ``file_id`` string. If an invalid parameter is given, it will ``return None``.
telethon/utils.py
def pack_bot_file_id(file): """ Inverse operation for `resolve_bot_file_id`. The only parameters this method will accept are :tl:`Document` and :tl:`Photo`, and it will return a variable-length ``file_id`` string. If an invalid parameter is given, it will ``return None``. """ if isinstance...
def pack_bot_file_id(file): """ Inverse operation for `resolve_bot_file_id`. The only parameters this method will accept are :tl:`Document` and :tl:`Photo`, and it will return a variable-length ``file_id`` string. If an invalid parameter is given, it will ``return None``. """ if isinstance...
[ "Inverse", "operation", "for", "resolve_bot_file_id", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L1001-L1046
[ "def", "pack_bot_file_id", "(", "file", ")", ":", "if", "isinstance", "(", "file", ",", "types", ".", "MessageMediaDocument", ")", ":", "file", "=", "file", ".", "document", "elif", "isinstance", "(", "file", ",", "types", ".", "MessageMediaPhoto", ")", ":...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
resolve_invite_link
Resolves the given invite link. Returns a tuple of ``(link creator user id, global chat id, random int)``. Note that for broadcast channels, the link creator user ID will be zero to protect their identity. Normal chats and megagroup channels will have such ID. Note that the chat ID may not be accu...
telethon/utils.py
def resolve_invite_link(link): """ Resolves the given invite link. Returns a tuple of ``(link creator user id, global chat id, random int)``. Note that for broadcast channels, the link creator user ID will be zero to protect their identity. Normal chats and megagroup channels will have such ID....
def resolve_invite_link(link): """ Resolves the given invite link. Returns a tuple of ``(link creator user id, global chat id, random int)``. Note that for broadcast channels, the link creator user ID will be zero to protect their identity. Normal chats and megagroup channels will have such ID....
[ "Resolves", "the", "given", "invite", "link", ".", "Returns", "a", "tuple", "of", "(", "link", "creator", "user", "id", "global", "chat", "id", "random", "int", ")", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L1049-L1071
[ "def", "resolve_invite_link", "(", "link", ")", ":", "link_hash", ",", "is_link", "=", "parse_username", "(", "link", ")", "if", "not", "is_link", ":", "# Perhaps the user passed the link hash directly", "link_hash", "=", "link", "try", ":", "return", "struct", "....
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
resolve_inline_message_id
Resolves an inline message ID. Returns a tuple of ``(message id, peer, dc id, access hash)`` The ``peer`` may either be a :tl:`PeerUser` referencing the user who sent the message via the bot in a private conversation or small group chat, or a :tl:`PeerChannel` if the message was sent in a channel. ...
telethon/utils.py
def resolve_inline_message_id(inline_msg_id): """ Resolves an inline message ID. Returns a tuple of ``(message id, peer, dc id, access hash)`` The ``peer`` may either be a :tl:`PeerUser` referencing the user who sent the message via the bot in a private conversation or small group chat, or a :t...
def resolve_inline_message_id(inline_msg_id): """ Resolves an inline message ID. Returns a tuple of ``(message id, peer, dc id, access hash)`` The ``peer`` may either be a :tl:`PeerUser` referencing the user who sent the message via the bot in a private conversation or small group chat, or a :t...
[ "Resolves", "an", "inline", "message", "ID", ".", "Returns", "a", "tuple", "of", "(", "message", "id", "peer", "dc", "id", "access", "hash", ")" ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L1074-L1092
[ "def", "resolve_inline_message_id", "(", "inline_msg_id", ")", ":", "try", ":", "dc_id", ",", "message_id", ",", "pid", ",", "access_hash", "=", "struct", ".", "unpack", "(", "'<iiiq'", ",", "_decode_telegram_base64", "(", "inline_msg_id", ")", ")", "peer", "=...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
stripped_photo_to_jpg
Adds the JPG header and footer to a stripped image. Ported from https://github.com/telegramdesktop/tdesktop/blob/bec39d89e19670eb436dc794a8f20b657cb87c71/Telegram/SourceFiles/ui/image/image.cpp#L225
telethon/utils.py
def stripped_photo_to_jpg(stripped): """ Adds the JPG header and footer to a stripped image. Ported from https://github.com/telegramdesktop/tdesktop/blob/bec39d89e19670eb436dc794a8f20b657cb87c71/Telegram/SourceFiles/ui/image/image.cpp#L225 """ if len(stripped) < 3 or stripped[0] != 1: retur...
def stripped_photo_to_jpg(stripped): """ Adds the JPG header and footer to a stripped image. Ported from https://github.com/telegramdesktop/tdesktop/blob/bec39d89e19670eb436dc794a8f20b657cb87c71/Telegram/SourceFiles/ui/image/image.cpp#L225 """ if len(stripped) < 3 or stripped[0] != 1: retur...
[ "Adds", "the", "JPG", "header", "and", "footer", "to", "a", "stripped", "image", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/utils.py#L1128-L1141
[ "def", "stripped_photo_to_jpg", "(", "stripped", ")", ":", "if", "len", "(", "stripped", ")", "<", "3", "or", "stripped", "[", "0", "]", "!=", "1", ":", "return", "stripped", "header", "=", "bytearray", "(", "b'\\xff\\xd8\\xff\\xe0\\x00\\x10JFIF\\x00\\x01\\x01\\...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
MTProtoPlainSender.send
Sends and receives the result for the given request.
telethon/network/mtprotoplainsender.py
async def send(self, request): """ Sends and receives the result for the given request. """ body = bytes(request) msg_id = self._state._get_new_msg_id() await self._connection.send( struct.pack('<qqi', 0, msg_id, len(body)) + body ) body = awa...
async def send(self, request): """ Sends and receives the result for the given request. """ body = bytes(request) msg_id = self._state._get_new_msg_id() await self._connection.send( struct.pack('<qqi', 0, msg_id, len(body)) + body ) body = awa...
[ "Sends", "and", "receives", "the", "result", "for", "the", "given", "request", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/network/mtprotoplainsender.py#L26-L56
[ "async", "def", "send", "(", "self", ",", "request", ")", ":", "body", "=", "bytes", "(", "request", ")", "msg_id", "=", "self", ".", "_state", ".", "_get_new_msg_id", "(", ")", "await", "self", ".", "_connection", ".", "send", "(", "struct", ".", "p...
1ead9757d366b58c1e0567cddb0196e20f1a445f
train
DocsWriter._rel
Get the relative path for the given path from the current file by working around https://bugs.python.org/issue20012.
telethon_generator/docswriter.py
def _rel(self, path): """ Get the relative path for the given path from the current file by working around https://bugs.python.org/issue20012. """ return os.path.relpath( str(path), self._parent).replace(os.path.sep, '/')
def _rel(self, path): """ Get the relative path for the given path from the current file by working around https://bugs.python.org/issue20012. """ return os.path.relpath( str(path), self._parent).replace(os.path.sep, '/')
[ "Get", "the", "relative", "path", "for", "the", "given", "path", "from", "the", "current", "file", "by", "working", "around", "https", ":", "//", "bugs", ".", "python", ".", "org", "/", "issue20012", "." ]
LonamiWebs/Telethon
python
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon_generator/docswriter.py#L33-L39
[ "def", "_rel", "(", "self", ",", "path", ")", ":", "return", "os", ".", "path", ".", "relpath", "(", "str", "(", "path", ")", ",", "self", ".", "_parent", ")", ".", "replace", "(", "os", ".", "path", ".", "sep", ",", "'/'", ")" ]
1ead9757d366b58c1e0567cddb0196e20f1a445f