@@ -384,7 +384,10 @@ def reconfig(self, file, pattern, replacement):
384
384
# Not found; append (silently)
385
385
self .write_text_file (file , replacement , append = True )
386
386
387
- def pattern_search (self , location , pattern , multi_line = False , return_match = False ):
387
+ # pylint: disable=too-many-arguments
388
+ def pattern_search (
389
+ self , location , pattern , multi_line = False , return_match = False , find_all = False
390
+ ):
388
391
"""
389
392
Similar to grep, but uses pure python
390
393
multi_line will search the entire file as a large text glob,
@@ -394,16 +397,17 @@ def pattern_search(self, location, pattern, multi_line=False, return_match=False
394
397
"""
395
398
location = self .path (location )
396
399
found = False
400
+ search_function = re .findall if find_all else re .search
397
401
398
402
if self .exists (location ) and not self .isdir (location ):
399
403
if multi_line :
400
404
with open (location , "r+" , encoding = "utf-8" ) as file :
401
- match = re . search (pattern , file .read (), flags = re .DOTALL )
405
+ match = search_function (pattern , file .read (), flags = re .DOTALL )
402
406
if match :
403
407
found = True
404
408
else :
405
409
for line in fileinput .FileInput (location ):
406
- match = re . search (pattern , line )
410
+ match = search_function (pattern , line )
407
411
if match :
408
412
found = True
409
413
break
0 commit comments