Return helpers.TotalList instances on client.get_ methods

This commit is contained in:
Lonami Exo
2018-08-02 23:00:10 +02:00
parent a1837431b6
commit 7cce7aa3e4
7 changed files with 46 additions and 20 deletions

View File

@@ -1,4 +1,5 @@
"""Various helpers not related to the Telegram API itself"""
import collections
import os
import struct
from hashlib import sha1, sha256
@@ -65,3 +66,25 @@ def get_password_hash(pw, current_salt):
return sha256(pw_hash).digest()
# endregion
# region Custom Classes
class TotalList(list):
"""
A list with an extra `total` property, which may not match its `len`
since the total represents the total amount of items *available*
somewhere else, not the items *in this list*.
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.total = 0
def __str__(self):
return '[{}, total={}]'.format(
', '.join(str(x) for x in self), self.total)
def __repr__(self):
return '[{}, total={}]'.format(
', '.join(repr(x) for x in self), self.total)
# endregion