11from __future__ import annotations
22
33import asyncio
4+ import contextlib
45import json
56import os
67from datetime import datetime , timedelta , timezone
1819
1920import azure .storage .blob as asb
2021import fsspec
21- from aiopath import AsyncPath
2222from azure .core .exceptions import HttpResponseError
2323from azure .storage .blob import BlobBlock
2424from azure .storage .blob .aio import BlobClient
@@ -597,7 +597,7 @@ async def stream_dl(
597597
598598 async def stream_up (
599599 self ,
600- local_path : str | Path | AsyncPath ,
600+ local_path : str | Path ,
601601 remote_path : str ,
602602 size : int = 16384 ,
603603 / ,
@@ -619,41 +619,39 @@ async def stream_up(
619619 recurs:
620620 To try again recursively
621621 """
622- if isinstance (local_path , ( str , Path ) ):
623- local_path = AsyncPath (local_path )
624- async with (
625- BlobClient .from_connection_string (
622+ if isinstance (local_path , str ):
623+ local_path = Path (local_path )
624+ with local_path . open ( "rb" ) as src :
625+ async with BlobClient .from_connection_string (
626626 self .connection_string , * (remote_path .split ("/" , maxsplit = 1 ))
627- ) as target ,
628- local_path .open ("rb" ) as src ,
629- ):
630- block_list = []
631- while True :
632- chunk = await src .read (size )
633- chunk = cast ("IO" , chunk )
634- if not chunk :
635- break
636- block_id = uuid4 ().hex
637- try :
638- await target .stage_block (block_id = block_id , data = chunk )
639- except HttpResponseError as err :
640- if "The specified blob or block content is invalid." not in str (
641- err
642- ):
643- raise
644- await asyncio .sleep (1 )
645- await target .commit_block_list ([])
646- await target .delete_blob ()
647- if recurs is False :
648- await self .stream_up (
649- local_path ,
650- remote_path ,
651- recurs = True ,
652- )
653- else :
654- raise
655- block_list .append (BlobBlock (block_id = block_id ))
656- await target .commit_block_list (block_list )
627+ ) as target :
628+ block_list = []
629+ while True :
630+ chunk = src .read (size )
631+ chunk = cast ("IO" , chunk )
632+ if not chunk :
633+ break
634+ block_id = uuid4 ().hex
635+ try :
636+ await target .stage_block (block_id = block_id , data = chunk )
637+ except HttpResponseError as err :
638+ if "The specified blob or block content is invalid." not in str (
639+ err
640+ ):
641+ raise
642+ await asyncio .sleep (1 )
643+ await target .commit_block_list ([])
644+ await target .delete_blob ()
645+ if recurs is False :
646+ await self .stream_up (
647+ local_path ,
648+ remote_path ,
649+ recurs = True ,
650+ )
651+ else :
652+ raise
653+ block_list .append (BlobBlock (block_id = block_id ))
654+ await target .commit_block_list (block_list )
657655
658656 async def walk (self , path : str , maxdepth = None , ** kwargs ):
659657 """
0 commit comments