11# Copyright (c) 2024 FileCloud. All Rights Reserved.
22import datetime
3- import threading
43import logging
54import pathlib
65import re
6+ import threading
77import time
88import xml .etree .ElementTree as ET
99from io import SEEK_CUR , SEEK_END , SEEK_SET , BufferedReader , BytesIO
@@ -50,6 +50,7 @@ def str_to_bool(value):
5050
5151log = logging .getLogger (__name__ )
5252
53+
5354class Progress :
5455 """
5556 Way to track progress of uploads/downloads.
@@ -66,15 +67,18 @@ def __init__(self) -> None:
6667 """
6768 Progress callback of uploads/downloads
6869 """
69- def update (self , completed_bytes : int , total_bytes : int , chunk_complete : bool ) -> None :
70+
71+ def update (
72+ self , completed_bytes : int , total_bytes : int , chunk_complete : bool
73+ ) -> None :
7074 with self ._lock :
7175 self ._completed_bytes = completed_bytes
7276 self ._total_bytes = total_bytes
7377
7478 def completed_bytes (self ) -> int :
7579 with self ._lock :
7680 return self ._completed_bytes
77-
81+
7882 def total_bytes (self ) -> int :
7983 with self ._lock :
8084 return self ._total_bytes
@@ -526,8 +530,11 @@ def waitforfileremoval(self, path: str, maxwaits: float = 30):
526530 raise TimeoutError (f"File { path } not removed after { maxwaits } seconds" )
527531
528532 def downloadfile_no_retry (
529- self , path : str , dstPath : Union [pathlib .Path , str ], redirect : bool = True ,
530- progress : Optional [Progress ] = None
533+ self ,
534+ path : str ,
535+ dstPath : Union [pathlib .Path , str ],
536+ redirect : bool = True ,
537+ progress : Optional [Progress ] = None ,
531538 ) -> None :
532539 """
533540 Download file at 'path' to local 'dstPath'
@@ -548,12 +555,15 @@ def downloadfile_no_retry(
548555 for chunk in resp .iter_content (128 * 1024 ):
549556 completed_bytes += len (chunk )
550557 dstF .write (chunk )
551- if progress is not None :
558+ if progress is not None :
552559 progress .update (completed_bytes , content_length , False )
553560
554561 def downloadfile (
555- self , path : str , dstPath : Union [pathlib .Path , str ], redirect : bool = True ,
556- progress : Optional [Progress ] = None
562+ self ,
563+ path : str ,
564+ dstPath : Union [pathlib .Path , str ],
565+ redirect : bool = True ,
566+ progress : Optional [Progress ] = None ,
557567 ) -> None :
558568 """
559569 Download file at 'path' to local 'dstPath'. Retries.
@@ -605,7 +615,7 @@ def upload_bytes(
605615 data : bytes ,
606616 serverpath : str ,
607617 datemodified : datetime .datetime = datetime .datetime .now (),
608- progress : Optional [Progress ] = None
618+ progress : Optional [Progress ] = None ,
609619 ) -> None :
610620 """
611621 Upload bytes 'data' to server at 'serverpath'.
@@ -617,20 +627,22 @@ def upload_str(
617627 data : str ,
618628 serverpath : str ,
619629 datemodified : datetime .datetime = datetime .datetime .now (),
620- progress : Optional [Progress ] = None
630+ progress : Optional [Progress ] = None ,
621631 ) -> None :
622632 """
623633 Upload str 'data' UTF-8 encoded to server at 'serverpath'.
624634 """
625- self .upload_bytes (data .encode ("utf-8" ), serverpath , datemodified , progress = progress )
635+ self .upload_bytes (
636+ data .encode ("utf-8" ), serverpath , datemodified , progress = progress
637+ )
626638
627639 def upload_file (
628640 self ,
629641 localpath : pathlib .Path ,
630642 serverpath : str ,
631643 datemodified : datetime .datetime = datetime .datetime .now (),
632644 adminproxyuserid : Optional [str ] = None ,
633- progress : Optional [Progress ] = None
645+ progress : Optional [Progress ] = None ,
634646 ) -> None :
635647 """
636648 Upload file at 'localpath' to server at 'serverpath'.
@@ -641,7 +653,7 @@ def upload_file(
641653 serverpath ,
642654 datemodified ,
643655 adminproxyuserid = adminproxyuserid ,
644- progress = progress
656+ progress = progress ,
645657 )
646658
647659 def _serverdatetime (self , dt : datetime .datetime ):
0 commit comments