Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_normal_auto_platform_linux(self, value, expected):
if isinstance(expected, str):
sanitized = sanitize_filepath(value, platform="auto")
assert is_valid_filepath(sanitized, platform="auto")
else:
with pytest.raises(expected):
sanitize_filepath(value, platform="auto")
def test_normal_check_reserved(self, value, check_reserved, expected):
assert (
sanitize_filepath(value, platform="windows", check_reserved=check_reserved) == expected
)
def test_normal_auto_platform_linux(self, value, expected):
if isinstance(expected, str):
sanitized = sanitize_filepath(value, platform="auto")
assert is_valid_filepath(sanitized, platform="auto")
else:
with pytest.raises(expected):
sanitize_filepath(value, platform="auto")
def test_normal_pathlike(self, value, replace_text, expected):
sanitized_name = sanitize_filepath(value, replace_text)
assert sanitized_name == expected
assert is_pathlike_obj(sanitized_name)
validate_filepath(sanitized_name)
assert is_valid_filepath(sanitized_name)
def test_normal_path_separator(self, platform, value, expected):
sanitized = sanitize_filepath(value, platform=platform)
assert sanitized == expected
assert is_valid_filepath(sanitized, platform=platform)
def test_normal_reserved_name(self, value, test_platform, expected):
filename = sanitize_filepath(value, platform=test_platform)
assert filename == expected
assert is_valid_filepath(filename, platform=test_platform)
def test_normal_multibyte(self, test_platform, value, replace_text, expected):
sanitized_name = sanitize_filepath(value, replace_text, platform=test_platform)
assert sanitized_name == expected
validate_filepath(sanitized_name, platform=test_platform)
assert is_valid_filepath(sanitized_name, platform=test_platform)
photosdb = osxphotos.PhotosDB(library_path)
else:
photosdb = osxphotos.PhotosDB()
photos = photosdb.photos()
for p in photos:
if not p.ismissing:
albums = p.albums
if not albums:
albums = [default_album]
for album in albums:
click.echo(f"exporting {p.original_filename} in album {album}")
# make sure no invalid characters in destination path (could be in album name)
album_name = sanitize_filepath(album, platform="auto")
# create destination folder, if necessary, based on album name
dest_dir = os.path.join(export_path, album_name)
# verify path is a valid path
if not is_valid_filepath(dest_dir, platform="auto"):
sys.exit(f"Invalid filepath {dest_dir}")
# create destination dir if needed
if not os.path.isdir(dest_dir):
os.makedirs(dest_dir)
filename = p.original_filename
# export the photo but only if --edited, photo has adjustments, and
# path_edited is not None (can be None if edited photo is missing)
if edited and p.hasadjustments and p.path_edited:
def __init__(self, base, file_path=None, full_file_path=None):
super().__init__(base, file_path, full_file_path)
self._path = self._path.replace('%', '%%')
self._path = self.remove_dotslash(self._path)
# noinspection PyUnresolvedReferences
self._path = pathvalidate.sanitize_filepath(self._path, '_').strip(". /\\").strip()
if not len(self._path):
self._path = '_'
elif directory:
# got a directory template, render it and check results are valid
dirnames, unmatched = photo.render_template(directory)
if not dirnames:
raise click.BadOptionUsage(
"directory",
f"Invalid template '{directory}': results={dirnames} unmatched={unmatched}",
)
elif unmatched:
raise click.BadOptionUsage(
"directory",
f"Invalid template '{directory}': results={dirnames} unmatched={unmatched}",
)
dest_paths = []
for dirname in dirnames:
dirname = sanitize_filepath(dirname, platform="auto")
dest_path = os.path.join(dest, dirname)
if not is_valid_filepath(dest_path, platform="auto"):
raise ValueError(f"Invalid file path: '{dest_path}'")
if not dry_run and not os.path.isdir(dest_path):
os.makedirs(dest_path)
dest_paths.append(dest_path)
else:
dest_paths = [dest]
return dest_paths