wintergram-userbot 1.3__tar.gz → 1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. {wintergram_userbot-1.3/wintergram_userbot.egg-info → wintergram_userbot-1.4}/PKG-INFO +1 -1
  2. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/pyproject.toml +1 -1
  3. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/__init__.py +1 -1
  4. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/network/mtproto.py +45 -3
  5. {wintergram_userbot-1.3 → wintergram_userbot-1.4/wintergram_userbot.egg-info}/PKG-INFO +1 -1
  6. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/MANIFEST.in +0 -0
  7. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/README.md +0 -0
  8. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/setup.cfg +0 -0
  9. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/api/__init__.py +0 -0
  10. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/api/functions.py +0 -0
  11. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/api/updates.py +0 -0
  12. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/client.py +0 -0
  13. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/crypto/__init__.py +0 -0
  14. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/crypto/aes.py +0 -0
  15. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/crypto/auth_key.py +0 -0
  16. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/crypto/dh.py +0 -0
  17. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/crypto/rsa.py +0 -0
  18. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/crypto/srp.py +0 -0
  19. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/errors.py +0 -0
  20. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/network/__init__.py +0 -0
  21. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/network/connection.py +0 -0
  22. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/network/transport.py +0 -0
  23. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/session/__init__.py +0 -0
  24. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/session/session.py +0 -0
  25. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/session/storage.py +0 -0
  26. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/tl/__init__.py +0 -0
  27. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/tl/schema_resolver.py +0 -0
  28. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/tl/schemas/__init__.py +0 -0
  29. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/tl/schemas/data/core.json +0 -0
  30. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/tl/schemas/data/latest.json +0 -0
  31. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/tl/schemas/data/v113.json +0 -0
  32. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/tl/schemas/data/v119.json +0 -0
  33. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/tl/schemas/data/v128.json +0 -0
  34. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/tl/schemas/data/v133.json +0 -0
  35. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/tl/serializer.py +0 -0
  36. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot/tl/types.py +0 -0
  37. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot.egg-info/SOURCES.txt +0 -0
  38. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot.egg-info/dependency_links.txt +0 -0
  39. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot.egg-info/requires.txt +0 -0
  40. {wintergram_userbot-1.3 → wintergram_userbot-1.4}/wintergram_userbot.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wintergram-userbot
3
- Version: 1.3
3
+ Version: 1.4
4
4
  Summary: WinterGram Userbot for custom MTProto server
5
5
  Author: WinterGram Team
6
6
  Requires-Python: >=3.8
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "wintergram-userbot"
7
- version = "1.3"
7
+ version = "1.4"
8
8
  description = "WinterGram Userbot for custom MTProto server"
9
9
  readme = "README.md"
10
10
  authors = [{name = "WinterGram Team"}]
@@ -4,7 +4,7 @@
4
4
  Поддерживаются слои (layers) от 167 до 228 включительно.
5
5
  """
6
6
 
7
- __version__ = "1.3"
7
+ __version__ = "1.4"
8
8
 
9
9
  from .client import WinterGramClient
10
10
  from .errors import (
@@ -67,6 +67,21 @@ ID_PONG = 0x347773C5
67
67
  ID_GZIP_PACKED = 0x3072CFA1
68
68
  ID_PING = 0x7ABE77EC
69
69
 
70
+ # little-endian сигнатура gzip_packed в начале тела ответа
71
+ GZIP_MAGIC_LE = struct.pack("<I", ID_GZIP_PACKED)
72
+
73
+
74
+ def inflate(data: bytes) -> bytes:
75
+ """Распаковывает gzip/zlib/deflate - сервер встречается со всеми тремя."""
76
+ if not data:
77
+ raise ValueError("empty packed payload")
78
+ for wbits in (16 + zlib.MAX_WBITS, zlib.MAX_WBITS, -zlib.MAX_WBITS):
79
+ try:
80
+ return zlib.decompress(data, wbits)
81
+ except zlib.error:
82
+ continue
83
+ raise ValueError("cannot inflate %d bytes" % len(data))
84
+
70
85
  # якоря эр (по убыванию) для определения layer
71
86
  ERA_ORDER = (228, 202, 198, 181, 167)
72
87
 
@@ -309,7 +324,33 @@ class MTProtoConnection:
309
324
  desc = self._schema.by_id(ident)
310
325
  if desc is None:
311
326
  raise TLParseError("unknown constructor 0x%08x" % ident)
312
- return decode_constructor(r, desc, self._schema)
327
+ return self.unpack_object(decode_constructor(r, desc, self._schema))
328
+
329
+ @staticmethod
330
+ def _is_gzip(obj) -> bool:
331
+ if not isinstance(obj, dict):
332
+ return False
333
+ if obj.get("_id") == ID_GZIP_PACKED:
334
+ return True
335
+ return str(obj.get("_", "")).lower() == "gzip_packed"
336
+
337
+ def unpack_object(self, obj, depth=0):
338
+ """Распаковывает gzip_packed и декодирует то, что внутри.
339
+
340
+ Сервер заворачивает крупные ответы (messages.getDialogs и др.)
341
+ в gzip_packed: он приходит полем result у rpc_result, поэтому
342
+ проверка по сигнатуре тела ответа его не ловит.
343
+ """
344
+ while depth < 4 and self._is_gzip(obj):
345
+ packed = obj.get("packed_data") or obj.get("bytes") or b""
346
+ raw = inflate(packed)
347
+ rr = TLReader(raw)
348
+ desc = self._schema.by_id(rr.read_uint())
349
+ if desc is None:
350
+ raise TLParseError("unknown constructor inside gzip_packed")
351
+ obj = decode_constructor(rr, desc, self._schema)
352
+ depth += 1
353
+ return obj
313
354
 
314
355
  def _handle_rpc_result(self, req_msg_id: int, r: TLReader):
315
356
  raw = bytes(r.data[r.pos:])
@@ -323,10 +364,10 @@ class MTProtoConnection:
323
364
  self._pending.pop(req_msg_id, None)
324
365
  return
325
366
  body = raw
326
- if body[:4] == b"\x30\xcf\xa1\x07": # gzip_packed little-endian
367
+ if body[:4] == GZIP_MAGIC_LE:
327
368
  pack_r = TLReader(body)
328
369
  pack_r.read_uint()
329
- body = zlib.decompress(pack_r.read_bytes())
370
+ body = inflate(pack_r.read_bytes())
330
371
  rr = TLReader(body)
331
372
  ident = rr.read_uint()
332
373
  if ident == ID_RPC_ERROR:
@@ -346,6 +387,7 @@ class MTProtoConnection:
346
387
  return
347
388
  try:
348
389
  obj = decode_constructor(rr, desc, self._schema)
390
+ obj = self.unpack_object(obj)
349
391
  except TLParseError as e:
350
392
  fut.set_exception(
351
393
  RPCError(0, "parse failed for 0x%08x: %s (raw=%s)" % (ident, e, body.hex()))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wintergram-userbot
3
- Version: 1.3
3
+ Version: 1.4
4
4
  Summary: WinterGram Userbot for custom MTProto server
5
5
  Author: WinterGram Team
6
6
  Requires-Python: >=3.8