mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-08 16:04:51 +00:00
Make use of tempfile.NamedTemporaryFile in getfile, use context managers
This commit is contained in:
parent
b45960212b
commit
0f4e29584a
1 changed files with 6 additions and 3 deletions
|
|
@ -2250,7 +2250,7 @@ class Client:
|
||||||
|
|
||||||
limit = 1024 * 1024
|
limit = 1024 * 1024
|
||||||
offset = 0
|
offset = 0
|
||||||
fd, file_name = tempfile.mkstemp()
|
file_name = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = session.send(
|
r = session.send(
|
||||||
|
|
@ -2262,7 +2262,9 @@ class Client:
|
||||||
)
|
)
|
||||||
|
|
||||||
if isinstance(r, types.upload.File):
|
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:
|
while True:
|
||||||
chunk = r.bytes
|
chunk = r.bytes
|
||||||
|
|
||||||
|
|
@ -2299,7 +2301,8 @@ class Client:
|
||||||
cdn_session.start()
|
cdn_session.start()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with os.fdopen(fd, "wb") as f:
|
with tempfile.NamedTemporaryFile('wb', delete=False) as f:
|
||||||
|
file_name = f.name
|
||||||
while True:
|
while True:
|
||||||
r2 = cdn_session.send(
|
r2 = cdn_session.send(
|
||||||
functions.upload.GetCdnFile(
|
functions.upload.GetCdnFile(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue