grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026B (R}i0ñûã@s4dZddlZddlZddlZddlmZdddddd d d d d ddddddddddddddgZeZ Gdd„deƒZ Gdd„deƒZ dZ dZ dd d!d d"d d"d d d"d d"d g ZGd#d$„d$ƒZGd%d&„d&ƒZed'ƒZed(ƒZed)ƒZed*ƒZed+ƒ\ZZZZZZZd,d„Zd-d „Zd.d „Zd/d „Z d0d1„Z!d2d3„Z"d4d5„Z#Gd6d„de$ƒZ%Gd7d„de%ƒZ&Gd8d„de%ƒZ'Gd9d:„d:ƒZ(Gd;d„de&ƒZ)GdZ=d?Z>e=e>fd@dA„Z?e=e>fdBdC„Z@dDZAe BeAdd¡ C¡ZDdEd„ZEdFdG„ZFeGdHk�r0eFejHƒdS)Ia$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).éN)ÚrepeatÚ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Ú weekheaderc@seZdZdd„Zdd„ZdS)rcCs ||_dS)N)r )Úselfr ©rú-/opt/alt/python37/lib64/python3.7/calendar.pyÚ__init__szIllegalMonthError.__init__cCs d|jS)Nz!bad month number %r; must be 1-12)r )rrrrÚ__str__szIllegalMonthError.__str__N)Ú__name__Ú __module__Ú __qualname__rrrrrrrsc@seZdZdd„Zdd„ZdS)rcCs ||_dS)N)r )rr rrrr szIllegalWeekdayError.__init__cCs d|jS)Nz7bad weekday number %r; must be 0 (Monday) to 6 (Sunday))r )rrrrr"szIllegalWeekdayError.__str__N)r r!r"rrrrrrrséééééc@sFeZdZdd„edƒDƒZe ddd„¡dd„Zd d „Zd d „Zd S)Ú_localized_monthcCs g|]}t d|dd¡j‘qS)iÑr#)ÚdatetimeÚdateÚstrftime)Ú.0Úirrrú 4sz_localized_month.é rcCsdS)NÚr)ÚxrrrÚ5óz_localized_month.cCs ||_dS)N)Úformat)rr4rrrr7sz_localized_month.__init__cs4ˆj|}t|tƒr&‡fdd„|DƒS|ˆjƒSdS)Ncsg|]}|ˆjƒ‘qSr)r4)r,Úf)rrrr.=sz0_localized_month.__getitem__..)Ú_monthsÚ isinstanceÚslicer4)rr-Úfuncsr)rrÚ __getitem__:s  z_localized_month.__getitem__cCsdS)Né r)rrrrÚ__len__Asz_localized_month.__len__N) r r!r"Úranger6Úinsertrr:r<rrrrr(2s r(c@s6eZdZdd„edƒDƒZdd„Zdd„Zdd „Zd S) Ú_localized_daycCs g|]}t dd|d¡j‘qS)iÑr#)r)r*r+)r,r-rrrr.Hsz_localized_day.écCs ||_dS)N)r4)rr4rrrrJsz_localized_day.__init__cs4ˆj|}t|tƒr&‡fdd„|DƒS|ˆjƒSdS)Ncsg|]}|ˆjƒ‘qSr)r4)r,r5)rrrr.Psz._localized_day.__getitem__..)Ú_daysr7r8r4)rr-r9r)rrr:Ms  z_localized_day.__getitem__cCsdS)Nr@r)rrrrr<Tsz_localized_day.__len__N)r r!r"r=rArr:r<rrrrr?Esr?z%Az%az%Bz%br@cCs$|ddko"|ddkp"|ddkS)z5Return True for leap years, False for non-leap years.érédi�r)ÚyearrrrrdscCs@|d8}|d8}|d|d|d|d|d|dS)zFReturn number of leap years in range [y1, y2). Assume y1 <= y2.r#rBrCi�r)Zy1Zy2rrrriscCs8tj|krtjks&nd|d}t |||¡ ¡S)zBReturn weekday (0-6 ~ Mon-Sun) for year, month (1-12), day (1-31).iÐi�)r)ZMINYEARZMAXYEARr*r )rDr Údayrrrr qs cCsJd|krdksnt|ƒ‚t||dƒ}t||tko>t|ƒ}||fS)zQReturn weekday (0-6 ~ Mon-Sun) and number of days (28-31) for year, month.r#r/)rr ÚmdaysÚFebruaryr)rDr Úday1Úndaysrrrr xs  cCst||tkot|ƒS)N)rFrGr)rDr rrrÚmonthlen‚srJcCs$|dkr|ddfS||dfSdS)Nr#r/r)rDr rrrÚ prevmonth†s rKcCs$|dkr|ddfS||dfSdS)Nr/r#r)rDr rrrÚ nextmonth�s rLc@sšeZdZdZd#dd„Zdd„Zdd„ZeeeƒZd d „Z d d „Z d d„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zd$dd„Zd%dd„Zd&d d!„Zd"S)'rzo Base calendar class. This class doesn't do any formatting. It simply provides data to subclasses. rcCs ||_dS)N)r)rrrrrršszCalendar.__init__cCs |jdS)Nr@)Ú _firstweekday)rrrrÚgetfirstweekday�szCalendar.getfirstweekdaycCs ||_dS)N)rM)rrrrrr szCalendar.setfirstweekdayccs*x$t|j|jdƒD]}|dVqWdS)zt Return an iterator for one week of weekday numbers starting with the configured first one. r@N)r=r)rr-rrrÚ iterweekdays¥szCalendar.iterweekdaysccs0x*| ||¡D]\}}}t |||¡VqWdS)zÔ 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. N)Úitermonthdays3r)r*)rrDr ÚyÚmÚdrrrÚitermonthdates­szCalendar.itermonthdatesccsft||ƒ\}}||jd}td|ƒEdHtd|dƒEdH|j||d}td|ƒEdHdS)z† Like itermonthdates(), but will yield day numbers. For days outside the specified month the day number is 0. r@rNr#)r rrr=)rrDr rHrIÚ days_beforeÚ days_afterrrrÚ itermonthdays¶s zCalendar.itermonthdaysccs4x.t| ||¡|jƒD]\}}||dfVqWdS)zž Like itermonthdates(), but will yield (day number, weekday number) tuples. For days outside the specified month the day number is 0. r@N)Ú enumeraterWr)rrDr r-rSrrrÚitermonthdays2ÂszCalendar.itermonthdays2c csÈt||ƒ\}}||jd}|j||d}t||ƒ\}}t||ƒd} x"t| || ƒD]} ||| fVqZWx"td|dƒD]} ||| fVq~Wt||ƒ\}}x"td|dƒD]} ||| fVq°WdS)z‘ Like itermonthdates(), but will yield (year, month, day) tuples. Can be used for dates outside of datetime.date range. r@r#N)r rrKrJr=rL) rrDr rHrIrUrVrQrRÚendrSrrrrPÊszCalendar.itermonthdays3ccs@x:t| ||¡ƒD]&\}\}}}||||j|dfVqWdS)z� Like itermonthdates(), but will yield (year, month, day, day_of_week) tuples. Can be used for dates outside of datetime.date range. r@N)rXrPr)rrDr r-rQrRrSrrrÚitermonthdays4Üs zCalendar.itermonthdays4cs.t| ||¡ƒ‰‡fdd„tdtˆƒdƒDƒS)z� Return a matrix (list of lists) representing a month's calendar. Each row represents a week; week entries are datetime.date values. csg|]}ˆ||d…‘qS)r@r)r,r-)Údatesrrr.êsz/Calendar.monthdatescalendar..rr@)ÚlistrTr=Úlen)rrDr r)r\rÚmonthdatescalendaräszCalendar.monthdatescalendarcs.t| ||¡ƒ‰‡fdd„tdtˆƒdƒDƒS)zÕ 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. csg|]}ˆ||d…‘qS)r@r)r,r-)Údaysrrr.ôsz/Calendar.monthdays2calendar..rr@)r]rYr=r^)rrDr r)r`rÚmonthdays2calendarìszCalendar.monthdays2calendarcs.t| ||¡ƒ‰‡fdd„tdtˆƒdƒDƒS)zˆ Return a matrix representing a month's calendar. Each row represents a week; days outside this month are zero. csg|]}ˆ||d…‘qS)r@r)r,r-)r`rrr.üsz.Calendar.monthdayscalendar..rr@)r]rWr=r^)rrDr r)r`rÚmonthdayscalendaröszCalendar.monthdayscalendarécs>‡‡fdd„tttdƒDƒ‰‡‡fdd„tdtˆƒˆƒDƒS)a' 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. csg|]}ˆ ˆ|¡‘qSr)r_)r,r-)rrDrrr.sz.Calendar.yeardatescalendar..r/csg|]}ˆ||ˆ…‘qSrr)r,r-)ÚmonthsÚwidthrrr. sr)r=ÚJanuaryr^)rrDrer)rdrrerDrÚyeardatescalendarþs zCalendar.yeardatescalendarcs>‡‡fdd„tttdƒDƒ‰‡‡fdd„tdtˆƒˆƒDƒS)zó 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. csg|]}ˆ ˆ|¡‘qSr)ra)r,r-)rrDrrr.sz.Calendar.yeardays2calendar..r/csg|]}ˆ||ˆ…‘qSrr)r,r-)rdrerrr.sr)r=rfr^)rrDrer)rdrrerDrÚyeardays2calendar s zCalendar.yeardays2calendarcs>‡‡fdd„tttdƒDƒ‰‡‡fdd„tdtˆƒˆƒDƒS)zÓ 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. csg|]}ˆ ˆ|¡‘qSr)rb)r,r-)rrDrrr.sz-Calendar.yeardayscalendar..r/csg|]}ˆ||ˆ…‘qSrr)r,r-)rdrerrr."sr)r=rfr^)rrDrer)rdrrerDrÚyeardayscalendars zCalendar.yeardayscalendarN)r)rc)rc)rc)r r!r"Ú__doc__rrNrÚpropertyrrOrTrWrYrPr[r_rarbrgrhrirrrrr”s"      c@sjeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zdd d„Z ddd„Z ddd„Z d dd„Z d!dd„Z dS)"rzr Subclass of Calendar that outputs a calendar as a simple plain text similar to the UNIX program cal. cCst| ||¡dd�dS)z3 Print a single week (no newline). r0)rZN)ÚprintÚ formatweek)rÚtheweekrerrrÚprweek+szTextCalendar.prweekcCs |dkrd}nd|}| |¡S)z* Returns a formatted day. rr0z%2i)Úcenter)rrEr reÚsrrrÚ formatday1szTextCalendar.formatdaycsd ‡‡fdd„|Dƒ¡S)zA Returns a single week in a string (no newline). ú c3s |]\}}ˆ ||ˆ¡VqdS)N)rr)r,rSÚwd)rrerrú ?sz*TextCalendar.formatweek..)Újoin)rrnrer)rrerrm;szTextCalendar.formatweekcCs(|dkrt}nt}||d|… |¡S)z4 Returns a formatted week day name. é N)rrrp)rrEreÚnamesrrrÚ formatweekdayAszTextCalendar.formatweekdaycsd ‡‡fdd„ˆ ¡Dƒ¡S)z- Return a header for a week. rsc3s|]}ˆ |ˆ¡VqdS)N)ry)r,r-)rrerrruOsz0TextCalendar.formatweekheader..)rvrO)rrer)rrerÚformatweekheaderKszTextCalendar.formatweekheaderTcCs"t|}|rd||f}| |¡S)z0 Return a formatted month name. z%s %r)rrp)rÚtheyearÚthemonthreÚwithyearrqrrrÚformatmonthnameQs zTextCalendar.formatmonthnamercCst| ||||¡dd�dS)z+ Print a month's calendar. r0)rZN)rlÚ formatmonth)rr{r|ÚwÚlrrrr ZszTextCalendar.prmonthcCsštd|ƒ}td|ƒ}| ||d|dd¡}| ¡}|d|7}|| |¡ ¡7}|d|7}x4| ||¡D]$}|| ||¡ ¡7}|d|7}qnW|S)z@ Return a month's calendar string (multi-line). r$r#r@Ú )Úmaxr~Úrstriprzrarm)rr{r|r€r�rqÚweekrrrr`s    zTextCalendar.formatmonthr$r#ércc sÂtd|ƒ}td|ƒ}td|ƒ}|ddd‰g}|j}|tˆƒ ˆ|||d¡ ¡ƒ|d|ƒˆ |¡‰�x@tˆ ˆ|¡ƒD�]*\}} t||dt ||dddƒƒ} |d|ƒ‡‡‡fdd„| Dƒ} |t | ˆ|ƒ ¡ƒ|d|ƒ‡fdd„| Dƒ} |t | ˆ|ƒ ¡ƒ|d|ƒtd d„| Dƒƒ} xvt| ƒD]j}g}x>| D]6}|t |ƒk�rr| d ¡n| ˆ  |||¡¡�qTW|t |ˆ|ƒ ¡ƒ|d|ƒ�qFWqˆWd   |¡S) zC Returns a year's calendar as a multi-line string. r$r#r@r‚r;c3s|]}ˆ ˆ|ˆd¡VqdS)FN)r~)r,Úk)Úcolwidthrr{rrru�sz*TextCalendar.formatyear..c3s|] }ˆVqdS)Nr)r,r‡)Úheaderrrru…scss|]}t|ƒVqdS)N)r^)r,Úcalrrrru‰sr0)rƒÚappendÚreprrpr„rzrXrhr=ÚminÚ formatstringr^rmrv)rr{r€r�ÚcrRÚvÚar-ÚrowrdrxZheadersZheightÚjZweeksrŠr)rˆr‰rr{rÚ formatyearps:   &  $     zTextCalendar.formatyearcCst| |||||¡dd�dS)zPrint a year's calendar.r0)rZN)rlr”)rr{r€r�r�rRrrrÚpryear•szTextCalendar.pryearN)T)rr)rr)r$r#r†rc)rrr†rc)r r!r"rjrorrrmryrzr~r rr”r•rrrrr%s     %c@s‚eZdZdZdddddddgZeZd Zd Zd Zd Z d Z d d „Z dd„Z dd„Z dd„Zd dd„Zd!dd„Zd"dd„Zd#dd„ZdS)$rz4 This calendar returns complete HTML pages. ZmonZtueZwedZthuZfriZsatZsunZnodayr rDcCs(|dkrd|jSd|j||fSdS)z/ Return a day as a table cell. rz z%dN)Úcssclass_nodayÚ cssclasses)rrEr rrrrr´s zHTMLCalendar.formatdaycs d ‡fdd„|Dƒ¡}d|S)z8 Return a complete week as a table row. r0c3s|]\}}ˆ ||¡VqdS)N)rr)r,rSrt)rrrruÂsz*HTMLCalendar.formatweek..z %s)rv)rrnrqr)rrrm¾szHTMLCalendar.formatweekcCsd|j|t|fS)z: Return a weekday name as a table header. z%s)Úcssclasses_weekday_headr)rrErrrryÅszHTMLCalendar.formatweekdaycs$d ‡fdd„ˆ ¡Dƒ¡}d|S)z< Return a header for a week as a table row. r0c3s|]}ˆ |¡VqdS)N)ry)r,r-)rrrruÐsz0HTMLCalendar.formatweekheader..z %s)rvrO)rrqr)rrrzÌszHTMLCalendar.formatweekheaderTcCs0|rdt||f}n dt|}d|j|fS)z5 Return a month name as a table row. z%s %sz%sz+%s)rÚcssclass_month_head)rr{r|r}rqrrrr~Ós  zHTMLCalendar.formatmonthnamecCs–g}|j}|d|jƒ|dƒ||j|||d�ƒ|dƒ|| ¡ƒ|dƒx*| ||¡D]}|| |¡ƒ|dƒq^W|dƒ|dƒd |¡S)z6 Return a formatted month as a table. z=r‚)r}z
r0)r‹Úcssclass_monthr~rzrarmrv)rr{r|r}r�r‘r…rrrrÞs   zHTMLCalendar.formatmonthrccCsÀg}|j}t|dƒ}|d|jƒ|dƒ|d||j|fƒxntttd|ƒD]Z}t|t||dƒƒ}|dƒx0|D](}|dƒ||j||d d �ƒ|d ƒqvW|d ƒqPW|d ƒd |¡S)z? Return a formatted year as a table of tables. r#z=r‚z,r/r;zzzz
%s
F)r}z
r0) r‹rƒÚ cssclass_yearÚcssclass_year_headr=rfr�rrv)rr{rer�r‘r-rdrRrrrr”òs$     zHTMLCalendar.formatyearú calendar.cssNcCs¬|dkrt ¡}g}|j}|d|ƒ|dƒ|dƒ|dƒ|d|ƒ|dk r^|d|ƒ|d|ƒ|d ƒ|d ƒ|| ||¡ƒ|d ƒ|d ƒd  |¡ |d¡S)zB Return a formatted year as a complete HTML page. Nz$ zn z z zC z4 zCalendar for %d z z z z r0Úxmlcharrefreplace)ÚsysÚgetdefaultencodingr‹r”rvÚencode)rr{reÚcssÚencodingr�r‘rrrÚformatyearpage s$    zHTMLCalendar.formatyearpage)T)T)rc)rcr�N)r r!r"rjr—r˜r–r™ršrœr›rrrmryrzr~rr”r¤rrrrršs    c@s$eZdZdd„Zdd„Zdd„ZdS)Údifferent_localecCs ||_dS)N)Úlocale)rr¦rrrr#szdifferent_locale.__init__cCs"t tj¡|_t tj|j¡dS)N)Ú_localeZ getlocaleÚLC_TIMEÚ oldlocaleÚ setlocaler¦)rrrrÚ __enter__&szdifferent_locale.__enter__cGst tj|j¡dS)N)r§rªr¨r©)rÚargsrrrÚ__exit__*szdifferent_locale.__exit__N)r r!r"rr«r­rrrrr¥"sr¥c@s,eZdZdZd dd„Zdd„Zd d d „ZdS) ra 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. rNcCs&t ||¡|dkrt ¡}||_dS)N)rrr§Úgetdefaultlocaler¦)rrr¦rrrr6s zLocaleTextCalendar.__init__c CsBt|jƒ�.|dkrt}nt}||}|d|… |¡SQRXdS)Nrw)r¥r¦rrrp)rrErerxÚnamerrrry<s  z LocaleTextCalendar.formatweekdayTc Cs8t|jƒ�$t|}|r$d||f}| |¡SQRXdS)Nz%s %r)r¥r¦rrp)rr{r|rer}rqrrrr~Es   z"LocaleTextCalendar.formatmonthname)rN)T)r r!r"rjrryr~rrrrr.s  c@s,eZdZdZd dd„Zdd„Zd d d „ZdS) ra 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. rNcCs&t ||¡|dkrt ¡}||_dS)N)rrr§r®r¦)rrr¦rrrrTs zLocaleHTMLCalendar.__init__c Cs0t|jƒ�t|}d|j||fSQRXdS)Nz%s)r¥r¦rr—)rrErqrrrryZs z LocaleHTMLCalendar.formatweekdayTc Cs6t|jƒ�"t|}|r$d||f}d|SQRXdS)Nz%s %sz.%s)r¥r¦r)rr{r|r}rqrrrr~_s   z"LocaleHTMLCalendar.formatmonthname)rN)T)r r!r"rjrryr~rrrrrMs cCs(t|krtksnt|ƒ‚|t_dS)N)ÚMONDAYÚSUNDAYrr�r)rrrrrlsér†cCstt|||ƒƒdS)z1Prints multi-column formatting for year calendarsN)rlrŽ)ÚcolsrˆÚspacingrrrr4€sr4cs |d9}| ‡fdd„|Dƒ¡S)zEReturns a string formatted from n strings, centered within n columns.rsc3s|]}| ˆ¡VqdS)N)rp)r,r�)rˆrrruˆszformatstring..)rv)r³rˆr´r)rˆrrŽ…srŽi²c Cs^|dd…\}}}}}}t ||d¡ ¡t|d}|d|}|d|} | d|} | S)zBUnrelated but handy function to calculate Unix timestamp from GMT.Nr†r#éé<)r)r*Ú toordinalÚ _EPOCH_ORD) ÚtuplerDr rEZhourZminuteÚsecondr`ZhoursZminutesZsecondsrrrr�s    c Cs¬ddl}| ¡}| d¡}| d¡}|jddtddd�|jd d td d d�|jd dtddd�|jddtddd�|jddddd�|jddddd�|jddddd�|jd d!d"d#d$d%�|jd&d'td(d)�|jd*d'td+d)�| |d d…¡}|j�r|j�s| d,¡t   d ¡|j|jf}|j d-k�rÚ|j�rDt |d.�}nt ƒ}|j}|dk�rbt  ¡}t||jd/�} t jjj} |jdk�r¢| |jtj ¡jf| Žƒn6|jdk�rÄ| |j|jf| Žƒn| d0¡t   d ¡nÎ|j�rît|d.�}ntƒ}t|j|jd1�} |jdk�r$|j| d2<|j| d3<|jdk�rH|j tj ¡jf| Ž} n2|jdk�rf|j |jf| Ž} n|j!|j|jf| Ž} t jj} |j�r |  "|j¡} t jjj} | | ƒdS)4Nrztext only argumentszhtml only argumentsz-wz--widthr$z width of date column (default 2))ÚtypeÚdefaultÚhelpz-lz--linesr#z)number of lines for each week (default 1)z-sz --spacingr†z"spacing between months (default 6)z-mz--monthsrczmonths per row (default 3)z-cz--cssz calendar.csszCSS to use for page)r¼r½z-Lz--localez.locale to be used from month and weekday namesz-ez --encodingzencoding to use for outputz-tz--typeÚtext)r¾Úhtmlzoutput type (text or html))r¼Úchoicesr½rDú?zyear number (1-9999))Únargsr»r½r zmonth number (1-12, text only)z/if --locale is specified --encoding is requiredr¿)r¦)r£r¢zincorrect number of arguments)r€r�r�rR)#ÚargparseÚArgumentParserZadd_argument_groupÚ add_argumentÚintÚ parse_argsr¦r£ÚerrorrŸÚexitr»rrr Údictr¢ÚstdoutÚbufferÚwriterDr¤r)r*Ztodayr rrreÚlinesr´rdr”rr¡) r¬rÃÚparserZ textgroupZ htmlgroupZoptionsr¦rŠr£ZoptdictrÍÚresultrrrÚmain™s¤                     rÑÚ__main__)IrjrŸr)r¦r§Ú itertoolsrÚ__all__Ú ValueErrorrÈrrrfrGrFr(r?rrrrr=r°ZTUESDAYZ WEDNESDAYZTHURSDAYZFRIDAYZSATURDAYr±rrr r rJrKrLÚobjectrrrr¥rrr�rNrrrbr rormr…rzrr rr r”rr•rZ _colwidthZ_spacingr4rŽZEPOCHr*r·r¸rrÑr ÚargvrrrrÚsv     u   h