Do not mkstemp twice
Also use elif to make it less confusing
This commit is contained in:
parent
8796e857af
commit
b6a42aa8cd
@ -2250,7 +2250,7 @@ class Client:
|
|||||||
|
|
||||||
limit = 1024 * 1024
|
limit = 1024 * 1024
|
||||||
offset = 0
|
offset = 0
|
||||||
file_name = None
|
fd, file_name = tempfile.mkstemp()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = session.send(
|
r = session.send(
|
||||||
@ -2261,8 +2261,6 @@ class Client:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
fd, file_name = tempfile.mkstemp()
|
|
||||||
|
|
||||||
if isinstance(r, types.upload.File):
|
if isinstance(r, types.upload.File):
|
||||||
with os.fdopen(fd, "wb") as f:
|
with os.fdopen(fd, "wb") as f:
|
||||||
while True:
|
while True:
|
||||||
@ -2288,7 +2286,7 @@ class Client:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if isinstance(r, types.upload.FileCdnRedirect):
|
elif isinstance(r, types.upload.FileCdnRedirect):
|
||||||
cdn_session = Session(
|
cdn_session = Session(
|
||||||
r.dc_id,
|
r.dc_id,
|
||||||
self.test_mode,
|
self.test_mode,
|
||||||
@ -2301,17 +2299,6 @@ class Client:
|
|||||||
cdn_session.start()
|
cdn_session.start()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# cant fdopen the closed file descriptor which could be closed due
|
|
||||||
# to the with statement in the branch just above.
|
|
||||||
# make a new temp file to write to
|
|
||||||
|
|
||||||
try:
|
|
||||||
os.remove(file_name)
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
fd, file_name = tempfile.mkstemp()
|
|
||||||
|
|
||||||
with os.fdopen(fd, "wb") as f:
|
with os.fdopen(fd, "wb") as f:
|
||||||
while True:
|
while True:
|
||||||
r2 = cdn_session.send(
|
r2 = cdn_session.send(
|
||||||
@ -2376,7 +2363,6 @@ class Client:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error(e, exc_info=True)
|
log.error(e, exc_info=True)
|
||||||
|
|
||||||
if file_name:
|
|
||||||
try:
|
try:
|
||||||
os.remove(file_name)
|
os.remove(file_name)
|
||||||
except OSError:
|
except OSError:
|
||||||
|
Loading…
Reference in New Issue
Block a user