mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +03:00
Fix requests returning vectors not working (closes #26)
This commit is contained in:
parent
8cde95ff95
commit
b5dfc5d514
|
@ -190,7 +190,7 @@ class TLGenerator:
|
||||||
builder.writeln('def on_response(self, reader):')
|
builder.writeln('def on_response(self, reader):')
|
||||||
# Do not read constructor's ID, since that's already been read somewhere else
|
# Do not read constructor's ID, since that's already been read somewhere else
|
||||||
if tlobject.is_function:
|
if tlobject.is_function:
|
||||||
builder.writeln('self.result = reader.tgread_object()')
|
TLGenerator.write_request_result_code(builder, tlobject)
|
||||||
else:
|
else:
|
||||||
if tlobject.args:
|
if tlobject.args:
|
||||||
for arg in tlobject.args:
|
for arg in tlobject.args:
|
||||||
|
@ -465,6 +465,33 @@ class TLGenerator:
|
||||||
# Restore .is_flag
|
# Restore .is_flag
|
||||||
arg.is_flag = True
|
arg.is_flag = True
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def write_request_result_code(builder, tlobject):
|
||||||
|
"""
|
||||||
|
Writes the receive code for the given function
|
||||||
|
|
||||||
|
:param builder: The source code builder
|
||||||
|
:param tlobject: The TLObject for which the 'self.result = ' will be written
|
||||||
|
"""
|
||||||
|
if tlobject.result.startswith('Vector<'):
|
||||||
|
# Vector results are a bit special since they can also be composed of
|
||||||
|
# integer values and such; however, the result of requests is not
|
||||||
|
# parsed as arguments are and it's a bit harder to tell which is which.
|
||||||
|
if tlobject.result == 'Vector<int>':
|
||||||
|
builder.writeln('reader.read_int() # Vector id')
|
||||||
|
builder.writeln('count = reader.read_int()')
|
||||||
|
builder.writeln('self.result = [reader.read_int() for _ in range(count)]')
|
||||||
|
|
||||||
|
elif tlobject.result == 'Vector<long>':
|
||||||
|
builder.writeln('reader.read_int() # Vector id')
|
||||||
|
builder.writeln('count = reader.read_long()')
|
||||||
|
builder.writeln('self.result = [reader.read_long() for _ in range(count)]')
|
||||||
|
|
||||||
|
else:
|
||||||
|
builder.writeln('self.result = reader.tgread_vector()')
|
||||||
|
else:
|
||||||
|
builder.writeln('self.result = reader.tgread_object()')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if TLGenerator.tlobjects_exist():
|
if TLGenerator.tlobjects_exist():
|
||||||
|
|
Loading…
Reference in New Issue
Block a user