@@ -86,7 +86,7 @@ def find(self, req: list, path: str | FsNode = "") -> list[FsNode]:
86
86
def download (self , path : str | FsNode ) -> bytes :
87
87
"""Downloads and returns the content of a file."""
88
88
path = path .user_path if isinstance (path , FsNode ) else path
89
- response = self ._session .adapter_dav .get (dav_get_obj_path (self ._session .user , path ))
89
+ response = self ._session .adapter_dav .get (quote ( dav_get_obj_path (self ._session .user , path ) ))
90
90
check_error (response , f"download: user={ self ._session .user } , path={ path } " )
91
91
return response .content
92
92
@@ -138,7 +138,7 @@ def upload(self, path: str | FsNode, content: bytes | str) -> FsNode:
138
138
"""
139
139
path = path .user_path if isinstance (path , FsNode ) else path
140
140
full_path = dav_get_obj_path (self ._session .user , path )
141
- response = self ._session .adapter_dav .put (full_path , content = content )
141
+ response = self ._session .adapter_dav .put (quote ( full_path ) , content = content )
142
142
check_error (response , f"upload: user={ self ._session .user } , path={ path } , size={ len (content )} " )
143
143
return FsNode (full_path .strip ("/" ), ** etag_fileid_from_response (response ))
144
144
@@ -219,11 +219,11 @@ def move(self, path_src: str | FsNode, path_dest: str | FsNode, overwrite=False)
219
219
full_dest_path = dav_get_obj_path (
220
220
self ._session .user , path_dest .user_path if isinstance (path_dest , FsNode ) else path_dest
221
221
)
222
- dest = self ._session .cfg .dav_endpoint + full_dest_path
222
+ dest = self ._session .cfg .dav_endpoint + quote ( full_dest_path )
223
223
headers = Headers ({"Destination" : dest , "Overwrite" : "T" if overwrite else "F" }, encoding = "utf-8" )
224
224
response = self ._session .adapter_dav .request (
225
225
"MOVE" ,
226
- dav_get_obj_path (self ._session .user , path_src ),
226
+ quote ( dav_get_obj_path (self ._session .user , path_src ) ),
227
227
headers = headers ,
228
228
)
229
229
check_error (response , f"move: user={ self ._session .user } , src={ path_src } , dest={ dest } , { overwrite } " )
@@ -241,11 +241,11 @@ def copy(self, path_src: str | FsNode, path_dest: str | FsNode, overwrite=False)
241
241
full_dest_path = dav_get_obj_path (
242
242
self ._session .user , path_dest .user_path if isinstance (path_dest , FsNode ) else path_dest
243
243
)
244
- dest = self ._session .cfg .dav_endpoint + full_dest_path
244
+ dest = self ._session .cfg .dav_endpoint + quote ( full_dest_path )
245
245
headers = Headers ({"Destination" : dest , "Overwrite" : "T" if overwrite else "F" }, encoding = "utf-8" )
246
246
response = self ._session .adapter_dav .request (
247
247
"COPY" ,
248
- dav_get_obj_path (self ._session .user , path_src ),
248
+ quote ( dav_get_obj_path (self ._session .user , path_src ) ),
249
249
headers = headers ,
250
250
)
251
251
check_error (response , f"copy: user={ self ._session .user } , src={ path_src } , dest={ dest } , { overwrite } " )
@@ -277,7 +277,7 @@ def setfav(self, path: str | FsNode, value: int | bool) -> None:
277
277
path = path .user_path if isinstance (path , FsNode ) else path
278
278
root = build_setfav_req (value )
279
279
webdav_response = self ._session .adapter_dav .request (
280
- "PROPPATCH" , dav_get_obj_path (self ._session .user , path ), content = element_tree_as_str (root )
280
+ "PROPPATCH" , quote ( dav_get_obj_path (self ._session .user , path ) ), content = element_tree_as_str (root )
281
281
)
282
282
check_error (webdav_response , f"setfav: path={ path } , value={ value } " )
283
283
@@ -301,7 +301,7 @@ def trashbin_restore(self, path: str | FsNode) -> None:
301
301
headers = Headers ({"Destination" : dest }, encoding = "utf-8" )
302
302
response = self ._session .adapter_dav .request (
303
303
"MOVE" ,
304
- f"/trashbin/{ self ._session .user } /{ path } " ,
304
+ quote ( f"/trashbin/{ self ._session .user } /{ path } " ) ,
305
305
headers = headers ,
306
306
)
307
307
check_error (response , f"trashbin_restore: user={ self ._session .user } , src={ path } , dest={ dest } " )
@@ -313,7 +313,7 @@ def trashbin_delete(self, path: str | FsNode, not_fail=False) -> None:
313
313
:param not_fail: if set to ``True`` and the object is not found, it does not raise an exception.
314
314
"""
315
315
path = path .user_path if isinstance (path , FsNode ) else path
316
- response = self ._session .adapter_dav .delete (f"/trashbin/{ self ._session .user } /{ path } " )
316
+ response = self ._session .adapter_dav .delete (quote ( f"/trashbin/{ self ._session .user } /{ path } " ) )
317
317
if response .status_code == 404 and not_fail :
318
318
return
319
319
check_error (response )
@@ -431,7 +431,7 @@ def _listdir(
431
431
root , dav_path = build_listdir_req (user , path , properties , prop_type )
432
432
webdav_response = self ._session .adapter_dav .request (
433
433
"PROPFIND" ,
434
- dav_path ,
434
+ quote ( dav_path ) ,
435
435
content = element_tree_as_str (root ),
436
436
headers = {"Depth" : "infinity" if depth == - 1 else str (depth )},
437
437
)
@@ -440,16 +440,17 @@ def _listdir(
440
440
)
441
441
442
442
def __download2stream (self , path : str , fp , ** kwargs ) -> None :
443
- with self ._session .adapter_dav .stream ("GET" , dav_get_obj_path (self ._session .user , path )) as response :
443
+ with self ._session .adapter_dav .stream ("GET" , quote ( dav_get_obj_path (self ._session .user , path ) )) as response :
444
444
check_error (response , f"download_stream: user={ self ._session .user } , path={ path } " )
445
445
for data_chunk in response .iter_raw (chunk_size = kwargs .get ("chunk_size" , 5 * 1024 * 1024 )):
446
446
fp .write (data_chunk )
447
447
448
448
def __upload_stream (self , path : str , fp , chunk_size : int ) -> FsNode :
449
- _dav_path = dav_get_obj_path (self ._session .user , "nc-py-api-" + random_string (56 ), root_path = "/uploads" )
449
+ _tmp_path = "nc-py-api-" + random_string (56 )
450
+ _dav_path = quote (dav_get_obj_path (self ._session .user , _tmp_path , root_path = "/uploads" ))
450
451
_v2 = bool (self ._session .cfg .options .upload_chunk_v2 and chunk_size >= 5 * 1024 * 1024 )
451
452
full_path = dav_get_obj_path (self ._session .user , path )
452
- headers = Headers ({"Destination" : self ._session .cfg .dav_endpoint + full_path }, encoding = "utf-8" )
453
+ headers = Headers ({"Destination" : self ._session .cfg .dav_endpoint + quote ( full_path ) }, encoding = "utf-8" )
453
454
if _v2 :
454
455
response = self ._session .adapter_dav .request ("MKCOL" , _dav_path , headers = headers )
455
456
else :
@@ -548,7 +549,7 @@ async def find(self, req: list, path: str | FsNode = "") -> list[FsNode]:
548
549
async def download (self , path : str | FsNode ) -> bytes :
549
550
"""Downloads and returns the content of a file."""
550
551
path = path .user_path if isinstance (path , FsNode ) else path
551
- response = await self ._session .adapter_dav .get (dav_get_obj_path (await self ._session .user , path ))
552
+ response = await self ._session .adapter_dav .get (quote ( dav_get_obj_path (await self ._session .user , path ) ))
552
553
check_error (response , f"download: user={ await self ._session .user } , path={ path } " )
553
554
return response .content
554
555
@@ -602,7 +603,7 @@ async def upload(self, path: str | FsNode, content: bytes | str) -> FsNode:
602
603
"""
603
604
path = path .user_path if isinstance (path , FsNode ) else path
604
605
full_path = dav_get_obj_path (await self ._session .user , path )
605
- response = await self ._session .adapter_dav .put (full_path , content = content )
606
+ response = await self ._session .adapter_dav .put (quote ( full_path ) , content = content )
606
607
check_error (response , f"upload: user={ await self ._session .user } , path={ path } , size={ len (content )} " )
607
608
return FsNode (full_path .strip ("/" ), ** etag_fileid_from_response (response ))
608
609
@@ -683,11 +684,11 @@ async def move(self, path_src: str | FsNode, path_dest: str | FsNode, overwrite=
683
684
full_dest_path = dav_get_obj_path (
684
685
await self ._session .user , path_dest .user_path if isinstance (path_dest , FsNode ) else path_dest
685
686
)
686
- dest = self ._session .cfg .dav_endpoint + full_dest_path
687
+ dest = self ._session .cfg .dav_endpoint + quote ( full_dest_path )
687
688
headers = Headers ({"Destination" : dest , "Overwrite" : "T" if overwrite else "F" }, encoding = "utf-8" )
688
689
response = await self ._session .adapter_dav .request (
689
690
"MOVE" ,
690
- dav_get_obj_path (await self ._session .user , path_src ),
691
+ quote ( dav_get_obj_path (await self ._session .user , path_src ) ),
691
692
headers = headers ,
692
693
)
693
694
check_error (response , f"move: user={ await self ._session .user } , src={ path_src } , dest={ dest } , { overwrite } " )
@@ -705,11 +706,11 @@ async def copy(self, path_src: str | FsNode, path_dest: str | FsNode, overwrite=
705
706
full_dest_path = dav_get_obj_path (
706
707
await self ._session .user , path_dest .user_path if isinstance (path_dest , FsNode ) else path_dest
707
708
)
708
- dest = self ._session .cfg .dav_endpoint + full_dest_path
709
+ dest = self ._session .cfg .dav_endpoint + quote ( full_dest_path )
709
710
headers = Headers ({"Destination" : dest , "Overwrite" : "T" if overwrite else "F" }, encoding = "utf-8" )
710
711
response = await self ._session .adapter_dav .request (
711
712
"COPY" ,
712
- dav_get_obj_path (await self ._session .user , path_src ),
713
+ quote ( dav_get_obj_path (await self ._session .user , path_src ) ),
713
714
headers = headers ,
714
715
)
715
716
check_error (response , f"copy: user={ await self ._session .user } , src={ path_src } , dest={ dest } , { overwrite } " )
@@ -741,7 +742,7 @@ async def setfav(self, path: str | FsNode, value: int | bool) -> None:
741
742
path = path .user_path if isinstance (path , FsNode ) else path
742
743
root = build_setfav_req (value )
743
744
webdav_response = await self ._session .adapter_dav .request (
744
- "PROPPATCH" , dav_get_obj_path (await self ._session .user , path ), content = element_tree_as_str (root )
745
+ "PROPPATCH" , quote ( dav_get_obj_path (await self ._session .user , path ) ), content = element_tree_as_str (root )
745
746
)
746
747
check_error (webdav_response , f"setfav: path={ path } , value={ value } " )
747
748
@@ -770,7 +771,7 @@ async def trashbin_restore(self, path: str | FsNode) -> None:
770
771
headers = Headers ({"Destination" : dest }, encoding = "utf-8" )
771
772
response = await self ._session .adapter_dav .request (
772
773
"MOVE" ,
773
- f"/trashbin/{ await self ._session .user } /{ path } " ,
774
+ quote ( f"/trashbin/{ await self ._session .user } /{ path } " ) ,
774
775
headers = headers ,
775
776
)
776
777
check_error (response , f"trashbin_restore: user={ await self ._session .user } , src={ path } , dest={ dest } " )
@@ -782,7 +783,7 @@ async def trashbin_delete(self, path: str | FsNode, not_fail=False) -> None:
782
783
:param not_fail: if set to ``True`` and the object is not found, it does not raise an exception.
783
784
"""
784
785
path = path .user_path if isinstance (path , FsNode ) else path
785
- response = await self ._session .adapter_dav .delete (f"/trashbin/{ await self ._session .user } /{ path } " )
786
+ response = await self ._session .adapter_dav .delete (quote ( f"/trashbin/{ await self ._session .user } /{ path } " ) )
786
787
if response .status_code == 404 and not_fail :
787
788
return
788
789
check_error (response )
@@ -900,7 +901,7 @@ async def _listdir(
900
901
root , dav_path = build_listdir_req (user , path , properties , prop_type )
901
902
webdav_response = await self ._session .adapter_dav .request (
902
903
"PROPFIND" ,
903
- dav_path ,
904
+ quote ( dav_path ) ,
904
905
content = element_tree_as_str (root ),
905
906
headers = {"Depth" : "infinity" if depth == - 1 else str (depth )},
906
907
)
@@ -910,17 +911,18 @@ async def _listdir(
910
911
911
912
async def __download2stream (self , path : str , fp , ** kwargs ) -> None :
912
913
async with self ._session .adapter_dav .stream (
913
- "GET" , dav_get_obj_path (await self ._session .user , path )
914
+ "GET" , quote ( dav_get_obj_path (await self ._session .user , path ) )
914
915
) as response :
915
916
check_error (response , f"download_stream: user={ await self ._session .user } , path={ path } " )
916
917
async for data_chunk in response .aiter_raw (chunk_size = kwargs .get ("chunk_size" , 5 * 1024 * 1024 )):
917
918
fp .write (data_chunk )
918
919
919
920
async def __upload_stream (self , path : str , fp , chunk_size : int ) -> FsNode :
920
- _dav_path = dav_get_obj_path (await self ._session .user , "nc-py-api-" + random_string (56 ), root_path = "/uploads" )
921
+ _tmp_path = "nc-py-api-" + random_string (56 )
922
+ _dav_path = quote (dav_get_obj_path (await self ._session .user , _tmp_path , root_path = "/uploads" ))
921
923
_v2 = bool (self ._session .cfg .options .upload_chunk_v2 and chunk_size >= 5 * 1024 * 1024 )
922
924
full_path = dav_get_obj_path (await self ._session .user , path )
923
- headers = Headers ({"Destination" : self ._session .cfg .dav_endpoint + full_path }, encoding = "utf-8" )
925
+ headers = Headers ({"Destination" : self ._session .cfg .dav_endpoint + quote ( full_path ) }, encoding = "utf-8" )
924
926
if _v2 :
925
927
response = await self ._session .adapter_dav .request ("MKCOL" , _dav_path , headers = headers )
926
928
else :
0 commit comments