Skip to content

Commit

Permalink
rewrite uri as static method (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssssarah authored and MFSY committed Jul 5, 2024
1 parent 7e3844b commit 7848a54
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions kgforge/specializations/stores/bluebrain_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -1311,16 +1311,17 @@ def _initialize_service(
**params,
)

def rewrite_uri(self, uri: str, context: Context, **kwargs) -> str:
@staticmethod
def rewrite_uri_static(endpoint: str, bucket: str, uri: str, context: Context, **kwargs) -> str:
is_file = kwargs.get("is_file", True)
encoding = kwargs.get("encoding", None)

# try decoding the url first
raw_url = unquote(uri)
if is_file: # for files
url_base = "/".join([self.endpoint, "files", self.bucket])
url_base = "/".join([endpoint, "files", bucket])
else: # for resources
url_base = "/".join([self.endpoint, "resources", self.bucket])
url_base = "/".join([endpoint, "resources", bucket])
matches = re.match(r"[\w\.:%/-]+/(\w+):(\w+)/[\w\.-/:%]+", raw_url)
if matches:
groups = matches.groups()
Expand Down Expand Up @@ -1361,5 +1362,8 @@ def rewrite_uri(self, uri: str, context: Context, **kwargs) -> str:
uri = "/".join((url_base, quote_plus(url, encoding=encoding)))
return uri

def rewrite_uri(self, uri: str, context: Context, **kwargs) -> str:
return BlueBrainNexus.rewrite_uri_static(self.endpoint, self.bucket, uri, context, **kwargs)

def _freeze_many(self, resources: List[Resource]) -> None:
raise not_supported()

0 comments on commit 7848a54

Please sign in to comment.