mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-14 05:26:36 +03:00
Avoid triggering FileMigrateError when possible
This commit is contained in:
parent
5a9a00e7ae
commit
a9cc35e604
|
@ -200,10 +200,13 @@ class DownloadMethods(UserMethods):
|
||||||
else:
|
else:
|
||||||
f = file
|
f = file
|
||||||
|
|
||||||
# The used sender will change if ``FileMigrateError`` occurs
|
dc_id, input_location = utils.get_input_location(input_location)
|
||||||
sender = self._sender
|
exported = dc_id and self.session.dc_id != dc_id
|
||||||
exported = False
|
if exported:
|
||||||
input_location = utils.get_input_location(input_location)
|
sender = await self._borrow_exported_sender(dc_id)
|
||||||
|
else:
|
||||||
|
# The used sender will also change if ``FileMigrateError`` occurs
|
||||||
|
sender = self._sender
|
||||||
|
|
||||||
__log__.info('Downloading file in chunks of %d bytes', part_size)
|
__log__.info('Downloading file in chunks of %d bytes', part_size)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -42,6 +42,10 @@ class MemorySession(Session):
|
||||||
self._server_address = server_address
|
self._server_address = server_address
|
||||||
self._port = port
|
self._port = port
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dc_id(self):
|
||||||
|
return self._dc_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def server_address(self):
|
def server_address(self):
|
||||||
return self._server_address
|
return self._server_address
|
||||||
|
|
|
@ -537,10 +537,15 @@ def sanitize_parse_mode(mode):
|
||||||
|
|
||||||
|
|
||||||
def get_input_location(location):
|
def get_input_location(location):
|
||||||
"""Similar to :meth:`get_input_peer`, but for input messages."""
|
"""
|
||||||
|
Similar to :meth:`get_input_peer`, but for input messages.
|
||||||
|
|
||||||
|
Note that this returns a tuple ``(dc_id, location)``, the
|
||||||
|
``dc_id`` being present if known.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
if location.SUBCLASS_OF_ID == 0x1523d462:
|
if location.SUBCLASS_OF_ID == 0x1523d462:
|
||||||
return location # crc32(b'InputFileLocation'):
|
return None, location # crc32(b'InputFileLocation'):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
_raise_cast_fail(location, 'InputFileLocation')
|
_raise_cast_fail(location, 'InputFileLocation')
|
||||||
|
|
||||||
|
@ -553,8 +558,8 @@ def get_input_location(location):
|
||||||
location = location.photo
|
location = location.photo
|
||||||
|
|
||||||
if isinstance(location, Document):
|
if isinstance(location, Document):
|
||||||
return InputDocumentFileLocation(
|
return (location.dc_id, InputDocumentFileLocation(
|
||||||
location.id, location.access_hash, location.version)
|
location.id, location.access_hash, location.version))
|
||||||
elif isinstance(location, Photo):
|
elif isinstance(location, Photo):
|
||||||
try:
|
try:
|
||||||
location = next(x for x in reversed(location.sizes)
|
location = next(x for x in reversed(location.sizes)
|
||||||
|
@ -563,8 +568,8 @@ def get_input_location(location):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if isinstance(location, (FileLocation, FileLocationUnavailable)):
|
if isinstance(location, (FileLocation, FileLocationUnavailable)):
|
||||||
return InputFileLocation(
|
return (getattr(location, 'dc_id', None), InputFileLocation(
|
||||||
location.volume_id, location.local_id, location.secret)
|
location.volume_id, location.local_id, location.secret))
|
||||||
|
|
||||||
_raise_cast_fail(location, 'InputFileLocation')
|
_raise_cast_fail(location, 'InputFileLocation')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user