How to use _iterencode_dict method in autotest

Best Python code snippet using autotest_python

AllRefJSONEncoder.py

Source:AllRefJSONEncoder.py Github

copy

Full Screen

...117 if k not in self.vec_ref_cnt or self.vec_ref_cnt[k] <= 1:118 yield from _iterencode_list(lst, _current_indent_level)119 elif k in self.vec_ref_serialized:120 converted = { "$ref": str(self.vec_ref_serialized[k]) }121 yield from _iterencode_dict(converted, _current_indent_level)122 elif self.vec_ref_cnt[k] > 1:123 self.ref_id += 1124 self.vec_ref_serialized[k] = self.ref_id125 converted = OrderedDict()126 converted["$id"] = str(self.ref_id)127 converted["$values"] = lst128 yield from _iterencode_dict(converted, _current_indent_level, reduce_level=True)129 else:130 raise Exception("Unhandled obj in _iterencode_list_ref")131 132 def _iterencode_dict_ref(dct, _current_indent_level):133 k = to_hashable(dct)134 if k not in self.dict_ref_cnt or self.dict_ref_cnt[k] <= 1:135 yield from _iterencode_dict(dct, _current_indent_level)136 elif k in self.dict_ref_serialized:137 converted = { "$ref": str(self.dict_ref_serialized[k]) }138 yield from _iterencode_dict(converted, _current_indent_level)139 elif self.dict_ref_cnt[k] > 1:140 self.ref_id += 1141 self.dict_ref_serialized[k] = self.ref_id142 converted = OrderedDict()143 converted["$id"] = str(self.ref_id)144 converted["$values"] = dct145 yield from _iterencode_dict(converted, _current_indent_level, reduce_level=True)146 else:147 raise Exception("Unhandled obj in _iterencode_dict_ref")148 149 def _iterencode_cls_ref(cls, _current_indent_level):150 if not hashable(cls) or cls not in self.cls_ref_cnt or self.cls_ref_cnt[cls] <= 1:151 converted = self._cls_to_dict(cls, skip_none_fields=AllRefJSONEncoder.skip_none_fields,152 serialize_only_annotated=AllRefJSONEncoder.serialize_only_annotated)153 yield from _iterencode_dict(converted, _current_indent_level)154 elif cls in self.cls_ref_serialized:155 converted = { "$ref": str(self.cls_ref_serialized[cls]) }156 yield from _iterencode_dict(converted, _current_indent_level)157 elif self.cls_ref_cnt[cls] > 1:158 self.ref_id += 1159 self.cls_ref_serialized[cls] = self.ref_id160 converted = OrderedDict()161 converted["$id"] = str(self.ref_id)162 converted = self._cls_to_dict(cls, skip_none_fields=AllRefJSONEncoder.skip_none_fields, 163 serialize_only_annotated=AllRefJSONEncoder.serialize_only_annotated, dct=converted)164 yield from _iterencode_dict(converted, _current_indent_level)165 else:166 raise Exception("Unhandled custom class obj in _iterencode_cls_ref")167 def _iterencode_list(lst, _current_indent_level, reduce_level=False):168 if not lst:169 yield '[]'170 return171 if markers is not None:172 markerid = id(lst)173 if markerid in markers:174 raise ValueError("Circular reference detected")175 markers[markerid] = lst176 buf = '['177 if _indent is not None:178 _current_indent_level += 1179 newline_indent = '\n' + _indent * _current_indent_level180 separator = _item_separator + newline_indent181 buf += newline_indent182 else:183 newline_indent = None184 separator = _item_separator185 first = True186 for value in lst:187 if first:188 first = False189 else:190 buf = separator191 if isinstance(value, str):192 yield buf + _encoder(value)193 elif value is None:194 yield buf + 'null'195 elif value is True:196 yield buf + 'true'197 elif value is False:198 yield buf + 'false'199 elif isinstance(value, int):200 # Subclasses of int/float may override __str__, but we still201 # want to encode them as integers/floats in JSON. One example202 # within the standard library is IntEnum.203 yield buf + _intstr(value)204 elif isinstance(value, float):205 # see comment above for int206 yield buf + _floatstr(value)207 else:208 yield buf209 if reduce_level and isinstance(value, (list, tuple)):210 chunks = _iterencode_list(value, _current_indent_level)211 elif reduce_level and isinstance(value, dict):212 chunks = _iterencode_dict(value, _current_indent_level)213 else:214 chunks = _iterencode(value, _current_indent_level)215 yield from chunks216 if newline_indent is not None:217 _current_indent_level -= 1218 yield '\n' + _indent * _current_indent_level219 yield ']'220 if markers is not None:221 del markers[markerid]222 def _iterencode_dict(dct, _current_indent_level, reduce_level=False):223 if not dct:224 yield '{}'225 return226 if markers is not None:227 markerid = id(dct)228 if markerid in markers:229 raise ValueError("Circular reference detected")230 markers[markerid] = dct231 yield '{'232 if _indent is not None:233 _current_indent_level += 1234 newline_indent = '\n' + _indent * _current_indent_level235 item_separator = _item_separator + newline_indent236 yield newline_indent237 else:238 newline_indent = None239 item_separator = _item_separator240 first = True241 if _sort_keys:242 items = sorted(dct.items(), key=lambda kv: kv[0])243 else:244 items = dct.items()245 for key, value in items:246 if isinstance(key, str):247 pass248 # JavaScript is weakly typed for these, so it makes sense to249 # also allow them. Many encoders seem to do something like this.250 elif isinstance(key, float):251 # see comment for int/float in _make_iterencode252 key = _floatstr(key)253 elif key is True:254 key = 'true'255 elif key is False:256 key = 'false'257 elif key is None:258 key = 'null'259 elif isinstance(key, int):260 # see comment for int/float in _make_iterencode261 key = _intstr(key)262 elif _skipkeys:263 continue264 else:265 raise TypeError(f'keys must be str, int, float, bool or None, '266 f'not {key.__class__.__name__}')267 if first:268 first = False269 else:270 yield item_separator271 yield _encoder(key)272 yield _key_separator273 if isinstance(value, str):274 yield _encoder(value)275 elif value is None:276 yield 'null'277 elif value is True:278 yield 'true'279 elif value is False:280 yield 'false'281 elif isinstance(value, int):282 # see comment for int/float in _make_iterencode283 yield _intstr(value)284 elif isinstance(value, float):285 # see comment for int/float in _make_iterencode286 yield _floatstr(value)287 else:288 if reduce_level and isinstance(value, (list, tuple)):289 chunks = _iterencode_list(value, _current_indent_level)290 elif reduce_level and isinstance(value, dict):291 chunks = _iterencode_dict(value, _current_indent_level)292 else:293 chunks = _iterencode(value, _current_indent_level)294 yield from chunks295 if newline_indent is not None:296 _current_indent_level -= 1297 yield '\n' + _indent * _current_indent_level298 yield '}'299 if markers is not None:300 del markers[markerid]301 def _iterencode(o, _current_indent_level):302 if isinstance(o, str):303 yield _encoder(o)304 elif o is None:305 yield 'null'...

Full Screen

Full Screen

_json.py

Source:_json.py Github

copy

Full Screen

...73 yield buf74 if isinstance(value, (list, tuple)):75 chunks = _iterencode_list(value, _current_indent_level)76 elif isinstance(value, dict):77 chunks = _iterencode_dict(value, _current_indent_level)78 else:79 chunks = _iterencode(value, _current_indent_level)80 for chunk in chunks:81 yield chunk82 if newline_indent is not None:83 _current_indent_level -= 184 yield '\n' + _indent * _current_indent_level85 yield ']'86 if markers is not None:87 del markers[markerid]88 def _iterencode_dict(dct, _current_indent_level):89 if not dct:90 yield '{}'91 return92 if markers is not None:93 markerid = id(dct)94 if markerid in markers:95 raise ValueError("Circular reference detected")96 markers[markerid] = dct97 yield '{'98 if _indent is not None:99 _current_indent_level += 1100 newline_indent = '\n' + _indent * _current_indent_level101 item_separator = _item_separator + newline_indent102 yield newline_indent103 else:104 newline_indent = None105 item_separator = _item_separator106 first = True107 if _sort_keys:108 items = sorted(dct.items(), key=lambda kv: kv[0])109 else:110 items = dct.items()111 for key, value in items:112 if isinstance(key, str):113 pass114 # JavaScript is weakly typed for these, so it makes sense to115 # also allow them. Many encoders seem to do something like this.116 elif isinstance(key, float):117 key = _floatstr(key)118 elif key is True:119 key = 'true'120 elif key is False:121 key = 'false'122 elif key is None:123 key = 'null'124 elif isinstance(key, int):125 key = str(key)126 elif _skipkeys:127 continue128 else:129 raise TypeError("key " + repr(key) + " is not a string")130 if first:131 first = False132 else:133 yield item_separator134 yield _encoder(key)135 yield _key_separator136 if isinstance(value, str):137 yield _encoder(value)138 elif value is None:139 yield 'null'140 elif value is True:141 yield 'true'142 elif value is False:143 yield 'false'144 elif isinstance(value, int):145 yield str(value)146 elif isinstance(value, float):147 yield _floatstr(value)148 else:149 if isinstance(value, (list, tuple)):150 chunks = _iterencode_list(value, _current_indent_level)151 elif isinstance(value, dict):152 chunks = _iterencode_dict(value, _current_indent_level)153 else:154 chunks = _iterencode(value, _current_indent_level)155 for chunk in chunks:156 yield chunk157 if newline_indent is not None:158 _current_indent_level -= 1159 yield '\n' + _indent * _current_indent_level160 yield '}'161 if markers is not None:162 del markers[markerid]163 def _iterencode(o, _current_indent_level):164 if isinstance(o, str):165 yield _encoder(o)166 elif o is None:167 yield 'null'168 elif o is True:169 yield 'true'170 elif o is False:171 yield 'false'172 elif isinstance(o, int):173 yield str(o)174 elif isinstance(o, float):175 yield _floatstr(o)176 elif isinstance(o, (list, tuple)):177 for chunk in _iterencode_list(o, _current_indent_level):178 yield chunk179 elif isinstance(o, dict):180 for chunk in _iterencode_dict(o, _current_indent_level):181 yield chunk182 else:183 if markers is not None:184 markerid = id(o)185 if markerid in markers:186 raise ValueError("Circular reference detected")187 markers[markerid] = o188 o = _default(o)189 for chunk in _iterencode(o, _current_indent_level):190 yield chunk191 if markers is not None:192 del markers[markerid]193 return _iterencode194# override the encoder...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful