# Buggy code
def vertical_month(
    month=datetime.date.today().month,
    year=datetime.date.today().year,
    today=datetime.date.today(),
    weeknumber=False,
    count=3,
    firstweekday=0,
):
    """
    returns a list() of str() of weeks for a vertical arranged calendar

    :param month: first month of the calendar,
                  if non given, current month is assumed
    :type month: int
    :param year: year of the first month included,
                 if non given, current year is assumed
    :type year: int
    :param today: day highlighted, if non is given, current date is assumed
    :type today: datetime.date()
    :param weeknumber: if not False the iso weeknumber will be shown for each
                       week, if weeknumber is 'right' it will be shown in its
                       own column, if it is 'left' it will be shown interleaved
                       with the month names
    :type weeknumber: str/bool
    :returns: calendar strings,  may also include some
              ANSI (color) escape strings
    :rtype: list() of str()
    """

    khal = list()
    w_number = "    " if weeknumber == "right" else ""
    calendar.setfirstweekday(firstweekday)
    _calendar = calendar.Calendar(firstweekday)
    khal.append(bstring("    " + calendar.weekheader(2) + " " + w_number))
    for _ in range(count):
        for week in _calendar.monthdatescalendar(year, month):
            new_month = len([day for day in week if day.day == 1])
            strweek = str_week(week, today)
            if new_month:
                m_name = bstring(calendar.month_abbr[week[6].month].ljust(4))
            elif weeknumber == "left":
                m_name = bstring(" {:2} ".format(getweeknumber(week[0])))
            else:
                m_name = "    "
            if weeknumber == "right":
                w_number = bstring(" {}".format(getweeknumber(week[0])))
            else:
                w_number = ""

            sweek = m_name + strweek + w_number
            if sweek != khal[-1]:
                khal.append(sweek)
        month = month + 1
        if month > 12:
            month = 1
            year = year + 1
    return khal


# Traceback (UnicodeDecodeError)
debug: using the config file at /home/foo/.config/khal/khal.conf
debug: Using config:
debug: [calendars]
debug: [[home]]
debug: path = /home/foo/.khal/calendars/home/
debug: color = dark blue
debug: [[work]]
debug: path = /home/foo/.khal/calendars/home/
debug: color = yellow
debug:
debug: [sqlite]
debug: path = /home/foo/.khal/khal.db
debug:
debug: [locale]
debug: timeformat = %H:%M
debug: dateformat = %d.%m.
debug: longdateformat = %d.%m.%Y
debug: datetimeformat = %d.%m. %H:%M
debug: longdatetimeformat = %d.%m.%Y %H:%M
debug:
debug: firstweekday = 0
debug: weeknumbers = False
debug: local_timezone = Europe/Berlin
debug: default_timezone = America/New_York
debug: encoding = utf-8
debug: unicode_symbols = True
debug:
debug: [default]
debug: default_command = calendar
debug: default_calendar = home
debug: show_all_days = False
debug: created version table
debug: created accounts table
debug: tables for calendar home exist
debug: created version table
debug: created accounts table
debug: tables for calendar work exist
Traceback (most recent call last):
File "/usr/bin/khal", line 9, in <module>
load_entry_point('khal==0.4.0.dev-124-g46ae09e-dirty', 'console_scripts', 'khal')()
File "/usr/lib/python2.7/site-packages/click/core.py", line 610, in __call__
return self.main(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/click/core.py", line 590, in main
rv = self.invoke(ctx)
File "/usr/lib/python2.7/site-packages/click/core.py", line 916, in invoke
return Command.invoke(self, ctx)
File "/usr/lib/python2.7/site-packages/click/core.py", line 782, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python2.7/site-packages/click/core.py", line 416, in invoke
return callback(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/khal/cli.py", line 161, in cli
ctx.invoke(cli.commands[command])
File "/usr/lib/python2.7/site-packages/click/core.py", line 416, in invoke
return callback(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/khal/cli.py", line 182, in calendar
events=events
File "/usr/lib/python2.7/site-packages/khal/controllers.py", line 138, in __init__
echo('\n'.join(rows).encode(encoding))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 452: ordinal not in range(128)

# Fixed code
def vertical_month(
    month=datetime.date.today().month,
    year=datetime.date.today().year,
    today=datetime.date.today(),
    weeknumber=False,
    count=3,
    firstweekday=0,
):
    """
    returns a list() of str() of weeks for a vertical arranged calendar

    :param month: first month of the calendar,
                  if non given, current month is assumed
    :type month: int
    :param year: year of the first month included,
                 if non given, current year is assumed
    :type year: int
    :param today: day highlighted, if non is given, current date is assumed
    :type today: datetime.date()
    :param weeknumber: if not False the iso weeknumber will be shown for each
                       week, if weeknumber is 'right' it will be shown in its
                       own column, if it is 'left' it will be shown interleaved
                       with the month names
    :type weeknumber: str/bool
    :returns: calendar strings,  may also include some
              ANSI (color) escape strings
    :rtype: list() of str()
    """

    khal = list()
    w_number = "    " if weeknumber == "right" else ""
    calendar.setfirstweekday(firstweekday)
    _calendar = calendar.Calendar(firstweekday)
    khal.append(bstring("    " + calendar.weekheader(2) + " " + w_number))
    for _ in range(count):
        for week in _calendar.monthdatescalendar(year, month):
            new_month = len([day for day in week if day.day == 1])
            strweek = str_week(week, today)
            if new_month:
                m_name = bstring(month_abbr(week[6].month).ljust(4))
            elif weeknumber == "left":
                m_name = bstring(" {:2} ".format(getweeknumber(week[0])))
            else:
                m_name = "    "
            if weeknumber == "right":
                w_number = bstring(" {}".format(getweeknumber(week[0])))
            else:
                w_number = ""

            sweek = m_name + strweek + w_number
            if sweek != khal[-1]:
                khal.append(sweek)
        month = month + 1
        if month > 12:
            month = 1
            year = year + 1
    return khal