mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-11-14 21:10:40 +00:00
Remove unused TcpClien.read(timeout=...) param, change other accessors
This commit is contained in:
@@ -22,13 +22,12 @@ class Connection:
|
||||
self.ip = ip
|
||||
self.port = port
|
||||
self._mode = mode
|
||||
self.timeout = timeout
|
||||
|
||||
self._send_counter = 0
|
||||
self._aes_encrypt, self._aes_decrypt = None, None
|
||||
|
||||
# TODO Rename "TcpClient" as some sort of generic socket?
|
||||
self.conn = TcpClient(proxy=proxy)
|
||||
self.conn = TcpClient(proxy=proxy, timeout=timeout)
|
||||
|
||||
# Sending messages
|
||||
if mode == 'tcp_full':
|
||||
@@ -53,8 +52,7 @@ class Connection:
|
||||
|
||||
def connect(self):
|
||||
self._send_counter = 0
|
||||
self.conn.connect(self.ip, self.port,
|
||||
timeout=round(self.timeout.seconds))
|
||||
self.conn.connect(self.ip, self.port)
|
||||
|
||||
if self._mode == 'tcp_abridged':
|
||||
self.conn.write(b'\xef')
|
||||
@@ -102,13 +100,12 @@ class Connection:
|
||||
|
||||
# region Receive message implementations
|
||||
|
||||
def recv(self, **kwargs):
|
||||
def recv(self):
|
||||
"""Receives and unpacks a message"""
|
||||
# TODO Don't ignore kwargs['timeout']?
|
||||
# Default implementation is just an error
|
||||
raise ValueError('Invalid connection mode specified: ' + self._mode)
|
||||
|
||||
def _recv_tcp_full(self, **kwargs):
|
||||
def _recv_tcp_full(self):
|
||||
packet_length_bytes = self.read(4)
|
||||
packet_length = int.from_bytes(packet_length_bytes, 'little')
|
||||
|
||||
@@ -124,10 +121,10 @@ class Connection:
|
||||
|
||||
return body
|
||||
|
||||
def _recv_intermediate(self, **kwargs):
|
||||
def _recv_intermediate(self):
|
||||
return self.read(int.from_bytes(self.read(4), 'little'))
|
||||
|
||||
def _recv_abridged(self, **kwargs):
|
||||
def _recv_abridged(self):
|
||||
length = int.from_bytes(self.read(1), 'little')
|
||||
if length >= 127:
|
||||
length = int.from_bytes(self.read(3) + b'\0', 'little')
|
||||
@@ -180,11 +177,11 @@ class Connection:
|
||||
raise ValueError('Invalid connection mode specified: ' + self._mode)
|
||||
|
||||
def _read_plain(self, length):
|
||||
return self.conn.read(length, timeout=self.timeout)
|
||||
return self.conn.read(length)
|
||||
|
||||
def _read_obfuscated(self, length):
|
||||
return self._aes_decrypt.encrypt(
|
||||
self.conn.read(length, timeout=self.timeout)
|
||||
self.conn.read(length)
|
||||
)
|
||||
|
||||
# endregion
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import gzip
|
||||
from datetime import timedelta
|
||||
from threading import RLock, Thread
|
||||
|
||||
from .. import helpers as utils
|
||||
@@ -91,15 +90,11 @@ class MtProtoSender:
|
||||
# No problem.
|
||||
pass
|
||||
|
||||
def _receive_message(self, **kwargs):
|
||||
"""Receives a single message from the connected endpoint.
|
||||
|
||||
An optional named parameter 'timeout' can be specified if
|
||||
one desires to override 'self.connection.timeout'.
|
||||
"""
|
||||
def _receive_message(self):
|
||||
"""Receives a single message from the connected endpoint."""
|
||||
# TODO Don't ignore updates
|
||||
self._logger.debug('Receiving a message...')
|
||||
body = self.connection.recv(**kwargs)
|
||||
body = self.connection.recv()
|
||||
message, remote_msg_id, remote_seq = self._decode_msg(body)
|
||||
|
||||
with BinaryReader(message) as reader:
|
||||
|
||||
Reference in New Issue
Block a user