@@ -8,14 +8,12 @@ def normalize_key(name, dupSign_start="{{{", dupSign_end="}}}", _isDebug_=False)
8
8
if type (_isDebug_ ) != bool : _isDebug_ = False
9
9
try :
10
10
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 )))
13
12
if type (dupSign_start ) not in [str , unicode ]: dupSign_start = "{{{"
14
13
if type (dupSign_end ) not in [str , unicode ]: dupSign_end = "}}}"
15
14
except Exception as e :
16
15
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 )))
19
17
if type (dupSign_start ) not in [str ]: dupSign_start = "{{{"
20
18
if type (dupSign_end ) not in [str ]: dupSign_end = "}}}"
21
19
@@ -37,14 +35,12 @@ def loads(Jstr, dupSign_start="{{{", dupSign_end="}}}", ordered_dict=False, _isD
37
35
if type (ordered_dict ) != bool : ordered_dict = False
38
36
try :
39
37
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 )))
42
39
if type (dupSign_start ) not in [str , unicode ]: dupSign_start = "{{{"
43
40
if type (dupSign_end ) not in [str , unicode ]: dupSign_end = "}}}"
44
41
except Exception as e :
45
42
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 )))
48
44
if type (dupSign_start ) not in [str ]: dupSign_start = "{{{"
49
45
if type (dupSign_end ) not in [str ]: dupSign_end = "}}}"
50
46
@@ -195,14 +191,12 @@ def get(self, name, separator="||", parse_index="$", _isDebug_=False):
195
191
if type (_isDebug_ ) != bool : _isDebug_ = False
196
192
try :
197
193
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 )))
200
195
if type (separator ) not in [str , unicode ]: separator = "||"
201
196
if type (parse_index ) not in [str , unicode ]: parse_index = "$"
202
197
except Exception as e :
203
198
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 )))
206
200
if type (separator ) not in [str ]: separator = "||"
207
201
if type (parse_index ) not in [str ]: parse_index = "$"
208
202
@@ -246,16 +240,14 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
246
240
if type (ordered_dict ) != bool : ordered_dict = False
247
241
try :
248
242
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 )))
251
244
if type (separator ) not in [str , unicode ]: separator = "||"
252
245
if type (parse_index ) not in [str , unicode ]: parse_index = "$"
253
246
if type (dupSign_start ) not in [str , unicode ]: dupSign_start = "{{{"
254
247
if type (dupSign_end ) not in [str , unicode ]: dupSign_end = "}}}"
255
248
except Exception as e :
256
249
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 )))
259
251
if type (separator ) not in [str ]: separator = "||"
260
252
if type (parse_index ) not in [str ]: parse_index = "$"
261
253
if type (dupSign_start ) not in [str ]: dupSign_start = "{{{"
@@ -308,6 +300,7 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
308
300
exec_expression += "[" + repr (k )+ "]"
309
301
310
302
exec (exec_expression + "=" + repr (value ))
303
+ return True
311
304
# Add new key
312
305
elif self .get (separator .join (name_split_first ), separator = separator , parse_index = parse_index ) != "JSON_DUPLICATE_KEYS_ERROR" :
313
306
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="{{{",
331
324
exec_expression += "[" + repr (k )+ "]"
332
325
333
326
exec (exec_expression + ".append({" + repr (name_split_lastKey )+ ":" + repr (value )+ "})" )
327
+ return True
334
328
elif type (self .get (separator .join (name_split_first ), separator = separator , parse_index = parse_index )) == dict :
335
329
exec_expression = "self.getObject()"
336
330
@@ -341,6 +335,7 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
341
335
exec_expression += "[" + repr (k )+ "]"
342
336
343
337
exec (exec_expression + "[" + repr (name_split_lastKey )+ "]=" + repr (value ))
338
+ return True
344
339
else :
345
340
if _isDebug_ : print ("\x1b [31m[-] KeyNameNotExistError: {}\x1b [0m" .format (separator .join (name_split_first )))
346
341
# Add new key
@@ -352,6 +347,7 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
352
347
self .__Jobj .append ({name_split_lastKey : value })
353
348
else :
354
349
self .__Jobj [name_split_lastKey ] = value
350
+ return True
355
351
else :
356
352
if _isDebug_ : print ("\x1b [31m[-] KeyNameInvalidError: {}\x1b [0m" .format (separator .join (name_split_first )))
357
353
else :
@@ -360,6 +356,8 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
360
356
if _isDebug_ : print ("\x1b [31m[-] ExceptionError: {}\x1b [0m" .format (e ))
361
357
else :
362
358
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
363
361
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
364
362
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
365
363
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
@@ -375,14 +373,12 @@ def update(self, name, value, separator="||", parse_index="$", _isDebug_=False):
375
373
if type (_isDebug_ ) != bool : _isDebug_ = False
376
374
try :
377
375
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 )))
380
377
if type (separator ) not in [str , unicode ]: separator = "||"
381
378
if type (parse_index ) not in [str , unicode ]: parse_index = "$"
382
379
except Exception as e :
383
380
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 )))
386
382
if type (separator ) not in [str ]: separator = "||"
387
383
if type (parse_index ) not in [str ]: parse_index = "$"
388
384
@@ -397,8 +393,11 @@ def update(self, name, value, separator="||", parse_index="$", _isDebug_=False):
397
393
exec_expression += "[" + repr (k )+ "]"
398
394
399
395
exec (exec_expression + "=" + repr (value ))
396
+ return True
400
397
except Exception as e :
401
398
if _isDebug_ : print ("\x1b [31m[-] ExceptionError: {}\x1b [0m" .format (e ))
399
+
400
+ return False
402
401
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
403
402
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
404
403
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
@@ -415,14 +414,12 @@ def delete(self, name, separator="||", parse_index="$", _isDebug_=False):
415
414
416
415
try :
417
416
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 )))
420
418
if type (separator ) not in [str , unicode ]: separator = "||"
421
419
if type (parse_index ) not in [str , unicode ]: parse_index = "$"
422
420
except Exception as e :
423
421
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 )))
426
423
if type (separator ) not in [str ]: separator = "||"
427
424
if type (parse_index ) not in [str ]: parse_index = "$"
428
425
@@ -437,8 +434,11 @@ def delete(self, name, separator="||", parse_index="$", _isDebug_=False):
437
434
exec_expression += "[" + repr (k )+ "]"
438
435
439
436
exec (exec_expression )
437
+ return True
440
438
except Exception as e :
441
439
if _isDebug_ : print ("\x1b [31m[-] ExceptionError: {}\x1b [0m" .format (e ))
440
+
441
+ return False
442
442
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
443
443
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
444
444
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
0 commit comments