From 0f4e29584ac46af38e8605f9720e3b0e8189693d Mon Sep 17 00:00:00 2001 From: Eric Blundell Date: Wed, 21 Mar 2018 04:07:55 -0500 Subject: [PATCH] Make use of tempfile.NamedTemporaryFile in getfile, use context managers --- pyrogram/client/client.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index cf4deb85..50009ba4 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -2250,7 +2250,7 @@ class Client: limit = 1024 * 1024 offset = 0 - fd, file_name = tempfile.mkstemp() + file_name = None try: r = session.send( @@ -2262,7 +2262,9 @@ class Client: ) if isinstance(r, types.upload.File): - with os.fdopen(fd, "wb") as f: + with tempfile.NamedTemporaryFile('wb', delete=False) as f: + file_name = f.name + while True: chunk = r.bytes @@ -2299,7 +2301,8 @@ class Client: cdn_session.start() try: - with os.fdopen(fd, "wb") as f: + with tempfile.NamedTemporaryFile('wb', delete=False) as f: + file_name = f.name while True: r2 = cdn_session.send( functions.upload.GetCdnFile(