Refactoring file and directory handling #5
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pathlib Integration: The use of
os
module is replaced with Python's more modernpathlib
module across various tools. This shift enhances readability and consistency in handling file paths.Field Validation Enhancements:
check_directory_traversal
, is implemented to prevent directory traversal attacks. It ensures the provided paths are within allowed directories.start_directory
fields in bothBuildDirectoryTree
andPrintAllFilesInDirectory
classes now usePath
instead ofstr
, ensuring better path handling.Refactoring File Extensions Handling:
set[str]
) instead of a list (list[str] | None
). This change simplifies the logic for including file types in the output.Improved Directory Traversal:
BuildDirectoryTree
andPrintAllFilesInDirectory
classes have been refactored to use recursive functions for directory traversal, enhancing their efficiency and readability.Testing Adjustments:
pathlib
and the new field validations.test_utils.py
, is added to specifically test thecheck_directory_traversal
function.