How to use _iterencode_list method in autotest

Best Python code snippet using autotest_python

_json.py

Source:_json.py Github

copy

Full Screen

...29 # Override the function30 _floatstr = _json_floatstr31 if _indent is not None and not isinstance(_indent, str):32 _indent = ' ' * _indent33 def _iterencode_list(lst, _current_indent_level):34 if not lst:35 yield '[]'36 return37 if markers is not None:38 markerid = id(lst)39 if markerid in markers:40 raise ValueError("Circular reference detected")41 markers[markerid] = lst42 buf = '['43 ## @THREEJS44 # - block the moronic functionality that puts each45 # index on its own line causing insane row counts46 #if _indent is not None:47 # _current_indent_level += 148 # newline_indent = '\n' + _indent * _current_indent_level49 # separator = _item_separator + newline_indent50 # buf += newline_indent51 #else:52 newline_indent = None53 separator = _item_separator54 first = True55 for value in lst:56 if first:57 first = False58 else:59 buf = separator60 if isinstance(value, str):61 yield buf + _encoder(value)62 elif value is None:63 yield buf + 'null'64 elif value is True:65 yield buf + 'true'66 elif value is False:67 yield buf + 'false'68 elif isinstance(value, int):69 yield buf + str(value)70 elif isinstance(value, float):71 yield buf + _floatstr(value)72 else: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:...

Full Screen

Full Screen

json.py

Source:json.py Github

copy

Full Screen

...33 flat_list_extend = flat_list.extend # a tiny bit faster34 for t in list_of_tuples:35 flat_list_extend(t)36 return flat_list37 def _iterencode_list(l, level):38 '''39 '''40 if not l:41 yield '[]'42 return43 if markers is not None:44 markerid = id(l)45 if markerid in markers:46 raise ValueError("Circular reference detected")47 markers[markerid] = l48 buf = '['49 newline_indent = None50 separator = _item_separator51 first = True52 for value in l:53 if first:54 first = False55 else:56 buf = separator57 if isinstance(value, str):58 yield buf + _encoder(value)59 elif value is None:60 yield buf + 'null'61 elif value is True:62 yield buf + 'true'63 elif value is False:64 yield buf + 'false'65 elif isinstance(value, int):66 yield buf + str(value)67 elif isinstance(value, float):68 yield buf + _float_str(value)69 else:70 yield buf71 if isinstance(value, list):72 chunks = _iterencode_list(value, level)73 elif isinstance(value, dict):74 chunks = _iterencode_dict(value, level)75 else:76 chunks = _iterencode(value, level)77 for chunk in chunks:78 yield chunk79 if newline_indent is not None:80 level -= 181 yield '\n' + _indent * level82 yield ']'83 if markers is not None:84 del markers[markerid]85 def _iterencode_dict(d, level):86 # if not d:87 # yield '{}'88 # return89 if markers is not None:90 markerid = id(d)91 if markerid in markers:92 raise ValueError("Circular reference detected")93 markers[markerid] = d94 yield '{'95 if _indent is not None:96 level += 197 newline_indent = '\n' + _indent * level98 item_separator = _item_separator + newline_indent99 yield newline_indent100 else:101 newline_indent = None102 item_separator = _item_separator103 first = True104 if _sort_keys:105 items = sorted(d.items(), key=lambda kv: kv[0])106 else:107 items = d.items()108 for key, value in items:109 # if not key:110 # continue111 if isinstance(value, dict) and not value:112 continue113 if isinstance(value, list) and len(value) == 0:114 continue115 elif isinstance(key, str):116 pass117 elif isinstance(key, float):118 key = _float_str(key)119 elif key is True:120 key = 'true'121 elif key is False:122 key = 'false'123 elif key is None:124 key = 'null'125 elif isinstance(key, int):126 key = str(key)127 elif _skipkeys:128 continue129 else:130 raise TypeError("key " + repr(key) + " is not a string")131 if first:132 first = False133 else:134 yield item_separator135 yield _encoder(key)136 yield _key_separator137 if isinstance(value, str):138 yield _encoder(value)139 # elif value is None:140 # yield 'null'141 elif value is True:142 yield 'true'143 elif value is False:144 yield 'false'145 elif isinstance(value, int):146 yield str(value)147 elif isinstance(value, float):148 yield _float_str(value)149 else:150 if isinstance(value, list):151 chunks = _iterencode_list(value, level)152 elif isinstance(value, dict):153 chunks = _iterencode_dict(value, level)154 else:155 chunks = _iterencode(value, level)156 for chunk in chunks:157 yield chunk158 if newline_indent is not None:159 level -= 1160 yield '\n' + _indent * level161 yield '}'162 if markers is not None:163 del markers[markerid]164 def _iterencode(o, level):165 if isinstance(o, str):166 yield _encoder(o)167 elif o is None:168 yield 'null'169 elif o is True:170 yield 'true'171 elif o is False:172 yield 'false'173 elif isinstance(o, int):174 yield str(o)175 elif isinstance(o, float):176 yield _float_str(o)177 elif isinstance(o, list):178 for chunk in _iterencode_list(o, level):179 yield chunk180 elif isinstance(o, dict):181 for chunk in _iterencode_dict(o, level):182 yield chunk183 elif isinstance(o, UUID):184 yield _encoder(str(o))185 elif isinstance(o, Matrix):186 for chunk in _iterencode_list(_matrix_list(o), level):187 yield chunk188 else:189 if markers is not None:190 markerid = id(o)191 if markerid in markers:192 raise ValueError("Circular reference detected")193 markers[markerid] = o194 o = _default(o)195 for chunk in _iterencode(o, level):196 yield chunk197 if markers is not None:198 del markers[markerid]199 if _indent is not None and not isinstance(_indent, str):200 _indent = ' ' * _indent...

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