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+
119# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
220# # # # # # # # # # # # # # # loads # # # # # # # # # # # # # #
321# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
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 ):
523 import json , re
624 from collections import OrderedDict
725
826 # User input data type validation
927 if type (dupSign_start ) != str : dupSign_start = "{{{"
1028 if type (dupSign_end ) != str : dupSign_end = "}}}"
1129 if type (ordered_dict ) != bool : ordered_dict = False
12- if type (_isDebug_ ) != bool : _isDebug_ = True
30+ if type (_isDebug_ ) != bool : _isDebug_ = False
1331
1432 if type (Jstr ) in [str ]:
1533 def __convert_Jloads_to_Jobj (Jloads , Jobj ):
@@ -115,7 +133,7 @@ def __convert_Jloads_to_Jobj(Jloads, Jobj):
115133# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
116134# # # # # # # # # # # # # # # load # # # # # # # # # # # # # #
117135# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
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 ):
119137 try :
120138 Jfile = open (Jfilepath )
121139 Jstr = Jfile .read ()
@@ -153,15 +171,15 @@ def getObject(self):
153171 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
154172 # # # # # # # # # # # # # # # get # # # # # # # # # # # # # # #
155173 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
156- def get (self , name , separator = "||" , parse_index = "$" , _isDebug_ = True ):
174+ def get (self , name , separator = "||" , parse_index = "$" , _isDebug_ = False ):
157175 import re
158176 from collections import OrderedDict
159177
160178 # User input data type validation
161179 if type (name ) != str : name = str (name )
162180 if type (separator ) != str : separator = "||"
163181 if type (parse_index ) != str : parse_index = "$"
164- if type (_isDebug_ ) != bool : _isDebug_ = True
182+ if type (_isDebug_ ) != bool : _isDebug_ = False
165183
166184 if type (self .getObject ()) in [list , dict , OrderedDict ]:
167185 try :
@@ -194,7 +212,7 @@ def get(self, name, separator="||", parse_index="$", _isDebug_=True):
194212 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
195213 # # # # # # # # # # # # # # # set # # # # # # # # # # # # # # #
196214 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
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 ):
198216 import re
199217 from collections import OrderedDict
200218
@@ -205,7 +223,7 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
205223 if type (dupSign_start ) != str : dupSign_start = "{{{"
206224 if type (dupSign_end ) != str : dupSign_end = "}}}"
207225 if type (ordered_dict ) != bool : ordered_dict = False
208- if type (_isDebug_ ) != bool : _isDebug_ = True
226+ if type (_isDebug_ ) != bool : _isDebug_ = False
209227
210228 if type (self .getObject ()) in [list , dict , OrderedDict ]:
211229 try :
@@ -237,10 +255,10 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
237255 => Add new key ( self.__Jobj[name_split_lastKey] = value )
238256 """
239257 # 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" :
241259 index = 2
242260 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" :
244262 break
245263 index += 1
246264
@@ -255,8 +273,8 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
255273
256274 exec (exec_expression + "=" + repr (value ))
257275 # 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 :
260278 if name_split_lastKey == "" :
261279 exec_expression = "self.getObject()"
262280
@@ -277,7 +295,7 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
277295 exec_expression += "[" + repr (k )+ "]"
278296
279297 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 :
281299 exec_expression = "self.getObject()"
282300
283301 for k in name_split_first :
@@ -314,14 +332,14 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
314332 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
315333 # # # # # # # # # # # # # # update # # # # # # # # # # # # # #
316334 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
317- def update (self , name , value , separator = "||" , parse_index = "$" , _isDebug_ = True ):
335+ def update (self , name , value , separator = "||" , parse_index = "$" , _isDebug_ = False ):
318336 import re
319337
320338 # User input data type validation
321339 if type (name ) != str : name = str (name )
322340 if type (separator ) != str : separator = "||"
323341 if type (parse_index ) != str : parse_index = "$"
324- if type (_isDebug_ ) != bool : _isDebug_ = True
342+ if type (_isDebug_ ) != bool : _isDebug_ = False
325343
326344 if self .get (name , separator = separator , parse_index = parse_index , _isDebug_ = _isDebug_ ) != "JSON_DUPLICATE_KEYS_ERROR" :
327345 try :
@@ -344,14 +362,14 @@ def update(self, name, value, separator="||", parse_index="$", _isDebug_=True):
344362 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
345363 # # # # # # # # # # # # # # delete # # # # # # # # # # # # #
346364 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
347- def delete (self , name , separator = "||" , parse_index = "$" , _isDebug_ = True ):
365+ def delete (self , name , separator = "||" , parse_index = "$" , _isDebug_ = False ):
348366 import re
349367
350368 # User input data type validation
351369 if type (name ) != str : name = str (name )
352370 if type (separator ) != str : separator = "||"
353371 if type (parse_index ) != str : parse_index = "$"
354- if type (_isDebug_ ) != bool : _isDebug_ = True
372+ if type (_isDebug_ ) != bool : _isDebug_ = False
355373
356374 if self .get (name , separator = separator , parse_index = parse_index , _isDebug_ = _isDebug_ ) != "JSON_DUPLICATE_KEYS_ERROR" :
357375 try :
@@ -374,14 +392,14 @@ def delete(self, name, separator="||", parse_index="$", _isDebug_=True):
374392 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
375393 # # # # # # # # # # # # # # dumps # # # # # # # # # # # # # #
376394 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
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 ):
378396 import json , re
379397 from collections import OrderedDict
380398
381399 # User input data type validation
382400 if type (dupSign_start ) != str : dupSign_start = "{{{"
383401 if type (dupSign_end ) != str : dupSign_end = "}}}"
384- if type (_isDebug_ ) != bool : _isDebug_ = True
402+ if type (_isDebug_ ) != bool : _isDebug_ = False
385403
386404 if type (self .getObject ()) in [list , dict , OrderedDict ]:
387405 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
400418 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
401419 # # # # # # # # # # # # # # dump # # # # # # # # # # # # # #
402420 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
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 ):
404422 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 )
405423
406424 try :
@@ -417,14 +435,14 @@ def dump(self, Jfilepath, dupSign_start="{{{", dupSign_end="}}}", _isDebug_=True
417435 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
418436 # # # # # # # # # # # # # flatten # # # # # # # # # # # # # #
419437 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
420- def flatten (self , separator = "||" , parse_index = "$" , ordered_dict = False , _isDebug_ = True ):
438+ def flatten (self , separator = "||" , parse_index = "$" , ordered_dict = False , _isDebug_ = False ):
421439 from collections import OrderedDict
422440
423441 # User input data type validation
424442 if type (separator ) != str : separator = "||"
425443 if type (parse_index ) != str : parse_index = "$"
426444 if type (ordered_dict ) != bool : ordered_dict = False
427- if type (_isDebug_ ) != bool : _isDebug_ = True
445+ if type (_isDebug_ ) != bool : _isDebug_ = False
428446
429447 if type (self .getObject ()) in [list , dict , OrderedDict ]:
430448 if len (self .getObject ()) > 0 :
@@ -472,15 +490,15 @@ def __convert_Jobj_to_Jflat(Jobj, key=None):
472490 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
473491 # # # # # # # # # # # # # unflatten # # # # # # # # # # # # #
474492 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
475- def unflatten (self , separator = "||" , parse_index = "$" , ordered_dict = False , _isDebug_ = True ):
493+ def unflatten (self , separator = "||" , parse_index = "$" , ordered_dict = False , _isDebug_ = False ):
476494 import re
477495 from collections import OrderedDict
478496
479497 # User input data type validation
480498 if type (separator ) != str : separator = "||"
481499 if type (parse_index ) != str : parse_index = "$"
482500 if type (ordered_dict ) != bool : ordered_dict = False
483- if type (_isDebug_ ) != bool : _isDebug_ = True
501+ if type (_isDebug_ ) != bool : _isDebug_ = False
484502
485503 if type (self .getObject ()) in [dict , OrderedDict ]:
486504 if len (self .getObject ()) > 0 :
0 commit comments