Gitlab Community Edition Instance

Commit 661ea598 authored by Marcel Hellkamp's avatar Marcel Hellkamp
Browse files

Refactoring

parent 99100bb9
...@@ -14,15 +14,6 @@ from pycdstar3.model import ApiError, JsonObject, FileDownload, FormUpdate ...@@ -14,15 +14,6 @@ from pycdstar3.model import ApiError, JsonObject, FileDownload, FormUpdate
__all__ = "CDStar", "CDStarVault", "FormUpdate", "ApiError" __all__ = "CDStar", "CDStarVault", "FormUpdate", "ApiError"
def _fix_filename(name):
# silently strip leading slashes
name = name.lstrip("/")
# Fail hard on relative filenames
if name != os.path.normpath(name):
raise ValueError("Archive file name not in a normalized form: {} != {}".format(name, os.path.normpath(name)))
return name
class CDStar: class CDStar:
""" Provide low-level methods for corresponding server-side REST endpoints. """ Provide low-level methods for corresponding server-side REST endpoints.
...@@ -350,6 +341,20 @@ class CDStar: ...@@ -350,6 +341,20 @@ class CDStar:
break break
def _fix_filename(name):
""" Normalize a remote archive file path and make sure it makes sense.
Raise if we find relative path segments (likely an error)
"""
# silently strip leading slashes
name = name.lstrip("/")
# Fail hard on relative filenames
if name != os.path.normpath(name):
raise ValueError("Archive file name not in a normalized form: {} != {}".format(name, os.path.normpath(name)))
return name
# Design notes for the following resource handles: # Design notes for the following resource handles:
# - The handle instances are really just a slim handle for a remote resource, NOT a wrapper, local copy or cache. # - The handle instances are really just a slim handle for a remote resource, NOT a wrapper, local copy or cache.
# They should not cache or store anything that might change remotely. # They should not cache or store anything that might change remotely.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment