def _construct_category(glyph_name, data):
<EOL>if glyph_name.startswith("<STR_LIT:_>"):<EOL><INDENT>return None, None<EOL><DEDENT>base_name = glyph_name.split("<STR_LIT:.>", <NUM_LIT:1>)[<NUM_LIT:0>]<EOL>base_attribute = data.names.get(base_name) or {}<EOL>if base_attribute:<EOL><INDENT>category = base_attribute.get("<STR_LIT>")<EOL>sub_category = base_attribute.get("<STR_LIT>")<EOL>return category, sub_category<EOL><DEDENT>if "<STR_LIT:_>" in base_name:<EOL><INDENT>base_names = base_name.split("<STR_LIT:_>")<EOL>base_names_attributes = [_lookup_attributes(name, data) for name in base_names]<EOL>first_attribute = base_names_attributes[<NUM_LIT:0>]<EOL>if first_attribute.get("<STR_LIT>") == "<STR_LIT>":<EOL><INDENT>category = first_attribute.get("<STR_LIT>")<EOL>sub_category = first_attribute.get("<STR_LIT>")<EOL>return category, sub_category<EOL><DEDENT>if first_attribute.get("<STR_LIT>") == "<STR_LIT>":<EOL><INDENT>if all(<EOL>a.get("<STR_LIT>") in (None, "<STR_LIT>", "<STR_LIT>")<EOL>for a in base_names_attributes[<NUM_LIT:1>:]<EOL>):<EOL><INDENT>category = first_attribute.get("<STR_LIT>")<EOL>sub_category = first_attribute.get("<STR_LIT>")<EOL>return category, sub_category<EOL><DEDENT>category = first_attribute.get("<STR_LIT>")<EOL>sub_category = "<STR_LIT>"<EOL>return category, sub_category<EOL><DEDENT><DEDENT>character = fontTools.agl.toUnicode(base_name)<EOL>if character:<EOL><INDENT>category, sub_category = _translate_category(<EOL>glyph_name, unicodedata.category(character[<NUM_LIT:0>])<EOL>)<EOL>return category, sub_category<EOL><DEDENT>return None, None<EOL>
Derive (sub)category of a glyph name.