MCPcopy
hub / github.com/django/django / default

Method default

django/core/serializers/json.py:90–113  ·  view source on GitHub ↗
(self, o)

Source from the content-addressed store, hash-verified

88 """
89
90 def default(self, o):
91 # See "Date Time String Format" in the ECMA-262 specification.
92 if isinstance(o, datetime.datetime):
93 r = o.isoformat()
94 if o.microsecond:
95 r = r[:23] + r[26:]
96 if r.endswith("+00:00"):
97 r = r.removesuffix("+00:00") + "Z"
98 return r
99 elif isinstance(o, datetime.date):
100 return o.isoformat()
101 elif isinstance(o, datetime.time):
102 if is_aware(o):
103 raise ValueError("JSON can't represent timezone-aware times.")
104 r = o.isoformat()
105 if o.microsecond:
106 r = r[:12]
107 return r
108 elif isinstance(o, datetime.timedelta):
109 return duration_iso_string(o)
110 elif isinstance(o, (decimal.Decimal, uuid.UUID, Promise)):
111 return str(o)
112 else:
113 return super().default(o)

Callers

nothing calls this directly

Calls 2

is_awareFunction · 0.90
duration_iso_stringFunction · 0.90

Tested by

no test coverage detected