Added custom errors, fixes to code generator

The code generator now handles okay the flags using True type
Also, double checking for the flag is now avoided in cases where the
flag was a Vector type
This commit is contained in:
Lonami
2016-09-05 18:35:12 +02:00
parent b027dd2c8f
commit 251c1830a5
12 changed files with 170 additions and 110 deletions

View File

@@ -1,6 +1,7 @@
from io import BytesIO, BufferedReader
from tl import tlobjects
from struct import unpack
from errors import *
import inspect
import os
@@ -16,7 +17,7 @@ class BinaryReader:
elif stream:
self.stream = stream
else:
raise ValueError("Either bytes or a stream must be provided")
raise InvalidParameterError("Either bytes or a stream must be provided")
self.reader = BufferedReader(self.stream)
@@ -96,11 +97,10 @@ class BinaryReader:
def tgread_object(self):
"""Reads a Telegram object"""
constructor_id = self.read_int()
constructor_id = self.read_int(signed=False)
clazz = tlobjects.get(constructor_id, None)
if clazz is None:
raise ImportError('Could not find a matching ID for the TLObject that was supposed to be read. '
'Found ID: {}'.format(hex(constructor_id)))
raise TypeNotFoundError(constructor_id)
# Now we need to determine the number of parameters of the class, so we can
# instantiate it with all of them set to None, and still, no need to write