/snap/core24/1643/usr/lib/python3.12
NameSizeModeActions
asyncio/-0755rm
collections/-0755rm
concurrent/-0755rm
ctypes/-0755rm
curses/-0755rm
dbm/-0755rm
email/-0755rm
encodings/-0755rm
html/-0755rm
http/-0755rm
importlib/-0755rm
json/-0755rm
lib-dynload/-0755rm
logging/-0755rm
multiprocessing/-0755rm
pydoc_data/-0755rm
re/-0755rm
sqlite3/-0755rm
test/-0755rm
tomllib/-0755rm
unittest/-0755rm
urllib/-0755rm
venv/-0755rm
wsgiref/-0755rm
xml/-0755rm
xmlrpc/-0755rm
zipfile/-0755rm
zoneinfo/-0755rm
__phello__/-0755rm
__pycache__/-0755rm
abc.py65380644editdlrm
aifc.py342110644editdlrm
antigravity.py5000644editdlrm
argparse.py1017500644editdlrm
ast.py642600644editdlrm
base64.py206020755editdlrm
bdb.py324630644editdlrm
bisect.py34230644editdlrm
bz2.py118470644editdlrm
calendar.py254180644editdlrm
cgi.py344180755editdlrm
cgitb.py124210644editdlrm
chunk.py55000644editdlrm
cmd.py148730644editdlrm
code.py106950644editdlrm
codecs.py368700644editdlrm
codeop.py59080644editdlrm
colorsys.py40620644editdlrm
compileall.py205980644editdlrm
configparser.py537890644editdlrm
contextlib.py276370644editdlrm
contextvars.py1290644editdlrm
copy.py84120644editdlrm
copyreg.py76140644editdlrm
cProfile.py65550755editdlrm
crypt.py39130644editdlrm
csv.py163860644editdlrm
dataclasses.py617530644editdlrm
datetime.py2680644editdlrm
decimal.py3200644editdlrm
difflib.py833080644editdlrm
dis.py302090644editdlrm
doctest.py1064790644editdlrm
enum.py816360644editdlrm
EXTERNALLY-MANAGED6450644editdlrm
filecmp.py101870644editdlrm
fileinput.py157140644editdlrm
fnmatch.py59990644editdlrm
fractions.py380670644editdlrm
ftplib.py347350644editdlrm
functools.py381260644editdlrm
genericpath.py55720644editdlrm
getopt.py74880644editdlrm
getpass.py59900644editdlrm
gettext.py217470644editdlrm
glob.py87320644editdlrm
graphlib.py96560644editdlrm
gzip.py248590644editdlrm
hashlib.py93490644editdlrm
heapq.py230240644editdlrm
hmac.py77160644editdlrm
imaplib.py536880644editdlrm
imghdr.py43980644editdlrm
inspect.py1254200644editdlrm
io.py35820644editdlrm
ipaddress.py782940644editdlrm
keyword.py10730644editdlrm
LICENSE.txt139360644editdlrm
linecache.py56490644editdlrm
locale.py785620644editdlrm
lzma.py132770644editdlrm
mailbox.py789110644editdlrm
mailcap.py93330644editdlrm
mimetypes.py228880644editdlrm
modulefinder.py236990644editdlrm
netrc.py69220644editdlrm
nntplib.py410870644editdlrm
ntpath.py300270644editdlrm
nturl2path.py28870644editdlrm
numbers.py114670644editdlrm
opcode.py131740644editdlrm
operator.py109650644editdlrm
optparse.py603690644editdlrm
os.py397860644editdlrm
pathlib.py511530644editdlrm
pdb.py694590755editdlrm
pickle.py649010644editdlrm
pickletools.py938610644editdlrm
pipes.py89780644editdlrm
pkgutil.py182810644editdlrm
platform.py433310755editdlrm
plistlib.py285820644editdlrm
poplib.py141630644editdlrm
posixpath.py176230644editdlrm
pprint.py241580644editdlrm
profile.py230920755editdlrm
pstats.py292890644editdlrm
pty.py61370644editdlrm
pyclbr.py113960644editdlrm
pydoc.py1130900755editdlrm
py_compile.py78780644editdlrm
queue.py114960644editdlrm
quopri.py71830755editdlrm
random.py346830644editdlrm
reprlib.py65690644editdlrm
rlcompleter.py78270644editdlrm
runpy.py128980644editdlrm
sched.py63510644editdlrm
secrets.py19840644editdlrm
selectors.py196710644editdlrm
shelve.py85600644editdlrm
shlex.py133530644editdlrm
shutil.py581200644editdlrm
signal.py24950644editdlrm
site.py239030644editdlrm
sitecustomize.py-0editdlrm
smtplib.py435310755editdlrm
sndhdr.py74480644editdlrm
socket.py374110644editdlrm
socketserver.py278510644editdlrm
sre_compile.py2310644editdlrm
sre_constants.py2320644editdlrm
sre_parse.py2290644editdlrm
ssl.py508220644editdlrm
stat.py54850644editdlrm
statistics.py502270644editdlrm
string.py117860644editdlrm
stringprep.py129170644editdlrm
struct.py2570644editdlrm
subprocess.py887250644editdlrm
sunau.py184780644editdlrm
symtable.py107530644editdlrm
sysconfig.py327680644editdlrm
tabnanny.py115300755editdlrm
tarfile.py1125550755editdlrm
telnetlib.py233010644editdlrm
tempfile.py373340644editdlrm
textwrap.py197180644editdlrm
this.py10030644editdlrm
threading.py601230644editdlrm
timeit.py134630755editdlrm
token.py24790644editdlrm
tokenize.py212140644editdlrm
trace.py291820755editdlrm
traceback.py463250644editdlrm
tracemalloc.py180470644editdlrm
tty.py20350644editdlrm
turtle.py1463610644editdlrm
types.py109930644editdlrm
typing.py1174280644editdlrm
uu.py73640755editdlrm
uuid.py296560644editdlrm
warnings.py217600644editdlrm
wave.py227690644editdlrm
weakref.py215130644editdlrm
webbrowser.py236270755editdlrm
xdrlib.py59420644editdlrm
zipapp.py75430644editdlrm
zipimport.py281320644editdlrm
_aix_support.py40210644editdlrm
_collections_abc.py320820644editdlrm
_compat_pickle.py87610644editdlrm
_compression.py56810644editdlrm
_distutils_system_mod.py57160644editdlrm
_markupbase.py146530644editdlrm
_osx_support.py220230644editdlrm
_pydatetime.py920970644editdlrm
_pydecimal.py2292200644editdlrm
_pyio.py935930644editdlrm
_pylong.py90470644editdlrm
_py_abc.py61890644editdlrm
_sitebuiltins.py31280644editdlrm
_strptime.py246150644editdlrm
_sysconfigdata__linux_x86_64-linux-gnu.py495050644editdlrm
_sysconfigdata__x86_64-linux-gnu.py495050644editdlrm
_threading_local.py72200644editdlrm
_weakrefset.py58930644editdlrm
__future__.py52180644editdlrm
__hello__.py2270644editdlrm
Edit: /snap/core24/1643/usr/lib/python3.12/calendar.py (25418B)
"""Calendar printing functions Note when comparing these calendars to the ones printed by cal(1): By default, these calendars have Monday as the first day of the week, and Sunday as the last (the European convention). Use setfirstweekday() to set the first day of the week (0=Monday, 6=Sunday).""" import sys import datetime from enum import IntEnum, global_enum import locale as _locale from itertools import repeat import warnings __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", "Day", "Month", "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"] # Exception raised for bad input (with string parameter for details) error = ValueError # Exceptions raised for bad input 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 def __getattr__(name): if name in ('January', 'February'): warnings.warn(f"The '{name}' attribute is deprecated, use '{name.upper()}' instead", DeprecationWarning, stacklevel=2) if name == 'January': return 1 else: return 2 raise AttributeError(f"module '{__name__}' has no attribute '{name}'") # Constants for months @global_enum class Month(IntEnum): JANUARY = 1 FEBRUARY = 2 MARCH = 3 APRIL = 4 MAY = 5 JUNE = 6 JULY = 7 AUGUST = 8 SEPTEMBER = 9 OCTOBER = 10 NOVEMBER = 11 DECEMBER = 12 # Constants for days @global_enum class Day(IntEnum): MONDAY = 0 TUESDAY = 1 WEDNESDAY = 2 THURSDAY = 3 FRIDAY = 4 SATURDAY = 5 SUNDAY = 6 # Number of days per month (except for February in leap years) mdays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] # This module used to have hard-coded lists of day and month names, as # English strings. The classes following emulate a read-only version of # that, but supply localized names. Note that the values are computed # fresh on each call, in case the user changes locale between calls. class _localized_month: _months = [datetime.date(2001, i+1, 1).strftime for i in range(12)] _months.insert(0, lambda x: "") def __init__(self, format): self.format = format def __getitem__(self, i): funcs = self._months[i] if isinstance(i, slice): return [f(self.format) for f in funcs] else: return funcs(self.format) def __len__(self): return 13 class _localized_day: # January 1, 2001, was a Monday. _days = [datetime.date(2001, 1, i+1).strftime for i in range(7)] def __init__(self, format): self.format = format def __getitem__(self, i): funcs = self._days[i] if isinstance(i, slice): return [f(self.format) for f in funcs] else: return funcs(self.format) def __len__(self): return 7 # Full and abbreviated names of weekdays day_name = _localized_day('%A') day_abbr = _localized_day('%a') # Full and abbreviated names of months (1-based arrays!!!) month_name = _localized_month('%B') month_abbr = _localized_month('%b') def isleap(year): """Return True for leap years, False for non-leap years.""" return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) def leapdays(y1, y2): """Return number of leap years in range [y1, y2). Assume y1 <= y2.""" y1 -= 1 y2 -= 1 return (y2//4 - y1//4) - (y2//100 - y1//100) + (y2//400 - y1//400) def weekday(year, month, day): """Return weekday (0-6 ~ Mon-Sun) for year, month (1-12), day (1-31).""" if not datetime.MINYEAR <= year <= datetime.MAXYEAR: year = 2000 + year % 400 return Day(datetime.date(year, month, day).weekday()) def monthrange(year, month): """Return weekday (0-6 ~ Mon-Sun) and number of days (28-31) for year, month.""" if not 1 <= month <= 12: raise IllegalMonthError(month) day1 = weekday(year, month, 1) ndays = mdays[month] + (month == FEBRUARY and isleap(year)) return day1, ndays def _monthlen(year, month): return mdays[month] + (month == FEBRUARY and isleap(year)) def _prevmonth(year, month): if month == 1: return year-1, 12 else: return year, month-1 def _nextmonth(year, month): if month == 12: return year+1, 1 else: return year, month+1 class Calendar(object): """ Base calendar class. This class doesn't do any formatting. It simply provides data to subclasses. """ def __init__(self, firstweekday=0): self.firstweekday = firstweekday # 0 = Monday, 6 = Sunday def getfirstweekday(self): return self._firstweekday % 7 def setfirstweekday(self, firstweekday): self._firstweekday = firstweekday firstweekday = property(getfirstweekday, setfirstweekday) def iterweekdays(self): """ Return an iterator for one week of weekday numbers starting with the configured first one. """ for i in range(self.firstweekday, self.firstweekday + 7): yield i%7 def itermonthdates(self, year, month): """ Return an iterator for one month. The iterator will yield datetime.date values and will always iterate through complete weeks, so it will yield dates outside the specified month. """ for y, m, d in self.itermonthdays3(year, month): yield datetime.date(y, m, d) def itermonthdays(self, year, month): """ Like itermonthdates(), but will yield day numbers. For days outside the specified month the day number is 0. """ day1, ndays = monthrange(year, month) days_before = (day1 - self.firstweekday) % 7 yield from repeat(0, days_before) yield from range(1, ndays + 1) days_after = (self.firstweekday - day1 - ndays) % 7 yield from repeat(0, days_after) def itermonthdays2(self, year, month): """ Like itermonthdates(), but will yield (day number, weekday number) tuples. For days outside the specified month the day number is 0. """ for i, d in enumerate(self.itermonthdays(year, month), self.firstweekday): yield d, i % 7 def itermonthdays3(self, year, month): """ Like itermonthdates(), but will yield (year, month, day) tuples. Can be used for dates outside of datetime.date range. """ 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 def itermonthdays4(self, year, month): """ Like itermonthdates(), but will yield (year, month, day, day_of_week) tuples. Can be used for dates outside of datetime.date range. """ for i, (y, m, d) in enumerate(self.itermonthdays3(year, month)): yield y, m, d, (self.firstweekday + i) % 7 def monthdatescalendar(self, year, month): """ Return a matrix (list of lists) representing a month's calendar. Each row represents a week; week entries are datetime.date values. """ dates = list(self.itermonthdates(year, month)) return [ dates[i:i+7] for i in range(0, len(dates), 7) ] def monthdays2calendar(self, year, month): """ Return a matrix representing a month's calendar. Each row represents a week; week entries are (day number, weekday number) tuples. Day numbers outside this month are zero. """ days = list(self.itermonthdays2(year, month)) return [ days[i:i+7] for i in range(0, len(days), 7) ] def monthdayscalendar(self, year, month): """ Return a matrix representing a month's calendar. Each row represents a week; days outside this month are zero. """ days = list(self.itermonthdays(year, month)) return [ days[i:i+7] for i in range(0, len(days), 7) ] def yeardatescalendar(self, year, width=3): """ Return the data for the specified year ready for formatting. The return value is a list of month rows. Each month row contains up to width months. Each month contains between 4 and 6 weeks and each week contains 1-7 days. Days are datetime.date objects. """ months = [self.monthdatescalendar(year, m) for m in Month] return [months[i:i+width] for i in range(0, len(months), width) ] def yeardays2calendar(self, year, width=3): """ Return the data for the specified year ready for formatting (similar to yeardatescalendar()). Entries in the week lists are (day number, weekday number) tuples. Day numbers outside this month are zero. """ months = [self.monthdays2calendar(year, m) for m in Month] return [months[i:i+width] for i in range(0, len(months), width) ] def yeardayscalendar(self, year, width=3): """ Return the data for the specified year ready for formatting (similar to yeardatescalendar()). Entries in the week lists are day numbers. Day numbers outside this month are zero. """ months = [self.monthdayscalendar(year, m) for m in Month] return [months[i:i+width] for i in range(0, len(months), width) ] class TextCalendar(Calendar): """ Subclass of Calendar that outputs a calendar as a simple plain text similar to the UNIX program cal. """ def prweek(self, theweek, width): """ Print a single week (no newline). """ print(self.formatweek(theweek, width), end='') def formatday(self, day, weekday, width): """ Returns a formatted day. """ if day == 0: s = '' else: s = '%2i' % day # right-align single-digit days return s.center(width) def formatweek(self, theweek, width): """ Returns a single week in a string (no newline). """ return ' '.join(self.formatday(d, wd, width) for (d, wd) in theweek) def formatweekday(self, day, width): """ Returns a formatted week day name. """ if width >= 9: names = day_name else: names = day_abbr return names[day][:width].center(width) def formatweekheader(self, width): """ Return a header for a week. """ return ' '.join(self.formatweekday(i, width) for i in self.iterweekdays()) def formatmonthname(self, theyear, themonth, width, withyear=True): """ Return a formatted month name. """ s = month_name[themonth] if withyear: s = "%s %r" % (s, theyear) return s.center(width) def prmonth(self, theyear, themonth, w=0, l=0): """ Print a month's calendar. """ print(self.formatmonth(theyear, themonth, w, l), end='') def formatmonth(self, theyear, themonth, w=0, l=0): """ Return a month's calendar string (multi-line). """ 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=2, l=1, c=6, m=3): """ Returns a year's calendar as a multi-line string. """ 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 in this row months = range(m*i+1, min(m*(i+1)+1, 13)) a('\n'*l) names = (self.formatmonthname(theyear, k, colwidth, False) for k in months) a(formatstring(names, colwidth, c).rstrip()) a('\n'*l) headers = (header for k in months) a(formatstring(headers, colwidth, c).rstrip()) a('\n'*l) # max number of weeks for this row height = max(len(cal) for cal in row) for j in range(height): weeks = [] for cal in row: if j >= len(cal): weeks.append('') else: weeks.append(self.formatweek(cal[j], w)) a(formatstring(weeks, colwidth, c).rstrip()) a('\n' * l) return ''.join(v) def pryear(self, theyear, w=0, l=0, c=6, m=3): """Print a year's calendar.""" print(self.formatyear(theyear, w, l, c, m), end='') class HTMLCalendar(Calendar): """ This calendar returns complete HTML pages. """ # CSS classes for the day s cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] # CSS classes for the day s cssclasses_weekday_head = cssclasses # CSS class for the days before and after current month cssclass_noday = "noday" # CSS class for the month's head cssclass_month_head = "month" # CSS class for the month cssclass_month = "month" # CSS class for the year's table head cssclass_year_head = "year" # CSS class for the whole year table cssclass_year = "year" def formatday(self, day, weekday): """ Return a day as a table cell. """ if day == 0: # day outside month return ' ' % self.cssclass_noday else: return '%d' % (self.cssclasses[weekday], day) def formatweek(self, theweek): """ Return a complete week as a table row. """ s = ''.join(self.formatday(d, wd) for (d, wd) in theweek) return '%s' % s def formatweekday(self, day): """ Return a weekday name as a table header. """ return '%s' % ( self.cssclasses_weekday_head[day], day_abbr[day]) def formatweekheader(self): """ Return a header for a week as a table row. """ s = ''.join(self.formatweekday(i) for i in self.iterweekdays()) return '%s' % s def formatmonthname(self, theyear, themonth, withyear=True): """ Return a month name as a table row. """ if withyear: s = '%s %s' % (month_name[themonth], theyear) else: s = '%s' % month_name[themonth] return '%s' % ( self.cssclass_month_head, s) def formatmonth(self, theyear, themonth, withyear=True): """ Return a formatted month as a table. """ v = [] a = v.append a('' % ( 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('
') a('\n') return ''.join(v) def formatyear(self, theyear, width=3): """ Return a formatted year as a table of tables. """ v = [] a = v.append width = max(width, 1) a('' % self.cssclass_year) a('\n') a('' % ( width, self.cssclass_year_head, theyear)) for i in range(JANUARY, JANUARY+12, width): # months in this row months = range(i, min(i+width, 13)) a('') for m in months: a('') a('') a('
%s
') a(self.formatmonth(theyear, m, withyear=False)) a('
') return ''.join(v) def formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None): """ Return a formatted year as a complete HTML page. """ if encoding is None: encoding = sys.getdefaultencoding() v = [] a = v.append a('\n' % encoding) a('\n') a('\n') a('\n') a('\n' % encoding) if css is not None: a('\n' % css) a('Calendar for %d\n' % theyear) a('\n') a('\n') a(self.formatyear(theyear, width)) a('\n') a('\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 None: return _locale.setlocale(_locale.LC_TIME, self.oldlocale) def _get_default_locale(): locale = _locale.setlocale(_locale.LC_TIME, None) if locale == "C": with different_locale(""): # The LC_TIME locale does not seem to be configured: # get the user preferred locale. locale = _locale.setlocale(_locale.LC_TIME, None) return locale class LocaleTextCalendar(TextCalendar): """ This class can be passed a locale name in the constructor and will return month and weekday names in the specified locale. """ def __init__(self, firstweekday=0, locale=None): TextCalendar.__init__(self, firstweekday) if locale is None: locale = _get_default_locale() self.locale = locale def formatweekday(self, day, width): with different_locale(self.locale): return super().formatweekday(day, width) def formatmonthname(self, theyear, themonth, width, withyear=True): with different_locale(self.locale): return super().formatmonthname(theyear, themonth, width, withyear) class LocaleHTMLCalendar(HTMLCalendar): """ This class can be passed a locale name in the constructor and will return month and weekday names in the specified locale. """ def __init__(self, firstweekday=0, locale=None): HTMLCalendar.__init__(self, firstweekday) if locale is None: locale = _get_default_locale() self.locale = locale def formatweekday(self, day): with different_locale(self.locale): return super().formatweekday(day) def formatmonthname(self, theyear, themonth, withyear=True): with different_locale(self.locale): return super().formatmonthname(theyear, themonth, withyear) # Support for old module level interface c = TextCalendar() firstweekday = c.getfirstweekday def setfirstweekday(firstweekday): if not MONDAY <= firstweekday <= SUNDAY: raise IllegalWeekdayError(firstweekday) c.firstweekday = 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 # Spacing of month columns for multi-column year calendar _colwidth = 7*3 - 1 # Amount printed by prweek() _spacing = 6 # Number of spaces between columns def format(cols, colwidth=_colwidth, spacing=_spacing): """Prints multi-column formatting for year calendars""" print(formatstring(cols, colwidth, spacing)) def formatstring(cols, colwidth=_colwidth, spacing=_spacing): """Returns a string formatted from n strings, centered within n columns.""" spacing *= ' ' return spacing.join(c.center(colwidth) for c in cols) EPOCH = 1970 _EPOCH_ORD = datetime.date(EPOCH, 1, 1).toordinal() def timegm(tuple): """Unrelated but handy function to calculate Unix timestamp from GMT.""" 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 use for 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" ) parser.add_argument( "month", nargs='?', type=int, help="month number (1-12, text only)" ) options = parser.parse_args(args[1:]) if options.locale and not options.encoding: parser.error("if --locale is specified --encoding is required") sys.exit(1) locale = options.locale, options.encoding if options.type == "html": if options.locale: cal = LocaleHTMLCalendar(locale=locale) else: cal = HTMLCalendar() encoding = options.encoding if encoding is None: encoding = sys.getdefaultencoding() optdict = dict(encoding=encoding, css=options.css) write = sys.stdout.buffer.write if options.year is None: write(cal.formatyearpage(datetime.date.today().year, **optdict)) elif options.month is None: write(cal.formatyearpage(options.year, **optdict)) else: parser.error("incorrect number of arguments") sys.exit(1) else: if options.locale: cal = LocaleTextCalendar(locale=locale) else: cal = TextCalendar() optdict = dict(w=options.width, l=options.lines) if options.month is None: optdict["c"] = options.spacing optdict["m"] = options.months if options.year is None: result = cal.formatyear(datetime.date.today().year, **optdict) elif options.month is None: result = cal.formatyear(options.year, **optdict) else: result = cal.formatmonth(options.year, options.month, **optdict) write = sys.stdout.write if options.encoding: result = result.encode(options.encoding) write = sys.stdout.buffer.write write(result) if __name__ == "__main__": main(sys.argv)