Skip to content

Commit

Permalink
patches
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed May 30, 2022
1 parent 3edac60 commit 6b846b6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions osparc/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,11 @@ def __deserialize(self, data, klass):
# convert str to class
if klass in self.NATIVE_TYPES_MAPPING:
klass = self.NATIVE_TYPES_MAPPING[klass]
# PATCH ----------------------
elif klass.startswith("AnyOf"):
from .models._any_of import deserialize_any_of
return deserialize_any_of(data, self.__deserialize)
# PATCH ----------------------
else:
klass = getattr(osparc.models, klass)

Expand Down Expand Up @@ -555,14 +557,14 @@ def __deserialize_file(self, response):
filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?',
content_disposition).group(1)
path = os.path.join(os.path.dirname(path), filename)

# PATCH -----------------
try:
with open(path, "w") as f:
f.write(response.data)
except TypeError:
with open(path, "wb") as f:
f.write(response.data)

# PATCH -----------------
return path

def __deserialize_primitive(self, data, klass):
Expand Down
3 changes: 2 additions & 1 deletion osparc/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ class Configuration(object):
)
)
"""

# PATCH ----------
def __init__(self, host="https://api.osparc.io",
api_key=None, api_key_prefix=None,
username=None, password=None,
signing_info=None):
# PATCH ----------
"""Constructor
"""
self.host = host
Expand Down
4 changes: 2 additions & 2 deletions osparc/models/_any_of.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

from .file import File

AnyOfFilenumberintegerstring = Union[File, float, int, str]
AnyOfFilenumberintegerbooleanstring = Union[File, float, int, bool, str]

def deserialize_any_of(
data: Any,
deserialize_func: Callable,
):
for klass in [File, float, int, str]:
for klass in [File, float, int, bool, str]:
with suppress(Exception):
return deserialize_func(data, klass)
raise ValueError(f"Cannot deserialize {data}")
2 changes: 2 additions & 0 deletions osparc/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,13 @@ def request(self, method, url, query_params=None, headers=None,
# In the python 3, the response.data is bytes.
# we need to decode it to string.
if six.PY3:
# PATCH-------------------------------------
try:
r.data = r.data.decode('utf8')
except UnicodeDecodeError:
# NOTE: hdf5 files cannot be decoded
pass
# PATCH-------------------------------------

if not 200 <= r.status <= 299:
raise ApiException(http_resp=r)
Expand Down

0 comments on commit 6b846b6

Please sign in to comment.