@extension(['<STR_LIT>', '<STR_LIT:c>'])<EOL>def choose(formatter, value, name, option, format):
if not option:<EOL><INDENT>return<EOL><DEDENT>words = format.split('<STR_LIT:|>')<EOL>num_words = len(words)<EOL>if num_words < <NUM_LIT:2>:<EOL><INDENT>return<EOL><DEDENT>choices = option.split('<STR_LIT:|>')<EOL>num_choices = len(choices)<EOL>if num_words not in (num_choices, num_choices + <NUM_LIT:1>):<EOL><INDENT>n = num_choices<EOL>raise ValueError('<STR_LIT>' % (n, n + <NUM_LIT:1>))<EOL><DEDENT>choice = get_choice(value)<EOL>try:<EOL><INDENT>index = choices.index(choice)<EOL><DEDENT>except ValueError:<EOL><INDENT>if num_words == num_choices:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>index = -<NUM_LIT:1><EOL><DEDENT>return formatter.format(words[index], value)<EOL>
Adds simple logic to format strings.

    Spec: `{:c[hoose](choice1|choice2|...):word1|word2|...[|default]}`

    Example::

       >>> smart.format(u'{num:choose(1|2|3):one|two|three|other}, num=1)
       u'one'
       >>> smart.format(u'{num:choose(1|2|3):one|two|three|other}, num=4)
       u'other'