11from __future__ import annotations
22
33import base64
4+ import logging
45import os
56import pathlib
67import platform
1112from collections .abc import Iterator
1213from io import BytesIO
1314from types import TracebackType
14- from typing import (TYPE_CHECKING , AnyStr , BinaryIO , Generator , Iterable , Optional , Type , Union )
15+ from typing import (TYPE_CHECKING , AnyStr , BinaryIO , Generator , Iterable ,
16+ Optional , Type , Union )
1517from urllib import parse
18+
1619from requests import RequestException
1720
18- import logging
21+ from .. _base_client import _RawResponse , _StreamingResponse
1922from .._property import _cached_property
2023from ..errors import NotFound
2124from ..service import files
2225from ..service ._internal import _escape_multi_segment_path_parameter
2326from ..service .files import DownloadResponse
24- from .._base_client import _RawResponse , _StreamingResponse
2527
2628if TYPE_CHECKING :
2729 from _typeshed import Self
2830
2931_LOG = logging .getLogger (__name__ )
3032
33+
3134class _DbfsIO (BinaryIO ):
3235 MAX_CHUNK_SIZE = 1024 * 1024
3336
@@ -699,13 +702,17 @@ def _download_raw_stream(self,
699702
700703 result = DownloadResponse .from_dict (res )
701704 if not isinstance (result .contents , _StreamingResponse ):
702- raise Exception ("Internal error: response contents is of unexpected type: " + type (result .contents ).__name__ )
705+ raise Exception ("Internal error: response contents is of unexpected type: " +
706+ type (result .contents ).__name__ )
703707
704708 return result
705709
706710 def _wrap_stream (self , file_path : str , downloadResponse : DownloadResponse ):
707711 underlying_response = _ResilientIterator ._extract_raw_response (downloadResponse )
708- return _ResilientResponse (self , file_path , downloadResponse .last_modified , offset = 0 ,
712+ return _ResilientResponse (self ,
713+ file_path ,
714+ downloadResponse .last_modified ,
715+ offset = 0 ,
709716 underlying_response = underlying_response )
710717
711718
@@ -728,8 +735,8 @@ def iter_content(self, chunk_size=1, decode_unicode=False):
728735 raise ValueError ('Decode unicode is not supported' )
729736
730737 iterator = self .underlying_response .iter_content (chunk_size = chunk_size , decode_unicode = False )
731- self .iterator = _ResilientIterator (iterator , self .file_path , self .file_last_modified ,
732- self .offset , self . api , chunk_size )
738+ self .iterator = _ResilientIterator (iterator , self .file_path , self .file_last_modified , self . offset ,
739+ self .api , chunk_size )
733740 return self .iterator
734741
735742 def close (self ):
@@ -761,7 +768,6 @@ def __init__(self, underlying_iterator, file_path: str, file_last_modified: str,
761768 self ._recovers_without_progressing_count : int = 0
762769 self ._closed : bool = False
763770
764-
765771 def _should_recover (self ) -> bool :
766772 if self ._total_recovers_count == self ._api ._config .files_api_client_download_max_total_recovers :
767773 _LOG .debug ("Total recovers limit exceeded" )
@@ -773,7 +779,7 @@ def _should_recover(self) -> bool:
773779
774780 def _recover (self ) -> bool :
775781 if not self ._should_recover ():
776- return False # recover suppressed, rethrow original exception
782+ return False # recover suppressed, rethrow original exception
777783
778784 self ._total_recovers_count += 1
779785 self ._recovers_without_progressing_count += 1
@@ -784,13 +790,15 @@ def _recover(self) -> bool:
784790 _LOG .debug ("Trying to recover from offset " + str (self ._offset ))
785791
786792 # following call includes all the required network retries
787- downloadResponse = self ._api ._download_raw_stream (self ._file_path , self ._offset , self ._file_last_modified )
793+ downloadResponse = self ._api ._download_raw_stream (self ._file_path , self ._offset ,
794+ self ._file_last_modified )
788795 underlying_response = _ResilientIterator ._extract_raw_response (downloadResponse )
789- self ._underlying_iterator = underlying_response .iter_content (chunk_size = self ._chunk_size , decode_unicode = False )
796+ self ._underlying_iterator = underlying_response .iter_content (chunk_size = self ._chunk_size ,
797+ decode_unicode = False )
790798 _LOG .debug ("Recover succeeded" )
791799 return True
792800 except :
793- return False # recover failed, rethrow original exception
801+ return False # recover failed, rethrow original exception
794802
795803 def __next__ (self ):
796804 if self ._closed :
0 commit comments