File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 1111import math
1212import os
1313import random
14+ import sys
1415import threading
1516import time
1617import urllib .parse
@@ -197,6 +198,11 @@ def stage_blocks(
197198 ) -> List [STAGE_BLOCK_FUTURE_TYPE ]:
198199 if not data :
199200 raise ValueError ("Data must not be empty." )
201+ if (
202+ isinstance (data , memoryview )
203+ and not self ._sdk_supports_memoryview_for_writes ()
204+ ):
205+ data = data .obj
200206 stage_block_partitions = self ._get_stage_block_partitions (data )
201207 futures = []
202208 for pos , length in stage_block_partitions :
@@ -371,3 +377,12 @@ def _get_url_without_query_string(
371377 None ,
372378 )
373379 )
380+
381+ def _sdk_supports_memoryview_for_writes (self ) -> bool :
382+ # The SDK validates objects passed to its HTTP request layer expose an __iter__()
383+ # method that can be used to iterate through bytes passed to it. However, memoryview
384+ # objects did not expose an __iter__() method till Python 3.10.
385+ #
386+ # We still want to leverage memorviews when we can to avoid unnecessary copies. So
387+ # we check the Python version to determine if we can use memoryviews for writes.
388+ return sys .version_info >= (3 , 10 )
You can’t perform that action at this time.
0 commit comments