From 9fe98cf689f0a43beb57b61bce0534b4b82eff64 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 22 Mar 2018 16:22:20 +0100 Subject: [PATCH 1/4] Update README.md --- examples/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/README.md b/examples/README.md index 6b14e3e5..66ca9405 100644 --- a/examples/README.md +++ b/examples/README.md @@ -2,7 +2,9 @@ This folder contains example scripts to show you how **Pyrogram** looks like. You can start with [hello_world.py](https://github.com/pyrogram/pyrogram/blob/master/examples/hello_world.py) and continue -with the more advanced examples. Every script is working right away (provided you correctly set up your credentials), meaning +with the more advanced examples. + +Every script is working right away (provided you correctly set up your credentials), meaning you can simply copy-paste and run, the only things you have to change are the target chats (username, id) and file paths for sending media (photo, video, ...). From a0e3ab419917da35b6748adbfb317789a8736ef8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 23 Mar 2018 08:27:23 +0100 Subject: [PATCH 2/4] Yet another markdown pattern fix --- pyrogram/client/style/markdown.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/style/markdown.py b/pyrogram/client/style/markdown.py index f3c7805d..d9e8c571 100644 --- a/pyrogram/client/style/markdown.py +++ b/pyrogram/client/style/markdown.py @@ -36,7 +36,7 @@ class Markdown: CODE_DELIMITER = "`" PRE_DELIMITER = "```" - MARKDOWN_RE = re.compile(r"```([\w ]*)\n([\w\W]*)(?:\n|)```|\[(.+)\]\((.+)\)|({d})(.+?)\5".format( + MARKDOWN_RE = re.compile(r"```([\w ]*)\n([\w\W]*)(?:\n|)```|\[(.+?)\]\((.+?)\)|({d})(.+?)\5".format( d="|".join( ["".join(i) for i in [ ["\{}".format(j) for j in i] From 1d9bb18a385ed1a8013b43197fa4f122a1386641 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 23 Mar 2018 12:59:03 +0100 Subject: [PATCH 3/4] Only match full t.me/joinchat links --- pyrogram/client/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index a86a4c97..859f2be5 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -131,7 +131,7 @@ class Client: Thread pool size for handling incoming updates. Defaults to 4. """ - INVITE_LINK_RE = re.compile(r"^(?:https?://)?(?:t\.me/joinchat/)?([\w-]+)$") + INVITE_LINK_RE = re.compile(r"^(?:https?://)?(?:t\.me/joinchat/)([\w-]+)$") DIALOGS_AT_ONCE = 100 UPDATES_WORKERS = 1 DOWNLOAD_WORKERS = 1 From ef71dcf56ac80e478ac09eb44477ad2ea5cf6229 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 23 Mar 2018 13:46:43 +0100 Subject: [PATCH 4/4] Remove **kwargs for generated classes (function/types) --- compiler/api/template/class.txt | 2 +- pyrogram/client/client.py | 47 +++++++++++++++++++++++---------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/compiler/api/template/class.txt b/compiler/api/template/class.txt index 2cba4bb9..d29caf05 100644 --- a/compiler/api/template/class.txt +++ b/compiler/api/template/class.txt @@ -11,7 +11,7 @@ class {class_name}(Object): """ ID = {object_id} - def __init__(self{arguments}, **kwargs): + def __init__(self{arguments}): {fields} @staticmethod diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 859f2be5..648c3b98 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1974,10 +1974,15 @@ class Client: Raises: :class:`pyrogram.Error` """ + if "Upload" in action.__name__: + action = action(progress) + else: + action = action() + return self.send( functions.messages.SetTyping( peer=self.resolve_peer(chat_id), - action=action(progress=progress) + action=action ) ) @@ -2171,14 +2176,21 @@ class Client: md5_sum = "".join([hex(i)[2:].zfill(2) for i in md5_sum.digest()]) break - session.send( - (functions.upload.SaveBigFilePart if is_big else functions.upload.SaveFilePart)( + if is_big: + rpc = functions.upload.SaveBigFilePart( file_id=file_id, file_part=file_part, - bytes=chunk, - file_total_parts=file_total_parts + file_total_parts=file_total_parts, + bytes=chunk ) - ) + else: + rpc = functions.upload.SaveFilePart( + file_id=file_id, + file_part=file_part, + bytes=chunk + ) + + assert self.send(rpc), "Couldn't upload file" if is_missing_part: return @@ -2191,14 +2203,22 @@ class Client: if progress: progress(min(file_part * part_size, file_size), file_size) except Exception as e: - log.error(e) + log.error(e, exc_info=True) else: - return (types.InputFileBig if is_big else types.InputFile)( - id=file_id, - parts=file_total_parts, - name=os.path.basename(path), - md5_checksum=md5_sum - ) + if is_big: + return types.InputFileBig( + id=file_id, + parts=file_total_parts, + name=os.path.basename(path), + + ) + else: + return types.InputFile( + id=file_id, + parts=file_total_parts, + name=os.path.basename(path), + md5_checksum=md5_sum + ) finally: session.stop() @@ -2318,7 +2338,6 @@ class Client: while True: r2 = cdn_session.send( functions.upload.GetCdnFile( - location=location, file_token=r.file_token, offset=offset, limit=limit