MCPcopy Index your code
hub / github.com/clips/pattern / iterencode

Method iterencode

pattern/web/json/encoder.py:245–313  ·  view source on GitHub ↗

Encode the given object and yield each string representation as available. For example:: for chunk in JSONEncoder().iterencode(bigobject): mysocket.write(chunk)

(self, o, _one_shot=False)

Source from the content-addressed store, hash-verified

243 return u''.join(chunks)
244
245 def iterencode(self, o, _one_shot=False):
246 """Encode the given object and yield each string
247 representation as available.
248
249 For example::
250
251 for chunk in JSONEncoder().iterencode(bigobject):
252 mysocket.write(chunk)
253
254 """
255 if self.check_circular:
256 markers = {}
257 else:
258 markers = None
259 if self.ensure_ascii:
260 _encoder = encode_basestring_ascii
261 else:
262 _encoder = encode_basestring
263 if self.encoding != 'utf-8':
264 def _encoder(o, _orig_encoder=_encoder, _encoding=self.encoding):
265 if isinstance(o, str):
266 o = o.decode(_encoding)
267 return _orig_encoder(o)
268
269 def floatstr(o, allow_nan=self.allow_nan,
270 _repr=FLOAT_REPR, _inf=PosInf, _neginf=-PosInf):
271 # Check for specials. Note that this type of test is processor
272 # and/or platform-specific, so do tests which don't depend on
273 # the internals.
274
275 if o != o:
276 text = 'NaN'
277 elif o == _inf:
278 text = 'Infinity'
279 elif o == _neginf:
280 text = '-Infinity'
281 else:
282 return _repr(o)
283
284 if not allow_nan:
285 raise ValueError(
286 "Out of range float values are not JSON compliant: " +
287 repr(o))
288
289 return text
290
291
292 key_memo = {}
293 if (_one_shot and c_make_encoder is not None
294 and self.indent is None):
295 _iterencode = c_make_encoder(
296 markers, self.default, _encoder, self.indent,
297 self.key_separator, self.item_separator, self.sort_keys,
298 self.skipkeys, self.allow_nan, key_memo, self.use_decimal,
299 self.namedtuple_as_object, self.tuple_as_array,
300 self.bigint_as_string, self.item_sort_key,
301 Decimal)
302 else:

Callers 3

encodeMethod · 0.95
dumpFunction · 0.45
iterencodeMethod · 0.45

Calls 3

_make_iterencodeFunction · 0.85
_iterencodeFunction · 0.85
clearMethod · 0.45

Tested by

no test coverage detected