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 11
11
import math
12
12
import os
13
13
import random
14
+ import sys
14
15
import threading
15
16
import time
16
17
import urllib .parse
@@ -197,6 +198,11 @@ def stage_blocks(
197
198
) -> List [STAGE_BLOCK_FUTURE_TYPE ]:
198
199
if not data :
199
200
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
200
206
stage_block_partitions = self ._get_stage_block_partitions (data )
201
207
futures = []
202
208
for pos , length in stage_block_partitions :
@@ -371,3 +377,12 @@ def _get_url_without_query_string(
371
377
None ,
372
378
)
373
379
)
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