Skip to content

Commit

Permalink
minor tweaks to portal_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed Jan 7, 2024
1 parent f2c543e commit 0abc046
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions dcicutils/portal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,10 @@ def normalize_server(server: str) -> Optional[str]:
elif (isinstance(env, str) and env) or (isinstance(server, str) and server):
init_from_env_server_app(env, server, app, unspecified=[arg])
else:
raise Exception("Portal init error; invalid args.")
raise Exception("Portal init error; insufficient args.")
self._app = app
if not self.vapp and not self.key:
raise Exception("Portal init error; neither key nor vapp defined.")

@property
def ini_file(self) -> Optional[str]:
Expand Down Expand Up @@ -235,6 +237,9 @@ def patch(self, url: str, data: Optional[dict] = None, json: Optional[dict] = No
def post(self, url: str, data: Optional[dict] = None, json: Optional[dict] = None, files: Optional[dict] = None,
raise_for_status: bool = False, **kwargs) -> OptionalResponse:
url = self.url(url)
if files and not ("headers" in kwargs):
# Setting headers to None when using files implies content-type multipart/form-data.
kwargs["headers"] = None
if not self.vapp:
response = requests.post(url, data=data, json=json, files=files, **self._kwargs(**kwargs))
else:
Expand Down Expand Up @@ -353,8 +358,10 @@ def url(self, url: str) -> str:
return self.server + url if self.server else url

def _kwargs(self, **kwargs) -> dict:
result_kwargs = {"headers": kwargs.get("headers", {"Content-type": Portal.MIME_TYPE_JSON,
"Accept": Portal.MIME_TYPE_JSON})}
if "headers" in kwargs:
result_kwargs = {"headers": kwargs["headers"]}
else:
result_kwargs = {"headers": {"Content-type": Portal.MIME_TYPE_JSON, "Accept": Portal.MIME_TYPE_JSON}}
if self.key_pair:
result_kwargs["auth"] = self.key_pair
if isinstance(timeout := kwargs.get("timeout"), int):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcicutils"
version = "8.7.0.1b15" # TODO: To become 8.7.1
version = "8.7.0.1b16" # TODO: To become 8.7.1
description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources"
authors = ["4DN-DCIC Team <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 0abc046

Please sign in to comment.