1
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
2
+ # # # # # # # # # # # Normalize Key name # # # # # # # # # # #
3
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
4
+ def normalize_key (name , dupSign_start = "{{{" , dupSign_end = "}}}" ):
5
+ import re
6
+
7
+ # User input data type validation
8
+ if type (dupSign_start ) != str : dupSign_start = "{{{"
9
+ if type (dupSign_end ) != str : dupSign_end = "}}}"
10
+
11
+ if type (name ) == str :
12
+ return re .sub ('{dupSign_start}_\d+_{dupSign_end}$' .format (dupSign_start = re .escape (dupSign_start ), dupSign_end = re .escape (dupSign_end )), "" , name )
13
+ return name
14
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
15
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
16
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
17
+
18
+
1
19
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
2
20
# # # # # # # # # # # # # # # loads # # # # # # # # # # # # # #
3
21
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
4
- def loads (Jstr , dupSign_start = "{{{" , dupSign_end = "}}}" , ordered_dict = False , _isDebug_ = True ):
22
+ def loads (Jstr , dupSign_start = "{{{" , dupSign_end = "}}}" , ordered_dict = False , _isDebug_ = False ):
5
23
import json , re
6
24
from collections import OrderedDict
7
25
8
26
# User input data type validation
9
27
if type (dupSign_start ) != str : dupSign_start = "{{{"
10
28
if type (dupSign_end ) != str : dupSign_end = "}}}"
11
29
if type (ordered_dict ) != bool : ordered_dict = False
12
- if type (_isDebug_ ) != bool : _isDebug_ = True
30
+ if type (_isDebug_ ) != bool : _isDebug_ = False
13
31
14
32
if type (Jstr ) in [str ]:
15
33
def __convert_Jloads_to_Jobj (Jloads , Jobj ):
@@ -115,7 +133,7 @@ def __convert_Jloads_to_Jobj(Jloads, Jobj):
115
133
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
116
134
# # # # # # # # # # # # # # # load # # # # # # # # # # # # # #
117
135
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
118
- def load (Jfilepath , dupSign_start = "{{{" , dupSign_end = "}}}" , ordered_dict = False , _isDebug_ = True ):
136
+ def load (Jfilepath , dupSign_start = "{{{" , dupSign_end = "}}}" , ordered_dict = False , _isDebug_ = False ):
119
137
try :
120
138
Jfile = open (Jfilepath )
121
139
Jstr = Jfile .read ()
@@ -153,15 +171,15 @@ def getObject(self):
153
171
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
154
172
# # # # # # # # # # # # # # # get # # # # # # # # # # # # # # #
155
173
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
156
- def get (self , name , separator = "||" , parse_index = "$" , _isDebug_ = True ):
174
+ def get (self , name , separator = "||" , parse_index = "$" , _isDebug_ = False ):
157
175
import re
158
176
from collections import OrderedDict
159
177
160
178
# User input data type validation
161
179
if type (name ) != str : name = str (name )
162
180
if type (separator ) != str : separator = "||"
163
181
if type (parse_index ) != str : parse_index = "$"
164
- if type (_isDebug_ ) != bool : _isDebug_ = True
182
+ if type (_isDebug_ ) != bool : _isDebug_ = False
165
183
166
184
if type (self .getObject ()) in [list , dict , OrderedDict ]:
167
185
try :
@@ -194,7 +212,7 @@ def get(self, name, separator="||", parse_index="$", _isDebug_=True):
194
212
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
195
213
# # # # # # # # # # # # # # # set # # # # # # # # # # # # # # #
196
214
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
197
- def set (self , name , value , separator = "||" , parse_index = "$" , dupSign_start = "{{{" , dupSign_end = "}}}" , ordered_dict = False , _isDebug_ = True ):
215
+ def set (self , name , value , separator = "||" , parse_index = "$" , dupSign_start = "{{{" , dupSign_end = "}}}" , ordered_dict = False , _isDebug_ = False ):
198
216
import re
199
217
from collections import OrderedDict
200
218
@@ -205,7 +223,7 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
205
223
if type (dupSign_start ) != str : dupSign_start = "{{{"
206
224
if type (dupSign_end ) != str : dupSign_end = "}}}"
207
225
if type (ordered_dict ) != bool : ordered_dict = False
208
- if type (_isDebug_ ) != bool : _isDebug_ = True
226
+ if type (_isDebug_ ) != bool : _isDebug_ = False
209
227
210
228
if type (self .getObject ()) in [list , dict , OrderedDict ]:
211
229
try :
@@ -237,10 +255,10 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
237
255
=> Add new key ( self.__Jobj[name_split_lastKey] = value )
238
256
"""
239
257
# Add duplicate key
240
- if self .get (separator .join (name_split ), separator = separator , parse_index = parse_index , _isDebug_ = False ) != "JSON_DUPLICATE_KEYS_ERROR" :
258
+ if self .get (separator .join (name_split ), separator = separator , parse_index = parse_index ) != "JSON_DUPLICATE_KEYS_ERROR" :
241
259
index = 2
242
260
while True :
243
- if self .get (separator .join (name_split )+ dupSign_start + "_" + str (index )+ "_" + dupSign_end , separator = separator , parse_index = parse_index , _isDebug_ = False ) == "JSON_DUPLICATE_KEYS_ERROR" :
261
+ if self .get (separator .join (name_split )+ dupSign_start + "_" + str (index )+ "_" + dupSign_end , separator = separator , parse_index = parse_index ) == "JSON_DUPLICATE_KEYS_ERROR" :
244
262
break
245
263
index += 1
246
264
@@ -255,8 +273,8 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
255
273
256
274
exec (exec_expression + "=" + repr (value ))
257
275
# Add new key
258
- elif self .get (separator .join (name_split_first ), separator = separator , parse_index = parse_index , _isDebug_ = False ) != "JSON_DUPLICATE_KEYS_ERROR" :
259
- if type (self .get (separator .join (name_split_first ), separator = separator , parse_index = parse_index , _isDebug_ = False )) == list :
276
+ elif self .get (separator .join (name_split_first ), separator = separator , parse_index = parse_index ) != "JSON_DUPLICATE_KEYS_ERROR" :
277
+ if type (self .get (separator .join (name_split_first ), separator = separator , parse_index = parse_index )) == list :
260
278
if name_split_lastKey == "" :
261
279
exec_expression = "self.getObject()"
262
280
@@ -277,7 +295,7 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
277
295
exec_expression += "[" + repr (k )+ "]"
278
296
279
297
exec (exec_expression + ".append({" + repr (name_split_lastKey )+ ":" + repr (value )+ "})" )
280
- elif type (self .get (separator .join (name_split_first ), separator = separator , parse_index = parse_index , _isDebug_ = False )) == dict :
298
+ elif type (self .get (separator .join (name_split_first ), separator = separator , parse_index = parse_index )) == dict :
281
299
exec_expression = "self.getObject()"
282
300
283
301
for k in name_split_first :
@@ -314,14 +332,14 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
314
332
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
315
333
# # # # # # # # # # # # # # update # # # # # # # # # # # # # #
316
334
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
317
- def update (self , name , value , separator = "||" , parse_index = "$" , _isDebug_ = True ):
335
+ def update (self , name , value , separator = "||" , parse_index = "$" , _isDebug_ = False ):
318
336
import re
319
337
320
338
# User input data type validation
321
339
if type (name ) != str : name = str (name )
322
340
if type (separator ) != str : separator = "||"
323
341
if type (parse_index ) != str : parse_index = "$"
324
- if type (_isDebug_ ) != bool : _isDebug_ = True
342
+ if type (_isDebug_ ) != bool : _isDebug_ = False
325
343
326
344
if self .get (name , separator = separator , parse_index = parse_index , _isDebug_ = _isDebug_ ) != "JSON_DUPLICATE_KEYS_ERROR" :
327
345
try :
@@ -344,14 +362,14 @@ def update(self, name, value, separator="||", parse_index="$", _isDebug_=True):
344
362
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
345
363
# # # # # # # # # # # # # # delete # # # # # # # # # # # # #
346
364
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
347
- def delete (self , name , separator = "||" , parse_index = "$" , _isDebug_ = True ):
365
+ def delete (self , name , separator = "||" , parse_index = "$" , _isDebug_ = False ):
348
366
import re
349
367
350
368
# User input data type validation
351
369
if type (name ) != str : name = str (name )
352
370
if type (separator ) != str : separator = "||"
353
371
if type (parse_index ) != str : parse_index = "$"
354
- if type (_isDebug_ ) != bool : _isDebug_ = True
372
+ if type (_isDebug_ ) != bool : _isDebug_ = False
355
373
356
374
if self .get (name , separator = separator , parse_index = parse_index , _isDebug_ = _isDebug_ ) != "JSON_DUPLICATE_KEYS_ERROR" :
357
375
try :
@@ -374,14 +392,14 @@ def delete(self, name, separator="||", parse_index="$", _isDebug_=True):
374
392
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
375
393
# # # # # # # # # # # # # # dumps # # # # # # # # # # # # # #
376
394
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
377
- 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 ):
395
+ def dumps (self , dupSign_start = "{{{" , dupSign_end = "}}}" , _isDebug_ = False , skipkeys = False , ensure_ascii = True , check_circular = True , allow_nan = True , cls = None , indent = None , separators = None , default = None , sort_keys = False ):
378
396
import json , re
379
397
from collections import OrderedDict
380
398
381
399
# User input data type validation
382
400
if type (dupSign_start ) != str : dupSign_start = "{{{"
383
401
if type (dupSign_end ) != str : dupSign_end = "}}}"
384
- if type (_isDebug_ ) != bool : _isDebug_ = True
402
+ if type (_isDebug_ ) != bool : _isDebug_ = False
385
403
386
404
if type (self .getObject ()) in [list , dict , OrderedDict ]:
387
405
dupSign_start_escape_regex = re .escape (json .dumps ({dupSign_start :"" })[2 :- 6 ])
@@ -400,7 +418,7 @@ def dumps(self, dupSign_start="{{{", dupSign_end="}}}", _isDebug_=True, skipkeys
400
418
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
401
419
# # # # # # # # # # # # # # dump # # # # # # # # # # # # # #
402
420
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
403
- 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 ):
421
+ def dump (self , Jfilepath , dupSign_start = "{{{" , dupSign_end = "}}}" , _isDebug_ = False , skipkeys = False , ensure_ascii = True , check_circular = True , allow_nan = True , cls = None , indent = None , separators = None , default = None , sort_keys = False ):
404
422
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 )
405
423
406
424
try :
@@ -417,14 +435,14 @@ def dump(self, Jfilepath, dupSign_start="{{{", dupSign_end="}}}", _isDebug_=True
417
435
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
418
436
# # # # # # # # # # # # # flatten # # # # # # # # # # # # # #
419
437
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
420
- def flatten (self , separator = "||" , parse_index = "$" , ordered_dict = False , _isDebug_ = True ):
438
+ def flatten (self , separator = "||" , parse_index = "$" , ordered_dict = False , _isDebug_ = False ):
421
439
from collections import OrderedDict
422
440
423
441
# User input data type validation
424
442
if type (separator ) != str : separator = "||"
425
443
if type (parse_index ) != str : parse_index = "$"
426
444
if type (ordered_dict ) != bool : ordered_dict = False
427
- if type (_isDebug_ ) != bool : _isDebug_ = True
445
+ if type (_isDebug_ ) != bool : _isDebug_ = False
428
446
429
447
if type (self .getObject ()) in [list , dict , OrderedDict ]:
430
448
if len (self .getObject ()) > 0 :
@@ -472,15 +490,15 @@ def __convert_Jobj_to_Jflat(Jobj, key=None):
472
490
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
473
491
# # # # # # # # # # # # # unflatten # # # # # # # # # # # # #
474
492
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
475
- def unflatten (self , separator = "||" , parse_index = "$" , ordered_dict = False , _isDebug_ = True ):
493
+ def unflatten (self , separator = "||" , parse_index = "$" , ordered_dict = False , _isDebug_ = False ):
476
494
import re
477
495
from collections import OrderedDict
478
496
479
497
# User input data type validation
480
498
if type (separator ) != str : separator = "||"
481
499
if type (parse_index ) != str : parse_index = "$"
482
500
if type (ordered_dict ) != bool : ordered_dict = False
483
- if type (_isDebug_ ) != bool : _isDebug_ = True
501
+ if type (_isDebug_ ) != bool : _isDebug_ = False
484
502
485
503
if type (self .getObject ()) in [dict , OrderedDict ]:
486
504
if len (self .getObject ()) > 0 :
0 commit comments