27 return encode(obj)+
"\n" 29 def encode(value, indent=""):
30 return type_name2bach_code[get_atlas_type(value)](value, indent)
32 int_characters =
"+-" + string.digits
33 float_characters =
".eE" + int_characters
34 plain_name_characters = string.digits + string.ascii_uppercase + string.ascii_lowercase +
"_" 36 def encode_name(value):
39 if isinstance(value, str):
42 if ch
in string_quoted:
46 if not ch
in plain_name_characters:
51 return '"%s"' %
"".join(res)
53 def encode_string(value, indent):
60 return '"%s"' %
"".join(res)
71 def encode_map(obj, indent=""):
72 if not obj:
return "{}" 74 indent = indent +
"\t" 75 for name, value
in list(obj.items()):
77 str_type = get_atlas_type(value)
79 str_name = encode_name(name)
80 str_value = encode(value, indent)
83 elif str_type==
"list":
84 if str_value.find(
"\t")>=0: add_nl = 1
86 str_list.append(
"%s%s: %s" % (indent, str_name, str_value))
87 return "{\n%s\n%s}" % (
",\n".join(str_list), indent[:-1])
89 def encode_list(lst, indent=""):
91 indent = indent +
"\t" 94 str_type = get_atlas_type(item)
95 str_value = encode(item, indent)
96 str_list.append(str_value)
97 if str_type
in [
"map",
"list"]:
100 str_list = list(map(
lambda s,i=indent:
"\n"+i+s, str_list))
101 res =
",".join(str_list) +
"\n" + indent[:-1]
103 res =
", ".join(str_list)
106 def encode_int(value, indent=""):
109 def encode_float(value, indent=""):
112 type_name2bach_code = {
"map": encode_map,
115 "float": encode_float,
116 "string": encode_string}