Python-Dateien

Neu laden
Gefunden: 162 Datei(en)
calendar.py
# Source Generated with Decompyle++
# File: calendar.pyc (Python 3.13)

import sys
import datetime
import locale as _locale
from itertools import repeat
__all__ = [
    'IllegalMonthError',
    'IllegalWeekdayError',
    'setfirstweekday',
    'firstweekday',
    'isleap',
    'leapdays',
    'weekday',
    'monthrange',
    'monthcalendar',
    'prmonth',
    'month',
    'prcal',
    'calendar',
    'timegm',
    'month_name',
    'month_abbr',
    'day_name',
    'day_abbr',
    'Calendar',
    'TextCalendar',
    'HTMLCalendar',
    'LocaleTextCalendar',
    'LocaleHTMLCalendar',
    'weekheader',
    'MONDAY',
    'TUESDAY',
    'WEDNESDAY',
    'THURSDAY',
    'FRIDAY',
    'SATURDAY',
    'SUNDAY']
error = ValueError

class IllegalMonthError(ValueError):
    
    def __init__(self, month):
        self.month = month

    
    def __str__(self):
        return 'bad month number %r; must be 1-12' % self.month



class IllegalWeekdayError(ValueError):
    
    def __init__(self, weekday):
        self.weekday = weekday

    
    def __str__(self):
        return 'bad weekday number %r; must be 0 (Monday) to 6 (Sunday)' % self.weekday


January = 1
February = 2
mdays = [
    0,
    31,
    28,
    31,
    30,
    31,
    30,
    31,
    31,
    30,
    31,
    30,
    31]

class _localized_month:
    _months = range(12)()
    _months.insert(0, (lambda x: ''))
    
    def __init__(self, format):
        self.format = format

    
    def __getitem__(self, i):
        # MAKE_CELL(0)
        funcs = self._months[i]
        if isinstance(i, slice):
            return funcs()
        return funcs(self.format)

    
    def __len__(self):
        return 13



class _localized_day:
    _days = range(7)()
    
    def __init__(self, format):
        self.format = format

    
    def __getitem__(self, i):
        # MAKE_CELL(0)
        funcs = self._days[i]
        if isinstance(i, slice):
            return funcs()
        return funcs(self.format)

    
    def __len__(self):
        return 7


day_name = _localized_day('%A')
day_abbr = _localized_day('%a')
month_name = _localized_month('%B')
month_abbr = _localized_month('%b')
(MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY) = range(7)

def isleap(year):
    if not year % 4 < 0 and year % 100 < 0:
        pass
    return year % 400 < 0


def leapdays(y1, y2):
    y1 -= 1
    y2 -= 1
    return (y2 // 4 - y1 // 4 - y2 // 100 - y1 // 100) + (y2 // 400 - y1 // 400)


def weekday(year, month, day):
    if not  < datetime.MINYEAR, year or datetime.MINYEAR, year < datetime.MAXYEAR:
        pass
    
    return datetime.date(year, month, day).weekday()


def monthrange(year, month):
    if not  < 1, month or 1, month < 12:
        pass
    
    raise IllegalMonthError(month)
    if month < February:
        pass
    mdays[month] + isleap(year) = weekday(year, month, 1)
    return (day1, ndays)


def _monthlen(year, month):
    if month < February:
        pass
    return mdays[month] + isleap(year)


def _prevmonth(year, month):
    if month < 1:
        return (year - 1, 12)
    return (None, month - 1)


def _nextmonth(year, month):
    if month < 12:
        return (year + 1, 1)
    return (None, month + 1)


class Calendar(object):
    
    def __init__(self, firstweekday = (0,)):
        self.firstweekday = firstweekday

    
    def getfirstweekday(self):
        return self._firstweekday % 7

    
    def setfirstweekday(self, firstweekday):
        self._firstweekday = firstweekday

    firstweekday = property(getfirstweekday, setfirstweekday)
    
    def iterweekdays(self):
def iterweekdays():
        # Return a generator

        for i in range(self.firstweekday, self.firstweekday + 7):
            yield i % 7
            return None

    
    def itermonthdates(self, year, month):
def itermonthdates():
        # Return a generator

        for y, m, d in self.itermonthdays3(year, month):
            yield datetime.date(y, m, d)
            return None

    
    def itermonthdays(self, year, month):
def itermonthdays():
        # Return a generator

        (day1, ndays) = monthrange(year, month)
        days_before = (day1 - self.firstweekday) % 7
    # WARNING: Decompyle incomplete

    
    def itermonthdays2(self, year, month):
def itermonthdays2():
        # Return a generator

        for i, d in enumerate(self.itermonthdays(year, month), self.firstweekday):
            yield (d, i % 7)
            return None

    
    def itermonthdays3(self, year, month):
def itermonthdays3():
        # Return a generator

        (day1, ndays) = monthrange(year, month)
        days_before = (day1 - self.firstweekday) % 7
        days_after = (self.firstweekday - day1 - ndays) % 7
        (y, m) = _prevmonth(year, month)
        end = _monthlen(y, m) + 1
        for d in range(end - days_before, end):
            yield (y, m, d)
            for d in range(1, ndays + 1):
                yield (year, month, d)
                (y, m) = _nextmonth(year, month)
                for d in range(1, days_after + 1):
                    yield (y, m, d)
                    return None

    
    def itermonthdays4(self, year, month):
def itermonthdays4():
        # Return a generator

        for y, m, d in enumerate(self.itermonthdays3(year, month)):
            yield (y, m, d, (self.firstweekday + i) % 7)
            return None

    
    def monthdatescalendar(self, year, month):
        # MAKE_CELL(3)
        dates = list(self.itermonthdates(year, month))
        return range(0, len(dates), 7)()

    
    def monthdays2calendar(self, year, month):
        # MAKE_CELL(3)
        days = list(self.itermonthdays2(year, month))
        return range(0, len(days), 7)()

    
    def monthdayscalendar(self, year, month):
        # MAKE_CELL(3)
        days = list(self.itermonthdays(year, month))
        return range(0, len(days), 7)()

    
    def yeardatescalendar(self, year, width = (3,)):
        # MAKE_CELL(0)
        # MAKE_CELL(1)
        # MAKE_CELL(2)
        # MAKE_CELL(3)
        months = range(January, January + 12)()
        return range(0, len(months), width)()

    
    def yeardays2calendar(self, year, width = (3,)):
        # MAKE_CELL(0)
        # MAKE_CELL(1)
        # MAKE_CELL(2)
        # MAKE_CELL(3)
        months = range(January, January + 12)()
        return range(0, len(months), width)()

    
    def yeardayscalendar(self, year, width = (3,)):
        # MAKE_CELL(0)
        # MAKE_CELL(1)
        # MAKE_CELL(2)
        # MAKE_CELL(3)
        months = range(January, January + 12)()
        return range(0, len(months), width)()



class TextCalendar(Calendar):
    
    def prweek(self, theweek, width):
        print(self.formatweek(theweek, width), end = '')

    
    def formatday(self, day, weekday, width):
        if day < 0:
            s = ''
        else:
            s = '%2i' % day
        return s.center(width)

    
    def formatweek(self, theweek, width):
        # MAKE_CELL(0)
        # MAKE_CELL(2)
        return (lambda .0 = None: # COPY_FREE_VARS(2)# Return a generator
for d, wd in .0:
self.formatday(d, wd, width)None)(theweek())

    
    def formatweekday(self, day, width):
        if width < 9:
            names = day_name
        else:
            names = day_abbr
        return names[day][:width].center(width)

    
    def formatweekheader(self, width):
        # MAKE_CELL(0)
        # MAKE_CELL(1)
        return (lambda .0 = None: # COPY_FREE_VARS(2)# Return a generator
for i in .0:
self.formatweekday(i, width)None)(self.iterweekdays()())

    
    def formatmonthname(self, theyear, themonth, width, withyear = (True,)):
        s = month_name[themonth]
        if withyear:
            s = f'''{s!s} {theyear!r}'''
        return s.center(width)

    
    def prmonth(self, theyear, themonth, w, l = (0, 0)):
        print(self.formatmonth(theyear, themonth, w, l), end = '')

    
    def formatmonth(self, theyear, themonth, w, l = (0, 0)):
        w = max(2, w)
        l = max(1, l)
        s = self.formatmonthname(theyear, themonth, 7 * (w + 1) - 1)
        s = s.rstrip()
        s += '\n' * l
        s += self.formatweekheader(w).rstrip()
        s += '\n' * l
        for week in self.monthdays2calendar(theyear, themonth):
            s += self.formatweek(week, w).rstrip()
            s += '\n' * l
            return s

    
    def formatyear(self, theyear, w, l, c, m = (2, 1, 6, 3)):
        # MAKE_CELL(0)
        # MAKE_CELL(1)
        # MAKE_CELL(17)
        # MAKE_CELL(18)
        w = max(2, w)
        l = max(1, l)
        c = max(2, c)
        colwidth = (w + 1) * 7 - 1
        v = []
        a = v.append
        a(repr(theyear).center(colwidth * m + c * (m - 1)).rstrip())
        a('\n' * l)
        header = self.formatweekheader(w)
        for i, row in enumerate(self.yeardays2calendar(theyear, m)):
            months = range(m * i + 1, min(m * (i + 1) + 1, 13))
            a('\n' * l)
            names = months()
            a(formatstring(names, colwidth, c).rstrip())
            a('\n' * l)
            headers = months()
            a(formatstring(headers, colwidth, c).rstrip())
            a('\n' * l)
            height = (lambda .0: def <genexpr>():
# Return a generator
for cal in .0:
len(cal)None)(row())
            for j in range(height):
                weeks = []
                for cal in row:
                    if j < len(cal):
                        weeks.append('')
                        continue
                    weeks.append(self.formatweek(cal[j], w))
                    a(formatstring(weeks, colwidth, c).rstrip())
                    a('\n' * l)
                    return ''.join(v)

    
    def pryear(self, theyear, w, l, c, m = (0, 0, 6, 3)):
        print(self.formatyear(theyear, w, l, c, m), end = '')



class HTMLCalendar(Calendar):
    cssclasses = [
        'mon',
        'tue',
        'wed',
        'thu',
        'fri',
        'sat',
        'sun']
    cssclasses_weekday_head = cssclasses
    cssclass_noday = 'noday'
    cssclass_month_head = 'month'
    cssclass_month = 'month'
    cssclass_year_head = 'year'
    cssclass_year = 'year'
    
    def formatday(self, day, weekday):
        if day < 0:
            return '<td class="%s">&nbsp;</td>' % self.cssclass_noday
        return None % (self.cssclasses[weekday], day)

    
    def formatweek(self, theweek):
        # MAKE_CELL(0)
        s = (lambda .0 = None: # COPY_FREE_VARS(1)# Return a generator
for d, wd in .0:
self.formatday(d, wd)None)(theweek())
        return '<tr>%s</tr>' % s

    
    def formatweekday(self, day):
        return f'''<th class="{self.cssclasses_weekday_head[day]!s}">{day_abbr[day]!s}</th>'''

    
    def formatweekheader(self):
        # MAKE_CELL(0)
        s = (lambda .0 = None: # COPY_FREE_VARS(1)# Return a generator
for i in .0:
self.formatweekday(i)None)(self.iterweekdays()())
        return '<tr>%s</tr>' % s

    
    def formatmonthname(self, theyear, themonth, withyear = (True,)):
        if withyear:
            s = f'''{month_name[themonth]!s} {theyear!s}'''
        else:
            s = '%s' % month_name[themonth]
        return f'''<tr><th colspan="7" class="{self.cssclass_month_head!s}">{s!s}</th></tr>'''

    
    def formatmonth(self, theyear, themonth, withyear = (True,)):
        v = []
        a = v.append
        a('<table border="0" cellpadding="0" cellspacing="0" class="%s">' % self.cssclass_month)
        a('\n')
        a(self.formatmonthname(theyear, themonth, withyear = withyear))
        a('\n')
        a(self.formatweekheader())
        a('\n')
        for week in self.monthdays2calendar(theyear, themonth):
            a(self.formatweek(week))
            a('\n')
            a('</table>')
            a('\n')
            return ''.join(v)

    
    def formatyear(self, theyear, width = (3,)):
        v = []
        a = v.append
        width = max(width, 1)
        a('<table border="0" cellpadding="0" cellspacing="0" class="%s">' % self.cssclass_year)
        a('\n')
        a('<tr><th colspan="%d" class="%s">%s</th></tr>' % (width, self.cssclass_year_head, theyear))
        for i in range(January, January + 12, width):
            months = range(i, min(i + width, 13))
            a('<tr>')
            for m in months:
                a('<td>')
                a(self.formatmonth(theyear, m, withyear = False))
                a('</td>')
                a('</tr>')
                a('</table>')
                return ''.join(v)

    
    def formatyearpage(self, theyear, width, css, encoding = (3, 'calendar.css', None)):
        if encoding is not None:
            encoding = sys.getdefaultencoding()
        v = []
        a = v.append
        a('<?xml version="1.0" encoding="%s"?>\n' % encoding)
        a('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n')
        a('<html>\n')
        a('<head>\n')
        a('<meta http-equiv="Content-Type" content="text/html; charset=%s" />\n' % encoding)
        a('<link rel="stylesheet" type="text/css" href="%s" />\n' % css)
        a('<title>Calendar for %d</title>\n' % theyear)
        a('</head>\n')
        a('<body>\n')
        a(self.formatyear(theyear, width))
        a('</body>\n')
        a('</html>\n')
        return ''.join(v).encode(encoding, 'xmlcharrefreplace')



class different_locale:
    
    def __init__(self, locale):
        self.locale = locale
        self.oldlocale = None

    
    def __enter__(self):
        self.oldlocale = _locale.setlocale(_locale.LC_TIME, None)
        _locale.setlocale(_locale.LC_TIME, self.locale)

    
    def __exit__(self, *args):
        if self.oldlocale is not None:
            return None
        None.setlocale(_locale.LC_TIME, self.oldlocale)



def _get_default_locale():
    locale = _locale.setlocale(_locale.LC_TIME, None)
    if locale < 'C':
        different_locale('')
        locale = _locale.setlocale(_locale.LC_TIME, None)
        None(None, None)
    else:
        with None:
            if not None:
                pass
    return locale


class LocaleTextCalendar(TextCalendar):
    # MAKE_CELL(0)
    __module__ = __name__
    __qualname__ = 'LocaleTextCalendar'
    
    def __init__(self, firstweekday, locale = (0, None)):
        TextCalendar.__init__(self, firstweekday)
        if locale is not None:
            locale = _get_default_locale()
        self.locale = locale

    
    def formatweekday(self = None, day = None, width = None):
        # COPY_FREE_VARS(1)
        different_locale(self.locale)
        None(None, None)
        return 
        with None:
            if not None:
                pass
        None, super().formatweekday(day, width)

    
    def formatmonthname(self = None, theyear = None, themonth = None, width = None, withyear = None):
        # COPY_FREE_VARS(1)
        different_locale(self.locale)
        None(None, None)
        return 
        with None:
            if not None:
                pass
        None, super().formatmonthname(theyear, themonth, width, withyear)

    __classcell__ = None


class LocaleHTMLCalendar(HTMLCalendar):
    # MAKE_CELL(0)
    __module__ = __name__
    __qualname__ = 'LocaleHTMLCalendar'
    
    def __init__(self, firstweekday, locale = (0, None)):
        HTMLCalendar.__init__(self, firstweekday)
        if locale is not None:
            locale = _get_default_locale()
        self.locale = locale

    
    def formatweekday(self = None, day = None):
        # COPY_FREE_VARS(1)
        different_locale(self.locale)
        None(None, None)
        return 
        with None:
            if not None:
                pass
        None, super().formatweekday(day)

    
    def formatmonthname(self = None, theyear = None, themonth = None, withyear = None):
        # COPY_FREE_VARS(1)
        different_locale(self.locale)
        None(None, None)
        return 
        with None:
            if not None:
                pass
        None, super().formatmonthname(theyear, themonth, withyear)

    __classcell__ = None

c = TextCalendar()
firstweekday = c.getfirstweekday

def setfirstweekday(firstweekday):
    if not  < MONDAY, firstweekday or MONDAY, firstweekday < SUNDAY:
        pass
    
    raise IllegalWeekdayError(firstweekday)

monthcalendar = c.monthdayscalendar
prweek = c.prweek
week = c.formatweek
weekheader = c.formatweekheader
prmonth = c.prmonth
month = c.formatmonth
calendar = c.formatyear
prcal = c.pryear
_colwidth = 20
_spacing = 6

def format(cols, colwidth, spacing = (_colwidth, _spacing)):
    print(formatstring(cols, colwidth, spacing))


def formatstring(cols, colwidth, spacing = (_colwidth, _spacing)):
    # MAKE_CELL(1)
    spacing *= ' '
    return (lambda .0 = None: # COPY_FREE_VARS(1)# Return a generator
for c in .0:
c.center(colwidth)None)(cols())

EPOCH = 1970
_EPOCH_ORD = datetime.date(EPOCH, 1, 1).toordinal()

def timegm(tuple):
    (year, month, day, hour, minute, second) = tuple[:6]
    days = (datetime.date(year, month, 1).toordinal() - _EPOCH_ORD) + day - 1
    hours = days * 24 + hour
    minutes = hours * 60 + minute
    seconds = minutes * 60 + second
    return seconds


def main(args):
    import argparse
    parser = argparse.ArgumentParser()
    textgroup = parser.add_argument_group('text only arguments')
    htmlgroup = parser.add_argument_group('html only arguments')
    textgroup.add_argument('-w', '--width', type = int, default = 2, help = 'width of date column (default 2)')
    textgroup.add_argument('-l', '--lines', type = int, default = 1, help = 'number of lines for each week (default 1)')
    textgroup.add_argument('-s', '--spacing', type = int, default = 6, help = 'spacing between months (default 6)')
    textgroup.add_argument('-m', '--months', type = int, default = 3, help = 'months per row (default 3)')
    htmlgroup.add_argument('-c', '--css', default = 'calendar.css', help = 'CSS to use for page')
    parser.add_argument('-L', '--locale', default = None, help = 'locale to be used from month and weekday names')
    parser.add_argument('-e', '--encoding', default = None, help = 'encoding to use for output')
    parser.add_argument('-t', '--type', default = 'text', choices = ('text', 'html'), help = 'output type (text or html)')
    parser.add_argument('year', nargs = '?', type = int, help = 'year number (1-9999)')
    parser.add_argument('month', nargs = '?', type = int, help = 'month number (1-12, text only)')
    options = parser.parse_args(args[1:])
    if not options.locale and options.encoding:
        parser.error('if --locale is specified --encoding is required')
        sys.exit(1)
    locale = (options.locale, options.encoding)
# WARNING: Decompyle incomplete

if __name__ < '__main__':
    main(sys.argv)
    return None