From 21dbbc3f0b5b8a8856e84520fbc7bf37d242b7f6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 31 Dec 2018 17:13:50 +0100 Subject: [PATCH 1/2] Fix style parsers randomly returning "unsorted" dicts. This is due to Python <3.6 having "unsorted" dicts. Dicts are inherently unsorted, but starting from Python 3.6 they keep the order in which the keys are inserted (useful for unpacking) --- pyrogram/client/style/html.py | 10 ++++++---- pyrogram/client/style/markdown.py | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pyrogram/client/style/html.py b/pyrogram/client/style/html.py index 63a80733..ec839fcd 100644 --- a/pyrogram/client/style/html.py +++ b/pyrogram/client/style/html.py @@ -17,6 +17,7 @@ # along with Pyrogram. If not, see . import re +from collections import OrderedDict from pyrogram.api.types import ( MessageEntityBold as Bold, @@ -75,10 +76,11 @@ class HTML: text = text.replace(match.group(), body) offset += len(style) * 2 + 5 + (len(url) + 8 if url else 0) - return dict( - message=utils.remove_surrogates(text), - entities=entities - ) + # TODO: OrderedDict to be removed in Python3.6 + return OrderedDict([ + ("message", utils.remove_surrogates(text)), + ("entities", entities) + ]) def unparse(self, message: str, entities: list): message = utils.add_surrogates(message).strip() diff --git a/pyrogram/client/style/markdown.py b/pyrogram/client/style/markdown.py index 7a67d0ae..f1ea23fc 100644 --- a/pyrogram/client/style/markdown.py +++ b/pyrogram/client/style/markdown.py @@ -17,6 +17,7 @@ # along with Pyrogram. If not, see . import re +from collections import OrderedDict from pyrogram.api.types import ( MessageEntityBold as Bold, @@ -97,10 +98,11 @@ class Markdown: entities.append(entity) message = message.replace(match.group(), body) - return dict( - message=utils.remove_surrogates(message), - entities=entities - ) + # TODO: OrderedDict to be removed in Python3.6 + return OrderedDict([ + ("message", utils.remove_surrogates(message)), + ("entities", entities) + ]) def unparse(self, message: str, entities: list): message = utils.add_surrogates(message).strip() From 4f04d4aee8e6b9c7f1202aa0a86f1c85965be767 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 31 Dec 2018 17:17:58 +0100 Subject: [PATCH 2/2] Update to v0.10.2 --- docs/source/start/Installation.rst | 2 +- pyrogram/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/start/Installation.rst b/docs/source/start/Installation.rst index 7619701d..3769b9f9 100644 --- a/docs/source/start/Installation.rst +++ b/docs/source/start/Installation.rst @@ -82,7 +82,7 @@ If no error shows up you are good to go. >>> import pyrogram >>> pyrogram.__version__ - '0.10.1' + '0.10.2' .. _TgCrypto: https://docs.pyrogram.ml/resources/TgCrypto .. _develop: http://github.com/pyrogram/pyrogram diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index f30c2c2f..bb155d90 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -23,7 +23,7 @@ __copyright__ = "Copyright (C) 2017-2018 Dan Tès