@@ -8,14 +8,12 @@ def normalize_key(name, dupSign_start="{{{", dupSign_end="}}}", _isDebug_=False)
88 if type (_isDebug_ ) != bool : _isDebug_ = False
99 try :
1010 if type (name ) not in [str , unicode ]:
11- if _isDebug_ : print ("\x1b [31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b [0m" .format (type (name )))
12- exit ()
11+ exit ("\x1b [31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b [0m" .format (type (name )))
1312 if type (dupSign_start ) not in [str , unicode ]: dupSign_start = "{{{"
1413 if type (dupSign_end ) not in [str , unicode ]: dupSign_end = "}}}"
1514 except Exception as e :
1615 if type (name ) not in [str ]:
17- if _isDebug_ : print ("\x1b [31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b [0m" .format (type (name )))
18- exit ()
16+ exit ("\x1b [31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b [0m" .format (type (name )))
1917 if type (dupSign_start ) not in [str ]: dupSign_start = "{{{"
2018 if type (dupSign_end ) not in [str ]: dupSign_end = "}}}"
2119
@@ -37,14 +35,12 @@ def loads(Jstr, dupSign_start="{{{", dupSign_end="}}}", ordered_dict=False, _isD
3735 if type (ordered_dict ) != bool : ordered_dict = False
3836 try :
3937 if type (Jstr ) not in [str , unicode ]:
40- if _isDebug_ : print ("\x1b [31m[-] DataTypeError: the JSON object must be str or unicode, not {}\x1b [0m" .format (type (Jstr )))
41- exit ()
38+ exit ("\x1b [31m[-] DataTypeError: the JSON object must be str or unicode, not {}\x1b [0m" .format (type (Jstr )))
4239 if type (dupSign_start ) not in [str , unicode ]: dupSign_start = "{{{"
4340 if type (dupSign_end ) not in [str , unicode ]: dupSign_end = "}}}"
4441 except Exception as e :
4542 if type (Jstr ) not in [str ]:
46- if _isDebug_ : print ("\x1b [31m[-] DataTypeError: the JSON object must be str or unicode, not {}\x1b [0m" .format (type (Jstr )))
47- exit ()
43+ exit ("\x1b [31m[-] DataTypeError: the JSON object must be str or unicode, not {}\x1b [0m" .format (type (Jstr )))
4844 if type (dupSign_start ) not in [str ]: dupSign_start = "{{{"
4945 if type (dupSign_end ) not in [str ]: dupSign_end = "}}}"
5046
@@ -195,14 +191,12 @@ def get(self, name, separator="||", parse_index="$", _isDebug_=False):
195191 if type (_isDebug_ ) != bool : _isDebug_ = False
196192 try :
197193 if type (name ) not in [str , unicode ]:
198- if _isDebug_ : print ("\x1b [31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b [0m" .format (type (name )))
199- exit ()
194+ exit ("\x1b [31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b [0m" .format (type (name )))
200195 if type (separator ) not in [str , unicode ]: separator = "||"
201196 if type (parse_index ) not in [str , unicode ]: parse_index = "$"
202197 except Exception as e :
203198 if type (name ) not in [str ]:
204- if _isDebug_ : print ("\x1b [31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b [0m" .format (type (name )))
205- exit ()
199+ exit ("\x1b [31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b [0m" .format (type (name )))
206200 if type (separator ) not in [str ]: separator = "||"
207201 if type (parse_index ) not in [str ]: parse_index = "$"
208202
@@ -246,16 +240,14 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
246240 if type (ordered_dict ) != bool : ordered_dict = False
247241 try :
248242 if type (name ) not in [str , unicode ]:
249- if _isDebug_ : print ("\x1b [31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b [0m" .format (type (name )))
250- exit ()
243+ exit ("\x1b [31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b [0m" .format (type (name )))
251244 if type (separator ) not in [str , unicode ]: separator = "||"
252245 if type (parse_index ) not in [str , unicode ]: parse_index = "$"
253246 if type (dupSign_start ) not in [str , unicode ]: dupSign_start = "{{{"
254247 if type (dupSign_end ) not in [str , unicode ]: dupSign_end = "}}}"
255248 except Exception as e :
256249 if type (name ) not in [str ]:
257- if _isDebug_ : print ("\x1b [31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b [0m" .format (type (name )))
258- exit ()
250+ exit ("\x1b [31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b [0m" .format (type (name )))
259251 if type (separator ) not in [str ]: separator = "||"
260252 if type (parse_index ) not in [str ]: parse_index = "$"
261253 if type (dupSign_start ) not in [str ]: dupSign_start = "{{{"
@@ -308,6 +300,7 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
308300 exec_expression += "[" + repr (k )+ "]"
309301
310302 exec (exec_expression + "=" + repr (value ))
303+ return True
311304 # Add new key
312305 elif self .get (separator .join (name_split_first ), separator = separator , parse_index = parse_index ) != "JSON_DUPLICATE_KEYS_ERROR" :
313306 if type (self .get (separator .join (name_split_first ), separator = separator , parse_index = parse_index )) == list :
@@ -331,6 +324,7 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
331324 exec_expression += "[" + repr (k )+ "]"
332325
333326 exec (exec_expression + ".append({" + repr (name_split_lastKey )+ ":" + repr (value )+ "})" )
327+ return True
334328 elif type (self .get (separator .join (name_split_first ), separator = separator , parse_index = parse_index )) == dict :
335329 exec_expression = "self.getObject()"
336330
@@ -341,6 +335,7 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
341335 exec_expression += "[" + repr (k )+ "]"
342336
343337 exec (exec_expression + "[" + repr (name_split_lastKey )+ "]=" + repr (value ))
338+ return True
344339 else :
345340 if _isDebug_ : print ("\x1b [31m[-] KeyNameNotExistError: {}\x1b [0m" .format (separator .join (name_split_first )))
346341 # Add new key
@@ -352,6 +347,7 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
352347 self .__Jobj .append ({name_split_lastKey : value })
353348 else :
354349 self .__Jobj [name_split_lastKey ] = value
350+ return True
355351 else :
356352 if _isDebug_ : print ("\x1b [31m[-] KeyNameInvalidError: {}\x1b [0m" .format (separator .join (name_split_first )))
357353 else :
@@ -360,6 +356,8 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
360356 if _isDebug_ : print ("\x1b [31m[-] ExceptionError: {}\x1b [0m" .format (e ))
361357 else :
362358 if _isDebug_ : print ("\x1b [31m[-] DataTypeError: the JSON object must be list, dict or OrderedDict, not {}\x1b [0m" .format (type (self .getObject ())))
359+
360+ return False
363361 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
364362 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
365363 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
@@ -375,14 +373,12 @@ def update(self, name, value, separator="||", parse_index="$", _isDebug_=False):
375373 if type (_isDebug_ ) != bool : _isDebug_ = False
376374 try :
377375 if type (name ) not in [str , unicode ]:
378- if _isDebug_ : print ("\x1b [31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b [0m" .format (type (name )))
379- exit ()
376+ exit ("\x1b [31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b [0m" .format (type (name )))
380377 if type (separator ) not in [str , unicode ]: separator = "||"
381378 if type (parse_index ) not in [str , unicode ]: parse_index = "$"
382379 except Exception as e :
383380 if type (name ) not in [str ]:
384- if _isDebug_ : print ("\x1b [31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b [0m" .format (type (name )))
385- exit ()
381+ exit ("\x1b [31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b [0m" .format (type (name )))
386382 if type (separator ) not in [str ]: separator = "||"
387383 if type (parse_index ) not in [str ]: parse_index = "$"
388384
@@ -397,8 +393,11 @@ def update(self, name, value, separator="||", parse_index="$", _isDebug_=False):
397393 exec_expression += "[" + repr (k )+ "]"
398394
399395 exec (exec_expression + "=" + repr (value ))
396+ return True
400397 except Exception as e :
401398 if _isDebug_ : print ("\x1b [31m[-] ExceptionError: {}\x1b [0m" .format (e ))
399+
400+ return False
402401 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
403402 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
404403 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
@@ -415,14 +414,12 @@ def delete(self, name, separator="||", parse_index="$", _isDebug_=False):
415414
416415 try :
417416 if type (name ) not in [str , unicode ]:
418- if _isDebug_ : print ("\x1b [31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b [0m" .format (type (name )))
419- exit ()
417+ exit ("\x1b [31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b [0m" .format (type (name )))
420418 if type (separator ) not in [str , unicode ]: separator = "||"
421419 if type (parse_index ) not in [str , unicode ]: parse_index = "$"
422420 except Exception as e :
423421 if type (name ) not in [str ]:
424- if _isDebug_ : print ("\x1b [31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b [0m" .format (type (name )))
425- exit ()
422+ exit ("\x1b [31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b [0m" .format (type (name )))
426423 if type (separator ) not in [str ]: separator = "||"
427424 if type (parse_index ) not in [str ]: parse_index = "$"
428425
@@ -437,8 +434,11 @@ def delete(self, name, separator="||", parse_index="$", _isDebug_=False):
437434 exec_expression += "[" + repr (k )+ "]"
438435
439436 exec (exec_expression )
437+ return True
440438 except Exception as e :
441439 if _isDebug_ : print ("\x1b [31m[-] ExceptionError: {}\x1b [0m" .format (e ))
440+
441+ return False
442442 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
443443 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
444444 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
0 commit comments