Fix TL schema naming conflicts (#690)
* Avoid variable conflicts with Telegram TL schema * Fix game button with no data attached to button * Update combinator.txt * Update compiler.py * Update tl_object.py Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com>
This commit is contained in:
parent
6745c9d815
commit
4d933b80f9
@ -416,11 +416,11 @@ def start(format: bool = False):
|
||||
write_flags = "\n ".join([
|
||||
"flags = 0",
|
||||
"\n ".join(write_flags),
|
||||
"data.write(Int(flags))\n "
|
||||
"b.write(Int(flags))\n "
|
||||
])
|
||||
|
||||
write_types += write_flags
|
||||
read_types += "flags = Int.read(data)\n "
|
||||
read_types += "flags = Int.read(b)\n "
|
||||
|
||||
continue
|
||||
|
||||
@ -433,55 +433,55 @@ def start(format: bool = False):
|
||||
elif flag_type in CORE_TYPES:
|
||||
write_types += "\n "
|
||||
write_types += f"if self.{arg_name} is not None:\n "
|
||||
write_types += f"data.write({flag_type.title()}(self.{arg_name}))\n "
|
||||
write_types += f"b.write({flag_type.title()}(self.{arg_name}))\n "
|
||||
|
||||
read_types += "\n "
|
||||
read_types += f"{arg_name} = {flag_type.title()}.read(data) if flags & (1 << {index}) else None"
|
||||
read_types += f"{arg_name} = {flag_type.title()}.read(b) if flags & (1 << {index}) else None"
|
||||
elif "vector" in flag_type.lower():
|
||||
sub_type = arg_type.split("<")[1][:-1]
|
||||
|
||||
write_types += "\n "
|
||||
write_types += f"if self.{arg_name} is not None:\n "
|
||||
write_types += "data.write(Vector(self.{}{}))\n ".format(
|
||||
write_types += "b.write(Vector(self.{}{}))\n ".format(
|
||||
arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else ""
|
||||
)
|
||||
|
||||
read_types += "\n "
|
||||
read_types += "{} = TLObject.read(data{}) if flags & (1 << {}) else []\n ".format(
|
||||
read_types += "{} = TLObject.read(b{}) if flags & (1 << {}) else []\n ".format(
|
||||
arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else "", index
|
||||
)
|
||||
else:
|
||||
write_types += "\n "
|
||||
write_types += f"if self.{arg_name} is not None:\n "
|
||||
write_types += f"data.write(self.{arg_name}.write())\n "
|
||||
write_types += f"b.write(self.{arg_name}.write())\n "
|
||||
|
||||
read_types += "\n "
|
||||
read_types += f"{arg_name} = TLObject.read(data) if flags & (1 << {index}) else None\n "
|
||||
read_types += f"{arg_name} = TLObject.read(b) if flags & (1 << {index}) else None\n "
|
||||
else:
|
||||
if arg_type in CORE_TYPES:
|
||||
write_types += "\n "
|
||||
write_types += f"data.write({arg_type.title()}(self.{arg_name}))\n "
|
||||
write_types += f"b.write({arg_type.title()}(self.{arg_name}))\n "
|
||||
|
||||
read_types += "\n "
|
||||
read_types += f"{arg_name} = {arg_type.title()}.read(data)\n "
|
||||
read_types += f"{arg_name} = {arg_type.title()}.read(b)\n "
|
||||
elif "vector" in arg_type.lower():
|
||||
sub_type = arg_type.split("<")[1][:-1]
|
||||
|
||||
write_types += "\n "
|
||||
write_types += "data.write(Vector(self.{}{}))\n ".format(
|
||||
write_types += "b.write(Vector(self.{}{}))\n ".format(
|
||||
arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else ""
|
||||
)
|
||||
|
||||
read_types += "\n "
|
||||
read_types += "{} = TLObject.read(data{})\n ".format(
|
||||
read_types += "{} = TLObject.read(b{})\n ".format(
|
||||
arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else ""
|
||||
)
|
||||
else:
|
||||
write_types += "\n "
|
||||
write_types += f"data.write(self.{arg_name}.write())\n "
|
||||
write_types += f"b.write(self.{arg_name}.write())\n "
|
||||
|
||||
read_types += "\n "
|
||||
read_types += f"{arg_name} = TLObject.read(data)\n "
|
||||
read_types += f"{arg_name} = TLObject.read(b)\n "
|
||||
|
||||
slots = ", ".join([f'"{i[0]}"' for i in sorted_args])
|
||||
return_arguments = ", ".join([f"{i[0]}={i[0]}" for i in sorted_args])
|
||||
|
@ -23,13 +23,13 @@ class {name}(TLObject): # type: ignore
|
||||
{fields}
|
||||
|
||||
@staticmethod
|
||||
def read(data: BytesIO, *args: Any) -> "{name}":
|
||||
def read(b: BytesIO, *args: Any) -> "{name}":
|
||||
{read_types}
|
||||
return {name}({return_arguments})
|
||||
|
||||
def write(self) -> bytes:
|
||||
data = BytesIO()
|
||||
data.write(Int(self.ID, False))
|
||||
b = BytesIO()
|
||||
b.write(Int(self.ID, False))
|
||||
|
||||
{write_types}
|
||||
return data.getvalue()
|
||||
return b.getvalue()
|
||||
|
@ -29,8 +29,8 @@ class TLObject:
|
||||
QUALNAME = "Base"
|
||||
|
||||
@classmethod
|
||||
def read(cls, data: BytesIO, *args: Any) -> Any:
|
||||
return cast(TLObject, objects[int.from_bytes(data.read(4), "little")]).read(data, *args)
|
||||
def read(cls, b: BytesIO, *args: Any) -> Any:
|
||||
return cast(TLObject, objects[int.from_bytes(b.read(4), "little")]).read(b, *args)
|
||||
|
||||
def write(self, *args: Any) -> bytes:
|
||||
pass
|
||||
|
@ -110,7 +110,7 @@ class CallbackQuery(Object, Update):
|
||||
# ignoring/replacing errors, this way, button clicks will still work.
|
||||
try:
|
||||
data = callback_query.data.decode()
|
||||
except UnicodeDecodeError:
|
||||
except (UnicodeDecodeError, AttributeError):
|
||||
data = callback_query.data
|
||||
|
||||
return CallbackQuery(
|
||||
|
Loading…
Reference in New Issue
Block a user