From 0f5927909d39ac1b37c1098c9f73ad94b7d95e1a Mon Sep 17 00:00:00 2001 From: Anton Grigoryev Date: Thu, 26 Feb 2015 14:46:38 +0300 Subject: [PATCH] Credentials parser. Now testing example is in REPO --- .gitignore | 3 +- mtproto.py | 29 +++++++++++++++---- testing.py | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 7 deletions(-) create mode 100644 testing.py diff --git a/.gitignore b/.gitignore index 42230581..633e675f 100644 --- a/.gitignore +++ b/.gitignore @@ -54,4 +54,5 @@ docs/_build/ target/ # testing apps -testing.py \ No newline at end of file +credentials +rsa.pub \ No newline at end of file diff --git a/mtproto.py b/mtproto.py index d8a33f28..a9f1b136 100644 --- a/mtproto.py +++ b/mtproto.py @@ -11,6 +11,7 @@ import re from datetime import datetime import sys import io +import configparser current_module = sys.modules[__name__] @@ -106,9 +107,20 @@ class TL: f = io.BytesIO(bstring) dict = self.deserialize(f, type=tl_element.type) + def serialize(self, type=None, subtype=None): + pass + + def deserialize(self, string, type=None, subtype=None): + + if isinstance(string, io.BytesIO): + bytes_io = string + elif isinstance(string, bytes): + bytes_io = io.BytesIO(string) + else: + raise Exception("Bad input type, use bytes string or BytesIO object") + + # Built-in bare types - def deserialize(self, bytes_io, type=None, subtype=None): - assert isinstance(bytes_io, io.BytesIO) if type == 'int': x = struct.unpack('