# Buggy code
def __getitem__(self, name):
    char = name[0]
    num = len(name)
    if char == "G":
        return self.format_era(char, num)
    elif char in ("y", "Y", "u"):
        return self.format_year(char, num)
    elif char in ("Q", "q"):
        return self.format_quarter(char, num)
    elif char in ("M", "L"):
        return self.format_month(char, num)
    elif char in ("w", "W"):
        return self.format_week(char, num)
    elif char == "d":
        return self.format(self.value.day, num)
    elif char == "D":
        return self.format_day_of_year(num)
    elif char == "F":
        return self.format_day_of_week_in_month()
    elif char in ("E", "e", "c"):
        return self.format_weekday(char, num)
    elif char == "a":
        return self.format_period(char)
    elif char == "h":
        if self.value.hour % 12 == 0:
            return self.format(12, num)
        else:
            return self.format(self.value.hour % 12, num)
    elif char == "H":
        return self.format(self.value.hour, num)
    elif char == "K":
        return self.format(self.value.hour % 12, num)
    elif char == "k":
        if self.value.hour == 0:
            return self.format(24, num)
        else:
            return self.format(self.value.hour, num)
    elif char == "m":
        return self.format(self.value.minute, num)
    elif char == "s":
        return self.format(self.value.second, num)
    elif char == "S":
        return self.format_frac_seconds(num)
    elif char == "A":
        return self.format_milliseconds_in_day(num)
    elif char in ("z", "Z", "v", "V", "x", "X", "O"):
        return self.format_timezone(char, num)
    else:
        raise KeyError("Unsupported date/time field %r" % char)


# Traceback (KeyError)
import babel
babel.__version__
'2.3.1'
from datetime import datetime
from babel.dates import format_time
format_time(datetime(2016, 4, 8, 12, 34, 56), locale='zh_TW')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/dev/shm/babel231/local/lib/python2.7/site-packages/babel/dates.py", line 787, in format_time
return parse_pattern(format).apply(time, locale)
File "/dev/shm/babel231/local/lib/python2.7/site-packages/babel/dates.py", line 1208, in apply
return self % DateTimeFormat(datetime, locale)
File "/dev/shm/babel231/local/lib/python2.7/site-packages/babel/dates.py", line 1205, in __mod__
return self.format % other
File "/dev/shm/babel231/local/lib/python2.7/site-packages/babel/dates.py", line 1242, in __getitem__
return self.format_period(char)
File "/dev/shm/babel231/local/lib/python2.7/site-packages/babel/dates.py", line 1384, in format_period
return get_period_names(locale=self.locale)[period]
File "/dev/shm/babel231/local/lib/python2.7/site-packages/babel/localedata.py", line 207, in __getitem__
orig = val = self._data[key]
KeyError: 'pm'

# Fixed code
def __getitem__(self, name):
    char = name[0]
    num = len(name)
    if char == "G":
        return self.format_era(char, num)
    elif char in ("y", "Y", "u"):
        return self.format_year(char, num)
    elif char in ("Q", "q"):
        return self.format_quarter(char, num)
    elif char in ("M", "L"):
        return self.format_month(char, num)
    elif char in ("w", "W"):
        return self.format_week(char, num)
    elif char == "d":
        return self.format(self.value.day, num)
    elif char == "D":
        return self.format_day_of_year(num)
    elif char == "F":
        return self.format_day_of_week_in_month()
    elif char in ("E", "e", "c"):
        return self.format_weekday(char, num)
    elif char == "a":
        # TODO: Add support for the rest of the period formats (a*, b*, B*)
        return self.format_period(char)
    elif char == "h":
        if self.value.hour % 12 == 0:
            return self.format(12, num)
        else:
            return self.format(self.value.hour % 12, num)
    elif char == "H":
        return self.format(self.value.hour, num)
    elif char == "K":
        return self.format(self.value.hour % 12, num)
    elif char == "k":
        if self.value.hour == 0:
            return self.format(24, num)
        else:
            return self.format(self.value.hour, num)
    elif char == "m":
        return self.format(self.value.minute, num)
    elif char == "s":
        return self.format(self.value.second, num)
    elif char == "S":
        return self.format_frac_seconds(num)
    elif char == "A":
        return self.format_milliseconds_in_day(num)
    elif char in ("z", "Z", "v", "V", "x", "X", "O"):
        return self.format_timezone(char, num)
    else:
        raise KeyError("Unsupported date/time field %r" % char)