From 24a1b9b36b9590dd4882da7585dea82c35eec661 Mon Sep 17 00:00:00 2001 From: Anton Grigoryev Date: Thu, 12 Mar 2015 02:51:24 +0300 Subject: [PATCH] Method_send implemented I want to call methods like a functions in Python. Then I can go further. --- mtproto.py | 45 ++++++++++++++++++++++++++++++++++----------- testing.py | 11 +++++------ 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/mtproto.py b/mtproto.py index 468339b5..c9facee2 100644 --- a/mtproto.py +++ b/mtproto.py @@ -39,35 +39,58 @@ class TlConstructor: param['subtype'] = None self.params.append(param) +class TlMethod: + def __init__(self, json_dict): + self.id = int(json_dict['id']) + self.type = json_dict['type'] + self.method = json_dict['method'] + self.params = json_dict['params'] + + class TL: def __init__(self): with open("TL_schema.JSON", 'r') as f: TL_dict = json.load(f) + # Read constructors + self.constructors = TL_dict['constructors'] self.constructor_id = {} self.constructor_type = {} - - # Read constructors - for elem in self.constructors: z = TlConstructor(elem) self.constructor_id[z.id] = z self.constructor_type[z.type] = z + self.methods = TL_dict['methods'] + self.method_id = {} + self.method_name = {} + for elem in self.methods: + z = TlMethod(elem) + self.method_id[z.id] = z + self.method_name[z.method] = z - def deserialize(self, byte_string, type_=None, subtype=None): + def method_call(self, method, **kwargs): + z = io.BytesIO() + tl_method = self.method_name[method] + z.write(struct.pack('