Skip to content

Commit

Permalink
improved
Browse files Browse the repository at this point in the history
  • Loading branch information
JungeWerther committed Jun 13, 2024
1 parent d05f362 commit 6cdb027
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _request(self,
debug=False,
) -> dict | str | list:
"""send a request with the specified parameters
TODO: implement POST, PUT methods.
(TODO) Currently only GET and POST are implemented.
"""

print("Requesting:", url)
Expand Down Expand Up @@ -239,23 +239,26 @@ def new_session(self, auth, headers):
setattr(self.config, "session", s)
return s

def _fromFile(self, path):
"""Read a file and return its contents as a json object. Disabled in production."""
try:
with open(path, "r") as f:
obj = json.loads(f.read())
if self.debug: print("Reading:", path)
except:
if path is not None:
raise ValueError("Unable to read file:", path)
else:
raise SyntaxError("'path' undefined")

return obj

def _test(self, base_url, rel_url="") -> str:
"""Test function. Can you pass base_url and rel_url to get url?"""
url = base_url + rel_url
# def _fromFile(self, path):
# """Read a file and return its contents as a json object. Disabled in production."""
# try:
# with open(path, "r") as f:
# obj = json.loads(f.read())
# if self.debug: print("Reading:", path)
# except:
# if path is not None:
# raise ValueError("Unable to read file:", path)
# else:
# raise SyntaxError("'path' undefined")

# return obj

def _combine(self, base: str, end: str="") -> str:
"""Concatenates base(url) and append an end(url). Example:\n\n
base = "https://api.com/" and end = ["users", "1"]. Then it will return
"https://api.com/users" and "https://api.com/1"
"""
url = str(base) + str(end)
return url

class Config():
Expand Down

0 comments on commit 6cdb027

Please sign in to comment.