def _convert(convdef, stri):
if '<STR_LIT:%>' in convdef:<EOL><INDENT>result = dt.datetime.strptime(stri, convdef)<EOL><DEDENT>elif '<STR_LIT:d>' in convdef or '<STR_LIT:s>' in convdef:<EOL><INDENT>regex_match = fmt_spec_regex.match(convdef)<EOL>match_dict = regex_match.groupdict() if regex_match else {}<EOL>align = match_dict.get('<STR_LIT>')<EOL>pad = match_dict.get('<STR_LIT>')<EOL>if align:<EOL><INDENT>align = align[-<NUM_LIT:1>]<EOL><DEDENT>if align and align in '<STR_LIT>' and not pad:<EOL><INDENT>pad = '<STR_LIT:U+0020>'<EOL><DEDENT>if align == '<STR_LIT:>>':<EOL><INDENT>stri = stri.lstrip(pad)<EOL><DEDENT>elif align == '<STR_LIT:<>':<EOL><INDENT>stri = stri.rstrip(pad)<EOL><DEDENT>elif align == '<STR_LIT>':<EOL><INDENT>stri = stri.strip(pad)<EOL><DEDENT>if '<STR_LIT:d>' in convdef:<EOL><INDENT>result = int(stri)<EOL><DEDENT>else:<EOL><INDENT>result = stri<EOL><DEDENT><DEDENT>else:<EOL><INDENT>result = stri<EOL><DEDENT>return result<EOL>
Convert the string *stri* to the given conversion definition *convdef*.