11"""Amazon S3 List Module (PRIVATE)."""
22
3+ import datetime
34import logging
4- from datetime import datetime
55from typing import Any , Dict , List , Optional
66
77import boto3 # type: ignore
1515def path2list (
1616 path : object ,
1717 boto3_session : boto3 .Session ,
18+ last_modified_begin : Optional [datetime .datetime ] = None ,
19+ last_modified_end : Optional [datetime .datetime ] = None ,
1820 suffix : str = None ,
19- lastModified_begin : Optional [datetime ] = None ,
20- lastModified_end : Optional [datetime ] = None ,
2121) -> List [str ]:
2222 """Convert Amazon S3 path to list of objects."""
2323 if isinstance (path , str ): # prefix
2424 paths : List [str ] = list_objects (
2525 path = path ,
2626 suffix = suffix ,
2727 boto3_session = boto3_session ,
28- lastModified_begin = lastModified_begin ,
29- lastModified_end = lastModified_end ,
28+ last_modified_begin = last_modified_begin ,
29+ last_modified_end = last_modified_end ,
3030 )
3131 elif isinstance (path , list ):
32- if lastModified_begin or lastModified_end :
33- raise exceptions .InvalidArgumentType ("Specify a list of files or (lastModified_begin and lastModified_end)" )
32+ if last_modified_begin or last_modified_end :
33+ raise exceptions .InvalidArgumentType (
34+ "Specify a list of files or (last_modified_begin and last_modified_end)"
35+ )
3436 paths = path if suffix is None else [x for x in path if x .endswith (suffix )]
3537 else :
3638 raise exceptions .InvalidArgumentType (f"{ type (path )} is not a valid path type. Please, use str or List[str]." )
@@ -41,9 +43,9 @@ def _list_objects(
4143 path : str ,
4244 delimiter : Optional [str ] = None ,
4345 suffix : Optional [str ] = None ,
46+ last_modified_begin : Optional [datetime .datetime ] = None ,
47+ last_modified_end : Optional [datetime .datetime ] = None ,
4448 boto3_session : Optional [boto3 .Session ] = None ,
45- lastModified_begin : Optional [datetime ] = None ,
46- lastModified_end : Optional [datetime ] = None ,
4749) -> List [str ]:
4850 bucket : str
4951 prefix : str
@@ -56,15 +58,15 @@ def _list_objects(
5658 response_iterator = paginator .paginate (** args )
5759 paths : List [str ] = []
5860
59- # validations for lastModified_begin and lastModified_end
61+ # validations for last_modified_begin and last_modified_end
6062 filtering_by_date = False
61- if lastModified_begin or lastModified_end :
62- if not ( hasattr (lastModified_begin , "tzinfo" ) and hasattr (lastModified_begin , "tzinfo" )) :
63+ if last_modified_begin or last_modified_end :
64+ if hasattr (last_modified_begin , "tzinfo" ) is None or hasattr (last_modified_begin , "tzinfo" ) is None :
6365 raise exceptions .InvalidArgumentType ("Timezone is not defined" )
64- if not lastModified_begin or not lastModified_end :
65- raise exceptions .InvalidArgumentType ("Both lastModified_begin and lastModified_end needs to be provided." )
66- if lastModified_begin > lastModified_end :
67- raise exceptions .InvalidArgumentType ("lastModified_begin is bigger than lastModified_end ." )
66+ if last_modified_begin is None or last_modified_end is None :
67+ raise exceptions .InvalidArgumentType ("Both last_modified_begin and last_modified_end needs to be provided." )
68+ if last_modified_begin > last_modified_end :
69+ raise exceptions .InvalidArgumentType ("last_modified_begin is bigger than last_modified_end ." )
6870 filtering_by_date = True
6971
7072 for page in response_iterator : # pylint: disable=too-many-nested-blocks
@@ -75,8 +77,8 @@ def _list_objects(
7577 key : str = content ["Key" ]
7678 if filtering_by_date :
7779 if (
78- content ["LastModified" ] >= lastModified_begin
79- and content ["LastModified" ] <= lastModified_end
80+ content ["LastModified" ] >= last_modified_begin
81+ and content ["LastModified" ] <= last_modified_end
8082 ):
8183 if (content is not None ) and ("Key" in content ):
8284 if (suffix is None ) or key .endswith (suffix ):
@@ -180,26 +182,30 @@ def list_directories(path: str, boto3_session: Optional[boto3.Session] = None) -
180182def list_objects (
181183 path : str ,
182184 suffix : Optional [str ] = None ,
185+ last_modified_begin : Optional [datetime .datetime ] = None ,
186+ last_modified_end : Optional [datetime .datetime ] = None ,
183187 boto3_session : Optional [boto3 .Session ] = None ,
184- lastModified_begin : Optional [datetime ] = None ,
185- lastModified_end : Optional [datetime ] = None ,
186188) -> List [str ]:
187189 """List Amazon S3 objects from a prefix.
188190
189191 Note
190192 ----
191- The filter by lastModified begin lastModified end is applied after list all S3 files
193+ The filter by last_modified begin last_modified end is applied after list all S3 files
192194
193195 Parameters
194196 ----------
195197 path : str
196198 S3 path (e.g. s3://bucket/prefix).
197199 suffix: str, optional
198200 Suffix for filtering S3 keys.
201+ last_modified_begin
202+ Filter the s3 files by the Last modified date of the object.
203+ The filter is applied only after list all s3 files.
204+ last_modified_end: datetime, optional
205+ Filter the s3 files by the Last modified date of the object.
206+ The filter is applied only after list all s3 files.
199207 boto3_session : boto3.Session(), optional
200208 Boto3 Session. The default boto3 session will be used if boto3_session receive None.
201- lastModified_begin lastModified_end: datetime, optional
202- Filter the s3 files by the Last modified date of the object
203209
204210 Returns
205211 -------
@@ -227,7 +233,7 @@ def list_objects(
227233 delimiter = None ,
228234 suffix = suffix ,
229235 boto3_session = boto3_session ,
230- lastModified_begin = lastModified_begin ,
231- lastModified_end = lastModified_end ,
236+ last_modified_begin = last_modified_begin ,
237+ last_modified_end = last_modified_end ,
232238 )
233239 return [p for p in paths if not p .endswith ("/" )]
0 commit comments