Skip to content

Commit

Permalink
fixed objectify, thanks Al Ex
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed Nov 18, 2024
1 parent dce2004 commit 3b4d7d1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions py4web/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,12 @@ def memoized_func(*args, **kwargs):

def objectify(obj): # pylint: disable=too-many-return-statements
"""converts the obj(ect) into a json serializable object"""
if hasattr(obj, "isoformat"):
return obj.isoformat().replace("T", " ")
if isinstance(obj, numbers.Integral):
return int(obj)
if isinstance(obj, (numbers.Rational, numbers.Real)):
return float(obj)
if isinstance(obj, (datetime.date, datetime.datetime, datetime.time)):
return obj.isoformat().replace("T", " ")
if isinstance(obj, str):
return obj
if isinstance(obj, dict):
Expand All @@ -310,7 +310,7 @@ def objectify(obj): # pylint: disable=too-many-return-statements
return obj.as_list()
if hasattr(obj, "as_dict"):
return obj.as_dict()
if hasattr(obj, "__iter__") or isinstance(obj, types.GeneratorType):
if isinstance(obj, (list, set, types.GeneratorType)):
return list(obj)
if hasattr(obj, "xml"):
return obj.xml()
Expand Down

0 comments on commit 3b4d7d1

Please sign in to comment.