mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-11-09 18:40:35 +00:00
Apply several lints
This commit is contained in:
@@ -248,7 +248,7 @@ class PacketCodec(abc.ABC):
|
||||
"""
|
||||
Codec is created when connection is just made.
|
||||
"""
|
||||
pass
|
||||
self._conn = connection
|
||||
|
||||
@abc.abstractmethod
|
||||
def encode_packet(self, data):
|
||||
|
||||
@@ -10,10 +10,6 @@ class HttpPacketCodec(PacketCodec):
|
||||
tag = None
|
||||
obfuscate_tag = None
|
||||
|
||||
def __init__(self, connection):
|
||||
self._ip = connection._ip
|
||||
self._port = connection._port
|
||||
|
||||
def encode_packet(self, data):
|
||||
return ('POST /api HTTP/1.1\r\n'
|
||||
'Host: {}:{}\r\n'
|
||||
@@ -21,7 +17,7 @@ class HttpPacketCodec(PacketCodec):
|
||||
'Connection: keep-alive\r\n'
|
||||
'Keep-Alive: timeout=100000, max=10000000\r\n'
|
||||
'Content-Length: {}\r\n\r\n'
|
||||
.format(self._ip, self._port, len(data))
|
||||
.format(self._conn._ip, self._conn._port, len(data))
|
||||
.encode('ascii') + data)
|
||||
|
||||
async def read_packet(self, reader):
|
||||
|
||||
@@ -8,7 +8,8 @@ from ...errors import InvalidChecksumError
|
||||
class FullPacketCodec(PacketCodec):
|
||||
tag = None
|
||||
|
||||
def __init__(self, _conn):
|
||||
def __init__(self, connection):
|
||||
super().__init__(connection)
|
||||
self._send_counter = 0 # Important or Telegram won't reply
|
||||
|
||||
def encode_packet(self, data):
|
||||
|
||||
@@ -28,7 +28,8 @@ class MTProxyIO:
|
||||
self._decrypt) = self.init_header(
|
||||
connection._secret, connection._dc_id, connection.packet_codec)
|
||||
|
||||
def init_header(self, secret, dc_id, packet_codec):
|
||||
@staticmethod
|
||||
def init_header(secret, dc_id, packet_codec):
|
||||
# Validate
|
||||
is_dd = (len(secret) == 17) and (secret[0] == 0xDD)
|
||||
is_rand_codec = issubclass(
|
||||
@@ -93,6 +94,14 @@ class TcpMTProxy(ObfuscatedConnection):
|
||||
packet_codec = None
|
||||
obfuscated_io = MTProxyIO
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
def __init__(self, ip, port, dc_id, *, loop, loggers, proxy=None):
|
||||
# connect to proxy's host and port instead of telegram's ones
|
||||
proxy_host, proxy_port = self.address_info(proxy)
|
||||
self._secret = bytes.fromhex(proxy[2])
|
||||
super().__init__(
|
||||
proxy_host, proxy_port, dc_id, loop=loop, loggers=loggers)
|
||||
|
||||
async def _connect(self, timeout=None, ssl=None):
|
||||
await super()._connect(timeout=timeout, ssl=ssl)
|
||||
|
||||
@@ -121,13 +130,6 @@ class TcpMTProxy(ObfuscatedConnection):
|
||||
raise ValueError("No proxy info specified for MTProxy connection")
|
||||
return proxy_info[:2]
|
||||
|
||||
def __init__(self, ip, port, dc_id, *, loop, loggers, proxy=None):
|
||||
# connect to proxy's host and port instead of telegram's ones
|
||||
proxy_host, proxy_port = self.address_info(proxy)
|
||||
self._secret = bytes.fromhex(proxy[2])
|
||||
super().__init__(
|
||||
proxy_host, proxy_port, dc_id, loop=loop, loggers=loggers)
|
||||
|
||||
|
||||
class ConnectionTcpMTProxyAbridged(TcpMTProxy):
|
||||
"""
|
||||
|
||||
@@ -17,7 +17,8 @@ class ObfuscatedIO:
|
||||
self._encrypt,
|
||||
self._decrypt) = self.init_header(connection.packet_codec)
|
||||
|
||||
def init_header(self, packet_codec):
|
||||
@staticmethod
|
||||
def init_header(packet_codec):
|
||||
# Obfuscated messages secrets cannot start with any of these
|
||||
keywords = (b'PVrG', b'GET ', b'POST', b'\xee\xee\xee\xee')
|
||||
while True:
|
||||
|
||||
@@ -39,6 +39,8 @@ class MTProtoState:
|
||||
self._log = loggers[__name__]
|
||||
self.time_offset = 0
|
||||
self.salt = 0
|
||||
|
||||
self.id = self._sequence = self._last_msg_id = None
|
||||
self.reset()
|
||||
|
||||
def reset(self):
|
||||
|
||||
Reference in New Issue
Block a user