'Render a timetuple as string according to the given format
@param timetuple: the timetuple (y, m, d, hh, mm, ss)
@param dtfmt: the date/time format (string)
@todo: support day-of-week options'

def render(self, timetuple, dtfmt):

    (y, m, d, hh, mm, ss) = timetuple
    T = current.T
    calendar = self.calendar
    from s3utils import s3_unicode
    rules = {'d': ('%02d' % d), 'b': T(calendar.MONTH_ABBR[(m - 1)]), 'B': T(calendar.MONTH_NAME[(m - 1)]), 'm': ('%02d' % m), 'y': ('%02d' % (y % 100)), 'Y': ('%04d' % y), 'H': ('%02d' % hh), 'I': ('%02d' % ((hh % 12) or 12)), 'p': (T('AM') if (hh < 12) else T('PM')), 'M': ('%02d' % mm), 'S': ('%02d' % ss)}
    result = []
    sequence = []
    def close(s):
        s = ''.join(s)
        if s:
            result.append(s)
    rule = False
    for c in s3_unicode(dtfmt):
        if (rule and (c in rules)):
            sequence.pop()
            close(sequence)
            result.append(s3_unicode(rules[c]))
            sequence = []
            rule = False
            continue
        if ((c == '%') and (not rule)):
            rule = True
        else:
            rule = False
        sequence.append(c)
    if sequence:
        close(sequence)
    return ''.join(result)
