|
| 1 | +# Pyrogram - Telegram MTProto API Client Library for Python |
| 2 | +# Copyright (C) 2017 Dan Tès <https://github.com/delivrance> |
| 3 | +# |
| 4 | +# This file is part of Pyrogram. |
| 5 | +# |
| 6 | +# Pyrogram is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU Lesser General Public License as published |
| 8 | +# by the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# Pyrogram is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU Lesser General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU Lesser General Public License |
| 17 | +# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +from io import BytesIO |
| 20 | + |
| 21 | +from ..object import Object |
| 22 | + |
| 23 | + |
| 24 | +class BoolFalse(Object): |
| 25 | + ID = 0xbc799737 |
| 26 | + value = False |
| 27 | + |
| 28 | + @classmethod |
| 29 | + def read(cls, *args) -> bool: |
| 30 | + return cls.value |
| 31 | + |
| 32 | + def __new__(cls) -> bytes: |
| 33 | + return int.to_bytes(cls.ID, 4, "little") |
| 34 | + |
| 35 | + |
| 36 | +class BoolTrue(BoolFalse): |
| 37 | + ID = 0x997275b5 |
| 38 | + value = True |
| 39 | + |
| 40 | + |
| 41 | +class Bool(Object): |
| 42 | + @classmethod |
| 43 | + def read(cls, b: BytesIO) -> bool: |
| 44 | + value = int.from_bytes(b.read(4), "little") |
| 45 | + |
| 46 | + return ( |
| 47 | + True if value == BoolTrue.ID |
| 48 | + else False if value == BoolFalse.ID |
| 49 | + else None |
| 50 | + ) |
| 51 | + |
| 52 | + def __new__(cls, value: bool) -> BoolTrue or BoolFalse: |
| 53 | + return BoolTrue() if value else BoolFalse() |
0 commit comments