From f13f2c8787d8943e39beb1e95d01464c6fc56c0d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 20 Jan 2018 16:21:25 +0100 Subject: [PATCH 1/7] Update README.rst --- README.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index df549955..6475b81d 100644 --- a/README.rst +++ b/README.rst @@ -49,7 +49,7 @@ Features `MTProto Mobile Protocol v2.0`_ and the mechanisms needed for establishing a reliable connection. -- **Updated**: Pyrogram makes use of the latest Telegram API version, currently `Layer 74`_. +- **Updated**: Pyrogram makes use of the latest Telegram API version, currently `Layer 75`_. - **Documented**: Pyrogram API public methods are documented and resemble the well established Telegram Bot API, thus offering a familiar look to Bot developers. @@ -148,7 +148,7 @@ License .. _`MTProto Mobile Protocol v2.0`: https://core.telegram.org/mtproto -.. _`Layer 74`: compiler/api/source/main_api.tl +.. _`Layer 75`: compiler/api/source/main_api.tl .. _`your own`: https://github.com/pyrogram/pyrogram/wiki/Getting-Started#api-keys @@ -191,7 +191,7 @@ License


Scheme Layer 74 + alt="Scheme Layer 75"> Date: Sat, 20 Jan 2018 19:40:09 +0100 Subject: [PATCH 2/7] Move starred expressions at the end --- pyrogram/client/client.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 49d45be0..c8985896 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -604,10 +604,10 @@ class Client: file=file, ttl_seconds=ttl_seconds ), - **self.markdown.parse(caption), silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, - random_id=self.rnd_id() + random_id=self.rnd_id(), + **self.markdown.parse(caption) ) ) except FilePartMissing as e: @@ -682,10 +682,10 @@ class Client: types.DocumentAttributeFilename(os.path.basename(audio)) ] ), - **self.markdown.parse(caption), silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, - random_id=self.rnd_id() + random_id=self.rnd_id(), + **self.markdown.parse(caption) ) ) except FilePartMissing as e: @@ -741,10 +741,10 @@ class Client: types.DocumentAttributeFilename(os.path.basename(document)) ] ), - **self.markdown.parse(caption), silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, - random_id=self.rnd_id() + random_id=self.rnd_id(), + **self.markdown.parse(caption) ) ) except FilePartMissing as e: @@ -816,10 +816,10 @@ class Client: ) ] ), - **self.markdown.parse(caption), silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, - random_id=self.rnd_id() + random_id=self.rnd_id(), + **self.markdown.parse(caption) ) ) except FilePartMissing as e: @@ -882,10 +882,10 @@ class Client: ) ] ), - **self.markdown.parse(caption), silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, - random_id=self.rnd_id() + random_id=self.rnd_id(), + **self.markdown.parse(caption) ) ) except FilePartMissing as e: From 652dcc282e44f257fc88a1c41f4683944597ba8b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 21 Jan 2018 16:50:05 +0100 Subject: [PATCH 3/7] Move metadata into setup.py --- setup.py | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 4aeea35e..9fd9e082 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ import re from sys import argv -from setuptools import setup +from setuptools import setup, find_packages from compiler.api import compiler as api_compiler from compiler.error import compiler as error_compiler @@ -31,9 +31,42 @@ if len(argv) > 1 and argv[1] != "sdist": error_compiler.start() # docs_compiler.start() +with open("pyrogram/__init__.py", encoding="utf-8") as f: + version = re.findall(r"__version__ = \"(.+)\"", f.read())[0] + # PyPI doesn't like raw html -with open("README.rst", encoding="UTF-8") as f: +with open("README.rst", encoding="utf-8") as f: readme = re.sub(r"\.\. \|.+\| raw:: html(?:\s{4}.+)+\n\n", "", f.read()) readme = re.sub(r"\|header\|", "|logo|\n\n|description|\n\n|scheme| |mtproto|", readme) -setup(long_description=readme) +setup( + name="Pyrogram", + version=version, + description="Telegram MTProto API Client Library for Python", + url="https://github.com/pyrogram/pyrogram", + author="Dan Tès", + author_email="admin@pyrogram.ml", + license="LGPLv3+", + keywords="telegram mtproto api client library python", + long_description=readme, + classifiers=[ + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Topic :: Internet", + "Topic :: Communications :: Chat", + "Topic :: Software Development :: Libraries", + "Topic :: Software Development :: Libraries :: Python Modules" + ], + packages=find_packages(), + zip_safe=False, + install_requires=["pyaes", "pysocks"], + include_package_data=True, +) From 564725a68ee21de4f51ac3f1922ccd0303bc95d7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 21 Jan 2018 16:50:25 +0100 Subject: [PATCH 4/7] Ditch setup.cfg --- setup.cfg | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 setup.cfg diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index bc330f79..00000000 --- a/setup.cfg +++ /dev/null @@ -1,31 +0,0 @@ -[metadata] -name = Pyrogram -version = attr: pyrogram.__version__ -description = Telegram MTProto API Client Library for Python -url = https://github.com/pyrogram/pyrogram -author = Dan Tès -author_email = admin@pyrogram.ml -license = LGPLv3+ -keywords = telegram mtproto api client library python -classifiers = - Development Status :: 3 - Alpha - Intended Audience :: Developers - License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+) - Operating System :: OS Independent - Programming Language :: Python - Programming Language :: Python :: 3 - Programming Language :: Python :: 3.3 - Programming Language :: Python :: 3.4 - Programming Language :: Python :: 3.5 - Programming Language :: Python :: 3.6 - Topic :: Internet - Topic :: Communications :: Chat - Topic :: Software Development :: Libraries - Topic :: Software Development :: Libraries :: Python Modules - -[options] -packages = find: -zip_safe = False -setup_requires = pyaes; pysocks -install_requires = pyaes; pysocks -include_package_data = True \ No newline at end of file From c7d2de3ee98753afad218bc539d4134991d183f2 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 21 Jan 2018 16:56:50 +0100 Subject: [PATCH 5/7] Force UTF-8 encoding when r/w'ing text files --- compiler/api/compiler.py | 20 ++++++++++---------- compiler/docs/compiler.py | 10 +++++----- compiler/error/compiler.py | 20 ++++++++++---------- pyrogram/api/errors/error.py | 2 +- pyrogram/client/client.py | 4 ++-- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index 1cfdb437..e1e95328 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -70,15 +70,15 @@ def start(): shutil.rmtree("{}/types".format(DESTINATION), ignore_errors=True) shutil.rmtree("{}/functions".format(DESTINATION), ignore_errors=True) - with open("{}/source/auth_key.tl".format(HOME)) as auth, \ - open("{}/source/sys_msgs.tl".format(HOME)) as system, \ - open("{}/source/main_api.tl".format(HOME)) as api: + with open("{}/source/auth_key.tl".format(HOME), encoding="utf-8") as auth, \ + open("{}/source/sys_msgs.tl".format(HOME), encoding="utf-8") as system, \ + open("{}/source/main_api.tl".format(HOME), encoding="utf-8") as api: schema = (auth.read() + system.read() + api.read()).splitlines() - with open("{}/template/class.txt".format(HOME)) as f: + with open("{}/template/class.txt".format(HOME), encoding="utf-8") as f: template = f.read() - with open(notice_path) as f: + with open(notice_path, encoding="utf-8") as f: notice = [] for line in f.readlines(): @@ -162,10 +162,10 @@ def start(): init = "{}/__init__.py".format(path) if not os.path.exists(init): - with open(init, "w") as f: + with open(init, "w", encoding="utf-8") as f: f.write(notice + "\n\n") - with open(init, "a") as f: + with open(init, "a", encoding="utf-8") as f: f.write("from .{} import {}\n".format(snek(c.name), capit(c.name))) sorted_args = sort_args(c.args) @@ -397,7 +397,7 @@ def start(): read_types += "\n " read_types += "{} = Object.read(b)\n ".format(arg_name) - with open("{}/{}.py".format(path, snek(c.name)), "w") as f: + with open("{}/{}.py".format(path, snek(c.name)), "w", encoding="utf-8") as f: f.write( template.format( notice=notice, @@ -414,7 +414,7 @@ def start(): ) ) - with open("{}/all.py".format(DESTINATION), "w") as f: + with open("{}/all.py".format(DESTINATION), "w", encoding="utf-8") as f: f.write(notice + "\n\n") f.write("layer = {}\n\n".format(layer)) f.write("objects = {") @@ -436,7 +436,7 @@ def start(): f.write("\n}\n") for k, v in namespaces.items(): - with open("{}/{}/__init__.py".format(DESTINATION, k), "a") as f: + with open("{}/{}/__init__.py".format(DESTINATION, k), "a", encoding="utf-8") as f: f.write("from . import {}\n".format(", ".join([i for i in v])) if v else "") diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index af9d1315..6a6345d1 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -44,7 +44,7 @@ def generate(source_path, base): if not i.startswith("__"): build("/".join([path, i]), level=level + 1) except NotADirectoryError: - with open(path + "/" + i) as f: + with open(path + "/" + i, encoding="utf-8") as f: p = ast.parse(f.read()) for node in ast.walk(p): @@ -59,7 +59,7 @@ def generate(source_path, base): os.makedirs(os.path.dirname(destination + "/" + full_path), exist_ok=True) - with open(destination + "/" + full_path, "w") as f: + with open(destination + "/" + full_path, "w", encoding="utf-8") as f: f.write( page_template.format( title=name, @@ -94,7 +94,7 @@ def generate(source_path, base): inner_path = base + "/index" + ".rst" module = "pyrogram.api.{}".format(base) - with open(destination + "/" + inner_path, "w") as f: + with open(destination + "/" + inner_path, "w", encoding="utf-8") as f: f.write( toctree.format( title=k.title(), @@ -111,10 +111,10 @@ def start(): global page_template global toctree - with open(home + "/template/page.txt") as f: + with open(home + "/template/page.txt", encoding="utf-8") as f: page_template = f.read() - with open(home + "/template/toctree.txt") as f: + with open(home + "/template/toctree.txt", encoding="utf-8") as f: toctree = f.read() generate(types_path, types_base) diff --git a/compiler/error/compiler.py b/compiler/error/compiler.py index 7b75647b..fee3be4d 100644 --- a/compiler/error/compiler.py +++ b/compiler/error/compiler.py @@ -43,7 +43,7 @@ def start(): files = [i for i in os.listdir("{}/source".format(home))] - with open(notice_path) as f: + with open(notice_path, encoding="utf-8") as f: notice = [] for line in f.readlines(): @@ -51,7 +51,7 @@ def start(): notice = "\n".join(notice) - with open("{}/all.py".format(dest), "w") as f_all: + with open("{}/all.py".format(dest), "w", encoding="utf-8") as f_all: f_all.write(notice + "\n\n") f_all.write("count = {count}\n\n") f_all.write("exceptions = {\n") @@ -66,14 +66,14 @@ def start(): init = "{}/__init__.py".format(dest) if not os.path.exists(init): - with open(init, "w") as f_init: + with open(init, "w", encoding="utf-8") as f_init: f_init.write(notice + "\n\n") - with open(init, "a") as f_init: + with open(init, "a", encoding="utf-8") as f_init: f_init.write("from .{}_{} import *\n".format(name.lower(), code)) - with open("{}/source/{}".format(home, i)) as f_csv, \ - open("{}/{}_{}.py".format(dest, name.lower(), code), "w") as f_class: + with open("{}/source/{}".format(home, i), encoding="utf-8") as f_csv, \ + open("{}/{}_{}.py".format(dest, name.lower(), code), "w", encoding="utf-8") as f_class: reader = csv.reader(f_csv, delimiter="\t") super_class = caml(name) @@ -98,10 +98,10 @@ def start(): sub_classes.append((sub_class, id, message)) - with open("{}/template/class.txt".format(home), "r") as f_class_template: + with open("{}/template/class.txt".format(home), "r", encoding="utf-8") as f_class_template: class_template = f_class_template.read() - with open("{}/template/sub_class.txt".format(home), "r") as f_sub_class_template: + with open("{}/template/sub_class.txt".format(home), "r", encoding="utf-8") as f_sub_class_template: sub_class_template = f_sub_class_template.read() class_template = class_template.format( @@ -123,10 +123,10 @@ def start(): f_all.write("}\n") - with open("{}/all.py".format(dest)) as f: + with open("{}/all.py".format(dest), encoding="utf-8") as f: content = f.read() - with open("{}/all.py".format(dest), "w") as f: + with open("{}/all.py".format(dest), "w", encoding="utf-8") as f: f.write(re.sub("{count}", str(count), content)) print("Compiling Errors: [100%]") diff --git a/pyrogram/api/errors/error.py b/pyrogram/api/errors/error.py index a861333d..aefbbca9 100644 --- a/pyrogram/api/errors/error.py +++ b/pyrogram/api/errors/error.py @@ -42,7 +42,7 @@ class Error(Exception): # TODO: Proper log unknown errors if self.CODE == 520: - with open("unknown_errors.txt", "a") as f: + with open("unknown_errors.txt", "a", encoding="utf-8") as f: f.write("{}\t{}\t{}\n".format(x.error_code, x.error_message, query_type)) @staticmethod diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index c8985896..131ce037 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -311,7 +311,7 @@ class Client: def load_session(self, session_name): try: - with open("{}.session".format(session_name)) as f: + with open("{}.session".format(session_name), encoding="utf-8") as f: s = json.load(f) except FileNotFoundError: self.dc_id = 1 @@ -326,7 +326,7 @@ class Client: auth_key = base64.b64encode(self.auth_key).decode() auth_key = [auth_key[i: i + 43] for i in range(0, len(auth_key), 43)] - with open("{}.session".format(self.session_name), "w") as f: + with open("{}.session".format(self.session_name), "w", encoding="utf-8") as f: json.dump( dict( dc_id=self.dc_id, From 0ac5b37278f90231f05221127401142b89f955d9 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 21 Jan 2018 16:59:06 +0100 Subject: [PATCH 6/7] Re-encode by replacing errors --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index d98ff762..5b78ac7c 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -__copyright__ = "Copyright (C) 2017-2018 Dan Tès " +__copyright__ = "Copyright (C) 2017-2018 Dan Tès ".encode(errors="replace").decode() __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)" __version__ = "0.4.0" From 70be5558c948c2bf1dcf750822c63d12b03a3094 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 21 Jan 2018 17:12:04 +0100 Subject: [PATCH 7/7] Update to v0.4.2 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 5b78ac7c..d6005bd8 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -18,7 +18,7 @@ __copyright__ = "Copyright (C) 2017-2018 Dan Tès ".encode(errors="replace").decode() __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)" -__version__ = "0.4.0" +__version__ = "0.4.2" from .api.errors import Error from .client import ChatAction