# -*- coding: utf-8 -*- """ Created on Tue Sep 2 19:26:15 2014 @author: agrigoryev """ import binascii import struct import socket import re from datetime import datetime import sys current_module = sys.modules[__name__] def vis(bs): l = len(bs) n = len(bs) // 8 for i in range(n): print(" ".join(["%02X" % b for b in bs[i*8:i*8+8]])) print(" ".join(["%02X" % b for b in bs[i*8+8:]])) class TlElement: def __init__(self, type_string): tl_re = re.compile("""([a-z]\w*) #name \#([0-9a-f]{8}) #id \s+(.*)\s+ #arguments list =\s+([A-Z]\w*); #result""", re.X) assert isinstance(type_string, str) x = tl_re.match(type_string) if x is not None: self.name = x.groups()[0] self.id = x.groups()[1] self.args = self.get_arg_list(x.groups()[2]) self.result = x.groups()[3] else: raise SyntaxError @staticmethod def get_arg_list(arg_string): arg_re = re.compile("(\w+):(\w+)(<(\w+)>)?") res = [] for s in arg_re.findall(arg_string): d = {'name': s[0], 'type': s[1]} if s[2]: d['subtype'] = s[3] res.append(d) return res class TL: def __init__(self): self.func_dict_id = {} self.func_dict_name = {} self.obj_dict_id = {} self.obj_dict_name = {} # Read constructors f = open("TL_schema", 'r') for line in f: if line.startswith("---functions---"): break try: z = TlElement(line) self.obj_dict_id[z.id] = z self.obj_dict_name[z.name] = z except SyntaxError: pass # Read methods for line in f: if line.startswith("---functions---"): break try: z = TlElement(line) self.func_dict_id[z.id] = z self.func_dict_name[z.name] = z except SyntaxError: pass def tl_serialize(self, elem, kwargs): assert isinstance(elem, TlElement) for arg in elem.args: pass return struct.pack(" 0: # if we have smth. in the socket packet_length = struct.unpack("