MCPcopy Create free account
hub / github.com/simplejson/simplejson / floatstr

Method floatstr

simplejson/encoder.py:345–370  ·  view source on GitHub ↗
(o, allow_nan=self.allow_nan, ignore_nan=self.ignore_nan,
                _repr=FLOAT_REPR, _inf=PosInf, _neginf=-PosInf)

Source from the content-addressed store, hash-verified

343 return _orig_encoder(o)
344
345 def floatstr(o, allow_nan=self.allow_nan, ignore_nan=self.ignore_nan,
346 _repr=FLOAT_REPR, _inf=PosInf, _neginf=-PosInf):
347 # Check for specials. Note that this type of test is processor
348 # and/or platform-specific, so do tests which don't depend on
349 # the internals.
350
351 if o != o:
352 text = 'NaN'
353 elif o == _inf:
354 text = 'Infinity'
355 elif o == _neginf:
356 text = '-Infinity'
357 else:
358 if type(o) != float:
359 # See #118, do not trust custom str/repr
360 o = float(o)
361 return _repr(o)
362
363 if ignore_nan:
364 text = 'null'
365 elif not allow_nan:
366 raise ValueError(
367 "Out of range float values are not JSON compliant: " +
368 repr(o))
369
370 return text
371
372 key_memo = {}
373 int_as_string_bitcount = (

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected