From c39bf3043dfb02a57706fb73e7df49579ccc4009 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 23 Jan 2018 15:17:48 +0100 Subject: [PATCH] Move formatting classes inside the Client sub-package --- .../{extensions => client/style}/__init__.py | 0 pyrogram/{extensions => client/style}/html.py | 36 ++++++++++-------- .../{extensions => client/style}/markdown.py | 23 ++---------- pyrogram/client/style/utils.py | 37 +++++++++++++++++++ 4 files changed, 61 insertions(+), 35 deletions(-) rename pyrogram/{extensions => client/style}/__init__.py (100%) rename pyrogram/{extensions => client/style}/html.py (68%) rename pyrogram/{extensions => client/style}/markdown.py (83%) create mode 100644 pyrogram/client/style/utils.py diff --git a/pyrogram/extensions/__init__.py b/pyrogram/client/style/__init__.py similarity index 100% rename from pyrogram/extensions/__init__.py rename to pyrogram/client/style/__init__.py diff --git a/pyrogram/extensions/html.py b/pyrogram/client/style/html.py similarity index 68% rename from pyrogram/extensions/html.py rename to pyrogram/client/style/html.py index aa6c3fc2..28091aa0 100644 --- a/pyrogram/extensions/html.py +++ b/pyrogram/client/style/html.py @@ -1,5 +1,22 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + import re -from struct import unpack from pyrogram.api.types import ( MessageEntityBold as Bold, @@ -10,6 +27,7 @@ from pyrogram.api.types import ( MessageEntityMentionName as MentionInvalid, InputMessageEntityMentionName as Mention, ) +from . import utils class HTML: @@ -17,24 +35,12 @@ class HTML: HTML_RE = re.compile(r"<(\w+)(?: href=\"(.*)\")?>(.*)") MENTION_RE = re.compile(r"tg://user\?id=(\d+)") - @classmethod - def add_surrogates(cls, text): - return cls.SMP_RE.sub( - lambda match: # Split SMP in two surrogates - "".join(chr(i) for i in unpack(". import re -from struct import unpack from pyrogram.api.types import ( MessageEntityBold as Bold, @@ -27,6 +26,7 @@ from pyrogram.api.types import ( MessageEntityPre as Pre, InputMessageEntityMentionName as Mention ) +from . import utils class Markdown: @@ -36,9 +36,6 @@ class Markdown: "`": Code } - # SMP = Supplementary Multilingual Plane: https://en.wikipedia.org/wiki/Plane_(Unicode)#Overview - SMP_RE = re.compile(r"[\U00010000-\U0010FFFF]") - # ``` python # for i in range(10): # print(i) @@ -69,26 +66,12 @@ class Markdown: MARKDOWN_RE = re.compile("|".join([PRE_RE, MENTION_RE, URL_RE, INLINE_RE])) - @classmethod - def add_surrogates(cls, text): - # Replace each SMP code point with a surrogate pair - return cls.SMP_RE.sub( - lambda match: # Split SMP in two surrogates - "".join(chr(i) for i in unpack(" +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +import re +from struct import unpack + +# SMP = Supplementary Multilingual Plane: https://en.wikipedia.org/wiki/Plane_(Unicode)#Overview +SMP_RE = re.compile(r"[\U00010000-\U0010FFFF]") + + +def add_surrogates(text): + # Replace each SMP code point with a surrogate pair + return SMP_RE.sub( + lambda match: # Split SMP in two surrogates + "".join(chr(i) for i in unpack("