def construct_format(f, type_map=CONSTRUCT_CODE):
formatted = "<STR_LIT>"<EOL>if type_map.get(f.type_id, None):<EOL><INDENT>return "<STR_LIT>" % (type_map.get(f.type_id), f.identifier)<EOL><DEDENT>elif f.type_id == '<STR_LIT:string>' and f.options.get('<STR_LIT:size>', None):<EOL><INDENT>return "<STR_LIT>" % (f.identifier, f.options['<STR_LIT:size>'].value)<EOL><DEDENT>elif f.type_id == '<STR_LIT:string>':<EOL><INDENT>return "<STR_LIT>" % (f.identifier)<EOL><DEDENT>elif f.type_id == '<STR_LIT>':<EOL><INDENT>fill = f.options['<STR_LIT>'].value<EOL>f_ = copy.copy(f)<EOL>f_.type_id = fill<EOL>size = f.options.get('<STR_LIT:size>', None)<EOL>size_fn = f.options.get('<STR_LIT>', None)<EOL>field_type = type_map.get(f_.type_id, None)<EOL>if field_type is None:<EOL><INDENT>field_type = "<STR_LIT>" % f_.type_id<EOL><DEDENT>else:<EOL><INDENT>field_type = "<STR_LIT>" % field_type<EOL><DEDENT>if size is not None:<EOL><INDENT>d = { "<STR_LIT>" : "<STR_LIT>", "<STR_LIT>" : "<STR_LIT>", "<STR_LIT>" : "<STR_LIT>",<EOL>"<STR_LIT>" : "<STR_LIT>", "<STR_LIT>" : "<STR_LIT>", "<STR_LIT>" : "<STR_LIT>" }<EOL>field_type_arr = d.get(field_type, field_type)<EOL>return "<STR_LIT>" % (f.identifier, size.value, field_type_arr)<EOL><DEDENT>elif f.options.get('<STR_LIT>') is not None:<EOL><INDENT>return "<STR_LIT>" % (f_.identifier, field_type, size_fn.value)<EOL><DEDENT>else:<EOL><INDENT>return "<STR_LIT>" % (f_.identifier, field_type)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return "<STR_LIT>" % (f.identifier, f.type_id)<EOL><DEDENT>return formatted<EOL>
Formats for binary-parser library.