Current Path: > > usr > lib64 > python3.6 >
Operation : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64 Software : Apache Server IP : 162.0.232.56 | Your IP: 216.73.216.111 Domains : 1034 Domain(s) Permission : [ 0755 ]
Name | Type | Size | Last Modified | Actions |
---|---|---|---|---|
__pycache__ | Directory | - | - | |
asyncio | Directory | - | - | |
collections | Directory | - | - | |
concurrent | Directory | - | - | |
config-3.6m-x86_64-linux-gnu | Directory | - | - | |
ctypes | Directory | - | - | |
curses | Directory | - | - | |
dbm | Directory | - | - | |
distutils | Directory | - | - | |
Directory | - | - | ||
encodings | Directory | - | - | |
ensurepip | Directory | - | - | |
html | Directory | - | - | |
http | Directory | - | - | |
importlib | Directory | - | - | |
json | Directory | - | - | |
lib-dynload | Directory | - | - | |
lib2to3 | Directory | - | - | |
logging | Directory | - | - | |
multiprocessing | Directory | - | - | |
pydoc_data | Directory | - | - | |
site-packages | Directory | - | - | |
sqlite3 | Directory | - | - | |
test | Directory | - | - | |
unittest | Directory | - | - | |
urllib | Directory | - | - | |
venv | Directory | - | - | |
wsgiref | Directory | - | - | |
xml | Directory | - | - | |
xmlrpc | Directory | - | - | |
__future__.py | File | 4841 bytes | December 23 2018 21:37:14. | |
__phello__.foo.py | File | 64 bytes | December 23 2018 21:37:14. | |
_bootlocale.py | File | 1301 bytes | December 23 2018 21:37:14. | |
_collections_abc.py | File | 26392 bytes | December 23 2018 21:37:14. | |
_compat_pickle.py | File | 8749 bytes | December 23 2018 21:37:14. | |
_compression.py | File | 5340 bytes | December 23 2018 21:37:14. | |
_dummy_thread.py | File | 5118 bytes | December 23 2018 21:37:14. | |
_markupbase.py | File | 14598 bytes | December 23 2018 21:37:14. | |
_osx_support.py | File | 19138 bytes | December 23 2018 21:37:14. | |
_pydecimal.py | File | 230228 bytes | December 23 2018 21:37:14. | |
_pyio.py | File | 88097 bytes | December 23 2018 21:37:14. | |
_sitebuiltins.py | File | 3115 bytes | December 23 2018 21:37:14. | |
_strptime.py | File | 24747 bytes | December 23 2018 21:37:14. | |
_sysconfigdata_dm_linux_x86_64-linux-gnu.py | File | 30191 bytes | July 01 2025 22:10:37. | |
_sysconfigdata_m_linux_x86_64-linux-gnu.py | File | 30367 bytes | July 01 2025 22:14:06. | |
_threading_local.py | File | 7214 bytes | December 23 2018 21:37:14. | |
_weakrefset.py | File | 5705 bytes | December 23 2018 21:37:14. | |
abc.py | File | 8727 bytes | December 23 2018 21:37:14. | |
aifc.py | File | 32454 bytes | December 23 2018 21:37:14. | |
antigravity.py | File | 477 bytes | December 23 2018 21:37:14. | |
argparse.py | File | 90372 bytes | December 23 2018 21:37:14. | |
ast.py | File | 12166 bytes | December 23 2018 21:37:14. | |
asynchat.py | File | 11328 bytes | December 23 2018 21:37:14. | |
asyncore.py | File | 20159 bytes | December 23 2018 21:37:14. | |
base64.py | File | 20388 bytes | December 23 2018 21:37:14. | |
bdb.py | File | 23556 bytes | December 23 2018 21:37:14. | |
binhex.py | File | 13954 bytes | December 23 2018 21:37:14. | |
bisect.py | File | 2595 bytes | December 23 2018 21:37:14. | |
bz2.py | File | 12478 bytes | December 23 2018 21:37:14. | |
cProfile.py | File | 5380 bytes | December 23 2018 21:37:14. | |
calendar.py | File | 23213 bytes | December 23 2018 21:37:14. | |
cgi.py | File | 37219 bytes | July 01 2025 22:09:53. | |
cgitb.py | File | 12018 bytes | December 23 2018 21:37:14. | |
chunk.py | File | 5425 bytes | December 23 2018 21:37:14. | |
cmd.py | File | 14860 bytes | December 23 2018 21:37:14. | |
code.py | File | 10614 bytes | December 23 2018 21:37:14. | |
codecs.py | File | 36276 bytes | December 23 2018 21:37:14. | |
codeop.py | File | 5994 bytes | December 23 2018 21:37:14. | |
colorsys.py | File | 4064 bytes | December 23 2018 21:37:14. | |
compileall.py | File | 12125 bytes | December 23 2018 21:37:14. | |
configparser.py | File | 53592 bytes | December 23 2018 21:37:14. | |
contextlib.py | File | 13162 bytes | December 23 2018 21:37:14. | |
copy.py | File | 8815 bytes | December 23 2018 21:37:14. | |
copyreg.py | File | 7007 bytes | December 23 2018 21:37:14. | |
crypt.py | File | 1864 bytes | December 23 2018 21:37:14. | |
csv.py | File | 16180 bytes | December 23 2018 21:37:14. | |
datetime.py | File | 82034 bytes | December 23 2018 21:37:14. | |
decimal.py | File | 320 bytes | December 23 2018 21:37:14. | |
difflib.py | File | 84377 bytes | December 23 2018 21:37:14. | |
dis.py | File | 18132 bytes | December 23 2018 21:37:14. | |
doctest.py | File | 104391 bytes | December 23 2018 21:37:14. | |
dummy_threading.py | File | 2815 bytes | December 23 2018 21:37:14. | |
enum.py | File | 33606 bytes | December 23 2018 21:37:14. | |
filecmp.py | File | 9830 bytes | December 23 2018 21:37:14. | |
fileinput.py | File | 14471 bytes | December 23 2018 21:37:14. | |
fnmatch.py | File | 3166 bytes | December 23 2018 21:37:14. | |
formatter.py | File | 15143 bytes | December 23 2018 21:37:14. | |
fractions.py | File | 23639 bytes | December 23 2018 21:37:14. | |
ftplib.py | File | 35617 bytes | July 01 2025 22:09:53. | |
functools.py | File | 31346 bytes | December 23 2018 21:37:14. | |
genericpath.py | File | 5028 bytes | July 01 2025 22:09:53. | |
getopt.py | File | 7489 bytes | December 23 2018 21:37:14. | |
getpass.py | File | 5994 bytes | December 23 2018 21:37:14. | |
gettext.py | File | 21530 bytes | December 23 2018 21:37:14. | |
glob.py | File | 5638 bytes | December 23 2018 21:37:14. | |
gzip.py | File | 20334 bytes | December 23 2018 21:37:14. | |
hashlib.py | File | 8799 bytes | July 01 2025 22:09:53. | |
heapq.py | File | 22929 bytes | December 23 2018 21:37:14. | |
hmac.py | File | 6381 bytes | July 01 2025 22:09:53. | |
imaplib.py | File | 53295 bytes | December 23 2018 21:37:14. | |
imghdr.py | File | 3795 bytes | December 23 2018 21:37:14. | |
imp.py | File | 10669 bytes | December 23 2018 21:37:14. | |
inspect.py | File | 116958 bytes | December 23 2018 21:37:14. | |
io.py | File | 3517 bytes | December 23 2018 21:37:14. | |
ipaddress.py | File | 77818 bytes | July 01 2025 22:09:53. | |
keyword.py | File | 2219 bytes | December 23 2018 21:37:14. | |
linecache.py | File | 5312 bytes | December 23 2018 21:37:14. | |
locale.py | File | 77300 bytes | December 23 2018 21:37:14. | |
lzma.py | File | 12983 bytes | December 23 2018 21:37:14. | |
macpath.py | File | 5971 bytes | December 23 2018 21:37:14. | |
macurl2path.py | File | 2732 bytes | December 23 2018 21:37:14. | |
mailbox.py | File | 78624 bytes | December 23 2018 21:37:14. | |
mailcap.py | File | 9067 bytes | July 01 2025 22:09:53. | |
mimetypes.py | File | 21042 bytes | December 23 2018 21:37:14. | |
modulefinder.py | File | 23027 bytes | December 23 2018 21:37:14. | |
netrc.py | File | 5684 bytes | December 23 2018 21:37:14. | |
nntplib.py | File | 43078 bytes | December 23 2018 21:37:14. | |
ntpath.py | File | 23094 bytes | December 23 2018 21:37:14. | |
nturl2path.py | File | 2444 bytes | December 23 2018 21:37:14. | |
numbers.py | File | 10243 bytes | December 23 2018 21:37:14. | |
opcode.py | File | 5822 bytes | December 23 2018 21:37:14. | |
operator.py | File | 10863 bytes | December 23 2018 21:37:14. | |
optparse.py | File | 60371 bytes | December 23 2018 21:37:14. | |
os.py | File | 37526 bytes | December 23 2018 21:37:14. | |
pathlib.py | File | 46238 bytes | July 01 2025 22:09:53. | |
pdb.py | File | 61320 bytes | December 23 2018 21:37:14. | |
pickle.py | File | 55691 bytes | December 23 2018 21:37:14. | |
pickletools.py | File | 91775 bytes | December 23 2018 21:37:14. | |
pipes.py | File | 8916 bytes | December 23 2018 21:37:14. | |
pkgutil.py | File | 21315 bytes | December 23 2018 21:37:14. | |
platform.py | File | 47214 bytes | July 01 2025 22:09:53. | |
plistlib.py | File | 32291 bytes | July 01 2025 22:09:53. | |
poplib.py | File | 14964 bytes | December 23 2018 21:37:14. | |
posixpath.py | File | 16324 bytes | July 01 2025 22:09:53. | |
pprint.py | File | 20860 bytes | December 23 2018 21:37:14. | |
profile.py | File | 22029 bytes | December 23 2018 21:37:14. | |
pstats.py | File | 26564 bytes | December 23 2018 21:37:14. | |
pty.py | File | 4763 bytes | December 23 2018 21:37:14. | |
py_compile.py | File | 7181 bytes | December 23 2018 21:37:14. | |
pyclbr.py | File | 13558 bytes | December 23 2018 21:37:14. | |
pydoc.py | File | 103501 bytes | July 01 2025 22:14:42. | |
queue.py | File | 8780 bytes | December 23 2018 21:37:14. | |
quopri.py | File | 7262 bytes | December 23 2018 21:37:14. | |
random.py | File | 27442 bytes | December 23 2018 21:37:14. | |
re.py | File | 15552 bytes | December 23 2018 21:37:14. | |
reprlib.py | File | 5336 bytes | December 23 2018 21:37:14. | |
rlcompleter.py | File | 7097 bytes | December 23 2018 21:37:14. | |
runpy.py | File | 11959 bytes | December 23 2018 21:37:14. | |
sched.py | File | 6511 bytes | December 23 2018 21:37:14. | |
secrets.py | File | 2038 bytes | December 23 2018 21:37:14. | |
selectors.py | File | 19438 bytes | December 23 2018 21:37:14. | |
shelve.py | File | 8515 bytes | December 23 2018 21:37:14. | |
shlex.py | File | 12956 bytes | December 23 2018 21:37:14. | |
shutil.py | File | 40829 bytes | July 01 2025 22:09:53. | |
signal.py | File | 2123 bytes | December 23 2018 21:37:14. | |
site.py | File | 21268 bytes | July 01 2025 22:09:53. | |
smtpd.py | File | 34719 bytes | December 23 2018 21:37:14. | |
smtplib.py | File | 44218 bytes | December 23 2018 21:37:14. | |
sndhdr.py | File | 7088 bytes | December 23 2018 21:37:14. | |
socket.py | File | 27443 bytes | December 23 2018 21:37:14. | |
socketserver.py | File | 27010 bytes | December 23 2018 21:37:14. | |
sre_compile.py | File | 19338 bytes | December 23 2018 21:37:14. | |
sre_constants.py | File | 6821 bytes | December 23 2018 21:37:14. | |
sre_parse.py | File | 36536 bytes | December 23 2018 21:37:14. | |
ssl.py | File | 44509 bytes | July 01 2025 22:09:53. | |
stat.py | File | 5038 bytes | December 23 2018 21:37:14. | |
statistics.py | File | 20673 bytes | December 23 2018 21:37:14. | |
string.py | File | 11795 bytes | December 23 2018 21:37:14. | |
stringprep.py | File | 12917 bytes | December 23 2018 21:37:14. | |
struct.py | File | 257 bytes | December 23 2018 21:37:14. | |
subprocess.py | File | 62339 bytes | December 23 2018 21:37:14. | |
sunau.py | File | 18095 bytes | December 23 2018 21:37:14. | |
symbol.py | File | 2119 bytes | December 23 2018 21:37:14. | |
symtable.py | File | 7277 bytes | December 23 2018 21:37:14. | |
sysconfig.py | File | 24876 bytes | July 01 2025 22:14:40. | |
tabnanny.py | File | 11411 bytes | December 23 2018 21:37:14. | |
tarfile.py | File | 111510 bytes | July 01 2025 22:09:53. | |
telnetlib.py | File | 23136 bytes | December 23 2018 21:37:14. | |
tempfile.py | File | 28066 bytes | July 01 2025 22:09:53. | |
textwrap.py | File | 19558 bytes | December 23 2018 21:37:14. | |
this.py | File | 1003 bytes | December 23 2018 21:37:14. | |
threading.py | File | 50136 bytes | July 01 2025 22:09:53. | |
timeit.py | File | 13342 bytes | December 23 2018 21:37:14. | |
token.py | File | 3075 bytes | December 23 2018 21:37:14. | |
tokenize.py | File | 29496 bytes | December 23 2018 21:37:14. | |
trace.py | File | 28733 bytes | December 23 2018 21:37:14. | |
traceback.py | File | 23458 bytes | December 23 2018 21:37:14. | |
tracemalloc.py | File | 16658 bytes | December 23 2018 21:37:14. | |
tty.py | File | 879 bytes | December 23 2018 21:37:14. | |
types.py | File | 8870 bytes | December 23 2018 21:37:14. | |
typing.py | File | 80274 bytes | December 23 2018 21:37:14. | |
uu.py | File | 6763 bytes | December 23 2018 21:37:14. | |
uuid.py | File | 24020 bytes | July 01 2025 22:09:53. | |
warnings.py | File | 18488 bytes | December 23 2018 21:37:14. | |
wave.py | File | 17709 bytes | December 23 2018 21:37:14. | |
weakref.py | File | 20466 bytes | December 23 2018 21:37:14. | |
webbrowser.py | File | 21767 bytes | December 23 2018 21:37:14. | |
xdrlib.py | File | 5913 bytes | December 23 2018 21:37:14. | |
zipapp.py | File | 7157 bytes | December 23 2018 21:37:14. | |
zipfile.py | File | 79924 bytes | July 01 2025 22:09:53. |
"""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 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"] # 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 # Constants for months referenced later January = 1 February = 2 # 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') # Constants for weekdays (MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY) = range(7) 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 (1970-...), month (1-12), day (1-31).""" return 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 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. """ date = datetime.date(year, month, 1) # Go back to the beginning of the week days = (date.weekday() - self.firstweekday) % 7 date -= datetime.timedelta(days=days) oneday = datetime.timedelta(days=1) while True: yield date try: date += oneday except OverflowError: # Adding one day could fail after datetime.MAXYEAR break if date.month != month and date.weekday() == self.firstweekday: break 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 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 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, i) for i in range(January, January+12) ] 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, i) for i in range(January, January+12) ] 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, i) for i in range(January, January+12) ] 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)) class HTMLCalendar(Calendar): """ This calendar returns complete HTML pages. """ # CSS classes for the day <td>s cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] def formatday(self, day, weekday): """ Return a day as a table cell. """ if day == 0: return '<td class="noday"> </td>' # day outside month else: return '<td class="%s">%d</td>' % (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 '<tr>%s</tr>' % s def formatweekday(self, day): """ Return a weekday name as a table header. """ return '<th class="%s">%s</th>' % (self.cssclasses[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 '<tr>%s</tr>' % 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 '<tr><th colspan="7" class="month">%s</th></tr>' % s def formatmonth(self, theyear, themonth, withyear=True): """ Return a formatted month as a table. """ v = [] a = v.append a('<table border="0" cellpadding="0" cellspacing="0" class="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): """ Return a formatted year as a table of tables. """ v = [] a = v.append width = max(width, 1) a('<table border="0" cellpadding="0" cellspacing="0" class="year">') a('\n') a('<tr><th colspan="%d" class="year">%s</th></tr>' % (width, theyear)) for i in range(January, January+12, width): # months in this row 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=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('<?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) if css is not None: 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 def __enter__(self): self.oldlocale = _locale.getlocale(_locale.LC_TIME) _locale.setlocale(_locale.LC_TIME, self.locale) def __exit__(self, *args): _locale.setlocale(_locale.LC_TIME, self.oldlocale) 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. If this locale includes an encoding all strings containing month and weekday names will be returned as unicode. """ def __init__(self, firstweekday=0, locale=None): TextCalendar.__init__(self, firstweekday) if locale is None: locale = _locale.getdefaultlocale() self.locale = locale def formatweekday(self, day, width): with different_locale(self.locale): if width >= 9: names = day_name else: names = day_abbr name = names[day] return name[:width].center(width) def formatmonthname(self, theyear, themonth, width, withyear=True): with different_locale(self.locale): s = month_name[themonth] if withyear: s = "%s %r" % (s, theyear) return s.center(width) 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. If this locale includes an encoding all strings containing month and weekday names will be returned as unicode. """ def __init__(self, firstweekday=0, locale=None): HTMLCalendar.__init__(self, firstweekday) if locale is None: locale = _locale.getdefaultlocale() self.locale = locale def formatweekday(self, day): with different_locale(self.locale): s = day_abbr[day] return '<th class="%s">%s</th>' % (self.cssclasses[day], s) def formatmonthname(self, theyear, themonth, withyear=True): with different_locale(self.locale): s = month_name[themonth] if withyear: s = '%s %s' % (s, theyear) return '<tr><th colspan="7" class="month">%s</th></tr>' % s # 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 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 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)
SILENT KILLER Tool