@@ -167,7 +167,7 @@ def get(self, name, separator="||", parse_index="$", _isDebug_=True):
167167 if type (self .getObject ()) in [list , dict , OrderedDict ]:
168168 try :
169169 Jobj = self .__Jobj
170- Jval = "JSON_DUPLICATE_KEYS_NOT_FOUND "
170+ Jval = "JSON_DUPLICATE_KEYS_ERROR "
171171 name_split = name .split (separator )
172172
173173 for i in range (len (name_split )):
@@ -179,14 +179,14 @@ def get(self, name, separator="||", parse_index="$", _isDebug_=True):
179179 Jobj = Jobj [int (name_split [i ].split (parse_index )[1 ])]
180180 else :
181181 if _isDebug_ : print ("\x1b [31m[-] KeyNotFoundError: \x1b [0m" + separator .join (name_split [:i + 1 ]))
182- return "JSON_DUPLICATE_KEYS_NOT_FOUND "
182+ return "JSON_DUPLICATE_KEYS_ERROR "
183183 return Jval
184184 except Exception as e :
185185 if _isDebug_ : print ("\x1b [31m[-] ExceptionError: {}\x1b [0m" .format (e ))
186- return "JSON_DUPLICATE_KEYS_NOT_FOUND "
186+ return "JSON_DUPLICATE_KEYS_ERROR "
187187 else :
188188 if _isDebug_ : print ("\x1b [31m[-] DataTypeError: the JSON object must be list, dict or OrderedDict, not {}\x1b [0m" .format (type (self .getObject ())))
189- return "JSON_DUPLICATE_KEYS_NOT_FOUND "
189+ return "JSON_DUPLICATE_KEYS_ERROR "
190190 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
191191 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
192192 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
@@ -206,7 +206,7 @@ def get(self, name, separator="||", parse_index="$", _isDebug_=True):
206206 # name_split_current = name_split[i-1]
207207 # name_split_last = separator.join(name_split[i:])
208208
209- # if self.get(separator.join([name_split_first, name_split_current]), separator=separator, parse_index=parse_index, _isDebug_=False) != "JSON_DUPLICATE_KEYS_NOT_FOUND ":
209+ # if self.get(separator.join([name_split_first, name_split_current]), separator=separator, parse_index=parse_index, _isDebug_=False) != "JSON_DUPLICATE_KEYS_ERROR ":
210210 # if re.search("^"+re.escape(parse_index)+"\d+"+re.escape(parse_index)+"$", name_split_current):
211211 # k = separator.join([ name_split_first, parse_index+str(len(self.get(name_split_first, separator=separator, parse_index=parse_index, _isDebug_=False)))+parse_index, separator.join([re.sub("^"+re.escape(parse_index)+"\d+"+re.escape(parse_index)+"$",parse_index+"0"+parse_index, ns) for ns in name_split_last.split(separator)]) ])
212212 # self.flatten()
@@ -215,7 +215,7 @@ def get(self, name, separator="||", parse_index="$", _isDebug_=True):
215215 # else:
216216 # i = 2
217217 # while True:
218- # if self.get(separator.join(name_split_first, name_split_current)+dupSign_start+"_"+str(i)+"_"+dupSign_end, separator=separator, parse_index=parse_index, _isDebug_=False) == "JSON_DUPLICATE_KEYS_NOT_FOUND ":
218+ # if self.get(separator.join(name_split_first, name_split_current)+dupSign_start+"_"+str(i)+"_"+dupSign_end, separator=separator, parse_index=parse_index, _isDebug_=False) == "JSON_DUPLICATE_KEYS_ERROR ":
219219 # self.flatten()
220220 # self.__Jobj[separator.join([separator.join(name_split_first, name_split_current)+dupSign_start+"_"+str(i)+"_"+dupSign_end]), separator.join([re.sub("^"+re.escape(parse_index)+"\d+"+re.escape(parse_index)+"$",parse_index+"0"+parse_index, ns) for ns in name_split_last.split(separator)])] = value
221221 # self.unflatten()
@@ -233,7 +233,7 @@ def get(self, name, separator="||", parse_index="$", _isDebug_=True):
233233 def update (self , name , value , separator = "||" , parse_index = "$" , _isDebug_ = True ):
234234 import re
235235
236- if self .get (name , separator = separator , parse_index = parse_index , _isDebug_ = _isDebug_ ) != "JSON_DUPLICATE_KEYS_NOT_FOUND " :
236+ if self .get (name , separator = separator , parse_index = parse_index , _isDebug_ = _isDebug_ ) != "JSON_DUPLICATE_KEYS_ERROR " :
237237 try :
238238 exec_expression = "self.getObject()"
239239
@@ -257,7 +257,7 @@ def update(self, name, value, separator="||", parse_index="$", _isDebug_=True):
257257 def delete (self , name , separator = "||" , parse_index = "$" , _isDebug_ = True ):
258258 import re
259259
260- if self .get (name , separator = separator , parse_index = parse_index , _isDebug_ = _isDebug_ ) != "JSON_DUPLICATE_KEYS_NOT_FOUND " :
260+ if self .get (name , separator = separator , parse_index = parse_index , _isDebug_ = _isDebug_ ) != "JSON_DUPLICATE_KEYS_ERROR " :
261261 try :
262262 exec_expression = "del self.getObject()"
263263
@@ -275,47 +275,54 @@ def delete(self, name, separator="||", parse_index="$", _isDebug_=True):
275275 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
276276
277277
278- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
279- # # # # # # # # # # # # # # # dumps # # # # # # # # # # # # # #
280- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
281- # def dumps(self, dupSign_start="{{{", dupSign_end="}}}", skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, default=None, sort_keys=False):
282- # import json, re
283- # from collections import OrderedDict
278+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
279+ # # # # # # # # # # # # # # dumps # # # # # # # # # # # # # #
280+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
281+ def dumps (self , dupSign_start = "{{{" , dupSign_end = "}}}" , _isDebug_ = True , skipkeys = False , ensure_ascii = True , check_circular = True , allow_nan = True , cls = None , indent = None , separators = None , default = None , sort_keys = False ):
282+ import json , re
283+ from collections import OrderedDict
284284
285- # try:
286- # if type(dupSign_start) not in [str, unicode]: dupSign_start = "{{{"
287- # except Exception as e:
288- # if type(dupSign_start) != str: dupSign_start = "{{{"
285+ if type (self .getObject ()) in [list , dict , OrderedDict ]:
286+ try :
287+ if type (dupSign_start ) not in [str , unicode ]: dupSign_start = "{{{"
288+ except Exception as e :
289+ if type (dupSign_start ) != str : dupSign_start = "{{{"
289290
290- # dupSign_start_escape_regex = re.escape(json.dumps({dupSign_start:""})[2:-6])
291+ dupSign_start_escape_regex = re .escape (json .dumps ({dupSign_start :"" })[2 :- 6 ])
291292
292293
293- # try:
294- # if type(dupSign_end) not in [str, unicode]: dupSign_end = "}}}"
295- # except Exception as e:
296- # if type(dupSign_end) != str: dupSign_end = "}}}"
294+ try :
295+ if type (dupSign_end ) not in [str , unicode ]: dupSign_end = "}}}"
296+ except Exception as e :
297+ if type (dupSign_end ) != str : dupSign_end = "}}}"
297298
298- # dupSign_end_escape_regex = re.escape(json.dumps({dupSign_end:""})[2:-6])
299+ dupSign_end_escape_regex = re .escape (json .dumps ({dupSign_end :"" })[2 :- 6 ])
299300
300301
301- # return re.sub(r'{dupSign_start}_\d+_{dupSign_end}":'.format(dupSign_start=dupSign_start_escape_regex, dupSign_end=dupSign_end_escape_regex), '":', json.dumps(self.__Jobj, skipkeys=skipkeys, ensure_ascii=ensure_ascii, check_circular=check_circular, allow_nan=allow_nan, cls=cls, indent=indent, separators=separators, default=default, sort_keys=sort_keys))
302- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
303- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
304- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
302+ return re .sub (r'{dupSign_start}_\d+_{dupSign_end}":' .format (dupSign_start = dupSign_start_escape_regex , dupSign_end = dupSign_end_escape_regex ), '":' , json .dumps (self .getObject (), skipkeys = skipkeys , ensure_ascii = ensure_ascii , check_circular = check_circular , allow_nan = allow_nan , cls = cls , indent = indent , separators = separators , default = default , sort_keys = sort_keys ))
303+ else :
304+ if _isDebug_ : print ("\x1b [31m[-] DataTypeError: the JSON object must be list, dict or OrderedDict, not {}\x1b [0m" .format (type (self .getObject ())))
305+ return "JSON_DUPLICATE_KEYS_ERROR"
306+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
307+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
308+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
305309
306310
307- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
308- # # # # # # # # # # # # # # # dump # # # # # # # # # # # # # #
309- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
310- # def dump(self, Jfilepath, dupSign_start="{{{", dupSign_end="}}}", skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, default=None, sort_keys=False):
311- # Jstr = self.dumps(dupSign_start=dupSign_start, dupSign_end=dupSign_end, skipkeys=skipkeys, ensure_ascii=ensure_ascii, check_circular=check_circular, allow_nan=allow_nan, cls=cls, indent=indent, separators=separators, default=default, sort_keys=sort_keys)
311+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
312+ # # # # # # # # # # # # # # dump # # # # # # # # # # # # # #
313+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
314+ def dump (self , Jfilepath , dupSign_start = "{{{" , dupSign_end = "}}}" , _isDebug_ = True , skipkeys = False , ensure_ascii = True , check_circular = True , allow_nan = True , cls = None , indent = None , separators = None , default = None , sort_keys = False ):
315+ Jstr = self .dumps (dupSign_start = dupSign_start , dupSign_end = dupSign_end , _isDebug_ = _isDebug_ , skipkeys = skipkeys , ensure_ascii = ensure_ascii , check_circular = check_circular , allow_nan = allow_nan , cls = cls , indent = indent , separators = separators , default = default , sort_keys = sort_keys )
312316
313- # Jfile = open(Jfilepath, "w")
314- # Jfile.write(Jstr)
315- # Jfile.close()
316- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
317- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
318- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
317+ try :
318+ Jfile = open (Jfilepath , "w" )
319+ Jfile .write (Jstr )
320+ Jfile .close ()
321+ except Exception as e :
322+ if _isDebug_ : print ("\x1b [31m[-] ExceptionError: {}\x1b [0m" .format (e ))
323+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
324+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
325+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
319326
320327
321328 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
0 commit comments