grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026o ®û|jÿ_ã@sôdZddlZddlZddlZddlmZgd¢ZeZ Gdd„deƒZ Gdd„deƒZ d Z d Z gd ¢ZGd d „d ƒZGdd„dƒZedƒZedƒZedƒZedƒZedƒ\ZZZZZZZdd„Zdd„Zdd„Zdd„Z dd„Z!dd „Z"d!d"„Z#Gd#d$„d$e$ƒZ%Gd%d&„d&e%ƒZ&Gd'd(„d(e%ƒZ'Gd)d*„d*ƒZ(Gd+d,„d,e&ƒZ)Gd-d.„d.e'ƒZ*e&ƒZ+e+j,Z-d/d0„Z.e+j/Z0e+j1Z1e+j2Z3e+j4Z5e+j6Z6e+j7Z8e+j9Z:e+j;Ze=e>fd3d4„Z?e=e>fd5d6„Z@d7ZAe BeAd d ¡ C¡ZDd8d9„ZEd:d;„ZFeGd6ó z_localized_month.é rcCódS)NÚr')Úxr'r'r(Ú7sz_localized_month.cCr#r$©Úformat©r&rJr'r'r(r)9r*z_localized_month.__init__có0ˆj|}t|tƒr‡fdd„|DƒS|ˆjƒS)Ncóg|]}|ˆjƒ‘qSr'rI©r@Úfr,r'r(rB?óz0_localized_month.__getitem__..)Ú_monthsÚ isinstanceÚslicerJ©r&rAZfuncsr'r,r(Ú __getitem__<ó   z_localized_month.__getitem__cCrE)Né r'r,r'r'r(Ú__len__Cóz_localized_month.__len__N) r/r0r1ÚrangerQÚinsertr)rUrXr'r'r'r(r94s  r9c@s6eZdZdd„edƒDƒZdd„Zdd„Zdd „Zd S) Ú_localized_daycCs g|] }t dd|d¡j‘qSr:r;r?r'r'r(rBJrCz_localized_day.écCr#r$rIrKr'r'r(r)Lr*z_localized_day.__init__crL)NcrMr'rIrNr,r'r(rBRrPz._localized_day.__getitem__..)Ú_daysrRrSrJrTr'r,r(rUOrVz_localized_day.__getitem__cCrE©Nr]r'r,r'r'r(rXVrYz_localized_day.__len__N)r/r0r1rZr^r)rUrXr'r'r'r(r\Gs  r\z%Az%az%Bz%br]cCs$|ddko|ddkp|ddkS)z5Return True for leap years, False for non-leap years.érédé�r')Úyearr'r'r(rfs$rcCs@|d8}|d8}|d|d|d|d|d|dS)zFReturn number of leap years in range [y1, y2). Assume y1 <= y2.r4r`rarbr')Zy1Zy2r'r'r(rks0rcCs8tj|kr tjksnd|d}t |||¡ ¡S)zBReturn weekday (0-6 ~ Mon-Sun) for year, month (1-12), day (1-31).iÐrb)r<ZMINYEARZMAXYEARr=r )rcr Údayr'r'r(r ss r cCsPd|kr dkst|ƒ‚t|ƒ‚t||dƒ}t||tko"t|ƒ}||fS)zQReturn weekday (0-6 ~ Mon-Sun) and number of days (28-31) for year, month.r4rD)rr ÚmdaysÚFebruaryr)rcr Úday1Úndaysr'r'r(r zsÿ r cCst||tko t|ƒSr$)rerfr©rcr r'r'r(Ú _monthlen„srjcCs |dkr |ddfS||dfS)Nr4rDr'rir'r'r(Ú _prevmonthˆó  rkcCs |dkr |ddfS||dfS)NrDr4r'rir'r'r(Ú _nextmonth�rlrmc@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. rcCr#r$©r©r&rr'r'r(r)œr*zCalendar.__init__cCs |jdSr_©Z _firstweekdayr,r'r'r(ÚgetfirstweekdayŸr*zCalendar.getfirstweekdaycCr#r$rpror'r'r(r¢r*zCalendar.setfirstweekdayccs(�t|j|jdƒD]}|dVq dS)zt Return an iterator for one week of weekday numbers starting with the configured first one. r]N)rZr)r&rAr'r'r(Ú iterweekdays§s€ ÿzCalendar.iterweekdaysccs.�| ||¡D] \}}}t |||¡VqdS)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=)r&rcr ÚyÚmÚdr'r'r(Úitermonthdates¯s€ÿzCalendar.itermonthdatesccsh�t||ƒ\}}||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]rNr4)r rrrZ)r&rcr rgrhÚ days_beforeÚ days_afterr'r'r(Ú itermonthdays¸s€zCalendar.itermonthdaysccs2�t| ||¡|jƒD] \}}||dfVq dS)zž Like itermonthdates(), but will yield (day number, weekday number) tuples. For days outside the specified month the day number is 0. r]N)Ú enumeraterzr)r&rcr rArvr'r'r(Úitermonthdays2Äs€ÿzCalendar.itermonthdays2c cs¾�t||ƒ\}}||jd}|j||d}t||ƒ\}}t||ƒd} t| || ƒD]} ||| fVq-td|dƒD]} ||| fVq=t||ƒ\}}td|dƒD]} ||| fVqTdS)z‘ Like itermonthdates(), but will yield (year, month, day) tuples. Can be used for dates outside of datetime.date range. r]r4N)r rrkrjrZrm) r&rcr rgrhrxryrtruÚendrvr'r'r(rsÌs€ÿzCalendar.itermonthdays3ccs>�t| ||¡ƒD]\}\}}}||||j|dfVq dS)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)r{rsr)r&rcr rArtrurvr'r'r(Úitermonthdays4Þs€ÿzCalendar.itermonthdays4có.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. cóg|] }ˆ||d…‘qS©r]r'r?©Zdatesr'r(rBìóz/Calendar.monthdatescalendar..rr])ÚlistrwrZÚlen©r&rcr r'r‚r(ÚmonthdatescalendaræózCalendar.monthdatescalendarcr)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. cr€r�r'r?©Údaysr'r(rBörƒz/Calendar.monthdays2calendar..rr])r„r|rZr…r†r'r‰r(Úmonthdays2calendarîszCalendar.monthdays2calendarcr)zˆ Return a matrix representing a month's calendar. Each row represents a week; days outside this month are zero. cr€r�r'r?r‰r'r(rBþrƒz.Calendar.monthdayscalendar..rr])r„rzrZr…r†r'r‰r(ÚmonthdayscalendarørˆzCalendar.monthdayscalendarécó>‡‡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. cóg|]}ˆ ˆ|¡‘qSr')r‡r?©r&rcr'r(rBó ÿÿz.Calendar.yeardatescalendar..rDcóg|] }ˆ||ˆ…‘qSr'r'r?©ÚmonthsÚwidthr'r(rB rƒr©rZÚJanuaryr…©r&rcr•r'©r”r&r•rcr(Úyeardatescalendaró  þ zCalendar.yeardatescalendarcrŽ)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. cr�r')r‹r?r�r'r(rBr‘z.Calendar.yeardays2calendar..rDcr’r'r'r?r“r'r(rBrƒrr–r˜r'r™r(Úyeardays2calendar r›zCalendar.yeardays2calendarcrŽ)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. cr�r')rŒr?r�r'r(rB r‘z-Calendar.yeardayscalendar..rDcr’r'r'r?r“r'r(rB$rƒrr–r˜r'r™r(Úyeardayscalendars  þ zCalendar.yeardayscalendarN)r©r�)r/r0r1Ú__doc__r)rqrÚpropertyrrrrwrzr|rsr~r‡r‹rŒršrœr�r'r'r'r(r–s$       rc@sjeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zdd d„Z ddd„Z ddd„Z ddd„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). rF©r}N)ÚprintÚ formatweek©r&Útheweekr•r'r'r(Úprweek-szTextCalendar.prweekcCs |dkrd}nd|}| |¡S)z* Returns a formatted day. rrFz%2i©Úcenter)r&rdr r•Úsr'r'r(Ú formatday3s zTextCalendar.formatdaycsd ‡‡fdd„|Dƒ¡S)zA Returns a single week in a string (no newline). ú c3s"�|] \}}ˆ ||ˆ¡VqdSr$©rª©r@rvZwd©r&r•r'r(Ú As€ z*TextCalendar.formatweek..©Újoinr¤r'r®r(r£=szTextCalendar.formatweekcCs(|dkrt}nt}||d|… |¡S)z4 Returns a formatted week day name. é N)rrr¨)r&rdr•Únamesr'r'r(Ú formatweekdayCszTextCalendar.formatweekdaycsd ‡‡fdd„ˆ ¡Dƒ¡S)z- Return a header for a week. r«c3s�|] }ˆ |ˆ¡VqdSr$©r´r?r®r'r(r¯Qs€z0TextCalendar.formatweekheader..©r±rrr®r'r®r(ÚformatweekheaderMszTextCalendar.formatweekheaderTcCs"t|}|r d||f}| |¡S)z0 Return a formatted month name. z%s %r)rr¨)r&ÚtheyearÚthemonthr•Úwithyearr©r'r'r(ÚformatmonthnameSs  zTextCalendar.formatmonthnamercCst| ||||¡dd�dS)z+ Print a month's calendar. rFr¡N)r¢Ú formatmonth)r&r¸r¹ÚwÚlr'r'r(r \szTextCalendar.prmonthcCs–td|ƒ}td|ƒ}| ||d|dd¡}| ¡}|d|7}|| |¡ ¡7}|d|7}| ||¡D]}|| ||¡ ¡7}|d|7}q6|S)z@ Return a month's calendar string (multi-line). r5r4r]Ú )Úmaxr»Úrstripr·r‹r£)r&r¸r¹r½r¾r©Úweekr'r'r(r¼bs    zTextCalendar.formatmonthr5r4ér�c s¬td|ƒ}td|ƒ}td|ƒ}|ddd‰g}|j}|tˆƒ ˆ|||d¡ ¡ƒ|d|ƒˆ |¡‰tˆ ˆ|¡ƒD]Ž\}} t||dt ||dddƒƒ} |d|ƒ‡‡‡fdd„| Dƒ} |t | ˆ|ƒ ¡ƒ|d|ƒ‡fdd„| Dƒ} |t | ˆ|ƒ ¡ƒ|d|ƒtd d„| Dƒƒ} t| ƒD]0}g}| D]}|t |ƒkr³| d ¡q¥| ˆ  |||¡¡q¥|t |ˆ|ƒ ¡ƒ|d|ƒqŸqBd   |¡S) zC Returns a year's calendar as a multi-line string. r5r4r]r¿rWc3s �|] }ˆ ˆ|ˆd¡VqdS)FN)r»©r@Úk)Úcolwidthr&r¸r'r(r¯ƒs€ÿz*TextCalendar.formatyear..c3s�|]}ˆVqdSr$r'rÄ)Úheaderr'r(r¯‡s€css�|]}t|ƒVqdSr$)r…)r@Úcalr'r'r(r¯‹s€rF)rÀÚappendÚreprr¨rÁr·r{rœrZÚminÚ formatstringr…r£r±)r&r¸r½r¾ÚcruÚvÚarAÚrowr”r³ZheadersZheightÚjZweeksrÈr')rÆrÇr&r¸r(Ú formatyearrs>   &  $ ÿ     ø zTextCalendar.formatyearcCst| |||||¡dd�dS)zPrint a year's calendar.rFr¡N)r¢rÒ)r&r¸r½r¾rÍrur'r'r(Úpryear—szTextCalendar.pryearN©T)rr)r5r4rÃr�)rrrÃr�)r/r0r1rŸr¦rªr£r´r·r»r r¼rÒrÓr'r'r'r(r's    %rc@sxeZdZdZgd¢ZeZdZdZdZdZ dZ dd„Z dd „Z d d „Z d d „Zddd„Zddd„Zddd„Zddd„ZdS)rz4 This calendar returns complete HTML pages. )ZmonZtueZwedZthuZfriZsatZsunZnodayr rccCs$|dkr d|jSd|j||fS)z/ Return a day as a table cell. rz z%d)Úcssclass_nodayÚ cssclasses)r&rdr r'r'r(rª¶s zHTMLCalendar.formatdaycs d ‡fdd„|Dƒ¡}d|S)z8 Return a complete week as a table row. rFc3s �|] \}}ˆ ||¡VqdSr$r¬r­r,r'r(r¯Äs€z*HTMLCalendar.formatweek..ú %sr°)r&r¥r©r'r,r(r£ÀszHTMLCalendar.formatweekcCsd|j|t|fS)z: Return a weekday name as a table header. z%s)Úcssclasses_weekday_headr©r&rdr'r'r(r´ÇsÿzHTMLCalendar.formatweekdaycs$d ‡fdd„ˆ ¡Dƒ¡}d|S)z< Return a header for a week as a table row. rFc3s�|]}ˆ |¡VqdSr$rµr?r,r'r(r¯Òó€z0HTMLCalendar.formatweekheader..r×r¶)r&r©r'r,r(r·ÎszHTMLCalendar.formatweekheaderTcCs0|r dt||f}ndt|}d|j|fS)z5 Return a month name as a table row. z%s %sz%sz+%s)rÚcssclass_month_head)r&r¸r¹rºr©r'r'r(r»Õs  ÿzHTMLCalendar.formatmonthnamecCs’g}|j}|d|jƒ|dƒ||j|||d�ƒ|dƒ|| ¡ƒ|dƒ| ||¡D] }|| |¡ƒ|dƒq.|dƒ|dƒd |¡S)z6 Return a formatted month as a table. ú=r¿©rºú
rF)rÉÚcssclass_monthr»r·r‹r£r±)r&r¸r¹rºrÎrÏrÂr'r'r(r¼às ÿ   zHTMLCalendar.formatmonthr�cCs¸g}|j}t|dƒ}|d|jƒ|dƒ|d||j|fƒtttd|ƒD]+}t|t||dƒƒ}|dƒ|D]}|dƒ||j||d d �ƒ|d ƒq9|d ƒq'|d ƒd |¡S)z? Return a formatted year as a table of tables. r4rÜr¿z,%srDrWzzFrÝzzrÞrF) rÉrÀÚ cssclass_yearÚcssclass_year_headrZr—rËr¼r±)r&r¸r•rÎrÏrAr”rur'r'r(rÒôs( ÿÿ   zHTMLCalendar.formatyearú calendar.cssNcCs¬|durt ¡}g}|j}|d|ƒ|dƒ|dƒ|dƒ|d|ƒ|dur/|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 rFÚxmlcharrefreplace)ÚsysÚgetdefaultencodingrÉrÒr±Úencode)r&r¸r•ÚcssÚencodingrÎrÏr'r'r(Úformatyearpage s$    zHTMLCalendar.formatyearpagerÔrž)r�râN)r/r0r1rŸrÖrØrÕrÛrßráràrªr£r´r·r»r¼rÒrér'r'r'r(rœs"   rc@s$eZdZdd„Zdd„Zdd„ZdS)Údifferent_localecCr#r$©Úlocale)r&rìr'r'r(r)%r*zdifferent_locale.__init__cCs"t tj¡|_t tj|j¡dSr$)Ú_localeZ getlocaleÚLC_TIMEÚ oldlocaleÚ setlocalerìr,r'r'r(Ú __enter__(szdifferent_locale.__enter__cGst tj|j¡dSr$)rírðrîrï)r&Úargsr'r'r(Ú__exit__,szdifferent_locale.__exit__N)r/r0r1r)rñrór'r'r'r(rê$s rêcó8eZdZdZd dd„Z‡fdd„Zd ‡fd d „ Z‡ZS) rá 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. rNcCó&t ||¡|durt ¡}||_dSr$)rr)ríÚgetdefaultlocalerì©r&rrìr'r'r(r)8ó  zLocaleTextCalendar.__init__cs<t|jƒ�tƒ ||¡WdƒS1swYdSr$©rêrìÚsuperr´)r&rdr•©Ú __class__r'r(r´>s  $ÿz LocaleTextCalendar.formatweekdayTcs@t|jƒ�tƒ ||||¡WdƒS1swYdSr$©rêrìrûr»)r&r¸r¹r•rºrür'r(r»Bs $ÿz"LocaleTextCalendar.formatmonthname©rNrÔ©r/r0r1rŸr)r´r»Ú __classcell__r'r'rür(r0s   rcrô) rrõrNcCrör$)rr)rír÷rìrør'r'r(r)NrùzLocaleHTMLCalendar.__init__cs:t|jƒ�tƒ |¡WdƒS1swYdSr$rúrÙrür'r(r´Ts  $ÿz LocaleHTMLCalendar.formatweekdayTcs>t|jƒ�tƒ |||¡WdƒS1swYdSr$rþ)r&r¸r¹rºrür'r(r»Xs $ÿz"LocaleHTMLCalendar.formatmonthnamerÿrÔrr'r'rür(rGs   rcCs.t|kr tkst|ƒ‚t|ƒ‚|t_dSr$)rr!rrÍrrnr'r'r(ras ÿ rérÃcCstt|||ƒƒdS)z1Prints multi-column formatting for year calendarsN)r¢rÌ©ZcolsrÆÚspacingr'r'r(rJusrJcs |d9}| ‡fdd„|Dƒ¡S)zEReturns a string formatted from n strings, centered within n columns.r«c3s�|]}| ˆ¡VqdSr$r§)r@rÍ©rÆr'r(r¯}rÚzformatstring..r°rr'rr(rÌzsrÌi²c Cs^|dd…\}}}}}}t ||d¡ ¡t|d}|d|}|d|} | d|} | S)zBUnrelated but handy function to calculate Unix timestamp from GMT.NrÃr4éé<)r<r=Ú toordinalÚ _EPOCH_ORD) Útuplercr rdZhourZminuteÚsecondrŠZhoursZminutesZsecondsr'r'r(r„s    rc 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…¡}|jrŠ|jsŠ| d,¡t   d ¡|j|jf}|j d-krí|jržt |d.�}nt ƒ}|j}|dur¬t  ¡}t||jd/�} t jjj} |jdurÎ| |jtj ¡jfi| ¤ŽƒdS|jdurá| |j|jfi| ¤ŽƒdS| d0¡t   d ¡dS|jröt|d.�}ntƒ}t|j|jd1�} |jdu�r|j| d2<|j| d3<|jdu�r%|j tj ¡jfi| ¤Ž} n|jdu�r6|j |jfi| ¤Ž} n |j!|j|jfi| ¤Ž} t jj} |j�rU|  "|j¡} t jjj} | | ƒdS)4Nrztext only argumentszhtml only argumentsz-wz--widthr5z width of date column (default 2))ÚtypeÚdefaultÚhelpz-lz--linesr4z)number of lines for each week (default 1)z-sz --spacingrÃz"spacing between months (default 6)z-mz--monthsr�zmonths per row (default 3)z-cz--cssrâzCSS to use for page)r rz-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 Úchoicesrrcú?zyear number (1-9999))Únargsr rr zmonth number (1-12, text only)z/if --locale is specified --encoding is requiredrrë)rèrçzincorrect number of arguments)r½r¾rÍru)#ÚargparseÚArgumentParserZadd_argument_groupÚ add_argumentÚintÚ parse_argsrìrèÚerrorräÚexitr rrråÚdictrçÚstdoutÚbufferÚwritercrér<r=Ztodayr rrr•Úlinesrr”rÒr¼ræ) ròrÚparserZ textgroupZ htmlgroupZoptionsrìrÈrèZoptdictrÚresultr'r'r(ÚmainŽs¸  ýýýýýýýüýý        "           r"Ú__main__)IrŸrär<rìríÚ itertoolsrÚ__all__Ú ValueErrorrrrr—rfrer9r\rrrrrZrrrrrr r!rrr r rjrkrmÚobjectrrrrêrrrÍrqrrrŒr r¦r£rÂr·rr r¼r rÒrrÓrZ _colwidthZ_spacingrJrÌZEPOCHr=rr rr"r/Úargvr'r'r'r(Úsp   u   hÿ