File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change 1
1
import json
2
2
import argparse
3
-
4
- JSON_DOUBLE_QUOTE_REPLACE = '<!>'
5
- JSON_SINGLE_QUOTE_REPLACE = '<*>'
3
+ import base64
6
4
7
5
8
6
def load_extra_params (string ):
9
- string = string .replace (JSON_DOUBLE_QUOTE_REPLACE ,'"' ).replace (JSON_SINGLE_QUOTE_REPLACE ,"'" )
10
7
try :
11
- return json .loads (string )
12
- except json .JSONDecodeError :
8
+ # Decode the base64 string back to JSON string
9
+ json_bytes = base64 .b64decode (string .encode ('utf-8' ))
10
+ json_str = json_bytes .decode ('utf-8' )
11
+ return json .loads (json_str )
12
+ except (base64 .binascii .Error , UnicodeDecodeError , json .JSONDecodeError ):
13
13
raise argparse .ArgumentTypeError (f"Invalid dictionary format: { string } " )
14
14
15
- def dump_extra_params (d :dict ):
16
- return json .dumps (d ).replace ("'" , JSON_SINGLE_QUOTE_REPLACE ).replace ('"' , JSON_DOUBLE_QUOTE_REPLACE )
15
+
16
+ def dump_extra_params (d : dict ):
17
+ # Convert dict to JSON string, then encode to base64
18
+ json_str = json .dumps (d )
19
+ json_bytes = json_str .encode ('utf-8' )
20
+ base64_bytes = base64 .b64encode (json_bytes )
21
+ return base64_bytes .decode ('utf-8' )
You can’t perform that action at this time.
0 commit comments