mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-23 01:46:35 +03:00
Handle invalid upload of text fd more gracefully
This commit is contained in:
parent
bdb74ac235
commit
a142b7de5e
|
@ -500,6 +500,11 @@ class UploadMethods:
|
||||||
if pos is not None:
|
if pos is not None:
|
||||||
file.seek(pos)
|
file.seek(pos)
|
||||||
|
|
||||||
|
if not isinstance(data, bytes):
|
||||||
|
raise TypeError(
|
||||||
|
'file descriptor returned {}, not bytes (you must '
|
||||||
|
'open the file in bytes mode)'.format(type(data)))
|
||||||
|
|
||||||
file = data
|
file = data
|
||||||
file_size = len(file)
|
file_size = len(file)
|
||||||
|
|
||||||
|
|
|
@ -741,7 +741,7 @@ def _get_extension(file):
|
||||||
elif isinstance(file, bytes):
|
elif isinstance(file, bytes):
|
||||||
kind = imghdr.what(io.BytesIO(file))
|
kind = imghdr.what(io.BytesIO(file))
|
||||||
return ('.' + kind) if kind else ''
|
return ('.' + kind) if kind else ''
|
||||||
elif isinstance(file, io.IOBase) and file.seekable():
|
elif isinstance(file, io.IOBase) and not isinstance(file, io.TextIOBase) and file.seekable():
|
||||||
kind = imghdr.what(file)
|
kind = imghdr.what(file)
|
||||||
return ('.' + kind) if kind is not None else ''
|
return ('.' + kind) if kind is not None else ''
|
||||||
elif getattr(file, 'name', None):
|
elif getattr(file, 'name', None):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user